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;
165 //FNetForceWeap: Byte; // spam server with this -- this is new weapon we want to use
166 FNetForceWeapFIdx
: LongWord; // frame index; ignore weapon change if it is lesser than this
167 //FCurrFrameIdx: LongWord; // increased in each `Update()`
169 FNextWeapDelay
: Byte; // frames (unused)
170 FBFGFireCounter
: SmallInt;
171 FLastSpawnerUID
: Word;
175 FSpectatePlayer
: Integer;
176 FFirePainTime
: Integer;
179 FSavedState
: TPlayerSavedState
;
181 FModel
: TPlayerModel
;
182 FPunchAnim
: TAnimation
;
185 FActionForce
: Boolean;
186 FActionChanged
: Boolean;
188 FFireAngle
: SmallInt;
190 FShellTimer
: Integer;
192 FSawSound
: TPlayableSound
;
193 FSawSoundIdle
: TPlayableSound
;
194 FSawSoundHit
: TPlayableSound
;
195 FSawSoundSelect
: TPlayableSound
;
196 FJetSoundOn
: TPlayableSound
;
197 FJetSoundOff
: TPlayableSound
;
198 FJetSoundFly
: TPlayableSound
;
202 FJustTeleported
: Boolean;
204 mEDamageType
: Integer;
207 weaponSwitchKeyReleased
: array[0..16] of Byte; // bit 0: was released on prev frame; bit 1: new status
210 function CollideLevel(XInc
, YInc
: Integer): Boolean;
211 function StayOnStep(XInc
, YInc
: Integer): Boolean;
212 function HeadInLiquid(XInc
, YInc
: Integer): Boolean;
213 function BodyInLiquid(XInc
, YInc
: Integer): Boolean;
214 function BodyInAcid(XInc
, YInc
: Integer): Boolean;
215 function FullInLift(XInc
, YInc
: Integer): Integer;
216 {procedure CollideItem();}
217 procedure FlySmoke(Times
: DWORD
= 1);
218 procedure OnFireFlame(Times
: DWORD
= 1);
219 function GetAmmoByWeapon(Weapon
: Byte): Word;
220 procedure SetAction(Action
: Byte; Force
: Boolean = False);
221 procedure OnDamage(Angle
: SmallInt); virtual;
222 function firediry(): Integer;
225 procedure Run(Direction
: TDirection
);
226 procedure NextWeapon();
227 procedure PrevWeapon();
234 function getNextWeaponIndex (): Byte; // return 255 for "no switch"
235 procedure resetWeaponQueue ();
236 function hasAmmoForWeapon (weapon
: Byte): Boolean;
238 procedure doDamage (v
: Integer);
240 function followCorpse(): Boolean;
243 FDamageBuffer
: Integer;
245 FAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
246 FMaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
247 FWeapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
248 FRulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
250 FMegaRulez
: Array [MR_SUIT
..MR_MAX
] of DWORD
;
251 FReloading
: Array [WP_FIRST
..WP_LAST
] of Word;
252 FTime
: Array [T_RESPAWN
..T_FLAGCAP
] of DWORD
;
253 FKeys
: Array [KEY_LEFT
..KEY_CHAT
] of TKeyState
;
255 FPreferredTeam
: Byte;
258 FWantsInGame
: Boolean;
262 FActualModelName
: string;
269 // debug: viewport offset
270 viewPortX
, viewPortY
, viewPortW
, viewPortH
: Integer;
272 function isValidViewPort (): Boolean; inline;
274 constructor Create(); virtual;
275 destructor Destroy(); override;
276 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); virtual;
277 function GetRespawnPoint(): Byte;
278 procedure PressKey(Key
: Byte; Time
: Word = 1);
279 procedure ReleaseKeys();
280 procedure ReleaseKeysNoWeapon();
281 procedure SetModel(ModelName
: String);
282 procedure SetColor(Color
: TRGB
);
283 procedure SetWeapon(W
: Byte);
284 function IsKeyPressed(K
: Byte): Boolean;
285 function GetKeys(): Byte;
286 function PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean; virtual;
287 function Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean; overload
;
288 function Collide(Panel
: TPanel
): Boolean; overload
;
289 function Collide(X
, Y
: Integer): Boolean; overload
;
290 procedure SetDirection(Direction
: TDirection
);
291 procedure GetSecret();
292 function TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
294 procedure Push(vx
, vy
: Integer);
295 procedure ChangeModel(ModelName
: String);
296 procedure SwitchTeam
;
297 procedure ChangeTeam(Team
: Byte);
299 function GetFlag(Flag
: Byte): Boolean;
300 procedure SetFlag(Flag
: Byte);
301 function DropFlag(): Boolean;
302 procedure AllRulez(Health
: Boolean);
303 procedure RestoreHealthArmor();
304 procedure FragCombo();
305 procedure GiveItem(ItemType
: Byte);
306 procedure Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte); virtual;
307 function Heal(value
: Word; Soft
: Boolean): Boolean; virtual;
308 procedure MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
309 procedure MakeBloodSimple(Count
: Word);
310 procedure Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
311 procedure Reset(Force
: Boolean);
312 procedure Spectate(NoMove
: Boolean = False);
313 procedure SwitchNoClip
;
314 procedure SoftReset();
315 procedure Draw(); virtual;
316 procedure DrawPain();
317 procedure DrawPickup();
318 procedure DrawRulez();
320 procedure DrawBubble();
322 procedure Update(); virtual;
323 procedure RememberState();
324 procedure RecallState();
325 procedure SaveState (st
: TStream
); virtual;
326 procedure LoadState (st
: TStream
); virtual;
327 procedure PauseSounds(Enable
: Boolean);
328 procedure NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
329 procedure DoLerp(Level
: Integer = 2);
330 procedure SetLerp(XTo
, YTo
: Integer);
331 procedure QueueWeaponSwitch(Weapon
: Byte);
332 procedure RealizeCurrentWeapon();
334 procedure JetpackOff
;
335 procedure CatchFire(Attacker
: Word);
337 //WARNING! this does nothing for now, but still call it!
338 procedure positionChanged (); //WARNING! call this after entity position was changed, or coldet will not work right!
340 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
341 procedure moveBy (dx
, dy
: Integer); inline;
343 procedure releaseAllWeaponSwitchKeys ();
344 procedure weaponSwitchKeysStateChange (index
: Integer; pressed
: Boolean);
345 function isWeaponSwitchKeyReleased (index
: Integer): Boolean;
346 procedure weaponSwitchKeysShiftNewStates ();
349 property Vel
: TPoint2i read FObj
.Vel
;
350 property Obj
: TObj read FObj
;
352 property Name
: String read FName write FName
;
353 property Model
: TPlayerModel read FModel
;
354 property Health
: Integer read FHealth write FHealth
;
355 property Lives
: Byte read FLives write FLives
;
356 property Armor
: Integer read FArmor write FArmor
;
357 property Air
: Integer read FAir write FAir
;
358 property JetFuel
: Integer read FJetFuel write FJetFuel
;
359 property Frags
: Integer read FFrags write FFrags
;
360 property Death
: Integer read FDeath write FDeath
;
361 property Kills
: Integer read FKills write FKills
;
362 property CurrWeap
: Byte read FCurrWeap write FCurrWeap
;
363 //property NetForceWeap: Byte read FNetForceWeap write FNetForceWeap;
364 property NetForceWeapFIdx
: LongWord read FNetForceWeapFIdx write FNetForceWeapFIdx
;
365 //property CurrFrameIdx: LongWord read FCurrFrameIdx write FCurrFrameIdx;
366 property MonsterKills
: Integer read FMonsterKills write FMonsterKills
;
367 property Secrets
: Integer read FSecrets
;
368 property GodMode
: Boolean read FGodMode write FGodMode
;
369 property NoTarget
: Boolean read FNoTarget write FNoTarget
;
370 property NoReload
: Boolean read FNoReload write FNoReload
;
371 property alive
: Boolean read FAlive write FAlive
;
372 property Flag
: Byte read FFlag
;
373 property Team
: Byte read FTeam write FTeam
;
374 property Direction
: TDirection read FDirection
;
375 property GameX
: Integer read FObj
.X write FObj
.X
;
376 property GameY
: Integer read FObj
.Y write FObj
.Y
;
377 property GameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
378 property GameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
379 property GameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
380 property GameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
381 property IncCam
: Integer read FIncCam write FIncCam
;
382 property UID
: Word read FUID write FUID
;
383 property JustTeleported
: Boolean read FJustTeleported write FJustTeleported
;
384 property NetTime
: LongWord read FNetTime write FNetTime
;
387 property eName
: String read FName write FName
;
388 property eHealth
: Integer read FHealth write FHealth
;
389 property eLives
: Byte read FLives write FLives
;
390 property eArmor
: Integer read FArmor write FArmor
;
391 property eAir
: Integer read FAir write FAir
;
392 property eJetFuel
: Integer read FJetFuel write FJetFuel
;
393 property eFrags
: Integer read FFrags write FFrags
;
394 property eDeath
: Integer read FDeath write FDeath
;
395 property eKills
: Integer read FKills write FKills
;
396 property eCurrWeap
: Byte read FCurrWeap write FCurrWeap
;
397 property eMonsterKills
: Integer read FMonsterKills write FMonsterKills
;
398 property eSecrets
: Integer read FSecrets write FSecrets
;
399 property eGodMode
: Boolean read FGodMode write FGodMode
;
400 property eNoTarget
: Boolean read FNoTarget write FNoTarget
;
401 property eNoReload
: Boolean read FNoReload write FNoReload
;
402 property eAlive
: Boolean read FAlive write FAlive
;
403 property eFlag
: Byte read FFlag
;
404 property eTeam
: Byte read FTeam write FTeam
;
405 property eDirection
: TDirection read FDirection
;
406 property eGameX
: Integer read FObj
.X write FObj
.X
;
407 property eGameY
: Integer read FObj
.Y write FObj
.Y
;
408 property eGameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
409 property eGameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
410 property eGameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
411 property eGameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
412 property eIncCam
: Integer read FIncCam write FIncCam
;
413 property eUID
: Word read FUID
;
414 property eJustTeleported
: Boolean read FJustTeleported
;
415 property eNetTime
: LongWord read FNetTime
;
417 // set this before assigning something to `eDamage`
418 property eDamageType
: Integer read mEDamageType write mEDamageType
;
419 property eDamage
: Integer write doDamage
;
430 WeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
431 CloseWeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
432 //SafeWeaponPrior: Array [WP_FIRST..WP_LAST] of Byte;
435 procedure save (st
: TStream
);
436 procedure load (st
: TStream
);
444 TBot
= class(TPlayer
)
446 FSelectedWeapon
: Byte;
449 FAIFlags
: Array of TAIFlag
;
450 FDifficult
: TDifficult
;
452 function GetRnd(a
: Byte): Boolean;
453 function GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
454 function RunDirection(): TDirection
;
455 function FullInStep(XInc
, YInc
: Integer): Boolean;
456 //function NeedItem(Item: Byte): Byte;
457 procedure SelectWeapon(Dist
: Integer);
458 procedure SetAIFlag(aName
, fValue
: String20
);
459 function GetAIFlag(aName
: String20
): String20
;
460 procedure RemoveAIFlag(aName
: String20
);
461 function Healthy(): Byte;
462 procedure UpdateMove();
463 procedure UpdateCombat();
464 function KeyPressed(Key
: Word): Boolean;
465 procedure ReleaseKey(Key
: Byte);
466 function TargetOnScreen(TX
, TY
: Integer): Boolean;
467 procedure OnDamage(Angle
: SmallInt); override;
470 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); override;
471 constructor Create(); override;
472 destructor Destroy(); override;
473 procedure Draw(); override;
474 function PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean; override;
475 function Heal(value
: Word; Soft
: Boolean): Boolean; override;
476 procedure Update(); override;
477 procedure SaveState (st
: TStream
); override;
478 procedure LoadState (st
: TStream
); override;
490 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
491 procedure moveBy (dx
, dy
: Integer); inline;
493 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
507 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
508 procedure moveBy (dx
, dy
: Integer); inline;
510 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
513 TCorpse
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
522 FAnimation
: TAnimation
;
523 FAnimationMask
: TAnimation
;
526 constructor Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
527 destructor Destroy(); override;
528 procedure Damage(Value
: Word; vx
, vy
: Integer);
531 procedure SaveState (st
: TStream
);
532 procedure LoadState (st
: TStream
);
534 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
535 procedure moveBy (dx
, dy
: Integer); inline;
537 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
539 function ObjPtr (): PObj
; inline;
541 property Obj
: TObj read FObj
; // copies object
542 property State
: Byte read FState
;
543 property Mess
: Boolean read FMess
;
546 TTeamStat
= Array [TEAM_RED
..TEAM_BLUE
] of
552 gPlayers
: Array of TPlayer
;
553 gCorpses
: Array of TCorpse
;
554 gGibs
: Array of TGib
;
555 gShells
: Array of TShell
;
556 gTeamStat
: TTeamStat
;
557 gFly
: Boolean = False;
558 gAimLine
: Boolean = False;
559 gChatBubble
: Byte = 0;
563 MAX_RUNVEL
: Integer = 8;
564 VEL_JUMP
: Integer = 10;
565 SHELL_TIMEOUT
: Cardinal = 60000;
567 function Lerp(X
, Y
, Factor
: Integer): Integer;
569 procedure g_Gibs_SetMax(Count
: Word);
570 function g_Gibs_GetMax(): Word;
571 procedure g_Corpses_SetMax(Count
: Word);
572 function g_Corpses_GetMax(): Word;
573 procedure g_Shells_SetMax(Count
: Word);
574 function g_Shells_GetMax(): Word;
576 procedure g_Player_Init();
577 procedure g_Player_Free();
578 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
579 function g_Player_CreateFromState (st
: TStream
): Word;
580 procedure g_Player_Remove(UID
: Word);
581 procedure g_Player_ResetTeams();
582 procedure g_Player_UpdateAll();
583 procedure g_Player_DrawAll();
584 procedure g_Player_DrawDebug(p
: TPlayer
);
585 procedure g_Player_DrawHealth();
586 procedure g_Player_RememberAll();
587 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
588 function g_Player_Get(UID
: Word): TPlayer
;
589 function g_Player_GetCount(): Byte;
590 function g_Player_GetStats(): TPlayerStatArray
;
591 function g_Player_ValidName(Name
: String): Boolean;
592 procedure g_Player_CreateCorpse(Player
: TPlayer
);
593 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: String; fColor
: TRGB
);
594 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
595 procedure g_Player_UpdatePhysicalObjects();
596 procedure g_Player_DrawCorpses();
597 procedure g_Player_DrawShells();
598 procedure g_Player_RemoveAllCorpses();
599 procedure g_Player_Corpses_SaveState (st
: TStream
);
600 procedure g_Player_Corpses_LoadState (st
: TStream
);
601 procedure g_Bot_Add(Team
, Difficult
: Byte);
602 procedure g_Bot_AddList(Team
: Byte; lname
: ShortString; num
: Integer = -1);
603 procedure g_Bot_MixNames();
604 procedure g_Bot_RemoveAll();
609 {$INCLUDE ../nogl/noGLuses.inc}
610 {$IFDEF ENABLE_HOLMES}
613 e_log
, g_map
, g_items
, g_console
, g_gfx
, Math
,
614 g_options
, g_triggers
, g_menu
, g_game
, g_grid
,
615 wadreader
, g_main
, g_monsters
, CONFIG
, g_language
,
616 g_net
, g_netmsg
, g_window
,
619 const PLR_SAVE_VERSION
= 0;
629 diag_precision
: Byte;
633 w_prior1
: Array [WP_FIRST
..WP_LAST
] of Byte;
634 w_prior2
: Array [WP_FIRST
..WP_LAST
] of Byte;
635 w_prior3
: Array [WP_FIRST
..WP_LAST
] of Byte;
639 TIME_RESPAWN1
= 1500;
640 TIME_RESPAWN2
= 2000;
641 TIME_RESPAWN3
= 3000;
644 JET_MAX
= 540; // ~30 sec
645 PLAYER_SUIT_TIME
= 30000;
646 PLAYER_INVUL_TIME
= 30000;
647 PLAYER_INVIS_TIME
= 35000;
648 FRAG_COMBO_TIME
= 3000;
652 ANGLE_RIGHTDOWN
= -35;
654 ANGLE_LEFTDOWN
= -145;
655 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
656 WEAPONPOINT
: Array [TDirection
] of TDFPoint
= ((X
:16; Y
:32), (X
:47; Y
:32));
659 BOT_UNSAFEDIST
= 128;
660 TEAMCOLOR
: Array [TEAM_RED
..TEAM_BLUE
] of TRGB
= ((R
:255; G
:0; B
:0),
662 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
663 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
664 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
665 DIFFICULT_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
666 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
667 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
668 DIFFICULT_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
669 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
670 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
671 WEAPON_PRIOR1
: Array [WP_FIRST
..WP_LAST
] of Byte =
672 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
673 WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
674 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
675 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
676 WEAPON_PRIOR2
: Array [WP_FIRST
..WP_LAST
] of Byte =
677 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
678 WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
679 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
680 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
681 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
682 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
683 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
684 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
685 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
686 WEAPON_RELOAD
: Array [WP_FIRST
..WP_LAST
] of Byte =
687 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
689 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
690 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
692 BOTNAMES_FILENAME
= 'botnames.txt';
693 BOTLIST_FILENAME
= 'botlist.txt';
697 MaxCorpses
: Word = 20;
698 MaxShells
: Word = 300;
699 CurrentGib
: Integer = 0;
700 CurrentShell
: Integer = 0;
701 BotNames
: Array of String;
702 BotList
: Array of TBotProfile
;
705 function Lerp(X
, Y
, Factor
: Integer): Integer;
707 Result
:= X
+ ((Y
- X
) div Factor
);
710 function SameTeam(UID1
, UID2
: Word): Boolean;
714 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
715 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
717 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
719 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
720 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
722 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
725 procedure g_Gibs_SetMax(Count
: Word);
728 SetLength(gGibs
, Count
);
730 if CurrentGib
>= Count
then
734 function g_Gibs_GetMax(): Word;
739 procedure g_Shells_SetMax(Count
: Word);
742 SetLength(gShells
, Count
);
744 if CurrentShell
>= Count
then
748 function g_Shells_GetMax(): Word;
754 procedure g_Corpses_SetMax(Count
: Word);
757 SetLength(gCorpses
, Count
);
760 function g_Corpses_GetMax(): Word;
762 Result
:= MaxCorpses
;
765 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
775 // Åñòü ëè ìåñòî â gPlayers:
776 if gPlayers
<> nil then
777 for a
:= 0 to High(gPlayers
) do
778 if gPlayers
[a
] = nil then
784 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
787 SetLength(gPlayers
, Length(gPlayers
)+1);
791 // Ñîçäàåì îáúåêò èãðîêà:
793 gPlayers
[a
] := TBot
.Create()
795 gPlayers
[a
] := TPlayer
.Create();
798 gPlayers
[a
].FActualModelName
:= ModelName
;
799 gPlayers
[a
].SetModel(ModelName
);
801 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
802 if gPlayers
[a
].FModel
= nil then
806 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
810 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
811 if Random(2) = 0 then
815 gPlayers
[a
].FPreferredTeam
:= Team
;
817 case gGameSettings
.GameMode
of
818 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
820 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
822 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
825 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
826 gPlayers
[a
].FColor
:= Color
;
827 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
828 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
830 gPlayers
[a
].FModel
.Color
:= Color
;
832 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
833 gPlayers
[a
].FAlive
:= False;
835 Result
:= gPlayers
[a
].FUID
;
838 function g_Player_CreateFromState (st
: TStream
): Word;
845 if (st
= nil) then exit
; //???
848 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
849 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
852 Bot
:= utils
.readBool(st
);
857 // Åñòü ëè ìåñòî â gPlayers:
858 for a
:= 0 to High(gPlayers
) do if (gPlayers
[a
] = nil) then begin ok
:= true; break
; end;
860 // Íåò ìåñòà - ðàñøèðÿåì gPlayers
863 SetLength(gPlayers
, Length(gPlayers
)+1);
867 // Ñîçäàåì îáúåêò èãðîêà
869 gPlayers
[a
] := TBot
.Create()
871 gPlayers
[a
] := TPlayer
.Create();
872 gPlayers
[a
].FIamBot
:= Bot
;
873 gPlayers
[a
].FPhysics
:= True;
876 gPlayers
[a
].FUID
:= utils
.readWord(st
);
878 gPlayers
[a
].FName
:= utils
.readStr(st
);
880 gPlayers
[a
].FTeam
:= utils
.readByte(st
);
881 gPlayers
[a
].FPreferredTeam
:= gPlayers
[a
].FTeam
;
883 gPlayers
[a
].FAlive
:= utils
.readBool(st
);
884 // Èçðàñõîäîâàë ëè âñå æèçíè
885 gPlayers
[a
].FNoRespawn
:= utils
.readBool(st
);
887 b
:= utils
.readByte(st
);
888 if b
= 1 then gPlayers
[a
].FDirection
:= TDirection
.D_LEFT
else gPlayers
[a
].FDirection
:= TDirection
.D_RIGHT
; // b = 2
890 gPlayers
[a
].FHealth
:= utils
.readLongInt(st
);
892 gPlayers
[a
].FLives
:= utils
.readByte(st
);
894 gPlayers
[a
].FArmor
:= utils
.readLongInt(st
);
896 gPlayers
[a
].FAir
:= utils
.readLongInt(st
);
898 gPlayers
[a
].FJetFuel
:= utils
.readLongInt(st
);
900 gPlayers
[a
].FPain
:= utils
.readLongInt(st
);
902 gPlayers
[a
].FKills
:= utils
.readLongInt(st
);
904 gPlayers
[a
].FMonsterKills
:= utils
.readLongInt(st
);
906 gPlayers
[a
].FFrags
:= utils
.readLongInt(st
);
908 gPlayers
[a
].FFragCombo
:= utils
.readByte(st
);
909 // Âðåìÿ ïîñëåäíåãî ôðàãà
910 gPlayers
[a
].FLastFrag
:= utils
.readLongWord(st
);
912 gPlayers
[a
].FDeath
:= utils
.readLongInt(st
);
914 gPlayers
[a
].FFlag
:= utils
.readByte(st
);
916 gPlayers
[a
].FSecrets
:= utils
.readLongInt(st
);
918 gPlayers
[a
].FCurrWeap
:= utils
.readByte(st
);
919 //gPlayers[a].FNetForceWeap := gPlayers[a].FCurrWeap;
920 // Ñëåäóþùåå æåëàåìîå îðóæèå
921 gPlayers
[a
].FNextWeap
:= utils
.readWord(st
);
923 gPlayers
[a
].FNextWeapDelay
:= utils
.readByte(st
);
925 gPlayers
[a
].FBFGFireCounter
:= utils
.readSmallInt(st
);
927 gPlayers
[a
].FDamageBuffer
:= utils
.readLongInt(st
);
928 // Ïîñëåäíèé óäàðèâøèé
929 gPlayers
[a
].FLastSpawnerUID
:= utils
.readWord(st
);
930 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
931 gPlayers
[a
].FLastHit
:= utils
.readByte(st
);
933 Obj_LoadState(@gPlayers
[a
].FObj
, st
);
934 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
935 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FAmmo
[i
] := utils
.readWord(st
);
936 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
937 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FMaxAmmo
[i
] := utils
.readWord(st
);
939 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FWeapon
[i
] := utils
.readBool(st
);
940 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
941 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FReloading
[i
] := utils
.readWord(st
);
943 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_ITEM_BACKPACK
);
944 // Íàëè÷èå êðàñíîãî êëþ÷à
945 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_RED
);
946 // Íàëè÷èå çåëåíîãî êëþ÷à
947 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_GREEN
);
948 // Íàëè÷èå ñèíåãî êëþ÷à
949 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_BLUE
);
951 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_BERSERK
);
952 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
953 for i
:= MR_SUIT
to MR_MAX
do gPlayers
[a
].FMegaRulez
[i
] := utils
.readLongWord(st
);
954 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
955 for i
:= T_RESPAWN
to T_FLAGCAP
do gPlayers
[a
].FTime
[i
] := utils
.readLongWord(st
);
958 gPlayers
[a
].FActualModelName
:= utils
.readStr(st
);
960 gPlayers
[a
].FColor
.R
:= utils
.readByte(st
);
961 gPlayers
[a
].FColor
.G
:= utils
.readByte(st
);
962 gPlayers
[a
].FColor
.B
:= utils
.readByte(st
);
963 // Îáíîâëÿåì ìîäåëü èãðîêà
964 gPlayers
[a
].SetModel(gPlayers
[a
].FActualModelName
);
966 // Íåò ìîäåëè - ñîçäàíèå íåâîçìîæíî
967 if (gPlayers
[a
].FModel
= nil) then
971 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [gPlayers
[a
].FActualModelName
]));
975 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû
976 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
977 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
979 gPlayers
[a
].FModel
.Color
:= gPlayers
[a
].FColor
;
981 result
:= gPlayers
[a
].FUID
;
985 procedure g_Player_ResetTeams();
989 if g_Game_IsClient
then
991 if gPlayers
= nil then
993 for a
:= Low(gPlayers
) to High(gPlayers
) do
994 if gPlayers
[a
] <> nil then
995 case gGameSettings
.GameMode
of
997 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
999 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
1000 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
1001 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
1004 gPlayers
[a
].ChangeTeam(TEAM_RED
)
1006 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
1009 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
1013 procedure g_Bot_Add(Team
, Difficult
: Byte);
1016 _name
, _model
: String;
1019 if not g_Game_IsServer
then Exit
;
1021 // Ñïèñîê íàçâàíèé ìîäåëåé:
1022 m
:= g_PlayerModel_GetNames();
1027 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1028 Team
:= TEAM_COOP
// COOP
1030 if gGameSettings
.GameMode
= GM_DM
then
1031 Team
:= TEAM_NONE
// DM
1033 if Team
= TEAM_NONE
then // CTF / TDM
1035 // Àâòîáàëàíñ êîìàíä:
1039 for a
:= 0 to High(gPlayers
) do
1040 if gPlayers
[a
] <> nil then
1042 if gPlayers
[a
].Team
= TEAM_RED
then
1045 if gPlayers
[a
].Team
= TEAM_BLUE
then
1055 if Random(2) = 0 then
1061 // Âûáèðàåì áîòó èìÿ:
1063 if BotNames
<> nil then
1064 for a
:= 0 to High(BotNames
) do
1065 if g_Player_ValidName(BotNames
[a
]) then
1067 _name
:= BotNames
[a
];
1071 // Èìåíè íåò, çàäàåì ñëó÷àéíîå:
1074 _name
:= Format('DFBOT%.2d', [Random(100)]);
1075 until g_Player_ValidName(_name
);
1077 // Âûáèðàåì ñëó÷àéíóþ ìîäåëü:
1078 _model
:= m
[Random(Length(m
))];
1081 with g_Player_Get(g_Player_Create(_model
,
1082 _RGB(Min(Random(9)*32, 255),
1083 Min(Random(9)*32, 255),
1084 Min(Random(9)*32, 255)),
1085 Team
, True)) as TBot
do
1090 1: FDifficult
:= DIFFICULT_EASY
;
1091 2: FDifficult
:= DIFFICULT_MEDIUM
;
1092 else FDifficult
:= DIFFICULT_HARD
;
1095 for a
:= WP_FIRST
to WP_LAST
do
1097 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1098 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1099 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1102 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1104 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1105 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1110 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString; num
: Integer = -1);
1113 _name
, _model
: String;
1116 if not g_Game_IsServer
then Exit
;
1118 // Ñïèñîê íàçâàíèé ìîäåëåé:
1119 m
:= g_PlayerModel_GetNames();
1124 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1125 Team
:= TEAM_COOP
// COOP
1127 if gGameSettings
.GameMode
= GM_DM
then
1128 Team
:= TEAM_NONE
// DM
1130 if Team
= TEAM_NONE
then
1131 Team
:= BotList
[num
].team
; // CTF / TDM
1133 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1134 lName
:= AnsiLowerCase(lName
);
1135 if (num
< 0) or (num
> Length(BotList
)-1) then
1137 if (num
= -1) and (lName
<> '') and (BotList
<> nil) then
1138 for a
:= 0 to High(BotList
) do
1139 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1148 _name
:= BotList
[num
].name
;
1149 // Çàíÿòî - âûáèðàåì ñëó÷àéíîå:
1150 if not g_Player_ValidName(_name
) then
1152 _name
:= Format('DFBOT%.2d', [Random(100)]);
1153 until g_Player_ValidName(_name
);
1156 _model
:= BotList
[num
].model
;
1157 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1158 if not InSArray(_model
, m
) then
1159 _model
:= m
[Random(Length(m
))];
1162 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1166 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1167 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1168 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1169 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1170 FDifficult
.Cover
:= BotList
[num
].cover
;
1171 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1173 for a
:= WP_FIRST
to WP_LAST
do
1175 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1176 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1177 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1180 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1182 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1186 procedure g_Bot_RemoveAll();
1190 if not g_Game_IsServer
then Exit
;
1191 if gPlayers
= nil then Exit
;
1193 for a
:= 0 to High(gPlayers
) do
1194 if gPlayers
[a
] <> nil then
1195 if gPlayers
[a
] is TBot
then
1197 gPlayers
[a
].Lives
:= 0;
1198 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1199 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1200 g_Player_Remove(gPlayers
[a
].FUID
);
1206 procedure g_Bot_MixNames();
1211 if BotNames
<> nil then
1212 for a
:= 0 to High(BotNames
) do
1214 b
:= Random(Length(BotNames
));
1216 Botnames
[a
] := BotNames
[b
];
1221 procedure g_Player_Remove(UID
: Word);
1225 if gPlayers
= nil then Exit
;
1227 if g_Game_IsServer
and g_Game_IsNet
then
1228 MH_SEND_PlayerDelete(UID
);
1230 for i
:= 0 to High(gPlayers
) do
1231 if gPlayers
[i
] <> nil then
1232 if gPlayers
[i
].FUID
= UID
then
1234 if gPlayers
[i
] is TPlayer
then
1235 TPlayer(gPlayers
[i
]).Free()
1237 TBot(gPlayers
[i
]).Free();
1243 procedure g_Player_Init();
1253 if not FileExists(DataDir
+ BOTNAMES_FILENAME
) then
1256 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1257 AssignFile(F
, DataDir
+ BOTNAMES_FILENAME
);
1268 SetLength(BotNames
, Length(BotNames
)+1);
1269 BotNames
[High(BotNames
)] := s
;
1277 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1278 config
:= TConfig
.CreateFile(DataDir
+ BOTLIST_FILENAME
);
1282 while config
.SectionExists(IntToStr(a
)) do
1284 SetLength(BotList
, Length(BotList
)+1);
1286 with BotList
[High(BotList
)] do
1289 name
:= config
.ReadStr(IntToStr(a
), 'name', '');
1291 model
:= config
.ReadStr(IntToStr(a
), 'model', '');
1293 if config
.ReadStr(IntToStr(a
), 'team', 'red') = 'red' then
1298 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1299 color
.R
:= StrToIntDef(sa
[0], 0);
1300 color
.G
:= StrToIntDef(sa
[1], 0);
1301 color
.B
:= StrToIntDef(sa
[2], 0);
1302 // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì:
1303 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0);
1304 // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó:
1305 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0);
1306 // Òî÷íîñòü ñòðåëüáû ïîä óãëîì:
1307 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0);
1308 // Òî÷íîñòü ñòðåëüáû â ïîëåòå:
1309 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0);
1310 // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ:
1311 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0);
1312 // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà:
1313 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0);
1314 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ:
1315 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1316 if Length(sa
) = 10 then
1318 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1319 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ:
1320 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1321 if Length(sa
) = 10 then
1323 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1325 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1326 if Length(sa) = 10 then
1328 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1337 procedure g_Player_Free();
1341 if gPlayers
<> nil then
1343 for i
:= 0 to High(gPlayers
) do
1344 if gPlayers
[i
] <> nil then
1346 if gPlayers
[i
] is TPlayer
then
1347 TPlayer(gPlayers
[i
]).Free()
1349 TBot(gPlayers
[i
]).Free();
1360 procedure g_Player_UpdateAll();
1364 if gPlayers
= nil then Exit
;
1366 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1367 for i
:= 0 to High(gPlayers
) do
1369 if gPlayers
[i
] <> nil then
1371 if gPlayers
[i
] is TPlayer
then
1373 gPlayers
[i
].Update();
1374 if g_Game_IsClient
or not g_Game_IsNet
then
1376 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1381 // bot updates weapons in `UpdateCombat()`
1382 TBot(gPlayers
[i
]).Update();
1386 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1389 procedure g_Player_DrawAll();
1393 if gPlayers
= nil then Exit
;
1395 for i
:= 0 to High(gPlayers
) do
1396 if gPlayers
[i
] <> nil then
1397 if gPlayers
[i
] is TPlayer
then gPlayers
[i
].Draw()
1398 else TBot(gPlayers
[i
]).Draw();
1401 procedure g_Player_DrawDebug(p
: TPlayer
);
1405 if p
= nil then Exit
;
1406 if (@p
.FObj
) = nil then Exit
;
1408 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1410 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p
.FObj
.X
), gStdFont
);
1411 e_TextureFontPrint(0, fH
, 'Pos Y: ' + IntToStr(p
.FObj
.Y
), gStdFont
);
1412 e_TextureFontPrint(0, fH
* 2, 'Vel X: ' + IntToStr(p
.FObj
.Vel
.X
), gStdFont
);
1413 e_TextureFontPrint(0, fH
* 3, 'Vel Y: ' + IntToStr(p
.FObj
.Vel
.Y
), gStdFont
);
1414 e_TextureFontPrint(0, fH
* 4, 'Acc X: ' + IntToStr(p
.FObj
.Accel
.X
), gStdFont
);
1415 e_TextureFontPrint(0, fH
* 5, 'Acc Y: ' + IntToStr(p
.FObj
.Accel
.Y
), gStdFont
);
1418 procedure g_Player_DrawHealth();
1423 if gPlayers
= nil then Exit
;
1424 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1426 for i
:= 0 to High(gPlayers
) do
1427 if gPlayers
[i
] <> nil then
1429 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1430 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
* 2,
1431 IntToStr(gPlayers
[i
].FHealth
), gStdFont
);
1432 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1433 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
,
1434 IntToStr(gPlayers
[i
].FArmor
), gStdFont
);
1438 function g_Player_Get(UID
: Word): TPlayer
;
1444 if gPlayers
= nil then
1447 for a
:= 0 to High(gPlayers
) do
1448 if gPlayers
[a
] <> nil then
1449 if gPlayers
[a
].FUID
= UID
then
1451 Result
:= gPlayers
[a
];
1456 function g_Player_GetCount(): Byte;
1462 if gPlayers
= nil then
1465 for a
:= 0 to High(gPlayers
) do
1466 if gPlayers
[a
] <> nil then
1467 Result
:= Result
+ 1;
1470 function g_Player_GetStats(): TPlayerStatArray
;
1476 if gPlayers
= nil then Exit
;
1478 for a
:= 0 to High(gPlayers
) do
1479 if gPlayers
[a
] <> nil then
1481 SetLength(Result
, Length(Result
)+1);
1482 with Result
[High(Result
)] do
1484 Ping
:= gPlayers
[a
].FPing
;
1485 Loss
:= gPlayers
[a
].FLoss
;
1486 Name
:= gPlayers
[a
].FName
;
1487 Team
:= gPlayers
[a
].FTeam
;
1488 Frags
:= gPlayers
[a
].FFrags
;
1489 Deaths
:= gPlayers
[a
].FDeath
;
1490 Kills
:= gPlayers
[a
].FKills
;
1491 Color
:= gPlayers
[a
].FModel
.Color
;
1492 Lives
:= gPlayers
[a
].FLives
;
1493 Spectator
:= gPlayers
[a
].FSpectator
;
1498 procedure g_Player_RememberAll
;
1502 for i
:= Low(gPlayers
) to High(gPlayers
) do
1503 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
then
1504 gPlayers
[i
].RememberState
;
1507 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1511 gTeamStat
[TEAM_RED
].Goals
:= 0;
1512 gTeamStat
[TEAM_BLUE
].Goals
:= 0;
1514 if gPlayers
<> nil then
1515 for i
:= 0 to High(gPlayers
) do
1516 if gPlayers
[i
] <> nil then
1518 gPlayers
[i
].Reset(Force
);
1520 if gPlayers
[i
] is TPlayer
then
1522 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1523 gPlayers
[i
].Respawn(Silent
)
1525 gPlayers
[i
].Spectate();
1528 TBot(gPlayers
[i
]).Respawn(Silent
);
1532 procedure g_Player_CreateCorpse(Player
: TPlayer
);
1538 if Player
.alive
then
1541 // Ðàçðûâàåì ñâÿçü ñ ïðåæíèì òðóïîì:
1542 if gCorpses
<> nil then
1543 for i
:= 0 to High(gCorpses
) do
1544 if gCorpses
[i
] <> nil then
1545 if gCorpses
[i
].FPlayerUID
= Player
.FUID
then
1546 gCorpses
[i
].FPlayerUID
:= 0;
1548 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1553 if (FHealth
>= -50) or (gGibsCount
= 0) then
1555 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1559 for find_id
:= 0 to High(gCorpses
) do
1560 if gCorpses
[find_id
] = nil then
1567 find_id
:= Random(Length(gCorpses
));
1569 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.Name
, FHealth
< -20);
1570 gCorpses
[find_id
].FColor
:= FModel
.Color
;
1571 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1572 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1573 gCorpses
[find_id
].FPlayerUID
:= FUID
;
1576 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
,
1577 FObj
.Y
+ PLAYER_RECT_CY
,
1578 FModel
.Name
, FModel
.Color
);
1582 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1586 if (gShells
= nil) or (Length(gShells
) = 0) then
1589 with gShells
[CurrentShell
] do
1595 if T
= SHELL_BULLET
then
1597 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID
) then
1601 Obj
.Rect
.Width
:= 4;
1602 Obj
.Rect
.Height
:= 2;
1606 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID
) then
1610 Obj
.Rect
.Width
:= 7;
1611 Obj
.Rect
.Height
:= 3;
1617 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1618 positionChanged(); // this updates spatial accelerators
1619 RAngle
:= Random(360);
1620 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1622 if CurrentShell
>= High(gShells
) then
1629 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: string; fColor
: TRGB
);
1632 GibsArray
: TGibsArray
;
1635 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1637 if not g_PlayerModel_GetGibs(ModelName
, GibsArray
) then
1639 Blood
:= g_PlayerModel_GetBlood(ModelName
);
1641 for a
:= 0 to High(GibsArray
) do
1642 with gGibs
[CurrentGib
] do
1645 ID
:= GibsArray
[a
].ID
;
1646 MaskID
:= GibsArray
[a
].MaskID
;
1649 Obj
.Rect
:= GibsArray
[a
].Rect
;
1650 Obj
.X
:= fX
-GibsArray
[a
].Rect
.X
-(GibsArray
[a
].Rect
.Width
div 2);
1651 Obj
.Y
:= fY
-GibsArray
[a
].Rect
.Y
-(GibsArray
[a
].Rect
.Height
div 2);
1652 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1653 positionChanged(); // this updates spatial accelerators
1654 RAngle
:= Random(360);
1656 if gBloodCount
> 0 then
1657 g_GFX_Blood(fX
, fY
, 16*gBloodCount
+Random(5*gBloodCount
), -16+Random(33), -16+Random(33),
1658 Random(48), Random(48), Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
1660 if CurrentGib
>= High(gGibs
) then
1667 procedure g_Player_UpdatePhysicalObjects();
1673 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1678 if T
= SHELL_BULLET
then
1679 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1681 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1686 if gGibs
<> nil then
1687 for i
:= 0 to High(gGibs
) do
1688 if gGibs
[i
].alive
then
1692 mr
:= g_Obj_Move(@Obj
, True, False, True);
1693 positionChanged(); // this updates spatial accelerators
1695 if WordBool(mr
and MOVE_FALLOUT
) then
1701 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1702 if WordBool(mr
and MOVE_HITWALL
) then
1703 Obj
.Vel
.X
:= -(vel
.X
div 2);
1704 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1705 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1707 if (Obj
.Vel
.X
>= 0) then
1709 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1710 if RAngle
>= 360 then
1711 RAngle
:= RAngle
mod 360;
1712 end else begin // Counter-clockwise
1713 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1715 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1718 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1719 if gTime
mod (GAME_TICK
*3) = 0 then
1720 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1724 if gCorpses
<> nil then
1725 for i
:= 0 to High(gCorpses
) do
1726 if gCorpses
[i
] <> nil then
1727 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1733 gCorpses
[i
].Update();
1736 if gShells
<> nil then
1737 for i
:= 0 to High(gShells
) do
1738 if gShells
[i
].alive
then
1742 mr
:= g_Obj_Move(@Obj
, True, False, True);
1743 positionChanged(); // this updates spatial accelerators
1745 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1751 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1752 if WordBool(mr
and MOVE_HITWALL
) then
1754 Obj
.Vel
.X
:= -(vel
.X
div 2);
1755 if not WordBool(mr
and MOVE_INWATER
) then
1756 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1758 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1760 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1761 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1762 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1764 if RAngle
mod 90 <> 0 then
1765 RAngle
:= (RAngle
div 90) * 90;
1767 else if not WordBool(mr
and MOVE_INWATER
) then
1768 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1771 if (Obj
.Vel
.X
>= 0) then
1773 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1774 if RAngle
>= 360 then
1775 RAngle
:= RAngle
mod 360;
1776 end else begin // Counter-clockwise
1777 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1779 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1785 procedure TGib
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1787 x
:= Obj
.X
+Obj
.Rect
.X
;
1788 y
:= Obj
.Y
+Obj
.Rect
.Y
;
1789 w
:= Obj
.Rect
.Width
;
1790 h
:= Obj
.Rect
.Height
;
1793 procedure TGib
.moveBy (dx
, dy
: Integer); inline;
1795 if (dx
<> 0) or (dy
<> 0) then
1804 procedure TShell
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1808 w
:= Obj
.Rect
.Width
;
1809 h
:= Obj
.Rect
.Height
;
1812 procedure TShell
.moveBy (dx
, dy
: Integer); inline;
1814 if (dx
<> 0) or (dy
<> 0) then
1823 procedure TGib
.positionChanged (); inline; begin end;
1824 procedure TShell
.positionChanged (); inline; begin end;
1827 procedure g_Player_DrawCorpses();
1832 if gGibs
<> nil then
1833 for i
:= 0 to High(gGibs
) do
1834 if gGibs
[i
].alive
then
1837 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1840 a
.X
:= Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2);
1841 a
.y
:= Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2);
1843 e_DrawAdv(ID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1846 e_DrawAdv(MaskID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1852 if gCorpses
<> nil then
1853 for i
:= 0 to High(gCorpses
) do
1854 if gCorpses
[i
] <> nil then
1858 procedure g_Player_DrawShells();
1863 if gShells
<> nil then
1864 for i
:= 0 to High(gShells
) do
1865 if gShells
[i
].alive
then
1868 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1874 e_DrawAdv(SpriteID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1878 procedure g_Player_RemoveAllCorpses();
1884 SetLength(gGibs
, MaxGibs
);
1885 SetLength(gShells
, MaxGibs
);
1889 if gCorpses
<> nil then
1890 for i
:= 0 to High(gCorpses
) do
1894 SetLength(gCorpses
, MaxCorpses
);
1897 procedure g_Player_Corpses_SaveState (st
: TStream
);
1901 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ
1903 for i
:= 0 to High(gCorpses
) do if (gCorpses
[i
] <> nil) then Inc(count
);
1905 // Êîëè÷åñòâî òðóïîâ
1906 utils
.writeInt(st
, LongInt(count
));
1908 if (count
= 0) then exit
;
1911 for i
:= 0 to High(gCorpses
) do
1913 if gCorpses
[i
] <> nil then
1916 utils
.writeStr(st
, gCorpses
[i
].FModelName
);
1918 utils
.writeBool(st
, gCorpses
[i
].Mess
);
1919 // Ñîõðàíÿåì äàííûå òðóïà:
1920 gCorpses
[i
].SaveState(st
);
1926 procedure g_Player_Corpses_LoadState (st
: TStream
);
1934 g_Player_RemoveAllCorpses();
1936 // Êîëè÷åñòâî òðóïîâ:
1937 count
:= utils
.readLongInt(st
);
1938 if (count
< 0) or (count
> Length(gCorpses
)) then raise XStreamError
.Create('invalid number of corpses');
1940 if (count
= 0) then exit
;
1943 for i
:= 0 to count
-1 do
1946 str
:= utils
.readStr(st
);
1948 b
:= utils
.readBool(st
);
1950 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1951 // Çàãðóæàåì äàííûå òðóïà
1952 gCorpses
[i
].LoadState(st
);
1959 function TPlayer
.isValidViewPort (): Boolean; inline; begin result
:= (viewPortW
> 0) and (viewPortH
> 0); end;
1961 procedure TPlayer
.BFGHit();
1963 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1964 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
1965 if g_Game_IsServer
and g_Game_IsNet
then
1966 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1967 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
1971 procedure TPlayer
.ChangeModel(ModelName
: string);
1973 locModel
: TPlayerModel
;
1975 locModel
:= g_PlayerModel_Get(ModelName
);
1976 if locModel
= nil then Exit
;
1982 procedure TPlayer
.SetModel(ModelName
: string);
1986 m
:= g_PlayerModel_Get(ModelName
);
1989 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
1990 m
:= g_PlayerModel_Get('doomer');
1993 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
1998 if FModel
<> nil then
2003 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2004 FModel
.Color
:= FColor
2006 FModel
.Color
:= TEAMCOLOR
[FTeam
];
2007 FModel
.SetWeapon(FCurrWeap
);
2008 FModel
.SetFlag(FFlag
);
2009 SetDirection(FDirection
);
2012 procedure TPlayer
.SetColor(Color
: TRGB
);
2015 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2016 if FModel
<> nil then FModel
.Color
:= Color
;
2019 procedure TPlayer
.SwitchTeam
;
2021 if g_Game_IsClient
then
2023 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
2025 if gGameOn
and FAlive
then
2026 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
2028 if FTeam
= TEAM_RED
then
2030 ChangeTeam(TEAM_BLUE
);
2031 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
2032 if g_Game_IsNet
then
2033 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
2037 ChangeTeam(TEAM_RED
);
2038 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
2039 if g_Game_IsNet
then
2040 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
2042 FPreferredTeam
:= FTeam
;
2045 procedure TPlayer
.ChangeTeam(Team
: Byte);
2052 TEAM_RED
, TEAM_BLUE
:
2053 FModel
.Color
:= TEAMCOLOR
[Team
];
2055 FModel
.Color
:= FColor
;
2057 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
2058 MH_SEND_PlayerStats(FUID
);
2062 procedure TPlayer.CollideItem();
2067 if gItems = nil then Exit;
2068 if not FAlive then Exit;
2070 for i := 0 to High(gItems) do
2073 if (ItemType <> ITEM_NONE) and alive then
2074 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
2075 PLAYER_RECT.Height, @Obj) then
2077 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
2079 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
2080 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
2081 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
2082 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
2083 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
2085 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
2086 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
2087 (gGameSettings.GameType = GT_SINGLE) and
2088 (g_Player_GetCount() > 1)) then
2089 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
2095 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
2097 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
2098 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
2102 constructor TPlayer
.Create();
2108 mEDamageType
:= HIT_SOME
;
2114 FSawSound
:= TPlayableSound
.Create();
2115 FSawSoundIdle
:= TPlayableSound
.Create();
2116 FSawSoundHit
:= TPlayableSound
.Create();
2117 FSawSoundSelect
:= TPlayableSound
.Create();
2118 FJetSoundFly
:= TPlayableSound
.Create();
2119 FJetSoundOn
:= TPlayableSound
.Create();
2120 FJetSoundOff
:= TPlayableSound
.Create();
2122 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
2123 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
2124 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
2125 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
2126 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
2127 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
2128 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
2130 FSpectatePlayer
:= -1;
2134 FSavedState
.WaitRecall
:= False;
2140 FActualModelName
:= 'doomer';
2143 FObj
.Rect
:= PLAYER_RECT
;
2145 FBFGFireCounter
:= -1;
2146 FJustTeleported
:= False;
2149 //FNetForceWeap := FCurrWeap;
2150 FNetForceWeapFIdx
:= 0;
2151 //FCurrFrameIdx := 0;
2154 releaseAllWeaponSwitchKeys();
2158 procedure TPlayer
.releaseAllWeaponSwitchKeys ();
2162 for f
:= 0 to High(weaponSwitchKeyReleased
) do weaponSwitchKeyReleased
[f
] := $03;
2165 procedure TPlayer
.weaponSwitchKeysStateChange (index
: Integer; pressed
: Boolean);
2167 Inc(index
, 2); // -2: prev; -1: next
2168 if (index
< 0) or (index
> High(weaponSwitchKeyReleased
)) then exit
;
2169 weaponSwitchKeyReleased
[index
] := weaponSwitchKeyReleased
[index
] or $02;
2170 if (pressed
) then weaponSwitchKeyReleased
[index
] := weaponSwitchKeyReleased
[index
] xor $02;
2173 function TPlayer
.isWeaponSwitchKeyReleased (index
: Integer): Boolean;
2175 Inc(index
, 2); // -2: prev; -1: next
2176 if (index
< 0) or (index
> High(weaponSwitchKeyReleased
)) then
2182 result
:= (weaponSwitchKeyReleased
[index
] and $01) <> 0;
2186 procedure TPlayer
.weaponSwitchKeysShiftNewStates ();
2190 // copy bit 1 to bit 0
2191 for f
:= 0 to High(weaponSwitchKeyReleased
) do
2193 weaponSwitchKeyReleased
[f
] :=
2194 (weaponSwitchKeyReleased
[f
] and $02) or
2195 ((weaponSwitchKeyReleased
[f
] shr 1) and $01);
2200 procedure TPlayer
.positionChanged (); inline;
2204 procedure TPlayer
.doDamage (v
: Integer);
2206 if (v
<= 0) then exit
;
2207 if (v
> 32767) then v
:= 32767;
2208 Damage(v
, 0, 0, 0, mEDamageType
);
2211 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
2215 if (not g_Game_IsClient
) and (not FAlive
) then
2220 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2221 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2223 if not g_Game_IsClient
then
2226 if t
= HIT_TRAP
then
2228 // Ëîâóøêà óáèâàåò ñðàçó:
2230 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2232 if t
= HIT_SELF
then
2236 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2239 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2240 FMegaRulez
[MR_SUIT
] := 0;
2241 FMegaRulez
[MR_INVUL
] := 0;
2242 FMegaRulez
[MR_INVIS
] := 0;
2246 // Íî îò îñòàëüíîãî ñïàñàåò:
2247 if FMegaRulez
[MR_INVUL
] >= gTime
then
2254 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2255 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2256 (SpawnerUID
= FUID
) or
2257 (not SameTeam(FUID
, SpawnerUID
)) then
2259 FLastSpawnerUID
:= SpawnerUID
;
2261 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2262 if gBloodCount
> 0 then
2264 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2265 if value
div 4 <= c
then
2266 c
:= c
- (value
div 4)
2270 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2274 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2275 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2278 if t
= HIT_WATER
then
2279 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2280 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2285 Inc(FDamageBuffer
, value
);
2289 FPain
:= FPain
+ value
;
2292 if g_Game_IsServer
and g_Game_IsNet
then
2294 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2295 MH_SEND_PlayerStats(FUID
);
2296 MH_SEND_PlayerPos(False, FUID
);
2300 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2303 if g_Game_IsClient
then
2308 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2310 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2313 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2315 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2319 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2320 MH_SEND_PlayerStats(FUID
);
2323 destructor TPlayer
.Destroy();
2325 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2327 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2331 FSawSoundIdle
.Free();
2332 FSawSoundHit
.Free();
2333 FJetSoundFly
.Free();
2335 FJetSoundOff
.Free();
2337 if FPunchAnim
<> nil then
2343 procedure TPlayer
.DrawBubble();
2345 bubX
, bubY
: Integer;
2348 Rw
, Gw
, Bw
: SmallInt;
2351 bubX
:= FObj
.X
+FObj
.Rect
.X
+ IfThen(FDirection
= TDirection
.D_LEFT
, -4, 18);
2352 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 18;
2360 1: // simple textual non-bubble
2362 bubX
:= FObj
.X
+FObj
.Rect
.X
- 11;
2363 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 17;
2364 e_TextureFontPrint(bubX
, bubY
, '[...]', gStdFont
);
2367 2: // advanced pixel-perfect bubble
2369 if FTeam
= TEAM_RED
then
2372 if FTeam
= TEAM_BLUE
then
2375 3: // colored bubble
2377 Rb
:= FModel
.Color
.R
;
2378 Gb
:= FModel
.Color
.G
;
2379 Bb
:= FModel
.Color
.B
;
2380 Rw
:= Min(Rb
* 2 + 64, 255);
2381 Gw
:= Min(Gb
* 2 + 64, 255);
2382 Bw
:= Min(Bb
* 2 + 64, 255);
2383 if (Abs(Rw
- Rb
) < 32)
2384 or (Abs(Gw
- Gb
) < 32)
2385 or (Abs(Bw
- Bb
) < 32) then
2387 Rb
:= Max(Rw
div 2 - 16, 0);
2388 Gb
:= Max(Gw
div 2 - 16, 0);
2389 Bb
:= Max(Bw
div 2 - 16, 0);
2392 4: // custom textured bubble
2394 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID
) then
2395 if FDirection
= TDirection
.D_RIGHT
then
2396 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False)
2398 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False, TMirrorType
.Horizontal
);
2404 e_DrawQuad(bubX
+ 1, bubY
, bubX
+ 18, bubY
+ 13, Rb
, Gb
, Bb
);
2405 e_DrawQuad(bubX
, bubY
+ 1, bubX
+ 19, bubY
+ 12, Rb
, Gb
, Bb
);
2407 e_DrawFillQuad(bubX
+ 1, bubY
+ 1, bubX
+ 18, bubY
+ 12, Rw
, Gw
, Bw
, 0);
2410 Dot
:= IfThen(FDirection
= TDirection
.D_LEFT
, 14, 5);
2411 e_DrawLine(1, bubX
+ Dot
, bubY
+ 14, bubX
+ Dot
, bubY
+ 16, Rb
, Gb
, Bb
);
2412 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
);
2413 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
);
2414 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
);
2415 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
);
2419 e_DrawFillQuad(bubX
+ Dot
, bubY
+ 8, bubX
+ Dot
+ 1, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2420 e_DrawFillQuad(bubX
+ Dot
+ 3, bubY
+ 8, bubX
+ Dot
+ 4, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2421 e_DrawFillQuad(bubX
+ Dot
+ 6, bubY
+ 8, bubX
+ Dot
+ 7, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2424 procedure TPlayer
.Draw();
2429 Mirror
: TMirrorType
;
2433 if Direction
= TDirection
.D_RIGHT
then
2434 Mirror
:= TMirrorType
.None
2436 Mirror
:= TMirrorType
.Horizontal
;
2438 if FPunchAnim
<> nil then
2440 FPunchAnim
.Draw(FObj
.X
+IfThen(Direction
= TDirection
.D_LEFT
, 15-FObj
.Rect
.X
, FObj
.Rect
.X
-15),
2441 FObj
.Y
+FObj
.Rect
.Y
-11, Mirror
);
2442 if FPunchAnim
.played
then
2449 if (FMegaRulez
[MR_INVUL
] > gTime
) and (gPlayerDrawn
<> Self
) then
2450 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID
) then
2452 e_GetTextureSize(ID
, @w
, @h
);
2453 if FDirection
= TDirection
.D_LEFT
then
2454 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)+4,
2455 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False)
2457 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)-2,
2458 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False);
2461 if FMegaRulez
[MR_INVIS
] > gTime
then
2463 if (gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2464 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
))) then
2466 if (FMegaRulez
[MR_INVIS
] - gTime
) <= 2100 then
2467 dr
:= not Odd((FMegaRulez
[MR_INVIS
] - gTime
) div 300)
2471 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 200)
2473 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2476 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 254);
2479 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2482 if g_debug_Frames
then
2484 e_DrawQuad(FObj
.X
+FObj
.Rect
.X
,
2486 FObj
.X
+FObj
.Rect
.X
+FObj
.Rect
.Width
-1,
2487 FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-1,
2491 if (gChatBubble
> 0) and (FKeys
[KEY_CHAT
].Pressed
) and not FGhost
then
2493 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2494 if gAimLine
and alive
and
2495 ((Self
= gPlayer1
) or (Self
= gPlayer2
)) then
2500 procedure TPlayer
.DrawAim();
2501 procedure drawCast (sz
: Integer; ax0
, ay0
, ax1
, ay1
: Integer);
2506 {$IFDEF ENABLE_HOLMES}
2507 if isValidViewPort
and (self
= gPlayer1
) then
2509 g_Holmes_plrLaser(ax0
, ay0
, ax1
, ay1
);
2513 e_DrawLine(sz
, ax0
, ay0
, ax1
, ay1
, 255, 0, 0, 96);
2514 if (g_Map_traceToNearestWall(ax0
, ay0
, ax1
, ay1
, @ex
, @ey
) <> nil) then
2516 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 255, 0, 96);
2520 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 0, 255, 96);
2525 wx
, wy
, xx
, yy
: Integer;
2529 wx
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
+ IfThen(FDirection
= TDirection
.D_LEFT
, 7, -7);
2530 wy
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
2539 1: begin // Chainsaw
2546 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2547 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2548 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2549 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2554 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2555 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2556 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2557 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2559 4: begin // Double Shotgun
2562 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2563 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2564 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2565 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2567 5: begin // Chaingun
2570 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2571 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2572 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2573 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2575 6: begin // Rocket Launcher
2578 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 2);
2579 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2580 if angle
= ANGLE_LEFTUP
then Dec(angle
, 2);
2581 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2583 7: begin // Plasmagun
2586 if angle
= ANGLE_RIGHTUP
then Inc(angle
);
2587 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 3);
2588 if angle
= ANGLE_LEFTUP
then Dec(angle
);
2589 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 3);
2594 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 1);
2595 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 2);
2596 if angle
= ANGLE_LEFTUP
then Dec(angle
, 1);
2597 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 2);
2599 9: begin // Super Chaingun
2602 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2603 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2604 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2605 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2608 xx
:= Trunc(Cos(-DegToRad(angle
)) * len
) + wx
;
2609 yy
:= Trunc(Sin(-DegToRad(angle
)) * len
) + wy
;
2610 {$IF DEFINED(D2F_DEBUG)}
2611 drawCast(sz
, wx
, wy
, xx
, yy
);
2613 e_DrawLine(sz
, wx
, wy
, xx
, yy
, 255, 0, 0, 96);
2617 procedure TPlayer
.DrawGUI();
2620 X
, Y
, SY
, a
, p
, m
: Integer;
2624 stat
: TPlayerStatArray
;
2626 X
:= gPlayerScreenSize
.X
;
2627 SY
:= gPlayerScreenSize
.Y
;
2630 if gShowGoals
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2632 if gGameSettings
.GameMode
= GM_CTF
then
2636 if gGameSettings
.GameMode
= GM_CTF
then
2638 s
:= 'TEXTURE_PLAYER_REDFLAG';
2639 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2640 s
:= 'TEXTURE_PLAYER_REDFLAG_S';
2641 if gFlags
[FLAG_RED
].State
= FLAG_STATE_DROPPED
then
2642 s
:= 'TEXTURE_PLAYER_REDFLAG_D';
2643 if g_Texture_Get(s
, ID
) then
2644 e_Draw(ID
, X
-16-32, 240-72-4, 0, True, False);
2647 s
:= IntToStr(gTeamStat
[TEAM_RED
].Goals
);
2648 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2649 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-72-4, s
, TEAMCOLOR
[TEAM_RED
]);
2651 if gGameSettings
.GameMode
= GM_CTF
then
2653 s
:= 'TEXTURE_PLAYER_BLUEFLAG';
2654 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2655 s
:= 'TEXTURE_PLAYER_BLUEFLAG_S';
2656 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_DROPPED
then
2657 s
:= 'TEXTURE_PLAYER_BLUEFLAG_D';
2658 if g_Texture_Get(s
, ID
) then
2659 e_Draw(ID
, X
-16-32, 240-32-4, 0, True, False);
2662 s
:= IntToStr(gTeamStat
[TEAM_BLUE
].Goals
);
2663 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2664 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-32-4, s
, TEAMCOLOR
[TEAM_BLUE
]);
2667 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID
) then
2668 e_DrawFill(ID
, X
, 0, 1, (gPlayerScreenSize
.Y
div 256)+IfThen(gPlayerScreenSize
.Y
mod 256 > 0, 1, 0),
2671 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID
) then
2672 e_Draw(ID
, X
+2, Y
, 0, True, False);
2674 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
2678 s
:= IntToStr(Frags
);
2679 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2680 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, Y
, s
, _RGB(255, 0, 0));
2685 stat
:= g_Player_GetStats();
2690 for a
:= 0 to High(stat
) do
2691 if stat
[a
].Name
<> Name
then
2693 if stat
[a
].Frags
> m
then m
:= stat
[a
].Frags
;
2694 if stat
[a
].Frags
> Frags
then p
:= p
+1;
2698 s
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2699 if Frags
>= m
then s
:= s
+'+' else s
:= s
+'-';
2700 s
:= s
+IntToStr(Abs(Frags
-m
));
2702 e_CharFont_GetSize(gMenuSmallFont
, s
, tw
, th
);
2703 e_CharFont_PrintEx(gMenuSmallFont
, X
-16-tw
, Y
+32, s
, _RGB(255, 0, 0));
2706 if gShowLives
and (gGameSettings
.MaxLives
> 0) then
2708 s
:= IntToStr(Lives
);
2709 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2710 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, SY
-32, s
, _RGB(0, 255, 0));
2714 e_CharFont_GetSize(gMenuSmallFont
, FName
, tw
, th
);
2715 e_CharFont_PrintEx(gMenuSmallFont
, X
+98-(tw
div 2), Y
+8, FName
, _RGB(255, 0, 0));
2717 if R_BERSERK
in FRulez
then
2718 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_BLACK
], X
+37, Y
+45, 0, True, False)
2720 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_LARGE
], X
+37, Y
+45, 0, True, False);
2722 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID
) then
2723 e_Draw(ID
, X
+36, Y
+77, 0, True, False);
2725 s
:= IntToStr(IfThen(FHealth
> 0, FHealth
, 0));
2726 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2727 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+40, s
, _RGB(255, 0, 0));
2729 s
:= IntToStr(FArmor
);
2730 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2731 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+68, s
, _RGB(255, 0, 0));
2733 s
:= IntToStr(GetAmmoByWeapon(FCurrWeap
));
2739 ID
:= gItemsTexturesID
[ITEM_WEAPON_KASTET
];
2744 ID
:= gItemsTexturesID
[ITEM_WEAPON_SAW
];
2746 WEAPON_PISTOL
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PISTOL
];
2747 WEAPON_CHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
];
2748 WEAPON_SHOTGUN1
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
];
2749 WEAPON_SHOTGUN2
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
];
2750 WEAPON_SUPERPULEMET
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SUPERPULEMET
];
2751 WEAPON_ROCKETLAUNCHER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
];
2752 WEAPON_PLASMA
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PLASMA
];
2753 WEAPON_BFG
: ID
:= gItemsTexturesID
[ITEM_WEAPON_BFG
];
2754 WEAPON_FLAMETHROWER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_FLAMETHROWER
];
2757 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2758 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+158, s
, _RGB(255, 0, 0));
2759 e_Draw(ID
, X
+20, Y
+160, 0, True, False);
2761 if R_KEY_RED
in FRulez
then
2762 e_Draw(gItemsTexturesID
[ITEM_KEY_RED
], X
+78, Y
+214, 0, True, False);
2764 if R_KEY_GREEN
in FRulez
then
2765 e_Draw(gItemsTexturesID
[ITEM_KEY_GREEN
], X
+95, Y
+214, 0, True, False);
2767 if R_KEY_BLUE
in FRulez
then
2768 e_Draw(gItemsTexturesID
[ITEM_KEY_BLUE
], X
+112, Y
+214, 0, True, False);
2770 if FJetFuel
> 0 then
2772 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2773 e_Draw(ID
, X
+2, Y
+116, 0, True, False);
2774 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID
) then
2775 e_Draw(ID
, X
+2, Y
+126, 0, True, False);
2776 e_DrawLine(4, X
+16, Y
+122, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+122, 0, 0, 196);
2777 e_DrawLine(4, X
+16, Y
+132, X
+16+Trunc(168*FJetFuel
/JET_MAX
), Y
+132, 208, 0, 0);
2781 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2782 e_Draw(ID
, X
+2, Y
+124, 0, True, False);
2783 e_DrawLine(4, X
+16, Y
+130, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+130, 0, 0, 196);
2786 if gShowPing
and g_Game_IsClient
then
2788 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
2789 e_TextureFontPrint(X
+ 4, Y
+ 242, s
, gStdFont
);
2795 e_TextureFontPrint(X
+ 4, Y
+ 242, _lc
[I_PLAYER_SPECT
], gStdFont
);
2796 e_TextureFontPrint(X
+ 4, Y
+ 258, _lc
[I_PLAYER_SPECT2
], gStdFont
);
2797 e_TextureFontPrint(X
+ 4, Y
+ 274, _lc
[I_PLAYER_SPECT1
], gStdFont
);
2800 e_TextureFontGetSize(gStdFont
, cw
, ch
);
2801 s
:= _lc
[I_PLAYER_SPECT4
];
2802 e_TextureFontPrintEx(gScreenWidth
div 2 - cw
*(Length(s
) div 2),
2803 gScreenHeight
-4-ch
, s
, gStdFont
, 255, 255, 255, 1, True);
2804 e_TextureFontPrint(X
+ 4, Y
+ 290, _lc
[I_PLAYER_SPECT1S
], gStdFont
);
2810 procedure TPlayer
.DrawRulez();
2814 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2815 if FMegaRulez
[MR_INVUL
] >= gTime
then
2817 if (FMegaRulez
[MR_INVUL
]-gTime
) <= 2100 then
2818 dr
:= not Odd((FMegaRulez
[MR_INVUL
]-gTime
) div 300)
2823 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2824 191, 191, 191, 0, TBlending
.Invert
);
2827 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2828 if FMegaRulez
[MR_SUIT
] >= gTime
then
2830 if (FMegaRulez
[MR_SUIT
]-gTime
) <= 2100 then
2831 dr
:= not Odd((FMegaRulez
[MR_SUIT
]-gTime
) div 300)
2836 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2837 0, 96, 0, 200, TBlending
.None
);
2840 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2841 if (FBerserk
>= 0) and (LongWord(FBerserk
) >= gTime
) and (gFlash
= 2) then
2843 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2844 255, 0, 0, 200, TBlending
.None
);
2848 procedure TPlayer
.DrawPain();
2852 if FPain
= 0 then Exit
;
2856 if a
< 15 then h
:= 0
2857 else if a
< 35 then h
:= 1
2858 else if a
< 55 then h
:= 2
2859 else if a
< 75 then h
:= 3
2860 else if a
< 95 then h
:= 4
2863 //if a > 255 then a := 255;
2865 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 255, 0, 0, 255-h
*50);
2866 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2869 procedure TPlayer
.DrawPickup();
2873 if FPickup
= 0 then Exit
;
2877 if a
< 15 then h
:= 1
2878 else if a
< 35 then h
:= 2
2879 else if a
< 55 then h
:= 3
2880 else if a
< 75 then h
:= 4
2883 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 150, 200, 150, 255-h
*50);
2886 procedure TPlayer
.DoPunch();
2891 if FPunchAnim
<> nil then begin
2896 st
:= 'FRAMES_PUNCH';
2897 if R_BERSERK
in FRulez
then
2898 st
:= st
+ '_BERSERK';
2899 if FKeys
[KEY_UP
].Pressed
then
2901 else if FKeys
[KEY_DOWN
].Pressed
then
2903 g_Frames_Get(id
, st
);
2904 FPunchAnim
:= TAnimation
.Create(id
, False, 1);
2907 procedure TPlayer
.Fire();
2909 f
, DidFire
: Boolean;
2910 wx
, wy
, xd
, yd
: Integer;
2913 if g_Game_IsClient
then Exit
;
2914 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
2915 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
2923 if FReloading
[FCurrWeap
] <> 0 then Exit
;
2928 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
2929 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
2930 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
2931 yd
:= wy
+firediry();
2937 if R_BERSERK
in FRulez
then
2939 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2940 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
2941 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
2944 locobj
.rect
.Width
:= 39;
2945 locobj
.rect
.Height
:= 52;
2946 locobj
.Vel
.X
:= (xd
-wx
) div 2;
2947 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
2948 locobj
.Accel
.X
:= xd
-wx
;
2949 locobj
.Accel
.y
:= yd
-wy
;
2951 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
2952 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
2954 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
2956 if (gFlash
= 1) and (FPain
< 50) then FPain
:= min(FPain
+ 25, 50);
2960 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
2964 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2969 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
2970 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
2972 FSawSoundSelect
.Stop();
2974 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
2976 else if not FSawSoundHit
.IsPlaying() then
2978 FSawSoundSelect
.Stop();
2979 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
2982 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2988 if FAmmo
[A_BULLETS
] > 0 then
2990 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
2991 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2992 Dec(FAmmo
[A_BULLETS
]);
2993 FFireAngle
:= FAngle
;
2996 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2997 GameVelX
, GameVelY
-2, SHELL_BULLET
);
3001 if FAmmo
[A_SHELLS
] > 0 then
3003 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3004 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
3005 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3006 Dec(FAmmo
[A_SHELLS
]);
3007 FFireAngle
:= FAngle
;
3011 FShellType
:= SHELL_SHELL
;
3015 if FAmmo
[A_SHELLS
] >= 2 then
3017 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
3018 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3019 Dec(FAmmo
[A_SHELLS
], 2);
3020 FFireAngle
:= FAngle
;
3024 FShellType
:= SHELL_DBLSHELL
;
3028 if FAmmo
[A_BULLETS
] > 0 then
3030 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
3031 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
3032 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3033 Dec(FAmmo
[A_BULLETS
]);
3034 FFireAngle
:= FAngle
;
3037 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3038 GameVelX
, GameVelY
-2, SHELL_BULLET
);
3041 WEAPON_ROCKETLAUNCHER
:
3042 if FAmmo
[A_ROCKETS
] > 0 then
3044 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
3045 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3046 Dec(FAmmo
[A_ROCKETS
]);
3047 FFireAngle
:= FAngle
;
3053 if FAmmo
[A_CELLS
] > 0 then
3055 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
3056 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3057 Dec(FAmmo
[A_CELLS
]);
3058 FFireAngle
:= FAngle
;
3064 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
3066 FBFGFireCounter
:= 17;
3067 if not FNoReload
then
3068 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
3069 Dec(FAmmo
[A_CELLS
], 40);
3073 WEAPON_SUPERPULEMET
:
3074 if FAmmo
[A_SHELLS
] > 0 then
3076 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3077 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
3078 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3079 Dec(FAmmo
[A_SHELLS
]);
3080 FFireAngle
:= FAngle
;
3083 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3084 GameVelX
, GameVelY
-2, SHELL_SHELL
);
3087 WEAPON_FLAMETHROWER
:
3088 if FAmmo
[A_FUEL
] > 0 then
3090 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
3091 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3093 FFireAngle
:= FAngle
;
3099 if g_Game_IsNet
then
3103 if FCurrWeap
<> WEAPON_BFG
then
3104 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
3106 if not FNoReload
then
3107 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
3110 MH_SEND_PlayerStats(FUID
);
3115 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
3116 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
3117 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
3120 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
3123 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
3124 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
3125 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
3126 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
3127 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
3132 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
3134 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
3135 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
3136 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
3139 procedure TPlayer
.JetpackOn
;
3143 FJetSoundOn
.SetPosition(0);
3144 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3148 procedure TPlayer
.JetpackOff
;
3152 FJetSoundOff
.SetPosition(0);
3153 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3156 procedure TPlayer
.CatchFire(Attacker
: Word);
3159 FFireAttacker
:= Attacker
;
3160 if g_Game_IsNet
and g_Game_IsServer
then
3161 MH_SEND_PlayerStats(FUID
);
3164 procedure TPlayer
.Jump();
3166 if gFly
or FJetpack
then
3168 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
3169 if FObj
.Vel
.Y
> -VEL_FLY
then
3170 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
3173 if FJetFuel
> 0 then
3175 if (FJetFuel
< 1) and g_Game_IsServer
then
3179 if g_Game_IsNet
then
3180 MH_SEND_PlayerStats(FUID
);
3186 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
3188 FCanJetpack
:= False;
3190 // Ïðûãàåì èëè âñïëûâàåì:
3191 if (CollideLevel(0, 1) or
3192 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
3193 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
3194 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
3196 FObj
.Vel
.Y
:= -VEL_JUMP
;
3197 FCanJetpack
:= False;
3201 if BodyInLiquid(0, 0) then
3202 FObj
.Vel
.Y
:= -VEL_SW
3203 else if (FJetFuel
> 0) and FCanJetpack
and
3204 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
3208 if g_Game_IsNet
then
3209 MH_SEND_PlayerStats(FUID
);
3214 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
3216 a
, i
, k
, ab
, ar
: Byte;
3220 srv
, netsrv
: Boolean;
3226 procedure PushItem(t
: Byte);
3230 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
3231 it
:= g_Items_ByIdx(id
);
3232 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
3234 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
3235 (FObj
.Vel
.Y
div 2)-Random(9));
3236 it
.positionChanged(); // this updates spatial accelerators
3240 if KillType
= K_HARDKILL
then // -5..+5; -5..0
3242 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
3243 (FObj
.Vel
.Y
div 2)-Random(6));
3245 else // -3..+3; -3..0
3247 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
3248 (FObj
.Vel
.Y
div 2)-Random(4));
3250 it
.positionChanged(); // this updates spatial accelerators
3253 if g_Game_IsNet
and g_Game_IsServer
then
3254 MH_SEND_ItemSpawn(True, id
);
3258 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
3259 Srv
:= g_Game_IsServer
;
3260 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
3261 if Srv
then FDeath
:= FDeath
+ 1;
3266 if not FPhysics
then
3272 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3274 if FLives
> 0 then FLives
:= FLives
- 1;
3275 if FLives
= 0 then FNoRespawn
:= True;
3278 // Íîìåð òèïà ñìåðòè:
3281 K_SIMPLEKILL
: a
:= 1;
3283 K_EXTRAHARDKILL
: a
:= 3;
3288 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
3290 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
3297 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
3299 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
3300 K_EXTRAHARDKILL
, K_FALLKILL
:
3301 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
3304 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3308 K_HARDKILL
, K_EXTRAHARDKILL
:
3312 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3313 if (KillType
<> K_FALLKILL
) and (Srv
) then
3314 g_Monsters_killedp();
3316 if SpawnerUID
= FUID
then
3318 if Srv
and (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3323 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3326 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
3327 begin // Óáèò äðóãèì èãðîêîì
3328 KP
:= g_Player_Get(SpawnerUID
);
3329 if (KP
<> nil) and Srv
then
3331 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3332 if SameTeam(FUID
, SpawnerUID
) then
3342 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3343 Inc(gTeamStat
[KP
.Team
].Goals
,
3344 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3346 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3349 plr
:= g_Player_Get(SpawnerUID
);
3357 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3361 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3365 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3370 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3371 begin // Óáèò ìîíñòðîì
3372 mon
:= g_Monsters_ByUID(SpawnerUID
);
3376 s
:= g_Mons_GetKilledByTypeId(mon
.MonsterType
);
3380 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3384 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3388 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3393 else // Îñîáûå òèïû ñìåðòè
3396 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3397 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3398 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3399 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3400 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3401 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3407 for a
:= WP_FIRST
to WP_LAST
do
3411 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3412 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3413 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3414 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3415 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3416 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3417 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3418 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
3419 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
3428 if R_ITEM_BACKPACK
in FRulez
then
3429 PushItem(ITEM_AMMO_BACKPACK
);
3431 // Âûáðîñ ðàêåòíîãî ðàíöà:
3432 if FJetFuel
> 0 then
3433 PushItem(ITEM_JETPACK
);
3436 if not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
3438 if R_KEY_RED
in FRulez
then
3439 PushItem(ITEM_KEY_RED
);
3441 if R_KEY_GREEN
in FRulez
then
3442 PushItem(ITEM_KEY_GREEN
);
3444 if R_KEY_BLUE
in FRulez
then
3445 PushItem(ITEM_KEY_BLUE
);
3452 g_Player_CreateCorpse(Self
);
3454 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3455 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3461 for i
:= Low(gPlayers
) to High(gPlayers
) do
3463 if gPlayers
[i
] = nil then continue
;
3464 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3467 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3468 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3473 OldLR
:= gLMSRespawn
;
3474 if (gGameSettings
.GameMode
= GM_COOP
) then
3478 // everyone is dead, restart the map
3479 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3481 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3482 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3483 gLMSRespawnTime
:= gTime
+ 5000;
3485 else if (a
= 1) then
3487 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3488 if (gPlayers
[k
] = gPlayer1
) or
3489 (gPlayers
[k
] = gPlayer2
) then
3490 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3491 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3492 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3495 else if (gGameSettings
.GameMode
= GM_TDM
) then
3497 if (ab
= 0) and (ar
<> 0) then
3500 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3502 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3503 Inc(gTeamStat
[TEAM_RED
].Goals
);
3504 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3505 gLMSRespawnTime
:= gTime
+ 5000;
3507 else if (ar
= 0) and (ab
<> 0) then
3510 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3512 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3513 Inc(gTeamStat
[TEAM_BLUE
].Goals
);
3514 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3515 gLMSRespawnTime
:= gTime
+ 5000;
3517 else if (ar
= 0) and (ab
= 0) then
3520 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3522 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3523 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3524 gLMSRespawnTime
:= gTime
+ 5000;
3527 else if (gGameSettings
.GameMode
= GM_DM
) then
3531 if gPlayers
[k
] <> nil then
3534 // survivor is the winner
3535 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3537 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3540 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3541 gLMSRespawnTime
:= gTime
+ 5000;
3543 else if (a
= 0) then
3545 // everyone is dead, restart the map
3546 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3548 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3549 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3550 gLMSRespawnTime
:= gTime
+ 5000;
3553 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3555 if NetMode
= NET_SERVER
then
3556 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
3558 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3564 MH_SEND_PlayerStats(FUID
);
3565 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3566 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3569 if srv
and FNoRespawn
then Spectate(True);
3570 FWantsInGame
:= True;
3573 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3575 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3576 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3579 function TPlayer
.BodyInAcid(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_ACID1
or PANEL_ACID2
, False);
3585 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3587 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3588 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3589 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3590 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3591 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3592 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3593 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3594 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3597 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3599 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3600 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3601 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3602 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3605 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3607 //if g_Game_IsClient then Exit;
3608 if Weapon
> High(FWeapon
) then Exit
;
3609 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3612 procedure TPlayer
.resetWeaponQueue ();
3615 FNextWeapDelay
:= 0;
3618 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3622 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3623 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_SHELLS
] > 0);
3624 WEAPON_PISTOL
, WEAPON_CHAINGUN
: result
:= (FAmmo
[A_BULLETS
] > 0);
3625 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3626 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3627 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3628 else result
:= (weapon
< length(FWeapon
));
3632 // return 255 for "no switch"
3633 function TPlayer
.getNextWeaponIndex (): Byte;
3636 wantThisWeapon
: array[0..64] of Boolean;
3637 weaponOrder
: array[0..16] of Integer; // value: index in `FWeapon`
3639 f
, dir
, cwi
, rwidx
, curlidx
: Integer;
3641 function real2log (ridx
: Integer): Integer;
3647 for f
:= 0 to High(weaponOrder
) do if (weaponOrder
[f
] = ridx
) then begin result
:= f
; exit
; end;
3653 result
:= 255; // default result: "no switch"
3655 // had weapon cycling on previous frame? remove that flag
3656 if (FNextWeap
and $2000) <> 0 then
3658 FNextWeap
:= FNextWeap
and $1FFF;
3659 FNextWeapDelay
:= 0;
3662 for f
:= 0 to High(weaponOrder
) do weaponOrder
[f
] := -1;
3664 // build weapon order (k8: i know, i know, learn how to do constants and such... gtfo, please!)
3665 // two knuckles are for "normal" and "berserk" (see `if` below -- it removes the one that is not needed)
3667 // bfg, launcher, plasma, flamethrower, ssg, minigun, sg, pistol, berserk, chainsaw, fist
3668 weaponOrder
[0] := WEAPON_SUPERPULEMET
;
3669 weaponOrder
[1] := WEAPON_BFG
;
3670 weaponOrder
[2] := WEAPON_ROCKETLAUNCHER
;
3671 weaponOrder
[3] := WEAPON_PLASMA
;
3672 weaponOrder
[4] := WEAPON_FLAMETHROWER
;
3673 weaponOrder
[5] := WEAPON_SHOTGUN2
;
3674 weaponOrder
[6] := WEAPON_CHAINGUN
;
3675 weaponOrder
[7] := WEAPON_SHOTGUN1
;
3676 weaponOrder
[8] := WEAPON_PISTOL
;
3677 weaponOrder
[9] := WEAPON_KASTET
+666; // berserk fist
3678 weaponOrder
[10] := WEAPON_SAW
;
3679 weaponOrder
[11] := WEAPON_KASTET
; // normal fist
3681 for f
:= 0 to High(weaponOrder
) do
3683 if (weaponOrder
[f
] = WEAPON_KASTET
) then
3685 // normal fist: remove if we have a berserk pack
3686 if (R_BERSERK
in FRulez
) then weaponOrder
[f
] := -1;
3689 if (weaponOrder
[f
] = WEAPON_KASTET
+666) then
3691 // berserk fist: remove if we don't have a berserk pack
3692 if (R_BERSERK
in FRulez
) then weaponOrder
[f
] := WEAPON_KASTET
else weaponOrder
[f
] := -1;
3700 WEAPON_SHOTGUN1 = 3;
3701 WEAPON_SHOTGUN2 = 4;
3702 WEAPON_CHAINGUN = 5;
3703 WEAPON_ROCKETLAUNCHER = 6;
3706 WEAPON_SUPERPULEMET = 9;
3707 WEAPON_FLAMETHROWER = 10;
3710 // cycling has priority
3711 if (FNextWeap
and $C000) <> 0 then
3713 if (FNextWeap
and $8000) <> 0 then dir
:= 1 else dir
:= -1; // should be reversed if we want "priority-driven cycling"
3714 FNextWeap
:= FNextWeap
or $2000; // we need this
3715 if FNextWeapDelay
> 0 then exit
; // cooldown time
3716 //cwi := real2log(FCurrWeap);
3717 //if (cwi < 0) then cwi := 0;
3719 for i
:= 0 to High(FWeapon
) do
3721 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3722 //rwidx := weaponOrder[cwi];
3723 rwidx
:= cwi
; // sorry
3724 if (rwidx
< 0) then continue
;
3725 if FWeapon
[rwidx
] then
3727 //e_WriteLog(Format(' SWITCH: cur=%d; new=%d (dir=%d; log=%d)', [FCurrWeap, rwidx, dir, cwi]), TMsgType.Warning);
3728 result
:= Byte(rwidx
);
3729 //FNextWeapDelay := 10; //k8: not needed anymore
3738 for i
:= 0 to High(wantThisWeapon
) do wantThisWeapon
[i
] := false;
3741 curlidx
:= -1; // start from a weapon with a highest priority (-1, 'cause loop will immediately increment this index)
3743 for i
:= 0 to High(FWeapon
) do
3745 if (FNextWeap
and (1 shl i
)) <> 0 then
3750 wantThisWeapon
[cwi
] := true;
3752 // if we hit currently selected weapon, start seachring from it, so we'll get "next weaker" weapon
3753 if (i
= FCurrWeap
) then curlidx
:= cwi
; // compare real, start from logical
3758 // slow down alterations a little
3761 // more than one weapon requested, assume "alteration", and check alteration delay
3762 if FNextWeapDelay
> 0 then
3764 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), TMsgType.Warning);
3770 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3771 // but clear all counters if no weapon should be switched
3778 //e_WriteLog(Format('*** wwc=%d; currweap=%d; logweap=%d', [wwc, FCurrWeap, curlidx]), TMsgType.Warning);
3780 // find next weapon to switch onto
3782 for i
:= 0 to High(weaponOrder
) do
3784 cwi
:= (cwi
+length(weaponOrder
)+1) mod length(weaponOrder
);
3785 if (cwi
= curlidx
) then continue
; // skip current weapon
3786 if not wantThisWeapon
[cwi
] then continue
;
3787 rwidx
:= weaponOrder
[cwi
];
3788 if (rwidx
< 0) then continue
;
3789 //e_WriteLog(Format(' trying logical %d (real %d); has=%d, hasammo=%d', [cwi, rwidx, Integer(FWeapon[rwidx]), Integer(hasAmmoForWeapon(rwidx))]), TMsgType.Warning);
3790 if FWeapon
[rwidx
] and ((wwc
= 1) or hasAmmoForWeapon(rwidx
)) then
3792 //e_WriteLog(' I FOUND HER!', TMsgType.Warning);
3794 result
:= Byte(rwidx
);
3796 //FNextWeapDelay := 10; // anyway, 'cause why not; k8: not needed anymore
3801 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3805 procedure TPlayer
.RealizeCurrentWeapon();
3806 function switchAllowed (): Boolean;
3811 if FBFGFireCounter
<> -1 then
3813 if FTime
[T_SWITCH
] > gTime
then
3815 for i
:= WP_FIRST
to WP_LAST
do
3816 if FReloading
[i
] > 0 then
3824 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3825 //FNextWeap := FNextWeap and $1FFF;
3826 //HACK: alteration delay will be reset when player released any weapon switch key
3827 FNextWeapDelay
:= 0; //k8: just in case
3828 //if FNextWeapDelay > 0 then Dec(FNextWeapDelay); // "alteration delay"
3830 if not switchAllowed
then
3832 //HACK for weapon cycling
3833 if (FNextWeap
and $E000) <> 0 then FNextWeap
:= 0;
3837 nw
:= getNextWeaponIndex();
3838 if nw
= 255 then exit
; // don't reset anything here
3839 if nw
> High(FWeapon
) then
3841 // don't forget to reset queue here!
3842 //e_WriteLog(Format(' RealizeCurrentWeapon: WUTAFUUUU?! (%d)', [nw]), TMsgType.Warning);
3849 //k8: emulate this on client immediately, or wait for server confirmation?
3851 if g_Game_IsClient then
3853 FNetForceWeap := nw;
3854 //FNetForceWeapFIdx := FCurrFrameIdx+5; // force for ~5 frames
3855 FNetForceWeapFIdx := gTime+5; // force for ~5 frames
3856 writeln('NETWEAPONSWITCH: fw=', NetForceWeap, '; fwfidx=', NetForceWeapFIdx, '; cfrm=', gTime);
3859 FNetForceWeapFIdx
:= gTime
+5; // force for ~5 frames
3861 if nw
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3862 FModel
.SetWeapon(nw
);
3863 FTime
[T_SWITCH
] := gTime
+156;
3864 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3865 //if g_Game_IsNet and g_Game_IsClient then
3869 procedure TPlayer
.NextWeapon();
3871 //if g_Game_IsClient then Exit;
3875 procedure TPlayer
.PrevWeapon();
3877 //if g_Game_IsClient then Exit;
3881 // used by network layer
3882 procedure TPlayer
.SetWeapon(W
: Byte);
3884 if FCurrWeap
<> W
then
3885 if (W
= WEAPON_SAW
) then
3886 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3889 FModel
.SetWeapon(CurrWeap
);
3890 //if g_Game_IsClient then resetWeaponQueue();
3893 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
3895 function allowBerserkSwitching (): Boolean;
3897 if (FBFGFireCounter
<> -1) then begin result
:= false; exit
; end;
3899 if gBerserkAutoswitch
then exit
;
3900 if not conIsCheatsEnabled
then exit
;
3908 if g_Game_IsClient
then Exit
;
3910 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3911 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
3916 if FHealth
< PLAYER_HP_SOFT
then
3918 IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3922 if gFlash
= 2 then Inc(FPickup
, 5);
3926 if FHealth
< PLAYER_HP_SOFT
then
3928 IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3932 if gFlash
= 2 then Inc(FPickup
, 5);
3936 if FArmor
< PLAYER_AP_SOFT
then
3938 FArmor
:= PLAYER_AP_SOFT
;
3941 if gFlash
= 2 then Inc(FPickup
, 5);
3945 if FArmor
< PLAYER_AP_LIMIT
then
3947 FArmor
:= PLAYER_AP_LIMIT
;
3950 if gFlash
= 2 then Inc(FPickup
, 5);
3954 if FHealth
< PLAYER_HP_LIMIT
then
3956 IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3960 if gFlash
= 2 then Inc(FPickup
, 5);
3964 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
3966 if FHealth
< PLAYER_HP_LIMIT
then
3967 FHealth
:= PLAYER_HP_LIMIT
;
3968 if FArmor
< PLAYER_AP_LIMIT
then
3969 FArmor
:= PLAYER_AP_LIMIT
;
3973 if gFlash
= 2 then Inc(FPickup
, 5);
3977 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3979 FWeapon
[WEAPON_SAW
] := True;
3981 if gFlash
= 2 then Inc(FPickup
, 5);
3982 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3985 ITEM_WEAPON_SHOTGUN1
:
3986 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3988 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
3989 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3991 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3992 FWeapon
[WEAPON_SHOTGUN1
] := True;
3994 if gFlash
= 2 then Inc(FPickup
, 5);
3995 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3998 ITEM_WEAPON_SHOTGUN2
:
3999 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
4001 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
4003 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4004 FWeapon
[WEAPON_SHOTGUN2
] := True;
4006 if gFlash
= 2 then Inc(FPickup
, 5);
4007 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4010 ITEM_WEAPON_CHAINGUN
:
4011 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
4013 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
4015 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4016 FWeapon
[WEAPON_CHAINGUN
] := True;
4018 if gFlash
= 2 then Inc(FPickup
, 5);
4019 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4022 ITEM_WEAPON_ROCKETLAUNCHER
:
4023 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
4025 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
4027 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
4028 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
4030 if gFlash
= 2 then Inc(FPickup
, 5);
4031 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4035 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
4037 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
4039 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4040 FWeapon
[WEAPON_PLASMA
] := True;
4042 if gFlash
= 2 then Inc(FPickup
, 5);
4043 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4047 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
4049 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
4051 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4052 FWeapon
[WEAPON_BFG
] := True;
4054 if gFlash
= 2 then Inc(FPickup
, 5);
4055 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4058 ITEM_WEAPON_SUPERPULEMET
:
4059 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
4061 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
4063 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4064 FWeapon
[WEAPON_SUPERPULEMET
] := True;
4066 if gFlash
= 2 then Inc(FPickup
, 5);
4067 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4070 ITEM_WEAPON_FLAMETHROWER
:
4071 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
4073 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
4075 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4076 FWeapon
[WEAPON_FLAMETHROWER
] := True;
4078 if gFlash
= 2 then Inc(FPickup
, 5);
4079 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4083 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4085 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4088 if gFlash
= 2 then Inc(FPickup
, 5);
4091 ITEM_AMMO_BULLETS_BOX
:
4092 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4094 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4097 if gFlash
= 2 then Inc(FPickup
, 5);
4101 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4103 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4106 if gFlash
= 2 then Inc(FPickup
, 5);
4109 ITEM_AMMO_SHELLS_BOX
:
4110 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4112 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
4115 if gFlash
= 2 then Inc(FPickup
, 5);
4119 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4121 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4124 if gFlash
= 2 then Inc(FPickup
, 5);
4127 ITEM_AMMO_ROCKET_BOX
:
4128 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4130 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
4133 if gFlash
= 2 then Inc(FPickup
, 5);
4137 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4139 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4142 if gFlash
= 2 then Inc(FPickup
, 5);
4146 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4148 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
4151 if gFlash
= 2 then Inc(FPickup
, 5);
4155 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4157 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4160 if gFlash
= 2 then Inc(FPickup
, 5);
4164 if not(R_ITEM_BACKPACK
in FRulez
) or
4165 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
4166 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
4167 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
4168 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
4169 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
4171 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
4172 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
4173 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
4174 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
4175 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
4177 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4178 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4179 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4180 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4181 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4182 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4183 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4184 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4186 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
4189 if gFlash
= 2 then Inc(FPickup
, 5);
4193 if not(R_KEY_RED
in FRulez
) then
4195 Include(FRulez
, R_KEY_RED
);
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_GREEN
in FRulez
) then
4205 Include(FRulez
, R_KEY_GREEN
);
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 not(R_KEY_BLUE
in FRulez
) then
4215 Include(FRulez
, R_KEY_BLUE
);
4217 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4218 if gFlash
= 2 then Inc(FPickup
, 5);
4219 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4223 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
4225 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
4229 if gFlash
= 2 then Inc(FPickup
, 5);
4233 if FAir
< AIR_MAX
then
4238 if gFlash
= 2 then Inc(FPickup
, 5);
4243 if not (R_BERSERK
in FRulez
) then
4245 Include(FRulez
, R_BERSERK
);
4246 if allowBerserkSwitching
then
4248 FCurrWeap
:= WEAPON_KASTET
;
4249 //FNetForceWeap := FCurrWeap;
4251 FModel
.SetWeapon(WEAPON_KASTET
);
4256 if gFlash
= 2 then Inc(FPickup
, 5);
4258 FBerserk
:= gTime
+30000;
4262 //k8:do we need it? if g_Game_IsNet and g_Game_IsServer then MH_SEND_PlayerStats(FUID);
4264 if FHealth
< PLAYER_HP_SOFT
then
4266 FHealth
:= PLAYER_HP_SOFT
;
4267 FBerserk
:= gTime
+30000;
4275 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
4277 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
4280 if gFlash
= 2 then Inc(FPickup
, 5);
4284 if FHealth
< PLAYER_HP_LIMIT
then
4286 IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
4290 if gFlash
= 2 then Inc(FPickup
, 5);
4294 if FArmor
< PLAYER_AP_LIMIT
then
4296 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
4299 if gFlash
= 2 then Inc(FPickup
, 5);
4303 if FJetFuel
< JET_MAX
then
4305 FJetFuel
:= JET_MAX
;
4308 if gFlash
= 2 then Inc(FPickup
, 5);
4312 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
4314 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
4317 if gFlash
= 2 then Inc(FPickup
, 5);
4322 procedure TPlayer
.Touch();
4326 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4329 // Áðîñèòü ôëàã òîâàðèùó:
4330 if gGameSettings
.GameMode
= GM_CTF
then
4335 procedure TPlayer
.Push(vx
, vy
: Integer);
4337 if (not FPhysics
) and FGhost
then
4339 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
4340 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
4341 if g_Game_IsNet
and g_Game_IsServer
then
4342 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4345 procedure TPlayer
.Reset(Force
: Boolean);
4351 FTime
[T_RESPAWN
] := 0;
4352 FTime
[T_FLAGCAP
] := 0;
4363 //FCurrFrameIdx := 0;
4364 //FNetForceWeap := FCurrWeap;
4365 //FNetForceWeapFIdx := 0;
4368 FSpectator
:= False;
4371 FSpectatePlayer
:= -1;
4372 FNoRespawn
:= False;
4374 FLives
:= gGameSettings
.MaxLives
;
4379 procedure TPlayer
.SoftReset();
4385 FBFGFireCounter
:= -1;
4393 SetAction(A_STAND
, True);
4396 function TPlayer
.GetRespawnPoint(): Byte;
4401 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4403 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4404 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
4406 if (Self
= gPlayer1
) or (Self
= gPlayer2
) then
4408 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
4409 if Self
= gPlayer1
then
4410 c
:= RESPAWNPOINT_PLAYER1
4412 c
:= RESPAWNPOINT_PLAYER2
;
4413 if g_Map_GetPointCount(c
) > 0 then
4419 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
4420 if Self
= gPlayer1
then
4421 c
:= RESPAWNPOINT_PLAYER2
4423 c
:= RESPAWNPOINT_PLAYER1
;
4424 if g_Map_GetPointCount(c
) > 0 then
4431 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
4432 if Random(2) = 0 then
4433 c
:= RESPAWNPOINT_PLAYER1
4435 c
:= RESPAWNPOINT_PLAYER2
;
4436 if g_Map_GetPointCount(c
) > 0 then
4443 // Òî÷êà ëþáîé èç êîìàíä
4444 if Random(2) = 0 then
4445 c
:= RESPAWNPOINT_RED
4447 c
:= RESPAWNPOINT_BLUE
;
4448 if g_Map_GetPointCount(c
) > 0 then
4455 c
:= RESPAWNPOINT_DM
;
4456 if g_Map_GetPointCount(c
) > 0 then
4464 if gGameSettings
.GameMode
= GM_DM
then
4467 c
:= RESPAWNPOINT_DM
;
4468 if g_Map_GetPointCount(c
) > 0 then
4474 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4475 if Random(2) = 0 then
4476 c
:= RESPAWNPOINT_PLAYER1
4478 c
:= RESPAWNPOINT_PLAYER2
;
4479 if g_Map_GetPointCount(c
) > 0 then
4485 // Òî÷êà ëþáîé èç êîìàíä
4486 if Random(2) = 0 then
4487 c
:= RESPAWNPOINT_RED
4489 c
:= RESPAWNPOINT_BLUE
;
4490 if g_Map_GetPointCount(c
) > 0 then
4498 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4500 // Òî÷êà ñâîåé êîìàíäû
4501 c
:= RESPAWNPOINT_DM
;
4502 if FTeam
= TEAM_RED
then
4503 c
:= RESPAWNPOINT_RED
;
4504 if FTeam
= TEAM_BLUE
then
4505 c
:= RESPAWNPOINT_BLUE
;
4506 if g_Map_GetPointCount(c
) > 0 then
4513 c
:= RESPAWNPOINT_DM
;
4514 if g_Map_GetPointCount(c
) > 0 then
4520 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4521 if Random(2) = 0 then
4522 c
:= RESPAWNPOINT_PLAYER1
4524 c
:= RESPAWNPOINT_PLAYER2
;
4525 if g_Map_GetPointCount(c
) > 0 then
4531 // Òî÷êà äðóãîé êîìàíäû
4532 c
:= RESPAWNPOINT_DM
;
4533 if FTeam
= TEAM_RED
then
4534 c
:= RESPAWNPOINT_BLUE
;
4535 if FTeam
= TEAM_BLUE
then
4536 c
:= RESPAWNPOINT_RED
;
4537 if g_Map_GetPointCount(c
) > 0 then
4545 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4547 RespawnPoint
: TRespawnPoint
;
4553 FBFGFireCounter
:= -1;
4557 //FNetForceWeap := FCurrWeap;
4559 if not g_Game_IsServer
then
4563 FWantsInGame
:= True;
4564 FJustTeleported
:= True;
4567 FTime
[T_RESPAWN
] := 0;
4571 // if server changes MaxLives we gotta be ready
4572 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4574 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4575 if FTime
[T_RESPAWN
] > gTime
then
4578 // Ïðîñðàë âñå æèçíè:
4581 if not FSpectator
then Spectate(True);
4582 FWantsInGame
:= True;
4586 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4587 begin // "Ñâîÿ èãðà"
4588 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4589 FRulez
:= FRulez
-[R_BERSERK
];
4591 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4593 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4594 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4597 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4598 c
:= GetRespawnPoint();
4603 // Âîñêðåøåíèå áåç îðóæèÿ:
4606 FHealth
:= PLAYER_HP_SOFT
;
4612 for a
:= WP_FIRST
to WP_LAST
do
4614 FWeapon
[a
] := False;
4618 FWeapon
[WEAPON_PISTOL
] := True;
4619 FWeapon
[WEAPON_KASTET
] := True;
4620 FCurrWeap
:= WEAPON_PISTOL
;
4621 //FNetForceWeap := FCurrWeap;
4624 FModel
.SetWeapon(FCurrWeap
);
4626 for b
:= A_BULLETS
to A_HIGH
do
4629 FAmmo
[A_BULLETS
] := 50;
4631 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
4632 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
4633 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
4634 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
4635 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
4637 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
4638 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4643 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4644 if not g_Map_GetPoint(c
, RespawnPoint
) then
4646 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4650 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4651 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4652 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4658 FDirection
:= RespawnPoint
.Direction
;
4659 if FDirection
= TDirection
.D_LEFT
then
4664 SetAction(A_STAND
, True);
4665 FModel
.Direction
:= FDirection
;
4667 for a
:= Low(FTime
) to High(FTime
) do
4670 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4675 FCanJetpack
:= False;
4680 // Àíèìàöèÿ âîçðîæäåíèÿ:
4681 if (not gLoadGameMode
) and (not Silent
) then
4682 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4684 Anim
:= TAnimation
.Create(ID
, False, 3);
4685 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4686 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4690 FSpectator
:= False;
4693 FSpectatePlayer
:= -1;
4696 if (gPlayer1
= nil) and (gLMSPID1
= FUID
) then
4698 if (gPlayer2
= nil) and (gLMSPID2
= FUID
) then
4701 //FNetForceWeap := FCurrWeap;
4703 if g_Game_IsNet
then
4705 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4706 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4708 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4709 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4714 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4717 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4718 else if (not NoMove
) then
4720 GameX
:= gMapInfo
.Width
div 2;
4721 GameY
:= gMapInfo
.Height
div 2;
4730 FWantsInGame
:= False;
4735 if Self
= gPlayer1
then
4740 if Self
= gPlayer2
then
4747 if g_Game_IsNet
then
4748 MH_SEND_PlayerStats(FUID
);
4751 procedure TPlayer
.SwitchNoClip
;
4755 FGhost
:= not FGhost
;
4756 FPhysics
:= not FGhost
;
4768 procedure TPlayer
.Run(Direction
: TDirection
);
4772 if MAX_RUNVEL
> 8 then
4776 if Direction
= TDirection
.D_LEFT
then
4778 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4779 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4782 if FObj
.Vel
.X
< MAX_RUNVEL
then
4783 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4785 // Âîçìîæíî, ïèíàåì êóñêè:
4786 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4788 b
:= Abs(FObj
.Vel
.X
);
4789 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4790 for a
:= 0 to High(gGibs
) do
4792 if gGibs
[a
].alive
and
4793 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4794 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4797 if FObj
.Vel
.X
< 0 then
4799 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4803 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4805 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4813 procedure TPlayer
.SeeDown();
4815 SetAction(A_SEEDOWN
);
4817 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4819 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4822 procedure TPlayer
.SeeUp();
4826 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4828 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4831 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4839 A_ATTACK
: Prior
:= 2;
4840 A_SEEUP
: Prior
:= 1;
4841 A_SEEDOWN
: Prior
:= 1;
4842 A_ATTACKUP
: Prior
:= 2;
4843 A_ATTACKDOWN
: Prior
:= 2;
4848 if (Prior
> FActionPrior
) or Force
then
4849 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4851 FActionPrior
:= Prior
;
4852 FActionAnim
:= Action
;
4853 FActionForce
:= Force
;
4854 FActionChanged
:= True;
4857 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4860 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4862 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4863 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4864 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4865 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4868 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4875 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4877 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4878 if g_Game_IsServer
and g_Game_IsNet
then
4879 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4883 FJustTeleported
:= True;
4888 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4890 Anim
:= TAnimation
.Create(ID
, False, 3);
4893 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4894 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4895 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4896 if g_Game_IsServer
and g_Game_IsNet
then
4897 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4898 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4902 FObj
.X
:= X
-PLAYER_RECT
.X
;
4903 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4904 if FAlive
and FGhost
then
4910 if not g_Game_IsNet
then
4914 SetDirection(TDirection
.D_LEFT
);
4920 SetDirection(TDirection
.D_RIGHT
);
4926 if FDirection
= TDirection
.D_RIGHT
then
4928 SetDirection(TDirection
.D_LEFT
);
4933 SetDirection(TDirection
.D_RIGHT
);
4939 if not silent
and (Anim
<> nil) then
4941 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4942 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4945 if g_Game_IsServer
and g_Game_IsNet
then
4946 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4947 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4954 function nonz(a
: Single): Single;
4962 function TPlayer
.followCorpse(): Boolean;
4967 if FAlive
or FSpectator
then
4969 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
4971 for i
:= 0 to High(gCorpses
) do
4972 if gCorpses
[i
] <> nil then
4973 if gCorpses
[i
].FPlayerUID
= FUID
then
4976 FObj
.X
:= gCorpses
[i
].FObj
.X
;
4977 FObj
.Y
:= gCorpses
[i
].FObj
.Y
;
4978 FObj
.Vel
.X
:= gCorpses
[i
].FObj
.Vel
.X
;
4979 FObj
.Vel
.Y
:= gCorpses
[i
].FObj
.Vel
.Y
;
4980 FObj
.Accel
.X
:= gCorpses
[i
].FObj
.Accel
.X
;
4981 FObj
.Accel
.Y
:= gCorpses
[i
].FObj
.Accel
.Y
;
4986 procedure TPlayer
.Update();
4989 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
4990 blockmon
, headwater
, dospawn
: Boolean;
4995 //Inc(FCurrFrameIdx);
4997 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
4998 AnyServer
:= g_Game_IsServer
;
5000 if g_Game_IsClient
and (NetInterpLevel
> 0) then
5001 DoLerp(NetInterpLevel
+ 1)
5008 if FClientID
>= 0 then
5010 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
5011 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
5012 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
5022 if FAlive
and (FPunchAnim
<> nil) then
5023 FPunchAnim
.Update();
5025 if FAlive
and (gFly
or FJetpack
) then
5028 if FDirection
= TDirection
.D_LEFT
then
5033 if FAlive
and (not FGhost
) then
5035 if FKeys
[KEY_UP
].Pressed
then
5037 if FKeys
[KEY_DOWN
].Pressed
then
5041 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
5044 i
:= g_basic
.Sign(FIncCam
);
5045 FIncCam
:= Abs(FIncCam
);
5046 DecMin(FIncCam
, 5, 0);
5047 FIncCam
:= FIncCam
*i
;
5050 // no need to do that each second frame, weapon queue will take care of it
5051 if FAlive
and FKeys
[KEY_NEXTWEAPON
].Pressed
{and AnyServer} then NextWeapon();
5052 if FAlive
and FKeys
[KEY_PREVWEAPON
].Pressed
{and AnyServer} then PrevWeapon();
5054 if gTime
mod (GAME_TICK
*2) <> 0 then
5056 if (FObj
.Vel
.X
= 0) and FAlive
then
5058 if FKeys
[KEY_LEFT
].Pressed
then
5059 Run(TDirection
.D_LEFT
);
5060 if FKeys
[KEY_RIGHT
].Pressed
then
5061 Run(TDirection
.D_RIGHT
);
5066 if not followCorpse() then
5067 g_Obj_Move(@FObj
, True, True, True);
5068 positionChanged(); // this updates spatial accelerators
5074 FActionChanged
:= False;
5078 // Let alive player do some actions
5079 if FKeys
[KEY_LEFT
].Pressed
then Run(TDirection
.D_LEFT
);
5080 if FKeys
[KEY_RIGHT
].Pressed
then Run(TDirection
.D_RIGHT
);
5081 //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
5082 //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
5083 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire();
5084 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
5085 if FKeys
[KEY_JUMP
].Pressed
then Jump()
5088 if AnyServer
and FJetpack
then
5092 if NetServer
then MH_SEND_PlayerStats(FUID
);
5094 FCanJetpack
:= True;
5101 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
5103 if FKeys
[k
].Pressed
then
5111 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5114 if (FTime
[T_RESPAWN
] <= gTime
) and
5115 gGameOn
and (not FAlive
) then
5117 if (g_Player_GetCount() > 1) then
5121 gExit
:= EXIT_RESTART
;
5126 // Dead spectator actions
5129 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
5130 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
5134 if (FSpectatePlayer
>= High(gPlayers
)) then
5135 FSpectatePlayer
:= -1
5139 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
5140 if gPlayers
[I
] <> nil then
5141 if gPlayers
[I
].alive
then
5142 if gPlayers
[I
].UID
<> FUID
then
5144 FSpectatePlayer
:= I
;
5149 if not SetSpect
then FSpectatePlayer
:= -1;
5160 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
5162 FYTo
:= FObj
.Y
- 32;
5163 FSpectatePlayer
:= -1;
5165 if FKeys
[KEY_DOWN
].Pressed
then
5167 FYTo
:= FObj
.Y
+ 32;
5168 FSpectatePlayer
:= -1;
5170 if FKeys
[KEY_LEFT
].Pressed
then
5172 FXTo
:= FObj
.X
- 32;
5173 FSpectatePlayer
:= -1;
5175 if FKeys
[KEY_RIGHT
].Pressed
then
5177 FXTo
:= FObj
.X
+ 32;
5178 FSpectatePlayer
:= -1;
5181 if (FXTo
< -64) then
5183 else if (FXTo
> gMapInfo
.Width
+ 32) then
5184 FXTo
:= gMapInfo
.Width
+ 32;
5185 if (FYTo
< -72) then
5187 else if (FYTo
> gMapInfo
.Height
+ 32) then
5188 FYTo
:= gMapInfo
.Height
+ 32;
5193 if not followCorpse() then
5194 g_Obj_Move(@FObj
, True, True, True);
5195 positionChanged(); // this updates spatial accelerators
5202 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
5203 if gPlayers
[FSpectatePlayer
] <> nil then
5204 if gPlayers
[FSpectatePlayer
].alive
then
5206 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
5207 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
5211 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
5212 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
5213 PANEL_BLOCKMON
, True);
5214 headwater
:= HeadInLiquid(0, 0);
5216 // Ñîïðîòèâëåíèå âîçäóõà:
5217 if (not FAlive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
5218 if FObj
.Vel
.X
<> 0 then
5219 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5221 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
5222 DecMin(FPain
, 5, 0);
5223 DecMin(FPickup
, 1, 0);
5225 if FAlive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
5227 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
5228 FMegaRulez
[MR_SUIT
] := 0;
5229 FMegaRulez
[MR_INVUL
] := 0;
5230 FMegaRulez
[MR_INVIS
] := 0;
5231 Kill(K_FALLKILL
, 0, HIT_FALL
);
5238 if FCurrWeap
= WEAPON_SAW
then
5239 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
5240 FSawSoundSelect
.IsPlaying()) then
5241 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
5244 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
5245 (not FJetSoundOff
.IsPlaying()) then
5247 FJetSoundFly
.SetPosition(0);
5248 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
5251 for b
:= WP_FIRST
to WP_LAST
do
5252 if FReloading
[b
] > 0 then
5258 if FShellTimer
> -1 then
5259 if FShellTimer
= 0 then
5261 if FShellType
= SHELL_SHELL
then
5262 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5263 GameVelX
, GameVelY
-2, SHELL_SHELL
)
5264 else if FShellType
= SHELL_DBLSHELL
then
5266 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5267 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
5268 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5269 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
5272 end else Dec(FShellTimer
);
5274 if (FBFGFireCounter
> -1) then
5275 if FBFGFireCounter
= 0 then
5279 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
5280 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
5281 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
5282 yd
:= wy
+firediry();
5283 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
5284 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
5285 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5286 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5287 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5290 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
5291 FBFGFireCounter
:= -1;
5294 FBFGFireCounter
:= 0
5296 Dec(FBFGFireCounter
);
5298 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
5300 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
5302 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
5305 if (headwater
or blockmon
) then
5311 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
5314 else if (FAir
mod 31 = 0) and not blockmon
then
5316 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
5317 if Random(2) = 0 then
5318 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5320 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5322 end else if FAir
< AIR_DEF
then
5325 if FFireTime
> 0 then
5327 if BodyInLiquid(0, 0) then
5332 else if FMegaRulez
[MR_SUIT
] >= gTime
then
5334 if FMegaRulez
[MR_SUIT
] = gTime
then
5341 if FFirePainTime
<= 0 then
5343 if g_Game_IsServer
then
5344 Damage(5, FFireAttacker
, 0, 0, HIT_FLAME
);
5345 FFirePainTime
:= 18;
5347 FFirePainTime
:= FFirePainTime
- 1;
5348 FFireTime
:= FFireTime
- 1;
5349 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
5350 MH_SEND_PlayerStats(FUID
);
5354 if FDamageBuffer
> 0 then
5356 if FDamageBuffer
>= 9 then
5360 if FDamageBuffer
< 30 then i
:= 9
5361 else if FDamageBuffer
< 100 then i
:= 18
5365 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
5366 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
5367 FHealth
:= FHealth
-ii
;
5370 FHealth
:= FHealth
+FArmor
;
5375 if FHealth
<= 0 then
5376 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
5377 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
5378 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
5382 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
5383 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
5384 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
5385 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
5392 end; // if FAlive then ...
5394 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
5396 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
5397 FModel
.GetCurrentAnimation
.MinLength
:= i
;
5398 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
5399 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
5401 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
5402 then SetAction(A_STAND
, True);
5404 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
5406 for b
:= Low(FKeys
) to High(FKeys
) do
5407 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
5411 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5413 x
:= FObj
.X
+PLAYER_RECT
.X
;
5414 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
5415 w
:= PLAYER_RECT
.Width
;
5416 h
:= PLAYER_RECT
.Height
;
5420 procedure TPlayer
.moveBy (dx
, dy
: Integer); inline;
5422 if (dx
<> 0) or (dy
<> 0) then
5431 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
5433 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5434 FObj
.Y
+PLAYER_RECT
.Y
,
5441 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
5443 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5444 FObj
.Y
+PLAYER_RECT
.Y
,
5448 Panel
.Width
, Panel
.Height
);
5451 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
5453 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
5454 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
5455 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
5456 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
5459 function g_Player_ValidName(Name
: string): Boolean;
5465 if gPlayers
= nil then Exit
;
5467 for a
:= 0 to High(gPlayers
) do
5468 if gPlayers
[a
] <> nil then
5469 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
5476 procedure TPlayer
.SetDirection(Direction
: TDirection
);
5480 d
:= FModel
.Direction
;
5482 FModel
.Direction
:= Direction
;
5483 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
5485 FDirection
:= Direction
;
5488 function TPlayer
.GetKeys(): Byte;
5492 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
5493 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
5494 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
5496 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
5497 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
5500 procedure TPlayer
.Use();
5504 if FTime
[T_USE
] > gTime
then Exit
;
5506 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
5507 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
5509 for a
:= 0 to High(gPlayers
) do
5510 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
5511 gPlayers
[a
].alive
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
5512 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5513 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
5515 gPlayers
[a
].Touch();
5516 if g_Game_IsNet
and g_Game_IsServer
then
5517 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
5520 FTime
[T_USE
] := gTime
+120;
5523 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
5527 WX
, WY
, XD
, YD
: Integer;
5539 if R_BERSERK
in FRulez
then
5541 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5542 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
5543 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
5546 locobj
.rect
.Width
:= 39;
5547 locobj
.rect
.Height
:= 52;
5548 locobj
.Vel
.X
:= (xd
-wx
) div 2;
5549 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
5550 locobj
.Accel
.X
:= xd
-wx
;
5551 locobj
.Accel
.y
:= yd
-wy
;
5553 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
5554 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
5556 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
5560 FPain
:= min(FPain
+ 25, 50);
5562 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
5567 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5568 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
5570 FSawSoundSelect
.Stop();
5572 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
5574 else if not FSawSoundHit
.IsPlaying() then
5576 FSawSoundSelect
.Stop();
5577 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
5584 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
5585 FFireAngle
:= FAngle
;
5587 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5588 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5593 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5594 FFireAngle
:= FAngle
;
5597 FShellType
:= SHELL_SHELL
;
5602 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5603 FFireAngle
:= FAngle
;
5606 FShellType
:= SHELL_DBLSHELL
;
5611 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5612 FFireAngle
:= FAngle
;
5614 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5615 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5618 WEAPON_ROCKETLAUNCHER
:
5620 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5621 FFireAngle
:= FAngle
;
5627 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5628 FFireAngle
:= FAngle
;
5634 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5635 FFireAngle
:= FAngle
;
5639 WEAPON_SUPERPULEMET
:
5641 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5642 FFireAngle
:= FAngle
;
5644 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5645 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5648 WEAPON_FLAMETHROWER
:
5650 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
5651 FFireAngle
:= FAngle
;
5658 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5659 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5660 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5663 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5665 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5666 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5669 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5673 if NetInterpLevel
< 1 then
5683 AX
:= Abs(FXTo
- FObj
.X
);
5684 AY
:= Abs(FYTo
- FObj
.Y
);
5685 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5687 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5692 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5694 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5695 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5696 PANEL_LIFTUP
, False) then Result
:= -1
5698 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5699 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5700 PANEL_LIFTDOWN
, False) then Result
:= 1
5704 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5711 if Flag
= FLAG_NONE
then
5714 if not g_Game_IsServer
then Exit
;
5716 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5717 if (Flag
= FTeam
) and
5718 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5719 (FFlag
<> FLAG_NONE
) then
5721 if FFlag
= FLAG_RED
then
5722 s
:= _lc
[I_PLAYER_FLAG_RED
]
5724 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5726 evtype
:= FLAG_STATE_SCORED
;
5728 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5729 Insert('.', ts
, Length(ts
) + 1 - 3);
5730 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5732 g_Map_ResetFlag(FFlag
);
5733 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5735 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5738 if g_Game_IsNet
then
5740 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5744 gFlags
[FFlag
].CaptureTime
:= 0;
5749 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5750 if (Flag
= FTeam
) and
5751 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5753 if Flag
= FLAG_RED
then
5754 s
:= _lc
[I_PLAYER_FLAG_RED
]
5756 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5758 evtype
:= FLAG_STATE_RETURNED
;
5759 gFlags
[Flag
].CaptureTime
:= 0;
5761 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5763 g_Map_ResetFlag(Flag
);
5764 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5767 if g_Game_IsNet
then
5769 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5775 // Ïîäîáðàë ÷óæîé ôëàã:
5776 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5780 if Flag
= FLAG_RED
then
5781 s
:= _lc
[I_PLAYER_FLAG_RED
]
5783 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5785 evtype
:= FLAG_STATE_CAPTURED
;
5787 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5789 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5791 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5794 if g_Game_IsNet
then
5796 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5802 procedure TPlayer
.SetFlag(Flag
: Byte);
5805 if FModel
<> nil then
5806 FModel
.SetFlag(FFlag
);
5809 function TPlayer
.DropFlag(): Boolean;
5814 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5816 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5817 with gFlags
[FFlag
] do
5821 Direction
:= FDirection
;
5822 State
:= FLAG_STATE_DROPPED
;
5824 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5825 (FObj
.Vel
.Y
div 2)-2+Random(5));
5826 positionChanged(); // this updates spatial accelerators
5828 if FFlag
= FLAG_RED
then
5829 s
:= _lc
[I_PLAYER_FLAG_RED
]
5831 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5833 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5834 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5836 if g_Game_IsNet
then
5837 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5843 procedure TPlayer
.GetSecret();
5848 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5850 Assert(Key
<= High(FKeys
));
5852 FKeys
[Key
].Pressed
:= True;
5853 FKeys
[Key
].Time
:= Time
;
5856 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5858 Result
:= FKeys
[K
].Pressed
;
5861 procedure TPlayer
.ReleaseKeys();
5865 for a
:= Low(FKeys
) to High(FKeys
) do
5867 FKeys
[a
].Pressed
:= False;
5872 procedure TPlayer
.ReleaseKeysNoWeapon();
5876 for a
:= Low(FKeys
) to High(FKeys
) do
5878 if (a
= KEY_PREVWEAPON
) or (a
= KEY_NEXTWEAPON
) then continue
;
5879 FKeys
[a
].Pressed
:= False;
5884 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5888 function TPlayer
.firediry(): Integer;
5890 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5891 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5895 procedure TPlayer
.RememberState();
5899 FSavedState
.Health
:= FHealth
;
5900 FSavedState
.Armor
:= FArmor
;
5901 FSavedState
.Air
:= FAir
;
5902 FSavedState
.JetFuel
:= FJetFuel
;
5903 FSavedState
.CurrWeap
:= FCurrWeap
;
5904 FSavedState
.NextWeap
:= FNextWeap
;
5905 FSavedState
.NextWeapDelay
:= FNextWeapDelay
;
5908 FSavedState
.Ammo
[i
] := FAmmo
[i
];
5910 FSavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5912 FSavedState
.Rulez
:= FRulez
;
5913 FSavedState
.WaitRecall
:= True;
5916 procedure TPlayer
.RecallState();
5920 if not FSavedState
.WaitRecall
then Exit
;
5922 FHealth
:= FSavedState
.Health
;
5923 FArmor
:= FSavedState
.Armor
;
5924 FAir
:= FSavedState
.Air
;
5925 FJetFuel
:= FSavedState
.JetFuel
;
5926 FCurrWeap
:= FSavedState
.CurrWeap
;
5927 //FNetForceWeap := FCurrWeap;
5928 FNextWeap
:= FSavedState
.NextWeap
;
5929 FNextWeapDelay
:= FSavedState
.NextWeapDelay
;
5932 FAmmo
[i
] := FSavedState
.Ammo
[i
];
5934 FMaxAmmo
[i
] := FSavedState
.MaxAmmo
[i
];
5936 FRulez
:= FSavedState
.Rulez
;
5937 FSavedState
.WaitRecall
:= False;
5939 if gGameSettings
.GameType
= GT_SERVER
then
5940 MH_SEND_PlayerStats(FUID
);
5943 procedure TPlayer
.SaveState (st
: TStream
);
5949 utils
.writeSign(st
, 'PLYR');
5950 utils
.writeInt(st
, Byte(PLR_SAVE_VERSION
)); // version
5952 utils
.writeBool(st
, FIamBot
);
5954 utils
.writeInt(st
, Word(FUID
));
5956 utils
.writeStr(st
, FName
);
5958 utils
.writeInt(st
, Byte(FTeam
));
5960 utils
.writeBool(st
, FAlive
);
5961 // Èçðàñõîäîâàë ëè âñå æèçíè
5962 utils
.writeBool(st
, FNoRespawn
);
5964 if FDirection
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
5965 utils
.writeInt(st
, Byte(b
));
5967 utils
.writeInt(st
, LongInt(FHealth
));
5969 utils
.writeInt(st
, Byte(FLives
));
5971 utils
.writeInt(st
, LongInt(FArmor
));
5973 utils
.writeInt(st
, LongInt(FAir
));
5975 utils
.writeInt(st
, LongInt(FJetFuel
));
5977 utils
.writeInt(st
, LongInt(FPain
));
5979 utils
.writeInt(st
, LongInt(FKills
));
5981 utils
.writeInt(st
, LongInt(FMonsterKills
));
5983 utils
.writeInt(st
, LongInt(FFrags
));
5985 utils
.writeInt(st
, Byte(FFragCombo
));
5986 // Âðåìÿ ïîñëåäíåãî ôðàãà
5987 utils
.writeInt(st
, LongWord(FLastFrag
));
5989 utils
.writeInt(st
, LongInt(FDeath
));
5991 utils
.writeInt(st
, Byte(FFlag
));
5993 utils
.writeInt(st
, LongInt(FSecrets
));
5995 utils
.writeInt(st
, Byte(FCurrWeap
));
5997 utils
.writeInt(st
, Word(FNextWeap
));
5999 utils
.writeInt(st
, Byte(FNextWeapDelay
));
6000 // Âðåìÿ çàðÿäêè BFG
6001 utils
.writeInt(st
, SmallInt(FBFGFireCounter
));
6003 utils
.writeInt(st
, LongInt(FDamageBuffer
));
6004 // Ïîñëåäíèé óäàðèâøèé
6005 utils
.writeInt(st
, Word(FLastSpawnerUID
));
6006 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6007 utils
.writeInt(st
, Byte(FLastHit
));
6009 Obj_SaveState(st
, @FObj
);
6010 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6011 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FAmmo
[i
]));
6012 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6013 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FMaxAmmo
[i
]));
6015 for i
:= WP_FIRST
to WP_LAST
do utils
.writeBool(st
, FWeapon
[i
]);
6016 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6017 for i
:= WP_FIRST
to WP_LAST
do utils
.writeInt(st
, Word(FReloading
[i
]));
6019 utils
.writeBool(st
, (R_ITEM_BACKPACK
in FRulez
));
6020 // Íàëè÷èå êðàñíîãî êëþ÷à
6021 utils
.writeBool(st
, (R_KEY_RED
in FRulez
));
6022 // Íàëè÷èå çåëåíîãî êëþ÷à
6023 utils
.writeBool(st
, (R_KEY_GREEN
in FRulez
));
6024 // Íàëè÷èå ñèíåãî êëþ÷à
6025 utils
.writeBool(st
, (R_KEY_BLUE
in FRulez
));
6027 utils
.writeBool(st
, (R_BERSERK
in FRulez
));
6028 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6029 for i
:= MR_SUIT
to MR_MAX
do utils
.writeInt(st
, LongWord(FMegaRulez
[i
]));
6030 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6031 for i
:= T_RESPAWN
to T_FLAGCAP
do utils
.writeInt(st
, LongWord(FTime
[i
]));
6033 utils
.writeStr(st
, FModel
.Name
);
6035 utils
.writeInt(st
, Byte(FColor
.R
));
6036 utils
.writeInt(st
, Byte(FColor
.G
));
6037 utils
.writeInt(st
, Byte(FColor
.B
));
6041 procedure TPlayer
.LoadState (st
: TStream
);
6050 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
6051 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
6053 FIamBot
:= utils
.readBool(st
);
6055 FUID
:= utils
.readWord(st
);
6057 str
:= utils
.readStr(st
);
6058 if (self
<> gPlayer1
) and (self
<> gPlayer2
) then FName
:= str
;
6060 FTeam
:= utils
.readByte(st
);
6062 FAlive
:= utils
.readBool(st
);
6063 // Èçðàñõîäîâàë ëè âñå æèçíè
6064 FNoRespawn
:= utils
.readBool(st
);
6066 b
:= utils
.readByte(st
);
6067 if b
= 1 then FDirection
:= TDirection
.D_LEFT
else FDirection
:= TDirection
.D_RIGHT
; // b = 2
6069 FHealth
:= utils
.readLongInt(st
);
6071 FLives
:= utils
.readByte(st
);
6073 FArmor
:= utils
.readLongInt(st
);
6075 FAir
:= utils
.readLongInt(st
);
6077 FJetFuel
:= utils
.readLongInt(st
);
6079 FPain
:= utils
.readLongInt(st
);
6081 FKills
:= utils
.readLongInt(st
);
6083 FMonsterKills
:= utils
.readLongInt(st
);
6085 FFrags
:= utils
.readLongInt(st
);
6087 FFragCombo
:= utils
.readByte(st
);
6088 // Âðåìÿ ïîñëåäíåãî ôðàãà
6089 FLastFrag
:= utils
.readLongWord(st
);
6091 FDeath
:= utils
.readLongInt(st
);
6093 FFlag
:= utils
.readByte(st
);
6095 FSecrets
:= utils
.readLongInt(st
);
6097 FCurrWeap
:= utils
.readByte(st
);
6098 //FNetForceWeap := FCurrWeap;
6100 FNextWeap
:= utils
.readWord(st
);
6102 FNextWeapDelay
:= utils
.readByte(st
);
6103 // Âðåìÿ çàðÿäêè BFG
6104 FBFGFireCounter
:= utils
.readSmallInt(st
);
6106 FDamageBuffer
:= utils
.readLongInt(st
);
6107 // Ïîñëåäíèé óäàðèâøèé
6108 FLastSpawnerUID
:= utils
.readWord(st
);
6109 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6110 FLastHit
:= utils
.readByte(st
);
6112 Obj_LoadState(@FObj
, st
);
6113 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6114 for i
:= A_BULLETS
to A_HIGH
do FAmmo
[i
] := utils
.readWord(st
);
6115 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6116 for i
:= A_BULLETS
to A_HIGH
do FMaxAmmo
[i
] := utils
.readWord(st
);
6118 for i
:= WP_FIRST
to WP_LAST
do FWeapon
[i
] := utils
.readBool(st
);
6119 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6120 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := utils
.readWord(st
);
6122 if utils
.readBool(st
) then Include(FRulez
, R_ITEM_BACKPACK
);
6123 // Íàëè÷èå êðàñíîãî êëþ÷à
6124 if utils
.readBool(st
) then Include(FRulez
, R_KEY_RED
);
6125 // Íàëè÷èå çåëåíîãî êëþ÷à
6126 if utils
.readBool(st
) then Include(FRulez
, R_KEY_GREEN
);
6127 // Íàëè÷èå ñèíåãî êëþ÷à
6128 if utils
.readBool(st
) then Include(FRulez
, R_KEY_BLUE
);
6130 if utils
.readBool(st
) then Include(FRulez
, R_BERSERK
);
6131 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6132 for i
:= MR_SUIT
to MR_MAX
do FMegaRulez
[i
] := utils
.readLongWord(st
);
6133 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6134 for i
:= T_RESPAWN
to T_FLAGCAP
do FTime
[i
] := utils
.readLongWord(st
);
6136 str
:= utils
.readStr(st
);
6138 FColor
.R
:= utils
.readByte(st
);
6139 FColor
.G
:= utils
.readByte(st
);
6140 FColor
.B
:= utils
.readByte(st
);
6141 if (self
= gPlayer1
) then
6143 str
:= gPlayer1Settings
.Model
;
6144 FColor
:= gPlayer1Settings
.Color
;
6146 else if (self
= gPlayer2
) then
6148 str
:= gPlayer2Settings
.Model
;
6149 FColor
:= gPlayer2Settings
.Color
;
6151 // Îáíîâëÿåì ìîäåëü èãðîêà
6153 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
6154 FModel
.Color
:= TEAMCOLOR
[FTeam
]
6156 FModel
.Color
:= FColor
;
6160 procedure TPlayer
.AllRulez(Health
: Boolean);
6166 FHealth
:= PLAYER_HP_LIMIT
;
6167 FArmor
:= PLAYER_AP_LIMIT
;
6171 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
6172 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
6173 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
6176 procedure TPlayer
.RestoreHealthArmor();
6178 FHealth
:= PLAYER_HP_LIMIT
;
6179 FArmor
:= PLAYER_AP_LIMIT
;
6182 procedure TPlayer
.FragCombo();
6186 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
6188 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
6190 if FFragCombo
< 5 then
6192 Param
:= FUID
or (FFragCombo
shl 16);
6193 if (FComboEvnt
>= Low(gDelayedEvents
)) and
6194 (FComboEvnt
<= High(gDelayedEvents
)) and
6195 gDelayedEvents
[FComboEvnt
].Pending
and
6196 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
6197 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
6199 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
6200 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
6203 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
6211 procedure TPlayer
.GiveItem(ItemType
: Byte);
6215 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
6217 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
6221 if FAir
< AIR_MAX
then
6228 if not (R_BERSERK
in FRulez
) then
6230 Include(FRulez
, R_BERSERK
);
6231 if FBFGFireCounter
< 1 then
6233 FCurrWeap
:= WEAPON_KASTET
;
6234 //FNetForceWeap := FCurrWeap;
6236 FModel
.SetWeapon(WEAPON_KASTET
);
6240 FBerserk
:= gTime
+30000;
6242 if FHealth
< PLAYER_HP_SOFT
then
6244 FHealth
:= PLAYER_HP_SOFT
;
6245 FBerserk
:= gTime
+30000;
6250 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
6252 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
6256 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
6258 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
6262 if FJetFuel
< JET_MAX
then
6264 FJetFuel
:= JET_MAX
;
6267 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
6268 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
6270 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
6271 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6273 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
6275 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
6277 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
6278 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6281 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
6282 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
6283 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
6284 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
6285 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
6286 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
6287 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
6288 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
6289 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
6291 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6292 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
6293 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6294 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
6295 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6296 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
6297 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6298 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
6299 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
6302 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
6303 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
6304 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
6305 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
6306 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
6308 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
6309 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
6310 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
6311 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
6312 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
6314 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6315 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6316 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6317 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6319 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
6322 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
6323 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
6324 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
6326 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
6327 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
6332 if g_Game_IsNet
and g_Game_IsServer
then
6333 MH_SEND_PlayerStats(FUID
);
6336 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
6341 if (Random(5) = 1) and (Times
= 1) then
6344 if BodyInLiquid(0, 0) then
6346 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
6347 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
6348 if Random(2) = 0 then
6349 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
6351 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
6355 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
6357 for i
:= 1 to Times
do
6359 Anim
:= TAnimation
.Create(id
, False, 3);
6361 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6362 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6368 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
6373 if (Random(10) = 1) and (Times
= 1) then
6376 if g_Frames_Get(id
, 'FRAMES_FLAME') then
6378 for i
:= 1 to Times
do
6380 Anim
:= TAnimation
.Create(id
, False, 3);
6382 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6383 Obj
.Y
+8+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6389 procedure TPlayer
.PauseSounds(Enable
: Boolean);
6391 FSawSound
.Pause(Enable
);
6392 FSawSoundIdle
.Pause(Enable
);
6393 FSawSoundHit
.Pause(Enable
);
6394 FSawSoundSelect
.Pause(Enable
);
6399 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
6404 FObj
.Rect
:= PLAYER_CORPSERECT
;
6405 FModelName
:= ModelName
;
6410 FState
:= CORPSE_STATE_MESS
;
6411 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
6415 FState
:= CORPSE_STATE_NORMAL
;
6416 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
6420 destructor TCorpse
.Destroy();
6427 function TCorpse
.ObjPtr (): PObj
; inline; begin result
:= @FObj
; end;
6429 procedure TCorpse
.positionChanged (); inline; begin end;
6431 procedure TCorpse
.moveBy (dx
, dy
: Integer); inline;
6433 if (dx
<> 0) or (dy
<> 0) then
6442 procedure TCorpse
.getMapBox (out x
, y
, w
, h
: Integer); inline;
6444 x
:= FObj
.X
+PLAYER_CORPSERECT
.X
;
6445 y
:= FObj
.Y
+PLAYER_CORPSERECT
.Y
;
6446 w
:= PLAYER_CORPSERECT
.Width
;
6447 h
:= PLAYER_CORPSERECT
.Height
;
6451 procedure TCorpse
.Damage(Value
: Word; vx
, vy
: Integer);
6456 if FState
= CORPSE_STATE_REMOVEME
then
6459 FDamage
:= FDamage
+ Value
;
6461 if FDamage
> 150 then
6463 if FAnimation
<> nil then
6468 FState
:= CORPSE_STATE_REMOVEME
;
6470 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
6471 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
6472 FModelName
, FColor
);
6473 // Çâóê ìÿñà îò òðóïà:
6474 pm
:= g_PlayerModel_Get(FModelName
);
6475 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
6479 if (gBodyKillEvent
<> -1)
6480 and gDelayedEvents
[gBodyKillEvent
].Pending
then
6481 gDelayedEvents
[gBodyKillEvent
].Pending
:= False;
6482 gBodyKillEvent
:= g_Game_DelayEvent(DE_BODYKILL
, 1050, 0);
6487 Blood
:= g_PlayerModel_GetBlood(FModelName
);
6488 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
6489 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
6490 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
6491 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
6492 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
6493 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
6497 procedure TCorpse
.Draw();
6499 if FState
= CORPSE_STATE_REMOVEME
then
6502 if FAnimation
<> nil then
6503 FAnimation
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6505 if FAnimationMask
<> nil then
6508 FAnimationMask
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6515 procedure TCorpse
.Update();
6519 if FState
= CORPSE_STATE_REMOVEME
then
6522 if gTime
mod (GAME_TICK
*2) <> 0 then
6524 g_Obj_Move(@FObj
, True, True, True);
6525 positionChanged(); // this updates spatial accelerators
6529 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6530 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
6532 st
:= g_Obj_Move(@FObj
, True, True, True);
6533 positionChanged(); // this updates spatial accelerators
6535 if WordBool(st
and MOVE_FALLOUT
) then
6537 FState
:= CORPSE_STATE_REMOVEME
;
6541 if FAnimation
<> nil then
6542 FAnimation
.Update();
6543 if FAnimationMask
<> nil then
6544 FAnimationMask
.Update();
6548 procedure TCorpse
.SaveState (st
: TStream
);
6555 utils
.writeSign(st
, 'CORP');
6556 utils
.writeInt(st
, Byte(0));
6558 utils
.writeInt(st
, Byte(FState
));
6560 utils
.writeInt(st
, Byte(FDamage
));
6562 utils
.writeInt(st
, Byte(FColor
.R
));
6563 utils
.writeInt(st
, Byte(FColor
.G
));
6564 utils
.writeInt(st
, Byte(FColor
.B
));
6566 Obj_SaveState(st
, @FObj
);
6567 utils
.writeInt(st
, Word(FPlayerUID
));
6569 anim
:= (FAnimation
<> nil);
6570 utils
.writeBool(st
, anim
);
6571 // Åñëè åñòü - ñîõðàíÿåì
6572 if anim
then FAnimation
.SaveState(st
);
6573 // Åñòü ëè ìàñêà àíèìàöèè
6574 anim
:= (FAnimationMask
<> nil);
6575 utils
.writeBool(st
, anim
);
6576 // Åñëè åñòü - ñîõðàíÿåì
6577 if anim
then FAnimationMask
.SaveState(st
);
6581 procedure TCorpse
.LoadState (st
: TStream
);
6588 if not utils
.checkSign(st
, 'CORP') then raise XStreamError
.Create('invalid corpse signature');
6589 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid corpse version');
6591 FState
:= utils
.readByte(st
);
6593 FDamage
:= utils
.readByte(st
);
6595 FColor
.R
:= utils
.readByte(st
);
6596 FColor
.G
:= utils
.readByte(st
);
6597 FColor
.B
:= utils
.readByte(st
);
6599 Obj_LoadState(@FObj
, st
);
6600 FPlayerUID
:= utils
.readWord(st
);
6602 anim
:= utils
.readBool(st
);
6603 // Åñëè åñòü - çàãðóæàåì
6606 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6607 FAnimation
.LoadState(st
);
6609 // Åñòü ëè ìàñêà àíèìàöèè
6610 anim
:= utils
.readBool(st
);
6611 // Åñëè åñòü - çàãðóæàåì
6614 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6615 FAnimationMask
.LoadState(st
);
6621 constructor TBot
.Create();
6628 FSpectator
:= False;
6635 for a
:= WP_FIRST
to WP_LAST
do
6637 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6638 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6639 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6643 destructor TBot
.Destroy();
6646 inherited Destroy();
6649 procedure TBot
.Draw();
6653 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6654 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6657 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6659 inherited Respawn(Silent
, Force
);
6662 FSelectedWeapon
:= FCurrWeap
;
6667 procedure TBot
.UpdateCombat();
6680 TTargetRecord
= array of TTarget
;
6682 function Compare(a
, b
: TTarget
): Integer;
6684 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6687 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6689 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6690 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6692 if a
.Dist
> b
.Dist
then // B áëèæå
6694 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6697 else // Ñòðàííî -> A
6702 a
, x1
, y1
, x2
, y2
: Integer;
6703 targets
: TTargetRecord
;
6705 Target
, BestTarget
: TTarget
;
6706 firew
, fireh
: Integer;
6710 vsPlayer
, vsMonster
, ok
: Boolean;
6713 function monsUpdate (mon
: TMonster
): Boolean;
6715 result
:= false; // don't stop
6716 if mon
.alive
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6718 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6720 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6721 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6723 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6724 if g_TraceVector(x1
, y1
, x2
, y2
) then
6726 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6727 SetLength(targets
, Length(targets
)+1);
6728 with targets
[High(targets
)] do
6735 Rect
:= mon
.Obj
.Rect
;
6736 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6737 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6738 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6747 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6748 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6750 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6751 if FCurrWeap
<> FSelectedWeapon
then
6754 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6755 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6757 RemoveAIFlag('NEEDFIRE');
6760 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6761 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6762 else PressKey(KEY_FIRE
);
6766 // Êîîðäèíàòû ñòâîëà:
6767 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6768 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6770 Target
.UID
:= FTargetUID
;
6773 if Target
.UID
<> 0 then
6774 begin // Öåëü åñòü - íàñòðàèâàåì
6775 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6778 tpla
:= g_Player_Get(Target
.UID
);
6782 if (@FObj
) <> nil then
6789 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6790 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6791 Target
.Rect
:= PLAYER_RECT
;
6792 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6793 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6794 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6795 Target
.IsPlayer
:= True;
6799 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6802 mon
:= g_Monsters_ByUID(Target
.UID
);
6805 Target
.X
:= mon
.Obj
.X
;
6806 Target
.Y
:= mon
.Obj
.Y
;
6808 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6809 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6810 Target
.Rect
:= mon
.Obj
.Rect
;
6811 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6812 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6813 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6814 Target
.IsPlayer
:= False;
6821 begin // Öåëè íåò - îáíóëÿåì
6826 Target
.Visible
:= False;
6827 Target
.Line
:= False;
6828 Target
.IsPlayer
:= False;
6833 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6834 if (not Target
.Line
) or (not Target
.Visible
) then
6838 for a
:= 0 to High(gPlayers
) do
6839 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].alive
) and
6840 (gPlayers
[a
].FUID
<> FUID
) and
6841 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6842 (not gPlayers
[a
].NoTarget
) and
6843 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6845 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6846 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6849 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6850 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6852 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6853 if g_TraceVector(x1
, y1
, x2
, y2
) then
6855 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6856 SetLength(targets
, Length(targets
)+1);
6857 with targets
[High(targets
)] do
6859 UID
:= gPlayers
[a
].FUID
;
6860 X
:= gPlayers
[a
].FObj
.X
;
6861 Y
:= gPlayers
[a
].FObj
.Y
;
6864 Rect
:= PLAYER_RECT
;
6865 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6866 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6867 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6875 if vsMonster
then g_Mons_ForEach(monsUpdate
);
6878 // Åñëè åñòü âîçìîæíûå öåëè:
6879 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6880 if targets
<> nil then
6882 // Âûáèðàåì íàèëó÷øóþ öåëü:
6883 BestTarget
:= targets
[0];
6884 if Length(targets
) > 1 then
6885 for a
:= 1 to High(targets
) do
6886 if Compare(BestTarget
, targets
[a
]) = 1 then
6887 BestTarget
:= targets
[a
];
6889 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6890 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6891 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6893 Target
:= BestTarget
;
6895 if (Healthy() = 3) or ((Healthy() = 2)) then
6896 begin // Åñëè çäîðîâû - äîãîíÿåì
6897 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6898 SetAIFlag('GORIGHT', '1');
6899 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6900 SetAIFlag('GOLEFT', '1');
6903 begin // Åñëè ïîáèòû - óáåãàåì
6904 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6905 SetAIFlag('GORIGHT', '1');
6906 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6907 SetAIFlag('GOLEFT', '1');
6910 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6911 SelectWeapon(Abs(x1
-Target
.cX
));
6916 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6917 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6918 if Target
.UID
<> 0 then
6920 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6921 Target
.Y
+ Target
.Rect
.Y
) then
6922 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6923 if (Healthy() = 3) or ((Healthy() = 2)) then
6924 begin // Åñëè çäîðîâû - äîãîíÿåì
6925 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6926 SetAIFlag('GORIGHT', '1');
6927 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6928 SetAIFlag('GOLEFT', '1');
6931 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6933 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6934 SetAIFlag('GORIGHT', '1');
6935 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6936 SetAIFlag('GOLEFT', '1');
6940 begin // Öåëü ïîêà íà "ýêðàíå"
6941 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
6942 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6943 FLastVisible
:= gTime
;
6944 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
6945 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6947 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6948 SetAIFlag('GORIGHT', '1');
6949 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6950 SetAIFlag('GOLEFT', '1');
6954 // Âûáèðàåì óãîë ââåðõ:
6955 if FDirection
= TDirection
.D_LEFT
then
6956 angle
:= ANGLE_LEFTUP
6958 angle
:= ANGLE_RIGHTUP
;
6960 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6961 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6963 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6964 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6965 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6966 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6967 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6968 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6969 begin // òî íóæíî ñòðåëÿòü ââåðõ
6970 SetAIFlag('NEEDFIRE', '1');
6971 SetAIFlag('NEEDSEEUP', '1');
6974 // Âûáèðàåì óãîë âíèç:
6975 if FDirection
= TDirection
.D_LEFT
then
6976 angle
:= ANGLE_LEFTDOWN
6978 angle
:= ANGLE_RIGHTDOWN
;
6980 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6981 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6983 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6984 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6985 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6986 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6987 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6988 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6989 begin // òî íóæíî ñòðåëÿòü âíèç
6990 SetAIFlag('NEEDFIRE', '1');
6991 SetAIFlag('NEEDSEEDOWN', '1');
6994 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
6995 if Target
.Visible
and
6996 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
6997 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
6999 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
7000 if ((FDirection
= TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) or
7001 ((FDirection
= TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
7002 begin // òî íóæíî ñòðåëÿòü âïåðåä
7003 SetAIFlag('NEEDFIRE', '1');
7004 SetAIFlag('NEEDSEEDOWN', '');
7005 SetAIFlag('NEEDSEEUP', '');
7007 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
7008 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
7009 if GetRnd(FDifficult
.CloseJump
) then
7010 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
7011 if Abs(FObj
.X
-Target
.X
) < 128 then
7015 if Random(a
) = 0 then
7016 SetAIFlag('NEEDJUMP', '1');
7020 // Åñëè öåëü âñå åùå åñòü:
7021 if Target
.UID
<> 0 then
7022 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
7023 Target
.UID
:= 0 // òî çàáûòü öåëü
7024 else // Åñëè âèäåëè íåäàâíî
7025 begin // íî öåëü óáèëè
7026 if Target
.IsPlayer
then
7027 begin // Öåëü - èãðîê
7028 pla
:= g_Player_Get(Target
.UID
);
7029 if (pla
= nil) or (not pla
.alive
) or pla
.NoTarget
or
7030 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
7031 Target
.UID
:= 0; // òî çàáûòü öåëü
7034 begin // Öåëü - ìîíñòð
7035 mon
:= g_Monsters_ByUID(Target
.UID
);
7036 if (mon
= nil) or (not mon
.alive
) then
7037 Target
.UID
:= 0; // òî çàáûòü öåëü
7040 end; // if Target.UID <> 0
7042 FTargetUID
:= Target
.UID
;
7044 // Åñëè âîçìîæíûõ öåëåé íåò:
7045 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
7046 if targets
= nil then
7047 if GetAIFlag('ATTACKLEFT') <> '' then
7048 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
7049 RemoveAIFlag('ATTACKLEFT');
7051 SetAIFlag('NEEDJUMP', '1');
7053 if RunDirection() = TDirection
.D_RIGHT
then
7054 begin // Èäåì íå â òó ñòîðîíó
7055 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7056 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
7057 SetAIFlag('NEEDFIRE', '1');
7058 SetAIFlag('GOLEFT', '1');
7062 begin // Èäåì â íóæíóþ ñòîðîíó
7063 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7064 SetAIFlag('NEEDFIRE', '1');
7065 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7066 SetAIFlag('GORIGHT', '1');
7070 if GetAIFlag('ATTACKRIGHT') <> '' then
7071 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
7072 RemoveAIFlag('ATTACKRIGHT');
7074 SetAIFlag('NEEDJUMP', '1');
7076 if RunDirection() = TDirection
.D_LEFT
then
7077 begin // Èäåì íå â òó ñòîðîíó
7078 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7079 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
7080 SetAIFlag('NEEDFIRE', '1');
7081 SetAIFlag('GORIGHT', '1');
7086 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7087 SetAIFlag('NEEDFIRE', '1');
7088 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7089 SetAIFlag('GOLEFT', '1');
7093 //HACK! (does it belong there?)
7094 RealizeCurrentWeapon();
7096 // Åñëè åñòü âîçìîæíûå öåëè:
7097 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
7098 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
7099 for a
:= 0 to High(targets
) do
7101 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
7102 if GetRnd(FDifficult
.DiagFire
) then
7104 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
7105 if FDirection
= TDirection
.D_LEFT
then
7106 angle
:= ANGLE_LEFTUP
7108 angle
:= ANGLE_RIGHTUP
;
7110 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7111 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7113 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7114 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7115 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7116 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7117 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7119 SetAIFlag('NEEDFIRE', '1');
7120 SetAIFlag('NEEDSEEUP', '1');
7123 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
7124 if FDirection
= TDirection
.D_LEFT
then
7125 angle
:= ANGLE_LEFTDOWN
7127 angle
:= ANGLE_RIGHTDOWN
;
7129 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7130 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7132 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7133 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7134 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7135 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7136 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7138 SetAIFlag('NEEDFIRE', '1');
7139 SetAIFlag('NEEDSEEDOWN', '1');
7143 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
7144 if targets
[a
].Line
and targets
[a
].Visible
and
7145 (((FDirection
= TDirection
.D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
7146 ((FDirection
= TDirection
.D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
7148 SetAIFlag('NEEDFIRE', '1');
7153 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
7154 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
7155 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
7156 40+GetInterval(FDifficult
.Cover
, 40)) then
7157 SetAIFlag('NEEDJUMP', '1');
7159 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
7160 ammo
:= GetAmmoByWeapon(FCurrWeap
);
7161 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
7162 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
7164 SetAIFlag('SELECTWEAPON', '1');
7166 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
7167 if GetAIFlag('SELECTWEAPON') = '1' then
7170 RemoveAIFlag('SELECTWEAPON');
7174 procedure TBot
.Update();
7187 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
7188 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
7190 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
7192 if g_debug_BotAIOff
= 3 then
7202 RealizeCurrentWeapon();
7209 procedure TBot
.ReleaseKey(Key
: Byte);
7218 function TBot
.KeyPressed(Key
: Word): Boolean;
7220 Result
:= FKeys
[Key
].Pressed
;
7223 function TBot
.GetAIFlag(aName
: String20
): String20
;
7229 aName
:= LowerCase(aName
);
7231 if FAIFlags
<> nil then
7232 for a
:= 0 to High(FAIFlags
) do
7233 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7235 Result
:= FAIFlags
[a
].Value
;
7240 procedure TBot
.RemoveAIFlag(aName
: String20
);
7244 if FAIFlags
= nil then Exit
;
7246 aName
:= LowerCase(aName
);
7248 for a
:= 0 to High(FAIFlags
) do
7249 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7251 if a
<> High(FAIFlags
) then
7252 for b
:= a
to High(FAIFlags
)-1 do
7253 FAIFlags
[b
] := FAIFlags
[b
+1];
7255 SetLength(FAIFlags
, Length(FAIFlags
)-1);
7260 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
7268 aName
:= LowerCase(aName
);
7270 if FAIFlags
<> nil then
7271 for a
:= 0 to High(FAIFlags
) do
7272 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7278 if ok
then FAIFlags
[a
].Value
:= fValue
7281 SetLength(FAIFlags
, Length(FAIFlags
)+1);
7282 with FAIFlags
[High(FAIFlags
)] do
7290 procedure TBot
.UpdateMove
;
7292 procedure GoLeft(Time
: Word = 1);
7294 ReleaseKey(KEY_LEFT
);
7295 ReleaseKey(KEY_RIGHT
);
7296 PressKey(KEY_LEFT
, Time
);
7297 SetDirection(TDirection
.D_LEFT
);
7300 procedure GoRight(Time
: Word = 1);
7302 ReleaseKey(KEY_LEFT
);
7303 ReleaseKey(KEY_RIGHT
);
7304 PressKey(KEY_RIGHT
, Time
);
7305 SetDirection(TDirection
.D_RIGHT
);
7308 function Rnd(a
: Word): Boolean;
7310 Result
:= Random(a
) = 0;
7313 procedure Turn(Time
: Word = 1200);
7315 if RunDirection() = TDirection
.D_LEFT
then GoRight(Time
) else GoLeft(Time
);
7320 ReleaseKey(KEY_LEFT
);
7321 ReleaseKey(KEY_RIGHT
);
7324 function CanRunLeft(): Boolean;
7326 Result
:= not CollideLevel(-1, 0);
7329 function CanRunRight(): Boolean;
7331 Result
:= not CollideLevel(1, 0);
7334 function CanRun(): Boolean;
7336 if RunDirection() = TDirection
.D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
7339 procedure Jump(Time
: Word = 30);
7341 PressKey(KEY_JUMP
, Time
);
7344 function NearHole(): Boolean;
7348 { TODO 5 : Ëåñòíèöû }
7349 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7350 for x
:= 1 to PLAYER_RECT
.Width
do
7351 if (not StayOnStep(x
*sx
, 0)) and
7352 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7353 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7362 function BorderHole(): Boolean;
7366 { TODO 5 : Ëåñòíèöû }
7367 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7368 for x
:= 1 to PLAYER_RECT
.Width
do
7369 if (not StayOnStep(x
*sx
, 0)) and
7370 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7371 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7373 for xx
:= x
to x
+32 do
7374 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
7384 function NearDeepHole(): Boolean;
7390 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7393 for x
:= 1 to PLAYER_RECT
.Width
do
7394 if (not StayOnStep(x
*sx
, 0)) and
7395 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7396 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7398 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7400 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
7405 end else Result
:= False;
7408 function OverDeepHole(): Boolean;
7415 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7417 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
7424 function OnGround(): Boolean;
7426 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
7429 function OnLadder(): Boolean;
7431 Result
:= FullInStep(0, 0);
7434 function BelowLadder(): Boolean;
7436 Result
:= (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
7437 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7438 (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
7439 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7442 function BelowLiftUp(): Boolean;
7444 Result
:= ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
7445 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7446 ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
7447 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7450 function OnTopLift(): Boolean;
7452 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7455 function CanJumpOver(): Boolean;
7459 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7463 if not CollideLevel(sx
, 0) then Exit
;
7465 for y
:= 1 to BOT_MAXJUMP
do
7466 if CollideLevel(0, -y
) then Exit
else
7467 if not CollideLevel(sx
, -y
) then
7474 function CanJumpUp(Dist
: ShortInt): Boolean;
7481 if CollideLevel(Dist
, 0) then Exit
;
7484 for y
:= 0 to BOT_MAXJUMP
do
7485 if CollideLevel(Dist
, -y
) then
7494 for yy
:= y
+1 to BOT_MAXJUMP
do
7495 if not CollideLevel(Dist
, -yy
) then
7504 for y
:= 0 to BOT_MAXJUMP
do
7505 if CollideLevel(0, -y
) then
7513 if y
< yy
then Exit
;
7518 function IsSafeTrigger(): Boolean;
7523 if gTriggers
= nil then
7525 for a
:= 0 to High(gTriggers
) do
7526 if Collide(gTriggers
[a
].X
,
7529 gTriggers
[a
].Height
) and
7530 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
7531 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
7532 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
7533 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
7534 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
7539 // Âîçìîæíî, íàæèìàåì êíîïêó:
7540 if Rnd(16) and IsSafeTrigger() then
7543 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7544 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7546 ReleaseKey(KEY_LEFT
);
7547 ReleaseKey(KEY_RIGHT
);
7551 // Èäåì âëåâî, åñëè íàäî áûëî:
7552 if GetAIFlag('GOLEFT') <> '' then
7554 RemoveAIFlag('GOLEFT');
7555 if CanRunLeft() then
7559 // Èäåì âïðàâî, åñëè íàäî áûëî:
7560 if GetAIFlag('GORIGHT') <> '' then
7562 RemoveAIFlag('GORIGHT');
7563 if CanRunRight() then
7567 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7568 if FObj
.X
< -32 then
7571 if FObj
.X
+32 > gMapInfo
.Width
then
7574 // Ïðûãàåì, åñëè íàäî áûëî:
7575 if GetAIFlag('NEEDJUMP') <> '' then
7578 RemoveAIFlag('NEEDJUMP');
7581 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7582 if GetAIFlag('NEEDSEEUP') <> '' then
7585 ReleaseKey(KEY_DOWN
);
7586 PressKey(KEY_UP
, 20);
7587 RemoveAIFlag('NEEDSEEUP');
7590 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7591 if GetAIFlag('NEEDSEEDOWN') <> '' then
7594 ReleaseKey(KEY_DOWN
);
7595 PressKey(KEY_DOWN
, 20);
7596 RemoveAIFlag('NEEDSEEDOWN');
7599 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7600 if GetAIFlag('GOINHOLE') <> '' then
7601 if not OnGround() then
7603 ReleaseKey(KEY_LEFT
);
7604 ReleaseKey(KEY_RIGHT
);
7605 RemoveAIFlag('GOINHOLE');
7606 SetAIFlag('FALLINHOLE', '1');
7609 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7610 if GetAIFlag('FALLINHOLE') <> '' then
7612 RemoveAIFlag('FALLINHOLE');
7614 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7615 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7616 if GetAIFlag('FALLINHOLE') = '' then
7617 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7623 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7625 CanJumpUp(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*32) and
7629 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7630 if OnGround() and NearHole() then
7631 if NearDeepHole() then // Åñëè ýòî áåçäíà
7633 0..3: Turn(); // Áåæèì îáðàòíî
7634 4: Jump(); // Ïðûãàåì
7635 5: begin // Ïðûãàåì îáðàòíî
7640 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7641 if GetAIFlag('GOINHOLE') = '' then
7643 0: Turn(); // Íå íóæíî òóäà
7644 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7645 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7646 if BorderHole() then
7647 SetAIFlag('GOINHOLE', '1');
7650 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7651 if (not CanRun()) and OnGround() then
7653 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7654 if CanJumpOver() or OnLadder() then
7656 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7657 if Random(2) = 0 then
7659 if IsSafeTrigger() then
7665 // Îñòàëîñü ìàëî âîçäóõà:
7666 if FAir
< 36 * 2 then
7669 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7670 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7671 if BodyInAcid(0, 0) then
7675 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7677 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7678 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7681 {function TBot.NeedItem(Item: Byte): Byte;
7686 procedure TBot
.SelectWeapon(Dist
: Integer);
7690 function HaveAmmo(weapon
: Byte): Boolean;
7693 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7694 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7695 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7696 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7697 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7698 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7699 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7700 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7701 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7702 else Result
:= True;
7707 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7709 if Dist
> BOT_LONGDIST
then
7710 begin // Äàëüíèé áîé
7712 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7714 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7718 else //if Dist > BOT_UNSAFEDIST then
7719 begin // Áëèæíèé áîé
7721 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7723 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7730 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7732 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7738 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7740 Result
:= inherited PickItem(ItemType
, force
, remove
);
7742 if Result
then SetAIFlag('SELECTWEAPON', '1');
7745 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7747 Result
:= inherited Heal(value
, Soft
);
7750 function TBot
.Healthy(): Byte;
7752 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7753 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7754 else if (FHealth
> 50) then Result
:= 2
7755 else if (FHealth
> 20) then Result
:= 1
7759 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7761 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7762 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7765 procedure TBot
.OnDamage(Angle
: SmallInt);
7773 if (Angle
= 0) or (Angle
= 180) then
7776 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7777 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7779 pla
:= g_Player_Get(FLastSpawnerUID
);
7780 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7781 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7784 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7785 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7787 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
7788 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7789 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7794 SetAIFlag('ATTACKLEFT', '1')
7796 SetAIFlag('ATTACKRIGHT', '1');
7800 function TBot
.RunDirection(): TDirection
;
7802 if Abs(Vel
.X
) >= 1 then
7804 if Vel
.X
> 0 then Result
:= TDirection
.D_RIGHT
else Result
:= TDirection
.D_LEFT
;
7806 Result
:= FDirection
;
7809 function TBot
.GetRnd(a
: Byte): Boolean;
7811 if a
= 0 then Result
:= False
7812 else if a
= 255 then Result
:= True
7813 else Result
:= Random(256) > 255-a
;
7816 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7818 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7822 procedure TDifficult
.save (st
: TStream
);
7824 utils
.writeInt(st
, Byte(DiagFire
));
7825 utils
.writeInt(st
, Byte(InvisFire
));
7826 utils
.writeInt(st
, Byte(DiagPrecision
));
7827 utils
.writeInt(st
, Byte(FlyPrecision
));
7828 utils
.writeInt(st
, Byte(Cover
));
7829 utils
.writeInt(st
, Byte(CloseJump
));
7830 st
.WriteBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7831 st
.WriteBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7834 procedure TDifficult
.load (st
: TStream
);
7836 DiagFire
:= utils
.readByte(st
);
7837 InvisFire
:= utils
.readByte(st
);
7838 DiagPrecision
:= utils
.readByte(st
);
7839 FlyPrecision
:= utils
.readByte(st
);
7840 Cover
:= utils
.readByte(st
);
7841 CloseJump
:= utils
.readByte(st
);
7842 st
.ReadBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7843 st
.ReadBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7847 procedure TBot
.SaveState (st
: TStream
);
7852 inherited SaveState(st
);
7853 utils
.writeSign(st
, 'BOT0');
7855 utils
.writeInt(st
, Byte(FSelectedWeapon
));
7857 utils
.writeInt(st
, Word(FTargetUID
));
7858 // Âðåìÿ ïîòåðè öåëè
7859 utils
.writeInt(st
, LongWord(FLastVisible
));
7860 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7861 dw
:= Length(FAIFlags
);
7862 utils
.writeInt(st
, LongInt(dw
));
7864 for i
:= 0 to dw
-1 do
7866 utils
.writeStr(st
, FAIFlags
[i
].Name
, 20);
7867 utils
.writeStr(st
, FAIFlags
[i
].Value
, 20);
7869 // Íàñòðîéêè ñëîæíîñòè
7870 FDifficult
.save(st
);
7874 procedure TBot
.LoadState (st
: TStream
);
7879 inherited LoadState(st
);
7880 if not utils
.checkSign(st
, 'BOT0') then raise XStreamError
.Create('invalid bot signature');
7882 FSelectedWeapon
:= utils
.readByte(st
);
7884 FTargetUID
:= utils
.readWord(st
);
7885 // Âðåìÿ ïîòåðè öåëè
7886 FLastVisible
:= utils
.readLongWord(st
);
7887 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7888 dw
:= utils
.readLongInt(st
);
7889 if (dw
< 0) or (dw
> 16384) then raise XStreamError
.Create('invalid number of bot AI flags');
7890 SetLength(FAIFlags
, dw
);
7892 for i
:= 0 to dw
-1 do
7894 FAIFlags
[i
].Name
:= utils
.readStr(st
, 20);
7895 FAIFlags
[i
].Value
:= utils
.readStr(st
, 20);
7897 // Íàñòðîéêè ñëîæíîñòè
7898 FDifficult
.load(st
);
7903 conRegVar('cheat_berserk_autoswitch', @gBerserkAutoswitch
, 'autoswitch to fist when berserk pack taken', '', true, true);