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 DrawIndicator();
321 procedure DrawBubble();
323 procedure Update(); virtual;
324 procedure RememberState();
325 procedure RecallState();
326 procedure SaveState (st
: TStream
); virtual;
327 procedure LoadState (st
: TStream
); virtual;
328 procedure PauseSounds(Enable
: Boolean);
329 procedure NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
330 procedure DoLerp(Level
: Integer = 2);
331 procedure SetLerp(XTo
, YTo
: Integer);
332 procedure QueueWeaponSwitch(Weapon
: Byte);
333 procedure RealizeCurrentWeapon();
335 procedure JetpackOff
;
336 procedure CatchFire(Attacker
: Word);
338 //WARNING! this does nothing for now, but still call it!
339 procedure positionChanged (); //WARNING! call this after entity position was changed, or coldet will not work right!
341 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
342 procedure moveBy (dx
, dy
: Integer); inline;
344 procedure releaseAllWeaponSwitchKeys ();
345 procedure weaponSwitchKeysStateChange (index
: Integer; pressed
: Boolean);
346 function isWeaponSwitchKeyReleased (index
: Integer): Boolean;
347 procedure weaponSwitchKeysShiftNewStates ();
350 property Vel
: TPoint2i read FObj
.Vel
;
351 property Obj
: TObj read FObj
;
353 property Name
: String read FName write FName
;
354 property Model
: TPlayerModel read FModel
;
355 property Health
: Integer read FHealth write FHealth
;
356 property Lives
: Byte read FLives write FLives
;
357 property Armor
: Integer read FArmor write FArmor
;
358 property Air
: Integer read FAir write FAir
;
359 property JetFuel
: Integer read FJetFuel write FJetFuel
;
360 property Frags
: Integer read FFrags write FFrags
;
361 property Death
: Integer read FDeath write FDeath
;
362 property Kills
: Integer read FKills write FKills
;
363 property CurrWeap
: Byte read FCurrWeap write FCurrWeap
;
364 //property NetForceWeap: Byte read FNetForceWeap write FNetForceWeap;
365 property NetForceWeapFIdx
: LongWord read FNetForceWeapFIdx write FNetForceWeapFIdx
;
366 //property CurrFrameIdx: LongWord read FCurrFrameIdx write FCurrFrameIdx;
367 property MonsterKills
: Integer read FMonsterKills write FMonsterKills
;
368 property Secrets
: Integer read FSecrets
;
369 property GodMode
: Boolean read FGodMode write FGodMode
;
370 property NoTarget
: Boolean read FNoTarget write FNoTarget
;
371 property NoReload
: Boolean read FNoReload write FNoReload
;
372 property alive
: Boolean read FAlive write FAlive
;
373 property Flag
: Byte read FFlag
;
374 property Team
: Byte read FTeam write FTeam
;
375 property Direction
: TDirection read FDirection
;
376 property GameX
: Integer read FObj
.X write FObj
.X
;
377 property GameY
: Integer read FObj
.Y write FObj
.Y
;
378 property GameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
379 property GameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
380 property GameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
381 property GameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
382 property IncCam
: Integer read FIncCam write FIncCam
;
383 property UID
: Word read FUID write FUID
;
384 property JustTeleported
: Boolean read FJustTeleported write FJustTeleported
;
385 property NetTime
: LongWord read FNetTime write FNetTime
;
388 property eName
: String read FName write FName
;
389 property eHealth
: Integer read FHealth write FHealth
;
390 property eLives
: Byte read FLives write FLives
;
391 property eArmor
: Integer read FArmor write FArmor
;
392 property eAir
: Integer read FAir write FAir
;
393 property eJetFuel
: Integer read FJetFuel write FJetFuel
;
394 property eFrags
: Integer read FFrags write FFrags
;
395 property eDeath
: Integer read FDeath write FDeath
;
396 property eKills
: Integer read FKills write FKills
;
397 property eCurrWeap
: Byte read FCurrWeap write FCurrWeap
;
398 property eMonsterKills
: Integer read FMonsterKills write FMonsterKills
;
399 property eSecrets
: Integer read FSecrets write FSecrets
;
400 property eGodMode
: Boolean read FGodMode write FGodMode
;
401 property eNoTarget
: Boolean read FNoTarget write FNoTarget
;
402 property eNoReload
: Boolean read FNoReload write FNoReload
;
403 property eAlive
: Boolean read FAlive write FAlive
;
404 property eFlag
: Byte read FFlag
;
405 property eTeam
: Byte read FTeam write FTeam
;
406 property eDirection
: TDirection read FDirection
;
407 property eGameX
: Integer read FObj
.X write FObj
.X
;
408 property eGameY
: Integer read FObj
.Y write FObj
.Y
;
409 property eGameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
410 property eGameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
411 property eGameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
412 property eGameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
413 property eIncCam
: Integer read FIncCam write FIncCam
;
414 property eUID
: Word read FUID
;
415 property eJustTeleported
: Boolean read FJustTeleported
;
416 property eNetTime
: LongWord read FNetTime
;
418 // set this before assigning something to `eDamage`
419 property eDamageType
: Integer read mEDamageType write mEDamageType
;
420 property eDamage
: Integer write doDamage
;
431 WeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
432 CloseWeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
433 //SafeWeaponPrior: Array [WP_FIRST..WP_LAST] of Byte;
436 procedure save (st
: TStream
);
437 procedure load (st
: TStream
);
445 TBot
= class(TPlayer
)
447 FSelectedWeapon
: Byte;
450 FAIFlags
: Array of TAIFlag
;
451 FDifficult
: TDifficult
;
453 function GetRnd(a
: Byte): Boolean;
454 function GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
455 function RunDirection(): TDirection
;
456 function FullInStep(XInc
, YInc
: Integer): Boolean;
457 //function NeedItem(Item: Byte): Byte;
458 procedure SelectWeapon(Dist
: Integer);
459 procedure SetAIFlag(aName
, fValue
: String20
);
460 function GetAIFlag(aName
: String20
): String20
;
461 procedure RemoveAIFlag(aName
: String20
);
462 function Healthy(): Byte;
463 procedure UpdateMove();
464 procedure UpdateCombat();
465 function KeyPressed(Key
: Word): Boolean;
466 procedure ReleaseKey(Key
: Byte);
467 function TargetOnScreen(TX
, TY
: Integer): Boolean;
468 procedure OnDamage(Angle
: SmallInt); override;
471 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); override;
472 constructor Create(); override;
473 destructor Destroy(); override;
474 procedure Draw(); override;
475 function PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean; override;
476 function Heal(value
: Word; Soft
: Boolean): Boolean; override;
477 procedure Update(); override;
478 procedure SaveState (st
: TStream
); override;
479 procedure LoadState (st
: TStream
); override;
491 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
492 procedure moveBy (dx
, dy
: Integer); inline;
494 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
508 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
509 procedure moveBy (dx
, dy
: Integer); inline;
511 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
514 TCorpse
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
523 FAnimation
: TAnimation
;
524 FAnimationMask
: TAnimation
;
527 constructor Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
528 destructor Destroy(); override;
529 procedure Damage(Value
: Word; vx
, vy
: Integer);
532 procedure SaveState (st
: TStream
);
533 procedure LoadState (st
: TStream
);
535 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
536 procedure moveBy (dx
, dy
: Integer); inline;
538 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
540 function ObjPtr (): PObj
; inline;
542 property Obj
: TObj read FObj
; // copies object
543 property State
: Byte read FState
;
544 property Mess
: Boolean read FMess
;
547 TTeamStat
= Array [TEAM_RED
..TEAM_BLUE
] of
553 gPlayers
: Array of TPlayer
;
554 gCorpses
: Array of TCorpse
;
555 gGibs
: Array of TGib
;
556 gShells
: Array of TShell
;
557 gTeamStat
: TTeamStat
;
558 gFly
: Boolean = False;
559 gAimLine
: Boolean = False;
560 gChatBubble
: Byte = 0;
561 gPlayerIndicator
: Boolean = True;
565 MAX_RUNVEL
: Integer = 8;
566 VEL_JUMP
: Integer = 10;
567 SHELL_TIMEOUT
: Cardinal = 60000;
569 function Lerp(X
, Y
, Factor
: Integer): Integer;
571 procedure g_Gibs_SetMax(Count
: Word);
572 function g_Gibs_GetMax(): Word;
573 procedure g_Corpses_SetMax(Count
: Word);
574 function g_Corpses_GetMax(): Word;
575 procedure g_Shells_SetMax(Count
: Word);
576 function g_Shells_GetMax(): Word;
578 procedure g_Player_Init();
579 procedure g_Player_Free();
580 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
581 function g_Player_CreateFromState (st
: TStream
): Word;
582 procedure g_Player_Remove(UID
: Word);
583 procedure g_Player_ResetTeams();
584 procedure g_Player_UpdateAll();
585 procedure g_Player_DrawAll();
586 procedure g_Player_DrawDebug(p
: TPlayer
);
587 procedure g_Player_DrawHealth();
588 procedure g_Player_RememberAll();
589 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
590 function g_Player_Get(UID
: Word): TPlayer
;
591 function g_Player_GetCount(): Byte;
592 function g_Player_GetStats(): TPlayerStatArray
;
593 function g_Player_ValidName(Name
: String): Boolean;
594 procedure g_Player_CreateCorpse(Player
: TPlayer
);
595 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: String; fColor
: TRGB
);
596 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
597 procedure g_Player_UpdatePhysicalObjects();
598 procedure g_Player_DrawCorpses();
599 procedure g_Player_DrawShells();
600 procedure g_Player_RemoveAllCorpses();
601 procedure g_Player_Corpses_SaveState (st
: TStream
);
602 procedure g_Player_Corpses_LoadState (st
: TStream
);
603 procedure g_Bot_Add(Team
, Difficult
: Byte);
604 procedure g_Bot_AddList(Team
: Byte; lname
: ShortString; num
: Integer = -1);
605 procedure g_Bot_MixNames();
606 procedure g_Bot_RemoveAll();
611 {$INCLUDE ../nogl/noGLuses.inc}
612 {$IFDEF ENABLE_HOLMES}
615 e_log
, g_map
, g_items
, g_console
, g_gfx
, Math
,
616 g_options
, g_triggers
, g_menu
, g_game
, g_grid
,
617 wadreader
, g_main
, g_monsters
, CONFIG
, g_language
,
618 g_net
, g_netmsg
, g_window
,
621 const PLR_SAVE_VERSION
= 0;
631 diag_precision
: Byte;
635 w_prior1
: Array [WP_FIRST
..WP_LAST
] of Byte;
636 w_prior2
: Array [WP_FIRST
..WP_LAST
] of Byte;
637 w_prior3
: Array [WP_FIRST
..WP_LAST
] of Byte;
641 TIME_RESPAWN1
= 1500;
642 TIME_RESPAWN2
= 2000;
643 TIME_RESPAWN3
= 3000;
646 JET_MAX
= 540; // ~30 sec
647 PLAYER_SUIT_TIME
= 30000;
648 PLAYER_INVUL_TIME
= 30000;
649 PLAYER_INVIS_TIME
= 35000;
650 FRAG_COMBO_TIME
= 3000;
654 ANGLE_RIGHTDOWN
= -35;
656 ANGLE_LEFTDOWN
= -145;
657 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
658 WEAPONPOINT
: Array [TDirection
] of TDFPoint
= ((X
:16; Y
:32), (X
:47; Y
:32));
661 BOT_UNSAFEDIST
= 128;
662 TEAMCOLOR
: Array [TEAM_RED
..TEAM_BLUE
] of TRGB
= ((R
:255; G
:0; B
:0),
664 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
665 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
666 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
667 DIFFICULT_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
668 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
669 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
670 DIFFICULT_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
671 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
672 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
673 WEAPON_PRIOR1
: Array [WP_FIRST
..WP_LAST
] of Byte =
674 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
675 WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
676 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
677 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
678 WEAPON_PRIOR2
: Array [WP_FIRST
..WP_LAST
] of Byte =
679 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
680 WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
681 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
682 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
683 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
684 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
685 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
686 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
687 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
688 WEAPON_RELOAD
: Array [WP_FIRST
..WP_LAST
] of Byte =
689 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
691 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
692 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
694 BOTNAMES_FILENAME
= 'botnames.txt';
695 BOTLIST_FILENAME
= 'botlist.txt';
699 MaxCorpses
: Word = 20;
700 MaxShells
: Word = 300;
701 CurrentGib
: Integer = 0;
702 CurrentShell
: Integer = 0;
703 BotNames
: Array of String;
704 BotList
: Array of TBotProfile
;
707 function Lerp(X
, Y
, Factor
: Integer): Integer;
709 Result
:= X
+ ((Y
- X
) div Factor
);
712 function SameTeam(UID1
, UID2
: Word): Boolean;
716 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
717 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
719 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
721 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
722 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
724 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
727 procedure g_Gibs_SetMax(Count
: Word);
730 SetLength(gGibs
, Count
);
732 if CurrentGib
>= Count
then
736 function g_Gibs_GetMax(): Word;
741 procedure g_Shells_SetMax(Count
: Word);
744 SetLength(gShells
, Count
);
746 if CurrentShell
>= Count
then
750 function g_Shells_GetMax(): Word;
756 procedure g_Corpses_SetMax(Count
: Word);
759 SetLength(gCorpses
, Count
);
762 function g_Corpses_GetMax(): Word;
764 Result
:= MaxCorpses
;
767 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
777 // Åñòü ëè ìåñòî â gPlayers:
778 if gPlayers
<> nil then
779 for a
:= 0 to High(gPlayers
) do
780 if gPlayers
[a
] = nil then
786 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
789 SetLength(gPlayers
, Length(gPlayers
)+1);
793 // Ñîçäàåì îáúåêò èãðîêà:
795 gPlayers
[a
] := TBot
.Create()
797 gPlayers
[a
] := TPlayer
.Create();
800 gPlayers
[a
].FActualModelName
:= ModelName
;
801 gPlayers
[a
].SetModel(ModelName
);
803 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
804 if gPlayers
[a
].FModel
= nil then
808 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
812 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
813 if Random(2) = 0 then
817 gPlayers
[a
].FPreferredTeam
:= Team
;
819 case gGameSettings
.GameMode
of
820 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
822 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
824 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
827 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
828 gPlayers
[a
].FColor
:= Color
;
829 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
830 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
832 gPlayers
[a
].FModel
.Color
:= Color
;
834 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
835 gPlayers
[a
].FAlive
:= False;
837 Result
:= gPlayers
[a
].FUID
;
840 function g_Player_CreateFromState (st
: TStream
): Word;
847 if (st
= nil) then exit
; //???
850 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
851 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
854 Bot
:= utils
.readBool(st
);
859 // Åñòü ëè ìåñòî â gPlayers:
860 for a
:= 0 to High(gPlayers
) do if (gPlayers
[a
] = nil) then begin ok
:= true; break
; end;
862 // Íåò ìåñòà - ðàñøèðÿåì gPlayers
865 SetLength(gPlayers
, Length(gPlayers
)+1);
869 // Ñîçäàåì îáúåêò èãðîêà
871 gPlayers
[a
] := TBot
.Create()
873 gPlayers
[a
] := TPlayer
.Create();
874 gPlayers
[a
].FIamBot
:= Bot
;
875 gPlayers
[a
].FPhysics
:= True;
878 gPlayers
[a
].FUID
:= utils
.readWord(st
);
880 gPlayers
[a
].FName
:= utils
.readStr(st
);
882 gPlayers
[a
].FTeam
:= utils
.readByte(st
);
883 gPlayers
[a
].FPreferredTeam
:= gPlayers
[a
].FTeam
;
885 gPlayers
[a
].FAlive
:= utils
.readBool(st
);
886 // Èçðàñõîäîâàë ëè âñå æèçíè
887 gPlayers
[a
].FNoRespawn
:= utils
.readBool(st
);
889 b
:= utils
.readByte(st
);
890 if b
= 1 then gPlayers
[a
].FDirection
:= TDirection
.D_LEFT
else gPlayers
[a
].FDirection
:= TDirection
.D_RIGHT
; // b = 2
892 gPlayers
[a
].FHealth
:= utils
.readLongInt(st
);
894 gPlayers
[a
].FLives
:= utils
.readByte(st
);
896 gPlayers
[a
].FArmor
:= utils
.readLongInt(st
);
898 gPlayers
[a
].FAir
:= utils
.readLongInt(st
);
900 gPlayers
[a
].FJetFuel
:= utils
.readLongInt(st
);
902 gPlayers
[a
].FPain
:= utils
.readLongInt(st
);
904 gPlayers
[a
].FKills
:= utils
.readLongInt(st
);
906 gPlayers
[a
].FMonsterKills
:= utils
.readLongInt(st
);
908 gPlayers
[a
].FFrags
:= utils
.readLongInt(st
);
910 gPlayers
[a
].FFragCombo
:= utils
.readByte(st
);
911 // Âðåìÿ ïîñëåäíåãî ôðàãà
912 gPlayers
[a
].FLastFrag
:= utils
.readLongWord(st
);
914 gPlayers
[a
].FDeath
:= utils
.readLongInt(st
);
916 gPlayers
[a
].FFlag
:= utils
.readByte(st
);
918 gPlayers
[a
].FSecrets
:= utils
.readLongInt(st
);
920 gPlayers
[a
].FCurrWeap
:= utils
.readByte(st
);
921 //gPlayers[a].FNetForceWeap := gPlayers[a].FCurrWeap;
922 // Ñëåäóþùåå æåëàåìîå îðóæèå
923 gPlayers
[a
].FNextWeap
:= utils
.readWord(st
);
925 gPlayers
[a
].FNextWeapDelay
:= utils
.readByte(st
);
927 gPlayers
[a
].FBFGFireCounter
:= utils
.readSmallInt(st
);
929 gPlayers
[a
].FDamageBuffer
:= utils
.readLongInt(st
);
930 // Ïîñëåäíèé óäàðèâøèé
931 gPlayers
[a
].FLastSpawnerUID
:= utils
.readWord(st
);
932 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
933 gPlayers
[a
].FLastHit
:= utils
.readByte(st
);
935 Obj_LoadState(@gPlayers
[a
].FObj
, st
);
936 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
937 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FAmmo
[i
] := utils
.readWord(st
);
938 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
939 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FMaxAmmo
[i
] := utils
.readWord(st
);
941 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FWeapon
[i
] := utils
.readBool(st
);
942 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
943 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FReloading
[i
] := utils
.readWord(st
);
945 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_ITEM_BACKPACK
);
946 // Íàëè÷èå êðàñíîãî êëþ÷à
947 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_RED
);
948 // Íàëè÷èå çåëåíîãî êëþ÷à
949 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_GREEN
);
950 // Íàëè÷èå ñèíåãî êëþ÷à
951 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_BLUE
);
953 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_BERSERK
);
954 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
955 for i
:= MR_SUIT
to MR_MAX
do gPlayers
[a
].FMegaRulez
[i
] := utils
.readLongWord(st
);
956 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
957 for i
:= T_RESPAWN
to T_FLAGCAP
do gPlayers
[a
].FTime
[i
] := utils
.readLongWord(st
);
960 gPlayers
[a
].FActualModelName
:= utils
.readStr(st
);
962 gPlayers
[a
].FColor
.R
:= utils
.readByte(st
);
963 gPlayers
[a
].FColor
.G
:= utils
.readByte(st
);
964 gPlayers
[a
].FColor
.B
:= utils
.readByte(st
);
965 // Îáíîâëÿåì ìîäåëü èãðîêà
966 gPlayers
[a
].SetModel(gPlayers
[a
].FActualModelName
);
968 // Íåò ìîäåëè - ñîçäàíèå íåâîçìîæíî
969 if (gPlayers
[a
].FModel
= nil) then
973 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [gPlayers
[a
].FActualModelName
]));
977 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû
978 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
979 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
981 gPlayers
[a
].FModel
.Color
:= gPlayers
[a
].FColor
;
983 result
:= gPlayers
[a
].FUID
;
987 procedure g_Player_ResetTeams();
991 if g_Game_IsClient
then
993 if gPlayers
= nil then
995 for a
:= Low(gPlayers
) to High(gPlayers
) do
996 if gPlayers
[a
] <> nil then
997 case gGameSettings
.GameMode
of
999 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
1001 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
1002 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
1003 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
1006 gPlayers
[a
].ChangeTeam(TEAM_RED
)
1008 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
1011 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
1015 procedure g_Bot_Add(Team
, Difficult
: Byte);
1018 _name
, _model
: String;
1021 if not g_Game_IsServer
then Exit
;
1023 // Ñïèñîê íàçâàíèé ìîäåëåé:
1024 m
:= g_PlayerModel_GetNames();
1029 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1030 Team
:= TEAM_COOP
// COOP
1032 if gGameSettings
.GameMode
= GM_DM
then
1033 Team
:= TEAM_NONE
// DM
1035 if Team
= TEAM_NONE
then // CTF / TDM
1037 // Àâòîáàëàíñ êîìàíä:
1041 for a
:= 0 to High(gPlayers
) do
1042 if gPlayers
[a
] <> nil then
1044 if gPlayers
[a
].Team
= TEAM_RED
then
1047 if gPlayers
[a
].Team
= TEAM_BLUE
then
1057 if Random(2) = 0 then
1063 // Âûáèðàåì áîòó èìÿ:
1065 if BotNames
<> nil then
1066 for a
:= 0 to High(BotNames
) do
1067 if g_Player_ValidName(BotNames
[a
]) then
1069 _name
:= BotNames
[a
];
1073 // Èìåíè íåò, çàäàåì ñëó÷àéíîå:
1076 _name
:= Format('DFBOT%.2d', [Random(100)]);
1077 until g_Player_ValidName(_name
);
1079 // Âûáèðàåì ñëó÷àéíóþ ìîäåëü:
1080 _model
:= m
[Random(Length(m
))];
1083 with g_Player_Get(g_Player_Create(_model
,
1084 _RGB(Min(Random(9)*32, 255),
1085 Min(Random(9)*32, 255),
1086 Min(Random(9)*32, 255)),
1087 Team
, True)) as TBot
do
1092 1: FDifficult
:= DIFFICULT_EASY
;
1093 2: FDifficult
:= DIFFICULT_MEDIUM
;
1094 else FDifficult
:= DIFFICULT_HARD
;
1097 for a
:= WP_FIRST
to WP_LAST
do
1099 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1100 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1101 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1104 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1106 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1107 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1112 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString; num
: Integer = -1);
1115 _name
, _model
: String;
1118 if not g_Game_IsServer
then Exit
;
1120 // Ñïèñîê íàçâàíèé ìîäåëåé:
1121 m
:= g_PlayerModel_GetNames();
1126 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1127 Team
:= TEAM_COOP
// COOP
1129 if gGameSettings
.GameMode
= GM_DM
then
1130 Team
:= TEAM_NONE
// DM
1132 if Team
= TEAM_NONE
then
1133 Team
:= BotList
[num
].team
; // CTF / TDM
1135 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1136 lName
:= AnsiLowerCase(lName
);
1137 if (num
< 0) or (num
> Length(BotList
)-1) then
1139 if (num
= -1) and (lName
<> '') and (BotList
<> nil) then
1140 for a
:= 0 to High(BotList
) do
1141 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1150 _name
:= BotList
[num
].name
;
1151 // Çàíÿòî - âûáèðàåì ñëó÷àéíîå:
1152 if not g_Player_ValidName(_name
) then
1154 _name
:= Format('DFBOT%.2d', [Random(100)]);
1155 until g_Player_ValidName(_name
);
1158 _model
:= BotList
[num
].model
;
1159 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1160 if not InSArray(_model
, m
) then
1161 _model
:= m
[Random(Length(m
))];
1164 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1168 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1169 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1170 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1171 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1172 FDifficult
.Cover
:= BotList
[num
].cover
;
1173 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1175 for a
:= WP_FIRST
to WP_LAST
do
1177 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1178 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1179 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1182 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1184 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1188 procedure g_Bot_RemoveAll();
1192 if not g_Game_IsServer
then Exit
;
1193 if gPlayers
= nil then Exit
;
1195 for a
:= 0 to High(gPlayers
) do
1196 if gPlayers
[a
] <> nil then
1197 if gPlayers
[a
] is TBot
then
1199 gPlayers
[a
].Lives
:= 0;
1200 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1201 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1202 g_Player_Remove(gPlayers
[a
].FUID
);
1208 procedure g_Bot_MixNames();
1213 if BotNames
<> nil then
1214 for a
:= 0 to High(BotNames
) do
1216 b
:= Random(Length(BotNames
));
1218 Botnames
[a
] := BotNames
[b
];
1223 procedure g_Player_Remove(UID
: Word);
1227 if gPlayers
= nil then Exit
;
1229 if g_Game_IsServer
and g_Game_IsNet
then
1230 MH_SEND_PlayerDelete(UID
);
1232 for i
:= 0 to High(gPlayers
) do
1233 if gPlayers
[i
] <> nil then
1234 if gPlayers
[i
].FUID
= UID
then
1236 if gPlayers
[i
] is TPlayer
then
1237 TPlayer(gPlayers
[i
]).Free()
1239 TBot(gPlayers
[i
]).Free();
1245 procedure g_Player_Init();
1255 if not FileExists(DataDir
+ BOTNAMES_FILENAME
) then
1258 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1259 AssignFile(F
, DataDir
+ BOTNAMES_FILENAME
);
1270 SetLength(BotNames
, Length(BotNames
)+1);
1271 BotNames
[High(BotNames
)] := s
;
1279 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1280 config
:= TConfig
.CreateFile(DataDir
+ BOTLIST_FILENAME
);
1284 while config
.SectionExists(IntToStr(a
)) do
1286 SetLength(BotList
, Length(BotList
)+1);
1288 with BotList
[High(BotList
)] do
1291 name
:= config
.ReadStr(IntToStr(a
), 'name', '');
1293 model
:= config
.ReadStr(IntToStr(a
), 'model', '');
1295 if config
.ReadStr(IntToStr(a
), 'team', 'red') = 'red' then
1300 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1301 color
.R
:= StrToIntDef(sa
[0], 0);
1302 color
.G
:= StrToIntDef(sa
[1], 0);
1303 color
.B
:= StrToIntDef(sa
[2], 0);
1304 // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì:
1305 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0);
1306 // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó:
1307 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0);
1308 // Òî÷íîñòü ñòðåëüáû ïîä óãëîì:
1309 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0);
1310 // Òî÷íîñòü ñòðåëüáû â ïîëåòå:
1311 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0);
1312 // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ:
1313 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0);
1314 // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà:
1315 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0);
1316 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ:
1317 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1318 if Length(sa
) = 10 then
1320 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1321 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ:
1322 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1323 if Length(sa
) = 10 then
1325 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1327 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1328 if Length(sa) = 10 then
1330 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1339 procedure g_Player_Free();
1343 if gPlayers
<> nil then
1345 for i
:= 0 to High(gPlayers
) do
1346 if gPlayers
[i
] <> nil then
1348 if gPlayers
[i
] is TPlayer
then
1349 TPlayer(gPlayers
[i
]).Free()
1351 TBot(gPlayers
[i
]).Free();
1362 procedure g_Player_UpdateAll();
1366 if gPlayers
= nil then Exit
;
1368 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1369 for i
:= 0 to High(gPlayers
) do
1371 if gPlayers
[i
] <> nil then
1373 if gPlayers
[i
] is TPlayer
then
1375 gPlayers
[i
].Update();
1376 if g_Game_IsClient
or not g_Game_IsNet
then
1378 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1383 // bot updates weapons in `UpdateCombat()`
1384 TBot(gPlayers
[i
]).Update();
1388 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1391 procedure g_Player_DrawAll();
1395 if gPlayers
= nil then Exit
;
1397 for i
:= 0 to High(gPlayers
) do
1398 if gPlayers
[i
] <> nil then
1399 if gPlayers
[i
] is TPlayer
then gPlayers
[i
].Draw()
1400 else TBot(gPlayers
[i
]).Draw();
1403 procedure g_Player_DrawDebug(p
: TPlayer
);
1407 if p
= nil then Exit
;
1408 if (@p
.FObj
) = nil then Exit
;
1410 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1412 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p
.FObj
.X
), gStdFont
);
1413 e_TextureFontPrint(0, fH
, 'Pos Y: ' + IntToStr(p
.FObj
.Y
), gStdFont
);
1414 e_TextureFontPrint(0, fH
* 2, 'Vel X: ' + IntToStr(p
.FObj
.Vel
.X
), gStdFont
);
1415 e_TextureFontPrint(0, fH
* 3, 'Vel Y: ' + IntToStr(p
.FObj
.Vel
.Y
), gStdFont
);
1416 e_TextureFontPrint(0, fH
* 4, 'Acc X: ' + IntToStr(p
.FObj
.Accel
.X
), gStdFont
);
1417 e_TextureFontPrint(0, fH
* 5, 'Acc Y: ' + IntToStr(p
.FObj
.Accel
.Y
), gStdFont
);
1420 procedure g_Player_DrawHealth();
1425 if gPlayers
= nil then Exit
;
1426 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1428 for i
:= 0 to High(gPlayers
) do
1429 if gPlayers
[i
] <> nil then
1431 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1432 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
* 2,
1433 IntToStr(gPlayers
[i
].FHealth
), gStdFont
);
1434 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1435 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
,
1436 IntToStr(gPlayers
[i
].FArmor
), gStdFont
);
1440 function g_Player_Get(UID
: Word): TPlayer
;
1446 if gPlayers
= nil then
1449 for a
:= 0 to High(gPlayers
) do
1450 if gPlayers
[a
] <> nil then
1451 if gPlayers
[a
].FUID
= UID
then
1453 Result
:= gPlayers
[a
];
1458 function g_Player_GetCount(): Byte;
1464 if gPlayers
= nil then
1467 for a
:= 0 to High(gPlayers
) do
1468 if gPlayers
[a
] <> nil then
1469 Result
:= Result
+ 1;
1472 function g_Player_GetStats(): TPlayerStatArray
;
1478 if gPlayers
= nil then Exit
;
1480 for a
:= 0 to High(gPlayers
) do
1481 if gPlayers
[a
] <> nil then
1483 SetLength(Result
, Length(Result
)+1);
1484 with Result
[High(Result
)] do
1486 Ping
:= gPlayers
[a
].FPing
;
1487 Loss
:= gPlayers
[a
].FLoss
;
1488 Name
:= gPlayers
[a
].FName
;
1489 Team
:= gPlayers
[a
].FTeam
;
1490 Frags
:= gPlayers
[a
].FFrags
;
1491 Deaths
:= gPlayers
[a
].FDeath
;
1492 Kills
:= gPlayers
[a
].FKills
;
1493 Color
:= gPlayers
[a
].FModel
.Color
;
1494 Lives
:= gPlayers
[a
].FLives
;
1495 Spectator
:= gPlayers
[a
].FSpectator
;
1500 procedure g_Player_RememberAll
;
1504 for i
:= Low(gPlayers
) to High(gPlayers
) do
1505 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
then
1506 gPlayers
[i
].RememberState
;
1509 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1513 gTeamStat
[TEAM_RED
].Goals
:= 0;
1514 gTeamStat
[TEAM_BLUE
].Goals
:= 0;
1516 if gPlayers
<> nil then
1517 for i
:= 0 to High(gPlayers
) do
1518 if gPlayers
[i
] <> nil then
1520 gPlayers
[i
].Reset(Force
);
1522 if gPlayers
[i
] is TPlayer
then
1524 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1525 gPlayers
[i
].Respawn(Silent
)
1527 gPlayers
[i
].Spectate();
1530 TBot(gPlayers
[i
]).Respawn(Silent
);
1534 procedure g_Player_CreateCorpse(Player
: TPlayer
);
1540 if Player
.alive
then
1543 // Ðàçðûâàåì ñâÿçü ñ ïðåæíèì òðóïîì:
1544 if gCorpses
<> nil then
1545 for i
:= 0 to High(gCorpses
) do
1546 if gCorpses
[i
] <> nil then
1547 if gCorpses
[i
].FPlayerUID
= Player
.FUID
then
1548 gCorpses
[i
].FPlayerUID
:= 0;
1550 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1555 if (FHealth
>= -50) or (gGibsCount
= 0) then
1557 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1561 for find_id
:= 0 to High(gCorpses
) do
1562 if gCorpses
[find_id
] = nil then
1569 find_id
:= Random(Length(gCorpses
));
1571 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.Name
, FHealth
< -20);
1572 gCorpses
[find_id
].FColor
:= FModel
.Color
;
1573 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1574 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1575 gCorpses
[find_id
].FPlayerUID
:= FUID
;
1578 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
,
1579 FObj
.Y
+ PLAYER_RECT_CY
,
1580 FModel
.Name
, FModel
.Color
);
1584 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1588 if (gShells
= nil) or (Length(gShells
) = 0) then
1591 with gShells
[CurrentShell
] do
1597 if T
= SHELL_BULLET
then
1599 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID
) then
1603 Obj
.Rect
.Width
:= 4;
1604 Obj
.Rect
.Height
:= 2;
1608 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID
) then
1612 Obj
.Rect
.Width
:= 7;
1613 Obj
.Rect
.Height
:= 3;
1619 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1620 positionChanged(); // this updates spatial accelerators
1621 RAngle
:= Random(360);
1622 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1624 if CurrentShell
>= High(gShells
) then
1631 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: string; fColor
: TRGB
);
1634 GibsArray
: TGibsArray
;
1637 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1639 if not g_PlayerModel_GetGibs(ModelName
, GibsArray
) then
1641 Blood
:= g_PlayerModel_GetBlood(ModelName
);
1643 for a
:= 0 to High(GibsArray
) do
1644 with gGibs
[CurrentGib
] do
1647 ID
:= GibsArray
[a
].ID
;
1648 MaskID
:= GibsArray
[a
].MaskID
;
1651 Obj
.Rect
:= GibsArray
[a
].Rect
;
1652 Obj
.X
:= fX
-GibsArray
[a
].Rect
.X
-(GibsArray
[a
].Rect
.Width
div 2);
1653 Obj
.Y
:= fY
-GibsArray
[a
].Rect
.Y
-(GibsArray
[a
].Rect
.Height
div 2);
1654 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1655 positionChanged(); // this updates spatial accelerators
1656 RAngle
:= Random(360);
1658 if gBloodCount
> 0 then
1659 g_GFX_Blood(fX
, fY
, 16*gBloodCount
+Random(5*gBloodCount
), -16+Random(33), -16+Random(33),
1660 Random(48), Random(48), Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
1662 if CurrentGib
>= High(gGibs
) then
1669 procedure g_Player_UpdatePhysicalObjects();
1675 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1680 if T
= SHELL_BULLET
then
1681 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1683 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1688 if gGibs
<> nil then
1689 for i
:= 0 to High(gGibs
) do
1690 if gGibs
[i
].alive
then
1694 mr
:= g_Obj_Move(@Obj
, True, False, True);
1695 positionChanged(); // this updates spatial accelerators
1697 if WordBool(mr
and MOVE_FALLOUT
) then
1703 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1704 if WordBool(mr
and MOVE_HITWALL
) then
1705 Obj
.Vel
.X
:= -(vel
.X
div 2);
1706 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1707 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1709 if (Obj
.Vel
.X
>= 0) then
1711 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1712 if RAngle
>= 360 then
1713 RAngle
:= RAngle
mod 360;
1714 end else begin // Counter-clockwise
1715 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1717 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1720 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1721 if gTime
mod (GAME_TICK
*3) = 0 then
1722 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1726 if gCorpses
<> nil then
1727 for i
:= 0 to High(gCorpses
) do
1728 if gCorpses
[i
] <> nil then
1729 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1735 gCorpses
[i
].Update();
1738 if gShells
<> nil then
1739 for i
:= 0 to High(gShells
) do
1740 if gShells
[i
].alive
then
1744 mr
:= g_Obj_Move(@Obj
, True, False, True);
1745 positionChanged(); // this updates spatial accelerators
1747 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1753 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1754 if WordBool(mr
and MOVE_HITWALL
) then
1756 Obj
.Vel
.X
:= -(vel
.X
div 2);
1757 if not WordBool(mr
and MOVE_INWATER
) then
1758 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1760 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1762 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1763 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1764 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1766 if RAngle
mod 90 <> 0 then
1767 RAngle
:= (RAngle
div 90) * 90;
1769 else if not WordBool(mr
and MOVE_INWATER
) then
1770 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1773 if (Obj
.Vel
.X
>= 0) then
1775 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1776 if RAngle
>= 360 then
1777 RAngle
:= RAngle
mod 360;
1778 end else begin // Counter-clockwise
1779 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1781 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1787 procedure TGib
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1789 x
:= Obj
.X
+Obj
.Rect
.X
;
1790 y
:= Obj
.Y
+Obj
.Rect
.Y
;
1791 w
:= Obj
.Rect
.Width
;
1792 h
:= Obj
.Rect
.Height
;
1795 procedure TGib
.moveBy (dx
, dy
: Integer); inline;
1797 if (dx
<> 0) or (dy
<> 0) then
1806 procedure TShell
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1810 w
:= Obj
.Rect
.Width
;
1811 h
:= Obj
.Rect
.Height
;
1814 procedure TShell
.moveBy (dx
, dy
: Integer); inline;
1816 if (dx
<> 0) or (dy
<> 0) then
1825 procedure TGib
.positionChanged (); inline; begin end;
1826 procedure TShell
.positionChanged (); inline; begin end;
1829 procedure g_Player_DrawCorpses();
1834 if gGibs
<> nil then
1835 for i
:= 0 to High(gGibs
) do
1836 if gGibs
[i
].alive
then
1839 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1842 a
.X
:= Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2);
1843 a
.y
:= Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2);
1845 e_DrawAdv(ID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1848 e_DrawAdv(MaskID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1854 if gCorpses
<> nil then
1855 for i
:= 0 to High(gCorpses
) do
1856 if gCorpses
[i
] <> nil then
1860 procedure g_Player_DrawShells();
1865 if gShells
<> nil then
1866 for i
:= 0 to High(gShells
) do
1867 if gShells
[i
].alive
then
1870 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1876 e_DrawAdv(SpriteID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1880 procedure g_Player_RemoveAllCorpses();
1886 SetLength(gGibs
, MaxGibs
);
1887 SetLength(gShells
, MaxGibs
);
1891 if gCorpses
<> nil then
1892 for i
:= 0 to High(gCorpses
) do
1896 SetLength(gCorpses
, MaxCorpses
);
1899 procedure g_Player_Corpses_SaveState (st
: TStream
);
1903 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ
1905 for i
:= 0 to High(gCorpses
) do if (gCorpses
[i
] <> nil) then Inc(count
);
1907 // Êîëè÷åñòâî òðóïîâ
1908 utils
.writeInt(st
, LongInt(count
));
1910 if (count
= 0) then exit
;
1913 for i
:= 0 to High(gCorpses
) do
1915 if gCorpses
[i
] <> nil then
1918 utils
.writeStr(st
, gCorpses
[i
].FModelName
);
1920 utils
.writeBool(st
, gCorpses
[i
].Mess
);
1921 // Ñîõðàíÿåì äàííûå òðóïà:
1922 gCorpses
[i
].SaveState(st
);
1928 procedure g_Player_Corpses_LoadState (st
: TStream
);
1936 g_Player_RemoveAllCorpses();
1938 // Êîëè÷åñòâî òðóïîâ:
1939 count
:= utils
.readLongInt(st
);
1940 if (count
< 0) or (count
> Length(gCorpses
)) then raise XStreamError
.Create('invalid number of corpses');
1942 if (count
= 0) then exit
;
1945 for i
:= 0 to count
-1 do
1948 str
:= utils
.readStr(st
);
1950 b
:= utils
.readBool(st
);
1952 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1953 // Çàãðóæàåì äàííûå òðóïà
1954 gCorpses
[i
].LoadState(st
);
1961 function TPlayer
.isValidViewPort (): Boolean; inline; begin result
:= (viewPortW
> 0) and (viewPortH
> 0); end;
1963 procedure TPlayer
.BFGHit();
1965 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1966 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
1967 if g_Game_IsServer
and g_Game_IsNet
then
1968 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1969 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
1973 procedure TPlayer
.ChangeModel(ModelName
: string);
1975 locModel
: TPlayerModel
;
1977 locModel
:= g_PlayerModel_Get(ModelName
);
1978 if locModel
= nil then Exit
;
1984 procedure TPlayer
.SetModel(ModelName
: string);
1988 m
:= g_PlayerModel_Get(ModelName
);
1991 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
1992 m
:= g_PlayerModel_Get('doomer');
1995 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
2000 if FModel
<> nil then
2005 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2006 FModel
.Color
:= FColor
2008 FModel
.Color
:= TEAMCOLOR
[FTeam
];
2009 FModel
.SetWeapon(FCurrWeap
);
2010 FModel
.SetFlag(FFlag
);
2011 SetDirection(FDirection
);
2014 procedure TPlayer
.SetColor(Color
: TRGB
);
2017 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2018 if FModel
<> nil then FModel
.Color
:= Color
;
2021 procedure TPlayer
.SwitchTeam
;
2023 if g_Game_IsClient
then
2025 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
2027 if gGameOn
and FAlive
then
2028 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
2030 if FTeam
= TEAM_RED
then
2032 ChangeTeam(TEAM_BLUE
);
2033 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
2034 if g_Game_IsNet
then
2035 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
2039 ChangeTeam(TEAM_RED
);
2040 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
2041 if g_Game_IsNet
then
2042 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
2044 FPreferredTeam
:= FTeam
;
2047 procedure TPlayer
.ChangeTeam(Team
: Byte);
2054 TEAM_RED
, TEAM_BLUE
:
2055 FModel
.Color
:= TEAMCOLOR
[Team
];
2057 FModel
.Color
:= FColor
;
2059 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
2060 MH_SEND_PlayerStats(FUID
);
2064 procedure TPlayer.CollideItem();
2069 if gItems = nil then Exit;
2070 if not FAlive then Exit;
2072 for i := 0 to High(gItems) do
2075 if (ItemType <> ITEM_NONE) and alive then
2076 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
2077 PLAYER_RECT.Height, @Obj) then
2079 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
2081 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
2082 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
2083 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
2084 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
2085 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
2087 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
2088 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
2089 (gGameSettings.GameType = GT_SINGLE) and
2090 (g_Player_GetCount() > 1)) then
2091 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
2097 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
2099 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
2100 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
2104 constructor TPlayer
.Create();
2110 mEDamageType
:= HIT_SOME
;
2116 FSawSound
:= TPlayableSound
.Create();
2117 FSawSoundIdle
:= TPlayableSound
.Create();
2118 FSawSoundHit
:= TPlayableSound
.Create();
2119 FSawSoundSelect
:= TPlayableSound
.Create();
2120 FJetSoundFly
:= TPlayableSound
.Create();
2121 FJetSoundOn
:= TPlayableSound
.Create();
2122 FJetSoundOff
:= TPlayableSound
.Create();
2124 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
2125 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
2126 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
2127 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
2128 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
2129 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
2130 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
2132 FSpectatePlayer
:= -1;
2136 FSavedState
.WaitRecall
:= False;
2142 FActualModelName
:= 'doomer';
2145 FObj
.Rect
:= PLAYER_RECT
;
2147 FBFGFireCounter
:= -1;
2148 FJustTeleported
:= False;
2151 //FNetForceWeap := FCurrWeap;
2152 FNetForceWeapFIdx
:= 0;
2153 //FCurrFrameIdx := 0;
2156 releaseAllWeaponSwitchKeys();
2160 procedure TPlayer
.releaseAllWeaponSwitchKeys ();
2164 for f
:= 0 to High(weaponSwitchKeyReleased
) do weaponSwitchKeyReleased
[f
] := $03;
2167 procedure TPlayer
.weaponSwitchKeysStateChange (index
: Integer; pressed
: Boolean);
2169 Inc(index
, 2); // -2: prev; -1: next
2170 if (index
< 0) or (index
> High(weaponSwitchKeyReleased
)) then exit
;
2171 weaponSwitchKeyReleased
[index
] := weaponSwitchKeyReleased
[index
] or $02;
2172 if (pressed
) then weaponSwitchKeyReleased
[index
] := weaponSwitchKeyReleased
[index
] xor $02;
2175 function TPlayer
.isWeaponSwitchKeyReleased (index
: Integer): Boolean;
2177 Inc(index
, 2); // -2: prev; -1: next
2178 if (index
< 0) or (index
> High(weaponSwitchKeyReleased
)) then
2184 result
:= (weaponSwitchKeyReleased
[index
] and $01) <> 0;
2188 procedure TPlayer
.weaponSwitchKeysShiftNewStates ();
2192 // copy bit 1 to bit 0
2193 for f
:= 0 to High(weaponSwitchKeyReleased
) do
2195 weaponSwitchKeyReleased
[f
] :=
2196 (weaponSwitchKeyReleased
[f
] and $02) or
2197 ((weaponSwitchKeyReleased
[f
] shr 1) and $01);
2202 procedure TPlayer
.positionChanged (); inline;
2206 procedure TPlayer
.doDamage (v
: Integer);
2208 if (v
<= 0) then exit
;
2209 if (v
> 32767) then v
:= 32767;
2210 Damage(v
, 0, 0, 0, mEDamageType
);
2213 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
2217 if (not g_Game_IsClient
) and (not FAlive
) then
2222 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2223 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2225 if not g_Game_IsClient
then
2228 if t
= HIT_TRAP
then
2230 // Ëîâóøêà óáèâàåò ñðàçó:
2232 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2234 if t
= HIT_SELF
then
2238 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2241 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2242 FMegaRulez
[MR_SUIT
] := 0;
2243 FMegaRulez
[MR_INVUL
] := 0;
2244 FMegaRulez
[MR_INVIS
] := 0;
2248 // Íî îò îñòàëüíîãî ñïàñàåò:
2249 if FMegaRulez
[MR_INVUL
] >= gTime
then
2256 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2257 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2258 (SpawnerUID
= FUID
) or
2259 (not SameTeam(FUID
, SpawnerUID
)) then
2261 FLastSpawnerUID
:= SpawnerUID
;
2263 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2264 if gBloodCount
> 0 then
2266 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2267 if value
div 4 <= c
then
2268 c
:= c
- (value
div 4)
2272 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2276 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2277 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2280 if t
= HIT_WATER
then
2281 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2282 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2287 Inc(FDamageBuffer
, value
);
2291 FPain
:= FPain
+ value
;
2294 if g_Game_IsServer
and g_Game_IsNet
then
2296 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2297 MH_SEND_PlayerStats(FUID
);
2298 MH_SEND_PlayerPos(False, FUID
);
2302 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2305 if g_Game_IsClient
then
2310 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2312 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2315 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2317 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2321 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2322 MH_SEND_PlayerStats(FUID
);
2325 destructor TPlayer
.Destroy();
2327 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2329 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2333 FSawSoundIdle
.Free();
2334 FSawSoundHit
.Free();
2335 FJetSoundFly
.Free();
2337 FJetSoundOff
.Free();
2339 if FPunchAnim
<> nil then
2345 procedure TPlayer
.DrawIndicator();
2347 indX
, indY
: Integer;
2353 indX
:= FObj
.X
+FObj
.Rect
.X
;
2354 indY
:= FObj
.Y
- 12;
2355 if g_Texture_Get('TEXTURE_PLAYER_INDICATOR', ID
) then
2357 e_GetTextureSize(ID
, @indW
, @indH
);
2358 e_Draw(ID
, indX
+ indW
div 2, indY
, 0, True, False);
2361 //e_TextureFontPrint(indX, indY, FName, gStdFont); // Shows player name overhead
2364 procedure TPlayer
.DrawBubble();
2366 bubX
, bubY
: Integer;
2369 Rw
, Gw
, Bw
: SmallInt;
2372 bubX
:= FObj
.X
+FObj
.Rect
.X
+ IfThen(FDirection
= TDirection
.D_LEFT
, -4, 18);
2373 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 18;
2381 1: // simple textual non-bubble
2383 bubX
:= FObj
.X
+FObj
.Rect
.X
- 11;
2384 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 17;
2385 e_TextureFontPrint(bubX
, bubY
, '[...]', gStdFont
);
2388 2: // advanced pixel-perfect bubble
2390 if FTeam
= TEAM_RED
then
2393 if FTeam
= TEAM_BLUE
then
2396 3: // colored bubble
2398 Rb
:= FModel
.Color
.R
;
2399 Gb
:= FModel
.Color
.G
;
2400 Bb
:= FModel
.Color
.B
;
2401 Rw
:= Min(Rb
* 2 + 64, 255);
2402 Gw
:= Min(Gb
* 2 + 64, 255);
2403 Bw
:= Min(Bb
* 2 + 64, 255);
2404 if (Abs(Rw
- Rb
) < 32)
2405 or (Abs(Gw
- Gb
) < 32)
2406 or (Abs(Bw
- Bb
) < 32) then
2408 Rb
:= Max(Rw
div 2 - 16, 0);
2409 Gb
:= Max(Gw
div 2 - 16, 0);
2410 Bb
:= Max(Bw
div 2 - 16, 0);
2413 4: // custom textured bubble
2415 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID
) then
2416 if FDirection
= TDirection
.D_RIGHT
then
2417 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False)
2419 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False, TMirrorType
.Horizontal
);
2425 e_DrawQuad(bubX
+ 1, bubY
, bubX
+ 18, bubY
+ 13, Rb
, Gb
, Bb
);
2426 e_DrawQuad(bubX
, bubY
+ 1, bubX
+ 19, bubY
+ 12, Rb
, Gb
, Bb
);
2428 e_DrawFillQuad(bubX
+ 1, bubY
+ 1, bubX
+ 18, bubY
+ 12, Rw
, Gw
, Bw
, 0);
2431 Dot
:= IfThen(FDirection
= TDirection
.D_LEFT
, 14, 5);
2432 e_DrawLine(1, bubX
+ Dot
, bubY
+ 14, bubX
+ Dot
, bubY
+ 16, Rb
, Gb
, Bb
);
2433 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
);
2434 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
);
2435 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
);
2436 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
);
2440 e_DrawFillQuad(bubX
+ Dot
, bubY
+ 8, bubX
+ Dot
+ 1, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2441 e_DrawFillQuad(bubX
+ Dot
+ 3, bubY
+ 8, bubX
+ Dot
+ 4, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2442 e_DrawFillQuad(bubX
+ Dot
+ 6, bubY
+ 8, bubX
+ Dot
+ 7, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2445 procedure TPlayer
.Draw();
2450 Mirror
: TMirrorType
;
2454 if Direction
= TDirection
.D_RIGHT
then
2455 Mirror
:= TMirrorType
.None
2457 Mirror
:= TMirrorType
.Horizontal
;
2459 if FPunchAnim
<> nil then
2461 FPunchAnim
.Draw(FObj
.X
+IfThen(Direction
= TDirection
.D_LEFT
, 15-FObj
.Rect
.X
, FObj
.Rect
.X
-15),
2462 FObj
.Y
+FObj
.Rect
.Y
-11, Mirror
);
2463 if FPunchAnim
.played
then
2470 if (FMegaRulez
[MR_INVUL
] > gTime
) and (gPlayerDrawn
<> Self
) then
2471 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID
) then
2473 e_GetTextureSize(ID
, @w
, @h
);
2474 if FDirection
= TDirection
.D_LEFT
then
2475 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)+4,
2476 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False)
2478 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)-2,
2479 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False);
2482 if FMegaRulez
[MR_INVIS
] > gTime
then
2484 if (gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2485 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
))) then
2487 if (FMegaRulez
[MR_INVIS
] - gTime
) <= 2100 then
2488 dr
:= not Odd((FMegaRulez
[MR_INVIS
] - gTime
) div 300)
2492 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 200)
2494 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2497 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 254);
2500 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2503 if g_debug_Frames
then
2505 e_DrawQuad(FObj
.X
+FObj
.Rect
.X
,
2507 FObj
.X
+FObj
.Rect
.X
+FObj
.Rect
.Width
-1,
2508 FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-1,
2512 if (gChatBubble
> 0) and (FKeys
[KEY_CHAT
].Pressed
) and not FGhost
then
2514 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2515 if gAimLine
and alive
and
2516 ((Self
= gPlayer1
) or (Self
= gPlayer2
)) then
2521 procedure TPlayer
.DrawAim();
2522 procedure drawCast (sz
: Integer; ax0
, ay0
, ax1
, ay1
: Integer);
2527 {$IFDEF ENABLE_HOLMES}
2528 if isValidViewPort
and (self
= gPlayer1
) then
2530 g_Holmes_plrLaser(ax0
, ay0
, ax1
, ay1
);
2534 e_DrawLine(sz
, ax0
, ay0
, ax1
, ay1
, 255, 0, 0, 96);
2535 if (g_Map_traceToNearestWall(ax0
, ay0
, ax1
, ay1
, @ex
, @ey
) <> nil) then
2537 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 255, 0, 96);
2541 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 0, 255, 96);
2546 wx
, wy
, xx
, yy
: Integer;
2550 wx
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
+ IfThen(FDirection
= TDirection
.D_LEFT
, 7, -7);
2551 wy
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
2560 1: begin // Chainsaw
2567 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2568 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2569 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2570 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2575 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2576 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2577 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2578 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2580 4: begin // Double Shotgun
2583 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2584 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2585 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2586 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2588 5: begin // Chaingun
2591 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2592 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2593 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2594 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2596 6: begin // Rocket Launcher
2599 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 2);
2600 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2601 if angle
= ANGLE_LEFTUP
then Dec(angle
, 2);
2602 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2604 7: begin // Plasmagun
2607 if angle
= ANGLE_RIGHTUP
then Inc(angle
);
2608 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 3);
2609 if angle
= ANGLE_LEFTUP
then Dec(angle
);
2610 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 3);
2615 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 1);
2616 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 2);
2617 if angle
= ANGLE_LEFTUP
then Dec(angle
, 1);
2618 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 2);
2620 9: begin // Super Chaingun
2623 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2624 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2625 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2626 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2629 xx
:= Trunc(Cos(-DegToRad(angle
)) * len
) + wx
;
2630 yy
:= Trunc(Sin(-DegToRad(angle
)) * len
) + wy
;
2631 {$IF DEFINED(D2F_DEBUG)}
2632 drawCast(sz
, wx
, wy
, xx
, yy
);
2634 e_DrawLine(sz
, wx
, wy
, xx
, yy
, 255, 0, 0, 96);
2638 procedure TPlayer
.DrawGUI();
2641 X
, Y
, SY
, a
, p
, m
: Integer;
2645 stat
: TPlayerStatArray
;
2647 X
:= gPlayerScreenSize
.X
;
2648 SY
:= gPlayerScreenSize
.Y
;
2651 if gShowGoals
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2653 if gGameSettings
.GameMode
= GM_CTF
then
2657 if gGameSettings
.GameMode
= GM_CTF
then
2659 s
:= 'TEXTURE_PLAYER_REDFLAG';
2660 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2661 s
:= 'TEXTURE_PLAYER_REDFLAG_S';
2662 if gFlags
[FLAG_RED
].State
= FLAG_STATE_DROPPED
then
2663 s
:= 'TEXTURE_PLAYER_REDFLAG_D';
2664 if g_Texture_Get(s
, ID
) then
2665 e_Draw(ID
, X
-16-32, 240-72-4, 0, True, False);
2668 s
:= IntToStr(gTeamStat
[TEAM_RED
].Goals
);
2669 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2670 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-72-4, s
, TEAMCOLOR
[TEAM_RED
]);
2672 if gGameSettings
.GameMode
= GM_CTF
then
2674 s
:= 'TEXTURE_PLAYER_BLUEFLAG';
2675 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2676 s
:= 'TEXTURE_PLAYER_BLUEFLAG_S';
2677 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_DROPPED
then
2678 s
:= 'TEXTURE_PLAYER_BLUEFLAG_D';
2679 if g_Texture_Get(s
, ID
) then
2680 e_Draw(ID
, X
-16-32, 240-32-4, 0, True, False);
2683 s
:= IntToStr(gTeamStat
[TEAM_BLUE
].Goals
);
2684 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2685 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-32-4, s
, TEAMCOLOR
[TEAM_BLUE
]);
2688 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID
) then
2689 e_DrawFill(ID
, X
, 0, 1, (gPlayerScreenSize
.Y
div 256)+IfThen(gPlayerScreenSize
.Y
mod 256 > 0, 1, 0),
2692 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID
) then
2693 e_Draw(ID
, X
+2, Y
, 0, True, False);
2695 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
2699 s
:= IntToStr(Frags
);
2700 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2701 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, Y
, s
, _RGB(255, 0, 0));
2706 stat
:= g_Player_GetStats();
2711 for a
:= 0 to High(stat
) do
2712 if stat
[a
].Name
<> Name
then
2714 if stat
[a
].Frags
> m
then m
:= stat
[a
].Frags
;
2715 if stat
[a
].Frags
> Frags
then p
:= p
+1;
2719 s
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2720 if Frags
>= m
then s
:= s
+'+' else s
:= s
+'-';
2721 s
:= s
+IntToStr(Abs(Frags
-m
));
2723 e_CharFont_GetSize(gMenuSmallFont
, s
, tw
, th
);
2724 e_CharFont_PrintEx(gMenuSmallFont
, X
-16-tw
, Y
+32, s
, _RGB(255, 0, 0));
2727 if gShowLives
and (gGameSettings
.MaxLives
> 0) then
2729 s
:= IntToStr(Lives
);
2730 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2731 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, SY
-32, s
, _RGB(0, 255, 0));
2735 e_CharFont_GetSize(gMenuSmallFont
, FName
, tw
, th
);
2736 e_CharFont_PrintEx(gMenuSmallFont
, X
+98-(tw
div 2), Y
+8, FName
, _RGB(255, 0, 0));
2738 if R_BERSERK
in FRulez
then
2739 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_BLACK
], X
+37, Y
+45, 0, True, False)
2741 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_LARGE
], X
+37, Y
+45, 0, True, False);
2743 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID
) then
2744 e_Draw(ID
, X
+36, Y
+77, 0, True, False);
2746 s
:= IntToStr(IfThen(FHealth
> 0, FHealth
, 0));
2747 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2748 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+40, s
, _RGB(255, 0, 0));
2750 s
:= IntToStr(FArmor
);
2751 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2752 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+68, s
, _RGB(255, 0, 0));
2754 s
:= IntToStr(GetAmmoByWeapon(FCurrWeap
));
2760 ID
:= gItemsTexturesID
[ITEM_WEAPON_KASTET
];
2765 ID
:= gItemsTexturesID
[ITEM_WEAPON_SAW
];
2767 WEAPON_PISTOL
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PISTOL
];
2768 WEAPON_CHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
];
2769 WEAPON_SHOTGUN1
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
];
2770 WEAPON_SHOTGUN2
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
];
2771 WEAPON_SUPERPULEMET
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SUPERPULEMET
];
2772 WEAPON_ROCKETLAUNCHER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
];
2773 WEAPON_PLASMA
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PLASMA
];
2774 WEAPON_BFG
: ID
:= gItemsTexturesID
[ITEM_WEAPON_BFG
];
2775 WEAPON_FLAMETHROWER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_FLAMETHROWER
];
2778 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2779 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+158, s
, _RGB(255, 0, 0));
2780 e_Draw(ID
, X
+20, Y
+160, 0, True, False);
2782 if R_KEY_RED
in FRulez
then
2783 e_Draw(gItemsTexturesID
[ITEM_KEY_RED
], X
+78, Y
+214, 0, True, False);
2785 if R_KEY_GREEN
in FRulez
then
2786 e_Draw(gItemsTexturesID
[ITEM_KEY_GREEN
], X
+95, Y
+214, 0, True, False);
2788 if R_KEY_BLUE
in FRulez
then
2789 e_Draw(gItemsTexturesID
[ITEM_KEY_BLUE
], X
+112, Y
+214, 0, True, False);
2791 if FJetFuel
> 0 then
2793 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2794 e_Draw(ID
, X
+2, Y
+116, 0, True, False);
2795 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID
) then
2796 e_Draw(ID
, X
+2, Y
+126, 0, True, False);
2797 e_DrawLine(4, X
+16, Y
+122, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+122, 0, 0, 196);
2798 e_DrawLine(4, X
+16, Y
+132, X
+16+Trunc(168*FJetFuel
/JET_MAX
), Y
+132, 208, 0, 0);
2802 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2803 e_Draw(ID
, X
+2, Y
+124, 0, True, False);
2804 e_DrawLine(4, X
+16, Y
+130, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+130, 0, 0, 196);
2807 if gShowPing
and g_Game_IsClient
then
2809 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
2810 e_TextureFontPrint(X
+ 4, Y
+ 242, s
, gStdFont
);
2816 e_TextureFontPrint(X
+ 4, Y
+ 242, _lc
[I_PLAYER_SPECT
], gStdFont
);
2817 e_TextureFontPrint(X
+ 4, Y
+ 258, _lc
[I_PLAYER_SPECT2
], gStdFont
);
2818 e_TextureFontPrint(X
+ 4, Y
+ 274, _lc
[I_PLAYER_SPECT1
], gStdFont
);
2821 e_TextureFontGetSize(gStdFont
, cw
, ch
);
2822 s
:= _lc
[I_PLAYER_SPECT4
];
2823 e_TextureFontPrintEx(gScreenWidth
div 2 - cw
*(Length(s
) div 2),
2824 gScreenHeight
-4-ch
, s
, gStdFont
, 255, 255, 255, 1, True);
2825 e_TextureFontPrint(X
+ 4, Y
+ 290, _lc
[I_PLAYER_SPECT1S
], gStdFont
);
2831 procedure TPlayer
.DrawRulez();
2835 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2836 if FMegaRulez
[MR_INVUL
] >= gTime
then
2838 if (FMegaRulez
[MR_INVUL
]-gTime
) <= 2100 then
2839 dr
:= not Odd((FMegaRulez
[MR_INVUL
]-gTime
) div 300)
2844 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2845 191, 191, 191, 0, TBlending
.Invert
);
2848 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2849 if FMegaRulez
[MR_SUIT
] >= gTime
then
2851 if (FMegaRulez
[MR_SUIT
]-gTime
) <= 2100 then
2852 dr
:= not Odd((FMegaRulez
[MR_SUIT
]-gTime
) div 300)
2857 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2858 0, 96, 0, 200, TBlending
.None
);
2861 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2862 if (FBerserk
>= 0) and (LongWord(FBerserk
) >= gTime
) and (gFlash
= 2) then
2864 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2865 255, 0, 0, 200, TBlending
.None
);
2869 procedure TPlayer
.DrawPain();
2873 if FPain
= 0 then Exit
;
2877 if a
< 15 then h
:= 0
2878 else if a
< 35 then h
:= 1
2879 else if a
< 55 then h
:= 2
2880 else if a
< 75 then h
:= 3
2881 else if a
< 95 then h
:= 4
2884 //if a > 255 then a := 255;
2886 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 255, 0, 0, 255-h
*50);
2887 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2890 procedure TPlayer
.DrawPickup();
2894 if FPickup
= 0 then Exit
;
2898 if a
< 15 then h
:= 1
2899 else if a
< 35 then h
:= 2
2900 else if a
< 55 then h
:= 3
2901 else if a
< 75 then h
:= 4
2904 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 150, 200, 150, 255-h
*50);
2907 procedure TPlayer
.DoPunch();
2912 if FPunchAnim
<> nil then begin
2917 st
:= 'FRAMES_PUNCH';
2918 if R_BERSERK
in FRulez
then
2919 st
:= st
+ '_BERSERK';
2920 if FKeys
[KEY_UP
].Pressed
then
2922 else if FKeys
[KEY_DOWN
].Pressed
then
2924 g_Frames_Get(id
, st
);
2925 FPunchAnim
:= TAnimation
.Create(id
, False, 1);
2928 procedure TPlayer
.Fire();
2930 f
, DidFire
: Boolean;
2931 wx
, wy
, xd
, yd
: Integer;
2934 if g_Game_IsClient
then Exit
;
2935 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
2936 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
2944 if FReloading
[FCurrWeap
] <> 0 then Exit
;
2949 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
2950 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
2951 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
2952 yd
:= wy
+firediry();
2958 if R_BERSERK
in FRulez
then
2960 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2961 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
2962 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
2965 locobj
.rect
.Width
:= 39;
2966 locobj
.rect
.Height
:= 52;
2967 locobj
.Vel
.X
:= (xd
-wx
) div 2;
2968 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
2969 locobj
.Accel
.X
:= xd
-wx
;
2970 locobj
.Accel
.y
:= yd
-wy
;
2972 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
2973 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
2975 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
2977 if (gFlash
= 1) and (FPain
< 50) then FPain
:= min(FPain
+ 25, 50);
2981 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
2985 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2990 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
2991 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
2993 FSawSoundSelect
.Stop();
2995 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
2997 else if not FSawSoundHit
.IsPlaying() then
2999 FSawSoundSelect
.Stop();
3000 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
3003 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3009 if FAmmo
[A_BULLETS
] > 0 then
3011 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
3012 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3013 Dec(FAmmo
[A_BULLETS
]);
3014 FFireAngle
:= FAngle
;
3017 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3018 GameVelX
, GameVelY
-2, SHELL_BULLET
);
3022 if FAmmo
[A_SHELLS
] > 0 then
3024 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3025 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
3026 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3027 Dec(FAmmo
[A_SHELLS
]);
3028 FFireAngle
:= FAngle
;
3032 FShellType
:= SHELL_SHELL
;
3036 if FAmmo
[A_SHELLS
] >= 2 then
3038 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
3039 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3040 Dec(FAmmo
[A_SHELLS
], 2);
3041 FFireAngle
:= FAngle
;
3045 FShellType
:= SHELL_DBLSHELL
;
3049 if FAmmo
[A_BULLETS
] > 0 then
3051 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
3052 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
3053 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3054 Dec(FAmmo
[A_BULLETS
]);
3055 FFireAngle
:= FAngle
;
3058 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3059 GameVelX
, GameVelY
-2, SHELL_BULLET
);
3062 WEAPON_ROCKETLAUNCHER
:
3063 if FAmmo
[A_ROCKETS
] > 0 then
3065 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
3066 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3067 Dec(FAmmo
[A_ROCKETS
]);
3068 FFireAngle
:= FAngle
;
3074 if FAmmo
[A_CELLS
] > 0 then
3076 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
3077 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3078 Dec(FAmmo
[A_CELLS
]);
3079 FFireAngle
:= FAngle
;
3085 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
3087 FBFGFireCounter
:= 17;
3088 if not FNoReload
then
3089 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
3090 Dec(FAmmo
[A_CELLS
], 40);
3094 WEAPON_SUPERPULEMET
:
3095 if FAmmo
[A_SHELLS
] > 0 then
3097 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3098 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
3099 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3100 Dec(FAmmo
[A_SHELLS
]);
3101 FFireAngle
:= FAngle
;
3104 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3105 GameVelX
, GameVelY
-2, SHELL_SHELL
);
3108 WEAPON_FLAMETHROWER
:
3109 if FAmmo
[A_FUEL
] > 0 then
3111 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
3112 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3114 FFireAngle
:= FAngle
;
3120 if g_Game_IsNet
then
3124 if FCurrWeap
<> WEAPON_BFG
then
3125 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
3127 if not FNoReload
then
3128 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
3131 MH_SEND_PlayerStats(FUID
);
3136 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
3137 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
3138 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
3141 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
3144 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
3145 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
3146 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
3147 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
3148 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
3153 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
3155 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
3156 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
3157 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
3160 procedure TPlayer
.JetpackOn
;
3164 FJetSoundOn
.SetPosition(0);
3165 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3169 procedure TPlayer
.JetpackOff
;
3173 FJetSoundOff
.SetPosition(0);
3174 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3177 procedure TPlayer
.CatchFire(Attacker
: Word);
3180 FFireAttacker
:= Attacker
;
3181 if g_Game_IsNet
and g_Game_IsServer
then
3182 MH_SEND_PlayerStats(FUID
);
3185 procedure TPlayer
.Jump();
3187 if gFly
or FJetpack
then
3189 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
3190 if FObj
.Vel
.Y
> -VEL_FLY
then
3191 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
3194 if FJetFuel
> 0 then
3196 if (FJetFuel
< 1) and g_Game_IsServer
then
3200 if g_Game_IsNet
then
3201 MH_SEND_PlayerStats(FUID
);
3207 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
3209 FCanJetpack
:= False;
3211 // Ïðûãàåì èëè âñïëûâàåì:
3212 if (CollideLevel(0, 1) or
3213 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
3214 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
3215 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
3217 FObj
.Vel
.Y
:= -VEL_JUMP
;
3218 FCanJetpack
:= False;
3222 if BodyInLiquid(0, 0) then
3223 FObj
.Vel
.Y
:= -VEL_SW
3224 else if (FJetFuel
> 0) and FCanJetpack
and
3225 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
3229 if g_Game_IsNet
then
3230 MH_SEND_PlayerStats(FUID
);
3235 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
3237 a
, i
, k
, ab
, ar
: Byte;
3241 srv
, netsrv
: Boolean;
3247 procedure PushItem(t
: Byte);
3251 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
3252 it
:= g_Items_ByIdx(id
);
3253 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
3255 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
3256 (FObj
.Vel
.Y
div 2)-Random(9));
3257 it
.positionChanged(); // this updates spatial accelerators
3261 if KillType
= K_HARDKILL
then // -5..+5; -5..0
3263 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
3264 (FObj
.Vel
.Y
div 2)-Random(6));
3266 else // -3..+3; -3..0
3268 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
3269 (FObj
.Vel
.Y
div 2)-Random(4));
3271 it
.positionChanged(); // this updates spatial accelerators
3274 if g_Game_IsNet
and g_Game_IsServer
then
3275 MH_SEND_ItemSpawn(True, id
);
3279 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
3280 Srv
:= g_Game_IsServer
;
3281 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
3282 if Srv
then FDeath
:= FDeath
+ 1;
3287 if not FPhysics
then
3293 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3295 if FLives
> 0 then FLives
:= FLives
- 1;
3296 if FLives
= 0 then FNoRespawn
:= True;
3299 // Íîìåð òèïà ñìåðòè:
3302 K_SIMPLEKILL
: a
:= 1;
3304 K_EXTRAHARDKILL
: a
:= 3;
3309 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
3311 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
3318 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
3320 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
3321 K_EXTRAHARDKILL
, K_FALLKILL
:
3322 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
3325 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3329 K_HARDKILL
, K_EXTRAHARDKILL
:
3333 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3334 if (KillType
<> K_FALLKILL
) and (Srv
) then
3335 g_Monsters_killedp();
3337 if SpawnerUID
= FUID
then
3339 if Srv
and (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3344 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3347 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
3348 begin // Óáèò äðóãèì èãðîêîì
3349 KP
:= g_Player_Get(SpawnerUID
);
3350 if (KP
<> nil) and Srv
then
3352 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3353 if SameTeam(FUID
, SpawnerUID
) then
3363 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3364 Inc(gTeamStat
[KP
.Team
].Goals
,
3365 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3367 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3370 plr
:= g_Player_Get(SpawnerUID
);
3378 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3382 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3386 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3391 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3392 begin // Óáèò ìîíñòðîì
3393 mon
:= g_Monsters_ByUID(SpawnerUID
);
3397 s
:= g_Mons_GetKilledByTypeId(mon
.MonsterType
);
3401 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3405 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3409 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3414 else // Îñîáûå òèïû ñìåðòè
3417 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3418 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3419 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3420 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3421 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3422 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3428 for a
:= WP_FIRST
to WP_LAST
do
3432 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3433 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3434 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3435 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3436 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3437 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3438 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3439 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
3440 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
3449 if R_ITEM_BACKPACK
in FRulez
then
3450 PushItem(ITEM_AMMO_BACKPACK
);
3452 // Âûáðîñ ðàêåòíîãî ðàíöà:
3453 if FJetFuel
> 0 then
3454 PushItem(ITEM_JETPACK
);
3457 if not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
3459 if R_KEY_RED
in FRulez
then
3460 PushItem(ITEM_KEY_RED
);
3462 if R_KEY_GREEN
in FRulez
then
3463 PushItem(ITEM_KEY_GREEN
);
3465 if R_KEY_BLUE
in FRulez
then
3466 PushItem(ITEM_KEY_BLUE
);
3473 g_Player_CreateCorpse(Self
);
3475 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3476 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3482 for i
:= Low(gPlayers
) to High(gPlayers
) do
3484 if gPlayers
[i
] = nil then continue
;
3485 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3488 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3489 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3494 OldLR
:= gLMSRespawn
;
3495 if (gGameSettings
.GameMode
= GM_COOP
) then
3499 // everyone is dead, restart the map
3500 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3502 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3503 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3504 gLMSRespawnTime
:= gTime
+ 5000;
3506 else if (a
= 1) then
3508 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3509 if (gPlayers
[k
] = gPlayer1
) or
3510 (gPlayers
[k
] = gPlayer2
) then
3511 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3512 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3513 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3516 else if (gGameSettings
.GameMode
= GM_TDM
) then
3518 if (ab
= 0) and (ar
<> 0) then
3521 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3523 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3524 Inc(gTeamStat
[TEAM_RED
].Goals
);
3525 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3526 gLMSRespawnTime
:= gTime
+ 5000;
3528 else if (ar
= 0) and (ab
<> 0) then
3531 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3533 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3534 Inc(gTeamStat
[TEAM_BLUE
].Goals
);
3535 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3536 gLMSRespawnTime
:= gTime
+ 5000;
3538 else if (ar
= 0) and (ab
= 0) then
3541 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3543 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3544 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3545 gLMSRespawnTime
:= gTime
+ 5000;
3548 else if (gGameSettings
.GameMode
= GM_DM
) then
3552 if gPlayers
[k
] <> nil then
3555 // survivor is the winner
3556 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3558 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3561 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3562 gLMSRespawnTime
:= gTime
+ 5000;
3564 else if (a
= 0) then
3566 // everyone is dead, restart the map
3567 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3569 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3570 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3571 gLMSRespawnTime
:= gTime
+ 5000;
3574 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3576 if NetMode
= NET_SERVER
then
3577 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
3579 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3585 MH_SEND_PlayerStats(FUID
);
3586 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3587 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3590 if srv
and FNoRespawn
then Spectate(True);
3591 FWantsInGame
:= True;
3594 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3596 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3597 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3600 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3602 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3603 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3606 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3608 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3609 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3610 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3611 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3612 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3613 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3614 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3615 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3618 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3620 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3621 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3622 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3623 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3626 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3628 //if g_Game_IsClient then Exit;
3629 if Weapon
> High(FWeapon
) then Exit
;
3630 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3633 procedure TPlayer
.resetWeaponQueue ();
3636 FNextWeapDelay
:= 0;
3639 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3643 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3644 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_SHELLS
] > 0);
3645 WEAPON_PISTOL
, WEAPON_CHAINGUN
: result
:= (FAmmo
[A_BULLETS
] > 0);
3646 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3647 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3648 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3649 else result
:= (weapon
< length(FWeapon
));
3653 // return 255 for "no switch"
3654 function TPlayer
.getNextWeaponIndex (): Byte;
3657 wantThisWeapon
: array[0..64] of Boolean;
3658 weaponOrder
: array[0..16] of Integer; // value: index in `FWeapon`
3660 f
, dir
, cwi
, rwidx
, curlidx
: Integer;
3662 function real2log (ridx
: Integer): Integer;
3668 for f
:= 0 to High(weaponOrder
) do if (weaponOrder
[f
] = ridx
) then begin result
:= f
; exit
; end;
3674 result
:= 255; // default result: "no switch"
3676 // had weapon cycling on previous frame? remove that flag
3677 if (FNextWeap
and $2000) <> 0 then
3679 FNextWeap
:= FNextWeap
and $1FFF;
3680 FNextWeapDelay
:= 0;
3683 for f
:= 0 to High(weaponOrder
) do weaponOrder
[f
] := -1;
3685 // build weapon order (k8: i know, i know, learn how to do constants and such... gtfo, please!)
3686 // two knuckles are for "normal" and "berserk" (see `if` below -- it removes the one that is not needed)
3688 // bfg, launcher, plasma, flamethrower, ssg, minigun, sg, pistol, berserk, chainsaw, fist
3689 weaponOrder
[0] := WEAPON_SUPERPULEMET
;
3690 weaponOrder
[1] := WEAPON_BFG
;
3691 weaponOrder
[2] := WEAPON_ROCKETLAUNCHER
;
3692 weaponOrder
[3] := WEAPON_PLASMA
;
3693 weaponOrder
[4] := WEAPON_FLAMETHROWER
;
3694 weaponOrder
[5] := WEAPON_SHOTGUN2
;
3695 weaponOrder
[6] := WEAPON_CHAINGUN
;
3696 weaponOrder
[7] := WEAPON_SHOTGUN1
;
3697 weaponOrder
[8] := WEAPON_PISTOL
;
3698 weaponOrder
[9] := WEAPON_KASTET
+666; // berserk fist
3699 weaponOrder
[10] := WEAPON_SAW
;
3700 weaponOrder
[11] := WEAPON_KASTET
; // normal fist
3702 for f
:= 0 to High(weaponOrder
) do
3704 if (weaponOrder
[f
] = WEAPON_KASTET
) then
3706 // normal fist: remove if we have a berserk pack
3707 if (R_BERSERK
in FRulez
) then weaponOrder
[f
] := -1;
3710 if (weaponOrder
[f
] = WEAPON_KASTET
+666) then
3712 // berserk fist: remove if we don't have a berserk pack
3713 if (R_BERSERK
in FRulez
) then weaponOrder
[f
] := WEAPON_KASTET
else weaponOrder
[f
] := -1;
3721 WEAPON_SHOTGUN1 = 3;
3722 WEAPON_SHOTGUN2 = 4;
3723 WEAPON_CHAINGUN = 5;
3724 WEAPON_ROCKETLAUNCHER = 6;
3727 WEAPON_SUPERPULEMET = 9;
3728 WEAPON_FLAMETHROWER = 10;
3731 // cycling has priority
3732 if (FNextWeap
and $C000) <> 0 then
3734 if (FNextWeap
and $8000) <> 0 then dir
:= 1 else dir
:= -1; // should be reversed if we want "priority-driven cycling"
3735 FNextWeap
:= FNextWeap
or $2000; // we need this
3736 if FNextWeapDelay
> 0 then exit
; // cooldown time
3737 //cwi := real2log(FCurrWeap);
3738 //if (cwi < 0) then cwi := 0;
3740 for i
:= 0 to High(FWeapon
) do
3742 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3743 //rwidx := weaponOrder[cwi];
3744 rwidx
:= cwi
; // sorry
3745 if (rwidx
< 0) then continue
;
3746 if FWeapon
[rwidx
] then
3748 //e_WriteLog(Format(' SWITCH: cur=%d; new=%d (dir=%d; log=%d)', [FCurrWeap, rwidx, dir, cwi]), TMsgType.Warning);
3749 result
:= Byte(rwidx
);
3750 //FNextWeapDelay := 10; //k8: not needed anymore
3759 for i
:= 0 to High(wantThisWeapon
) do wantThisWeapon
[i
] := false;
3762 curlidx
:= -1; // start from a weapon with a highest priority (-1, 'cause loop will immediately increment this index)
3764 for i
:= 0 to High(FWeapon
) do
3766 if (FNextWeap
and (1 shl i
)) <> 0 then
3771 wantThisWeapon
[cwi
] := true;
3773 // if we hit currently selected weapon, start seachring from it, so we'll get "next weaker" weapon
3774 if (i
= FCurrWeap
) then curlidx
:= cwi
; // compare real, start from logical
3779 // slow down alterations a little
3782 // more than one weapon requested, assume "alteration", and check alteration delay
3783 if FNextWeapDelay
> 0 then
3785 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), TMsgType.Warning);
3791 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3792 // but clear all counters if no weapon should be switched
3799 //e_WriteLog(Format('*** wwc=%d; currweap=%d; logweap=%d', [wwc, FCurrWeap, curlidx]), TMsgType.Warning);
3801 // find next weapon to switch onto
3803 for i
:= 0 to High(weaponOrder
) do
3805 cwi
:= (cwi
+length(weaponOrder
)+1) mod length(weaponOrder
);
3806 if (cwi
= curlidx
) then continue
; // skip current weapon
3807 if not wantThisWeapon
[cwi
] then continue
;
3808 rwidx
:= weaponOrder
[cwi
];
3809 if (rwidx
< 0) then continue
;
3810 //e_WriteLog(Format(' trying logical %d (real %d); has=%d, hasammo=%d', [cwi, rwidx, Integer(FWeapon[rwidx]), Integer(hasAmmoForWeapon(rwidx))]), TMsgType.Warning);
3811 if FWeapon
[rwidx
] and ((wwc
= 1) or hasAmmoForWeapon(rwidx
)) then
3813 //e_WriteLog(' I FOUND HER!', TMsgType.Warning);
3815 result
:= Byte(rwidx
);
3817 //FNextWeapDelay := 10; // anyway, 'cause why not; k8: not needed anymore
3822 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3826 procedure TPlayer
.RealizeCurrentWeapon();
3827 function switchAllowed (): Boolean;
3832 if FBFGFireCounter
<> -1 then
3834 if FTime
[T_SWITCH
] > gTime
then
3836 for i
:= WP_FIRST
to WP_LAST
do
3837 if FReloading
[i
] > 0 then
3845 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3846 //FNextWeap := FNextWeap and $1FFF;
3847 //HACK: alteration delay will be reset when player released any weapon switch key
3848 FNextWeapDelay
:= 0; //k8: just in case
3849 //if FNextWeapDelay > 0 then Dec(FNextWeapDelay); // "alteration delay"
3851 if not switchAllowed
then
3853 //HACK for weapon cycling
3854 if (FNextWeap
and $E000) <> 0 then FNextWeap
:= 0;
3858 nw
:= getNextWeaponIndex();
3859 if nw
= 255 then exit
; // don't reset anything here
3860 if nw
> High(FWeapon
) then
3862 // don't forget to reset queue here!
3863 //e_WriteLog(Format(' RealizeCurrentWeapon: WUTAFUUUU?! (%d)', [nw]), TMsgType.Warning);
3870 //k8: emulate this on client immediately, or wait for server confirmation?
3872 if g_Game_IsClient then
3874 FNetForceWeap := nw;
3875 //FNetForceWeapFIdx := FCurrFrameIdx+5; // force for ~5 frames
3876 FNetForceWeapFIdx := gTime+5; // force for ~5 frames
3877 writeln('NETWEAPONSWITCH: fw=', NetForceWeap, '; fwfidx=', NetForceWeapFIdx, '; cfrm=', gTime);
3880 FNetForceWeapFIdx
:= gTime
+5; // force for ~5 frames
3882 if nw
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3883 FModel
.SetWeapon(nw
);
3884 FTime
[T_SWITCH
] := gTime
+156;
3885 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3886 //if g_Game_IsNet and g_Game_IsClient then
3890 procedure TPlayer
.NextWeapon();
3892 //if g_Game_IsClient then Exit;
3896 procedure TPlayer
.PrevWeapon();
3898 //if g_Game_IsClient then Exit;
3902 // used by network layer
3903 procedure TPlayer
.SetWeapon(W
: Byte);
3905 if FCurrWeap
<> W
then
3906 if (W
= WEAPON_SAW
) then
3907 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3910 FModel
.SetWeapon(CurrWeap
);
3911 //if g_Game_IsClient then resetWeaponQueue();
3914 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
3916 function allowBerserkSwitching (): Boolean;
3918 if (FBFGFireCounter
<> -1) then begin result
:= false; exit
; end;
3920 if gBerserkAutoswitch
then exit
;
3921 if not conIsCheatsEnabled
then exit
;
3929 if g_Game_IsClient
then Exit
;
3931 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3932 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
3937 if FHealth
< PLAYER_HP_SOFT
then
3939 IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3943 if gFlash
= 2 then Inc(FPickup
, 5);
3947 if FHealth
< PLAYER_HP_SOFT
then
3949 IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3953 if gFlash
= 2 then Inc(FPickup
, 5);
3957 if FArmor
< PLAYER_AP_SOFT
then
3959 FArmor
:= PLAYER_AP_SOFT
;
3962 if gFlash
= 2 then Inc(FPickup
, 5);
3966 if FArmor
< PLAYER_AP_LIMIT
then
3968 FArmor
:= PLAYER_AP_LIMIT
;
3971 if gFlash
= 2 then Inc(FPickup
, 5);
3975 if FHealth
< PLAYER_HP_LIMIT
then
3977 IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3981 if gFlash
= 2 then Inc(FPickup
, 5);
3985 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
3987 if FHealth
< PLAYER_HP_LIMIT
then
3988 FHealth
:= PLAYER_HP_LIMIT
;
3989 if FArmor
< PLAYER_AP_LIMIT
then
3990 FArmor
:= PLAYER_AP_LIMIT
;
3994 if gFlash
= 2 then Inc(FPickup
, 5);
3998 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
4000 FWeapon
[WEAPON_SAW
] := True;
4002 if gFlash
= 2 then Inc(FPickup
, 5);
4003 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4006 ITEM_WEAPON_SHOTGUN1
:
4007 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
4009 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
4010 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
4012 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4013 FWeapon
[WEAPON_SHOTGUN1
] := True;
4015 if gFlash
= 2 then Inc(FPickup
, 5);
4016 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4019 ITEM_WEAPON_SHOTGUN2
:
4020 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
4022 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
4024 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4025 FWeapon
[WEAPON_SHOTGUN2
] := True;
4027 if gFlash
= 2 then Inc(FPickup
, 5);
4028 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4031 ITEM_WEAPON_CHAINGUN
:
4032 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
4034 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
4036 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4037 FWeapon
[WEAPON_CHAINGUN
] := True;
4039 if gFlash
= 2 then Inc(FPickup
, 5);
4040 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4043 ITEM_WEAPON_ROCKETLAUNCHER
:
4044 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
4046 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
4048 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
4049 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
4051 if gFlash
= 2 then Inc(FPickup
, 5);
4052 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4056 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
4058 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
4060 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4061 FWeapon
[WEAPON_PLASMA
] := True;
4063 if gFlash
= 2 then Inc(FPickup
, 5);
4064 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4068 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
4070 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
4072 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4073 FWeapon
[WEAPON_BFG
] := True;
4075 if gFlash
= 2 then Inc(FPickup
, 5);
4076 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4079 ITEM_WEAPON_SUPERPULEMET
:
4080 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
4082 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
4084 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4085 FWeapon
[WEAPON_SUPERPULEMET
] := True;
4087 if gFlash
= 2 then Inc(FPickup
, 5);
4088 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4091 ITEM_WEAPON_FLAMETHROWER
:
4092 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
4094 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
4096 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4097 FWeapon
[WEAPON_FLAMETHROWER
] := True;
4099 if gFlash
= 2 then Inc(FPickup
, 5);
4100 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4104 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4106 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4109 if gFlash
= 2 then Inc(FPickup
, 5);
4112 ITEM_AMMO_BULLETS_BOX
:
4113 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4115 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4118 if gFlash
= 2 then Inc(FPickup
, 5);
4122 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4124 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4127 if gFlash
= 2 then Inc(FPickup
, 5);
4130 ITEM_AMMO_SHELLS_BOX
:
4131 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4133 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
4136 if gFlash
= 2 then Inc(FPickup
, 5);
4140 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4142 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4145 if gFlash
= 2 then Inc(FPickup
, 5);
4148 ITEM_AMMO_ROCKET_BOX
:
4149 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4151 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
4154 if gFlash
= 2 then Inc(FPickup
, 5);
4158 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4160 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4163 if gFlash
= 2 then Inc(FPickup
, 5);
4167 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4169 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
4172 if gFlash
= 2 then Inc(FPickup
, 5);
4176 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4178 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4181 if gFlash
= 2 then Inc(FPickup
, 5);
4185 if not(R_ITEM_BACKPACK
in FRulez
) or
4186 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
4187 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
4188 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
4189 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
4190 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
4192 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
4193 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
4194 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
4195 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
4196 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
4198 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4199 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4200 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4201 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4202 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4203 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4204 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4205 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4207 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
4210 if gFlash
= 2 then Inc(FPickup
, 5);
4214 if not(R_KEY_RED
in FRulez
) then
4216 Include(FRulez
, R_KEY_RED
);
4218 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4219 if gFlash
= 2 then Inc(FPickup
, 5);
4220 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4224 if not(R_KEY_GREEN
in FRulez
) then
4226 Include(FRulez
, R_KEY_GREEN
);
4228 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4229 if gFlash
= 2 then Inc(FPickup
, 5);
4230 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4234 if not(R_KEY_BLUE
in FRulez
) then
4236 Include(FRulez
, R_KEY_BLUE
);
4238 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4239 if gFlash
= 2 then Inc(FPickup
, 5);
4240 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4244 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
4246 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
4250 if gFlash
= 2 then Inc(FPickup
, 5);
4254 if FAir
< AIR_MAX
then
4259 if gFlash
= 2 then Inc(FPickup
, 5);
4264 if not (R_BERSERK
in FRulez
) then
4266 Include(FRulez
, R_BERSERK
);
4267 if allowBerserkSwitching
then
4269 FCurrWeap
:= WEAPON_KASTET
;
4270 //FNetForceWeap := FCurrWeap;
4272 FModel
.SetWeapon(WEAPON_KASTET
);
4277 if gFlash
= 2 then Inc(FPickup
, 5);
4279 FBerserk
:= gTime
+30000;
4283 //k8:do we need it? if g_Game_IsNet and g_Game_IsServer then MH_SEND_PlayerStats(FUID);
4285 if FHealth
< PLAYER_HP_SOFT
then
4287 FHealth
:= PLAYER_HP_SOFT
;
4288 FBerserk
:= gTime
+30000;
4296 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
4298 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
4301 if gFlash
= 2 then Inc(FPickup
, 5);
4305 if FHealth
< PLAYER_HP_LIMIT
then
4307 IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
4311 if gFlash
= 2 then Inc(FPickup
, 5);
4315 if FArmor
< PLAYER_AP_LIMIT
then
4317 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
4320 if gFlash
= 2 then Inc(FPickup
, 5);
4324 if FJetFuel
< JET_MAX
then
4326 FJetFuel
:= JET_MAX
;
4329 if gFlash
= 2 then Inc(FPickup
, 5);
4333 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
4335 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
4338 if gFlash
= 2 then Inc(FPickup
, 5);
4343 procedure TPlayer
.Touch();
4347 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4350 // Áðîñèòü ôëàã òîâàðèùó:
4351 if gGameSettings
.GameMode
= GM_CTF
then
4356 procedure TPlayer
.Push(vx
, vy
: Integer);
4358 if (not FPhysics
) and FGhost
then
4360 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
4361 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
4362 if g_Game_IsNet
and g_Game_IsServer
then
4363 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4366 procedure TPlayer
.Reset(Force
: Boolean);
4372 FTime
[T_RESPAWN
] := 0;
4373 FTime
[T_FLAGCAP
] := 0;
4384 //FCurrFrameIdx := 0;
4385 //FNetForceWeap := FCurrWeap;
4386 //FNetForceWeapFIdx := 0;
4389 FSpectator
:= False;
4392 FSpectatePlayer
:= -1;
4393 FNoRespawn
:= False;
4395 FLives
:= gGameSettings
.MaxLives
;
4400 procedure TPlayer
.SoftReset();
4406 FBFGFireCounter
:= -1;
4414 SetAction(A_STAND
, True);
4417 function TPlayer
.GetRespawnPoint(): Byte;
4422 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4424 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4425 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
4427 if (Self
= gPlayer1
) or (Self
= gPlayer2
) then
4429 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
4430 if Self
= gPlayer1
then
4431 c
:= RESPAWNPOINT_PLAYER1
4433 c
:= RESPAWNPOINT_PLAYER2
;
4434 if g_Map_GetPointCount(c
) > 0 then
4440 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
4441 if Self
= gPlayer1
then
4442 c
:= RESPAWNPOINT_PLAYER2
4444 c
:= RESPAWNPOINT_PLAYER1
;
4445 if g_Map_GetPointCount(c
) > 0 then
4452 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
4453 if Random(2) = 0 then
4454 c
:= RESPAWNPOINT_PLAYER1
4456 c
:= RESPAWNPOINT_PLAYER2
;
4457 if g_Map_GetPointCount(c
) > 0 then
4464 // Òî÷êà ëþáîé èç êîìàíä
4465 if Random(2) = 0 then
4466 c
:= RESPAWNPOINT_RED
4468 c
:= RESPAWNPOINT_BLUE
;
4469 if g_Map_GetPointCount(c
) > 0 then
4476 c
:= RESPAWNPOINT_DM
;
4477 if g_Map_GetPointCount(c
) > 0 then
4485 if gGameSettings
.GameMode
= GM_DM
then
4488 c
:= RESPAWNPOINT_DM
;
4489 if g_Map_GetPointCount(c
) > 0 then
4495 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4496 if Random(2) = 0 then
4497 c
:= RESPAWNPOINT_PLAYER1
4499 c
:= RESPAWNPOINT_PLAYER2
;
4500 if g_Map_GetPointCount(c
) > 0 then
4506 // Òî÷êà ëþáîé èç êîìàíä
4507 if Random(2) = 0 then
4508 c
:= RESPAWNPOINT_RED
4510 c
:= RESPAWNPOINT_BLUE
;
4511 if g_Map_GetPointCount(c
) > 0 then
4519 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4521 // Òî÷êà ñâîåé êîìàíäû
4522 c
:= RESPAWNPOINT_DM
;
4523 if FTeam
= TEAM_RED
then
4524 c
:= RESPAWNPOINT_RED
;
4525 if FTeam
= TEAM_BLUE
then
4526 c
:= RESPAWNPOINT_BLUE
;
4527 if g_Map_GetPointCount(c
) > 0 then
4534 c
:= RESPAWNPOINT_DM
;
4535 if g_Map_GetPointCount(c
) > 0 then
4541 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4542 if Random(2) = 0 then
4543 c
:= RESPAWNPOINT_PLAYER1
4545 c
:= RESPAWNPOINT_PLAYER2
;
4546 if g_Map_GetPointCount(c
) > 0 then
4552 // Òî÷êà äðóãîé êîìàíäû
4553 c
:= RESPAWNPOINT_DM
;
4554 if FTeam
= TEAM_RED
then
4555 c
:= RESPAWNPOINT_BLUE
;
4556 if FTeam
= TEAM_BLUE
then
4557 c
:= RESPAWNPOINT_RED
;
4558 if g_Map_GetPointCount(c
) > 0 then
4566 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4568 RespawnPoint
: TRespawnPoint
;
4574 FBFGFireCounter
:= -1;
4578 //FNetForceWeap := FCurrWeap;
4580 if not g_Game_IsServer
then
4584 FWantsInGame
:= True;
4585 FJustTeleported
:= True;
4588 FTime
[T_RESPAWN
] := 0;
4592 // if server changes MaxLives we gotta be ready
4593 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4595 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4596 if FTime
[T_RESPAWN
] > gTime
then
4599 // Ïðîñðàë âñå æèçíè:
4602 if not FSpectator
then Spectate(True);
4603 FWantsInGame
:= True;
4607 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4608 begin // "Ñâîÿ èãðà"
4609 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4610 FRulez
:= FRulez
-[R_BERSERK
];
4612 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4614 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4615 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4618 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4619 c
:= GetRespawnPoint();
4624 // Âîñêðåøåíèå áåç îðóæèÿ:
4627 FHealth
:= PLAYER_HP_SOFT
;
4633 for a
:= WP_FIRST
to WP_LAST
do
4635 FWeapon
[a
] := False;
4639 FWeapon
[WEAPON_PISTOL
] := True;
4640 FWeapon
[WEAPON_KASTET
] := True;
4641 FCurrWeap
:= WEAPON_PISTOL
;
4642 //FNetForceWeap := FCurrWeap;
4645 FModel
.SetWeapon(FCurrWeap
);
4647 for b
:= A_BULLETS
to A_HIGH
do
4650 FAmmo
[A_BULLETS
] := 50;
4652 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
4653 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
4654 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
4655 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
4656 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
4658 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
4659 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4664 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4665 if not g_Map_GetPoint(c
, RespawnPoint
) then
4667 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4671 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4672 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4673 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4679 FDirection
:= RespawnPoint
.Direction
;
4680 if FDirection
= TDirection
.D_LEFT
then
4685 SetAction(A_STAND
, True);
4686 FModel
.Direction
:= FDirection
;
4688 for a
:= Low(FTime
) to High(FTime
) do
4691 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4696 FCanJetpack
:= False;
4701 // Àíèìàöèÿ âîçðîæäåíèÿ:
4702 if (not gLoadGameMode
) and (not Silent
) then
4703 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4705 Anim
:= TAnimation
.Create(ID
, False, 3);
4706 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4707 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4711 FSpectator
:= False;
4714 FSpectatePlayer
:= -1;
4717 if (gPlayer1
= nil) and (gLMSPID1
= FUID
) then
4719 if (gPlayer2
= nil) and (gLMSPID2
= FUID
) then
4722 //FNetForceWeap := FCurrWeap;
4724 if g_Game_IsNet
then
4726 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4727 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4729 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4730 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4735 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4738 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4739 else if (not NoMove
) then
4741 GameX
:= gMapInfo
.Width
div 2;
4742 GameY
:= gMapInfo
.Height
div 2;
4751 FWantsInGame
:= False;
4756 if Self
= gPlayer1
then
4761 if Self
= gPlayer2
then
4768 if g_Game_IsNet
then
4769 MH_SEND_PlayerStats(FUID
);
4772 procedure TPlayer
.SwitchNoClip
;
4776 FGhost
:= not FGhost
;
4777 FPhysics
:= not FGhost
;
4789 procedure TPlayer
.Run(Direction
: TDirection
);
4793 if MAX_RUNVEL
> 8 then
4797 if Direction
= TDirection
.D_LEFT
then
4799 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4800 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4803 if FObj
.Vel
.X
< MAX_RUNVEL
then
4804 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4806 // Âîçìîæíî, ïèíàåì êóñêè:
4807 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4809 b
:= Abs(FObj
.Vel
.X
);
4810 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4811 for a
:= 0 to High(gGibs
) do
4813 if gGibs
[a
].alive
and
4814 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4815 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4818 if FObj
.Vel
.X
< 0 then
4820 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4824 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4826 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4834 procedure TPlayer
.SeeDown();
4836 SetAction(A_SEEDOWN
);
4838 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4840 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4843 procedure TPlayer
.SeeUp();
4847 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4849 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4852 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4860 A_ATTACK
: Prior
:= 2;
4861 A_SEEUP
: Prior
:= 1;
4862 A_SEEDOWN
: Prior
:= 1;
4863 A_ATTACKUP
: Prior
:= 2;
4864 A_ATTACKDOWN
: Prior
:= 2;
4869 if (Prior
> FActionPrior
) or Force
then
4870 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4872 FActionPrior
:= Prior
;
4873 FActionAnim
:= Action
;
4874 FActionForce
:= Force
;
4875 FActionChanged
:= True;
4878 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4881 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4883 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4884 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4885 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4886 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4889 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4896 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4898 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4899 if g_Game_IsServer
and g_Game_IsNet
then
4900 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4904 FJustTeleported
:= True;
4909 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4911 Anim
:= TAnimation
.Create(ID
, False, 3);
4914 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4915 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4916 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4917 if g_Game_IsServer
and g_Game_IsNet
then
4918 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4919 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4923 FObj
.X
:= X
-PLAYER_RECT
.X
;
4924 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4925 if FAlive
and FGhost
then
4931 if not g_Game_IsNet
then
4935 SetDirection(TDirection
.D_LEFT
);
4941 SetDirection(TDirection
.D_RIGHT
);
4947 if FDirection
= TDirection
.D_RIGHT
then
4949 SetDirection(TDirection
.D_LEFT
);
4954 SetDirection(TDirection
.D_RIGHT
);
4960 if not silent
and (Anim
<> nil) then
4962 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4963 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4966 if g_Game_IsServer
and g_Game_IsNet
then
4967 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4968 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4975 function nonz(a
: Single): Single;
4983 function TPlayer
.followCorpse(): Boolean;
4988 if FAlive
or FSpectator
then
4990 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
4992 for i
:= 0 to High(gCorpses
) do
4993 if gCorpses
[i
] <> nil then
4994 if gCorpses
[i
].FPlayerUID
= FUID
then
4997 FObj
.X
:= gCorpses
[i
].FObj
.X
;
4998 FObj
.Y
:= gCorpses
[i
].FObj
.Y
;
4999 FObj
.Vel
.X
:= gCorpses
[i
].FObj
.Vel
.X
;
5000 FObj
.Vel
.Y
:= gCorpses
[i
].FObj
.Vel
.Y
;
5001 FObj
.Accel
.X
:= gCorpses
[i
].FObj
.Accel
.X
;
5002 FObj
.Accel
.Y
:= gCorpses
[i
].FObj
.Accel
.Y
;
5007 procedure TPlayer
.Update();
5010 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
5011 blockmon
, headwater
, dospawn
: Boolean;
5016 //Inc(FCurrFrameIdx);
5018 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
5019 AnyServer
:= g_Game_IsServer
;
5021 if g_Game_IsClient
and (NetInterpLevel
> 0) then
5022 DoLerp(NetInterpLevel
+ 1)
5029 if FClientID
>= 0 then
5031 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
5032 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
5033 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
5043 if FAlive
and (FPunchAnim
<> nil) then
5044 FPunchAnim
.Update();
5046 if FAlive
and (gFly
or FJetpack
) then
5049 if FDirection
= TDirection
.D_LEFT
then
5054 if FAlive
and (not FGhost
) then
5056 if FKeys
[KEY_UP
].Pressed
then
5058 if FKeys
[KEY_DOWN
].Pressed
then
5062 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
5065 i
:= g_basic
.Sign(FIncCam
);
5066 FIncCam
:= Abs(FIncCam
);
5067 DecMin(FIncCam
, 5, 0);
5068 FIncCam
:= FIncCam
*i
;
5071 // no need to do that each second frame, weapon queue will take care of it
5072 if FAlive
and FKeys
[KEY_NEXTWEAPON
].Pressed
{and AnyServer} then NextWeapon();
5073 if FAlive
and FKeys
[KEY_PREVWEAPON
].Pressed
{and AnyServer} then PrevWeapon();
5075 if gTime
mod (GAME_TICK
*2) <> 0 then
5077 if (FObj
.Vel
.X
= 0) and FAlive
then
5079 if FKeys
[KEY_LEFT
].Pressed
then
5080 Run(TDirection
.D_LEFT
);
5081 if FKeys
[KEY_RIGHT
].Pressed
then
5082 Run(TDirection
.D_RIGHT
);
5087 if not followCorpse() then
5088 g_Obj_Move(@FObj
, True, True, True);
5089 positionChanged(); // this updates spatial accelerators
5095 FActionChanged
:= False;
5099 // Let alive player do some actions
5100 if FKeys
[KEY_LEFT
].Pressed
then Run(TDirection
.D_LEFT
);
5101 if FKeys
[KEY_RIGHT
].Pressed
then Run(TDirection
.D_RIGHT
);
5102 //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
5103 //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
5104 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire();
5105 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
5106 if FKeys
[KEY_JUMP
].Pressed
then Jump()
5109 if AnyServer
and FJetpack
then
5113 if NetServer
then MH_SEND_PlayerStats(FUID
);
5115 FCanJetpack
:= True;
5122 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
5124 if FKeys
[k
].Pressed
then
5132 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5135 if (FTime
[T_RESPAWN
] <= gTime
) and
5136 gGameOn
and (not FAlive
) then
5138 if (g_Player_GetCount() > 1) then
5142 gExit
:= EXIT_RESTART
;
5147 // Dead spectator actions
5150 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
5151 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
5155 if (FSpectatePlayer
>= High(gPlayers
)) then
5156 FSpectatePlayer
:= -1
5160 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
5161 if gPlayers
[I
] <> nil then
5162 if gPlayers
[I
].alive
then
5163 if gPlayers
[I
].UID
<> FUID
then
5165 FSpectatePlayer
:= I
;
5170 if not SetSpect
then FSpectatePlayer
:= -1;
5181 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
5183 FYTo
:= FObj
.Y
- 32;
5184 FSpectatePlayer
:= -1;
5186 if FKeys
[KEY_DOWN
].Pressed
then
5188 FYTo
:= FObj
.Y
+ 32;
5189 FSpectatePlayer
:= -1;
5191 if FKeys
[KEY_LEFT
].Pressed
then
5193 FXTo
:= FObj
.X
- 32;
5194 FSpectatePlayer
:= -1;
5196 if FKeys
[KEY_RIGHT
].Pressed
then
5198 FXTo
:= FObj
.X
+ 32;
5199 FSpectatePlayer
:= -1;
5202 if (FXTo
< -64) then
5204 else if (FXTo
> gMapInfo
.Width
+ 32) then
5205 FXTo
:= gMapInfo
.Width
+ 32;
5206 if (FYTo
< -72) then
5208 else if (FYTo
> gMapInfo
.Height
+ 32) then
5209 FYTo
:= gMapInfo
.Height
+ 32;
5214 if not followCorpse() then
5215 g_Obj_Move(@FObj
, True, True, True);
5216 positionChanged(); // this updates spatial accelerators
5223 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
5224 if gPlayers
[FSpectatePlayer
] <> nil then
5225 if gPlayers
[FSpectatePlayer
].alive
then
5227 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
5228 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
5232 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
5233 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
5234 PANEL_BLOCKMON
, True);
5235 headwater
:= HeadInLiquid(0, 0);
5237 // Ñîïðîòèâëåíèå âîçäóõà:
5238 if (not FAlive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
5239 if FObj
.Vel
.X
<> 0 then
5240 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5242 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
5243 DecMin(FPain
, 5, 0);
5244 DecMin(FPickup
, 1, 0);
5246 if FAlive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
5248 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
5249 FMegaRulez
[MR_SUIT
] := 0;
5250 FMegaRulez
[MR_INVUL
] := 0;
5251 FMegaRulez
[MR_INVIS
] := 0;
5252 Kill(K_FALLKILL
, 0, HIT_FALL
);
5259 if FCurrWeap
= WEAPON_SAW
then
5260 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
5261 FSawSoundSelect
.IsPlaying()) then
5262 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
5265 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
5266 (not FJetSoundOff
.IsPlaying()) then
5268 FJetSoundFly
.SetPosition(0);
5269 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
5272 for b
:= WP_FIRST
to WP_LAST
do
5273 if FReloading
[b
] > 0 then
5279 if FShellTimer
> -1 then
5280 if FShellTimer
= 0 then
5282 if FShellType
= SHELL_SHELL
then
5283 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5284 GameVelX
, GameVelY
-2, SHELL_SHELL
)
5285 else if FShellType
= SHELL_DBLSHELL
then
5287 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5288 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
5289 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5290 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
5293 end else Dec(FShellTimer
);
5295 if (FBFGFireCounter
> -1) then
5296 if FBFGFireCounter
= 0 then
5300 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
5301 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
5302 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
5303 yd
:= wy
+firediry();
5304 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
5305 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
5306 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5307 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5308 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5311 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
5312 FBFGFireCounter
:= -1;
5315 FBFGFireCounter
:= 0
5317 Dec(FBFGFireCounter
);
5319 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
5321 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
5323 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
5326 if (headwater
or blockmon
) then
5332 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
5335 else if (FAir
mod 31 = 0) and not blockmon
then
5337 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
5338 if Random(2) = 0 then
5339 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5341 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5343 end else if FAir
< AIR_DEF
then
5346 if FFireTime
> 0 then
5348 if BodyInLiquid(0, 0) then
5353 else if FMegaRulez
[MR_SUIT
] >= gTime
then
5355 if FMegaRulez
[MR_SUIT
] = gTime
then
5362 if FFirePainTime
<= 0 then
5364 if g_Game_IsServer
then
5365 Damage(5, FFireAttacker
, 0, 0, HIT_FLAME
);
5366 FFirePainTime
:= 18;
5368 FFirePainTime
:= FFirePainTime
- 1;
5369 FFireTime
:= FFireTime
- 1;
5370 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
5371 MH_SEND_PlayerStats(FUID
);
5375 if FDamageBuffer
> 0 then
5377 if FDamageBuffer
>= 9 then
5381 if FDamageBuffer
< 30 then i
:= 9
5382 else if FDamageBuffer
< 100 then i
:= 18
5386 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
5387 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
5388 FHealth
:= FHealth
-ii
;
5391 FHealth
:= FHealth
+FArmor
;
5396 if FHealth
<= 0 then
5397 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
5398 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
5399 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
5403 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
5404 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
5405 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
5406 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
5413 end; // if FAlive then ...
5415 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
5417 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
5418 FModel
.GetCurrentAnimation
.MinLength
:= i
;
5419 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
5420 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
5422 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
5423 then SetAction(A_STAND
, True);
5425 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
5427 for b
:= Low(FKeys
) to High(FKeys
) do
5428 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
5432 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5434 x
:= FObj
.X
+PLAYER_RECT
.X
;
5435 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
5436 w
:= PLAYER_RECT
.Width
;
5437 h
:= PLAYER_RECT
.Height
;
5441 procedure TPlayer
.moveBy (dx
, dy
: Integer); inline;
5443 if (dx
<> 0) or (dy
<> 0) then
5452 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
5454 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5455 FObj
.Y
+PLAYER_RECT
.Y
,
5462 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
5464 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5465 FObj
.Y
+PLAYER_RECT
.Y
,
5469 Panel
.Width
, Panel
.Height
);
5472 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
5474 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
5475 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
5476 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
5477 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
5480 function g_Player_ValidName(Name
: string): Boolean;
5486 if gPlayers
= nil then Exit
;
5488 for a
:= 0 to High(gPlayers
) do
5489 if gPlayers
[a
] <> nil then
5490 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
5497 procedure TPlayer
.SetDirection(Direction
: TDirection
);
5501 d
:= FModel
.Direction
;
5503 FModel
.Direction
:= Direction
;
5504 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
5506 FDirection
:= Direction
;
5509 function TPlayer
.GetKeys(): Byte;
5513 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
5514 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
5515 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
5517 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
5518 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
5521 procedure TPlayer
.Use();
5525 if FTime
[T_USE
] > gTime
then Exit
;
5527 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
5528 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
5530 for a
:= 0 to High(gPlayers
) do
5531 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
5532 gPlayers
[a
].alive
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
5533 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5534 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
5536 gPlayers
[a
].Touch();
5537 if g_Game_IsNet
and g_Game_IsServer
then
5538 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
5541 FTime
[T_USE
] := gTime
+120;
5544 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
5548 WX
, WY
, XD
, YD
: Integer;
5560 if R_BERSERK
in FRulez
then
5562 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5563 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
5564 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
5567 locobj
.rect
.Width
:= 39;
5568 locobj
.rect
.Height
:= 52;
5569 locobj
.Vel
.X
:= (xd
-wx
) div 2;
5570 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
5571 locobj
.Accel
.X
:= xd
-wx
;
5572 locobj
.Accel
.y
:= yd
-wy
;
5574 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
5575 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
5577 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
5581 FPain
:= min(FPain
+ 25, 50);
5583 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
5588 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5589 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
5591 FSawSoundSelect
.Stop();
5593 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
5595 else if not FSawSoundHit
.IsPlaying() then
5597 FSawSoundSelect
.Stop();
5598 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
5605 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
5606 FFireAngle
:= FAngle
;
5608 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5609 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5614 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5615 FFireAngle
:= FAngle
;
5618 FShellType
:= SHELL_SHELL
;
5623 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5624 FFireAngle
:= FAngle
;
5627 FShellType
:= SHELL_DBLSHELL
;
5632 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5633 FFireAngle
:= FAngle
;
5635 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5636 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5639 WEAPON_ROCKETLAUNCHER
:
5641 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5642 FFireAngle
:= FAngle
;
5648 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5649 FFireAngle
:= FAngle
;
5655 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5656 FFireAngle
:= FAngle
;
5660 WEAPON_SUPERPULEMET
:
5662 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5663 FFireAngle
:= FAngle
;
5665 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5666 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5669 WEAPON_FLAMETHROWER
:
5671 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
5672 FFireAngle
:= FAngle
;
5679 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5680 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5681 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5684 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5686 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5687 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5690 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5694 if NetInterpLevel
< 1 then
5704 AX
:= Abs(FXTo
- FObj
.X
);
5705 AY
:= Abs(FYTo
- FObj
.Y
);
5706 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5708 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5713 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5715 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5716 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5717 PANEL_LIFTUP
, False) then Result
:= -1
5719 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5720 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5721 PANEL_LIFTDOWN
, False) then Result
:= 1
5725 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5732 if Flag
= FLAG_NONE
then
5735 if not g_Game_IsServer
then Exit
;
5737 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5738 if (Flag
= FTeam
) and
5739 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5740 (FFlag
<> FLAG_NONE
) then
5742 if FFlag
= FLAG_RED
then
5743 s
:= _lc
[I_PLAYER_FLAG_RED
]
5745 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5747 evtype
:= FLAG_STATE_SCORED
;
5749 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5750 Insert('.', ts
, Length(ts
) + 1 - 3);
5751 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5753 g_Map_ResetFlag(FFlag
);
5754 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5756 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5759 if g_Game_IsNet
then
5761 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5765 gFlags
[FFlag
].CaptureTime
:= 0;
5770 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5771 if (Flag
= FTeam
) and
5772 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5774 if Flag
= FLAG_RED
then
5775 s
:= _lc
[I_PLAYER_FLAG_RED
]
5777 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5779 evtype
:= FLAG_STATE_RETURNED
;
5780 gFlags
[Flag
].CaptureTime
:= 0;
5782 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5784 g_Map_ResetFlag(Flag
);
5785 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5788 if g_Game_IsNet
then
5790 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5796 // Ïîäîáðàë ÷óæîé ôëàã:
5797 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5801 if Flag
= FLAG_RED
then
5802 s
:= _lc
[I_PLAYER_FLAG_RED
]
5804 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5806 evtype
:= FLAG_STATE_CAPTURED
;
5808 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5810 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5812 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5815 if g_Game_IsNet
then
5817 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5823 procedure TPlayer
.SetFlag(Flag
: Byte);
5826 if FModel
<> nil then
5827 FModel
.SetFlag(FFlag
);
5830 function TPlayer
.DropFlag(): Boolean;
5835 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5837 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5838 with gFlags
[FFlag
] do
5842 Direction
:= FDirection
;
5843 State
:= FLAG_STATE_DROPPED
;
5845 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5846 (FObj
.Vel
.Y
div 2)-2+Random(5));
5847 positionChanged(); // this updates spatial accelerators
5849 if FFlag
= FLAG_RED
then
5850 s
:= _lc
[I_PLAYER_FLAG_RED
]
5852 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5854 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5855 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5857 if g_Game_IsNet
then
5858 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5864 procedure TPlayer
.GetSecret();
5869 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5871 Assert(Key
<= High(FKeys
));
5873 FKeys
[Key
].Pressed
:= True;
5874 FKeys
[Key
].Time
:= Time
;
5877 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5879 Result
:= FKeys
[K
].Pressed
;
5882 procedure TPlayer
.ReleaseKeys();
5886 for a
:= Low(FKeys
) to High(FKeys
) do
5888 FKeys
[a
].Pressed
:= False;
5893 procedure TPlayer
.ReleaseKeysNoWeapon();
5897 for a
:= Low(FKeys
) to High(FKeys
) do
5899 if (a
= KEY_PREVWEAPON
) or (a
= KEY_NEXTWEAPON
) then continue
;
5900 FKeys
[a
].Pressed
:= False;
5905 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5909 function TPlayer
.firediry(): Integer;
5911 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5912 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5916 procedure TPlayer
.RememberState();
5920 FSavedState
.Health
:= FHealth
;
5921 FSavedState
.Armor
:= FArmor
;
5922 FSavedState
.Air
:= FAir
;
5923 FSavedState
.JetFuel
:= FJetFuel
;
5924 FSavedState
.CurrWeap
:= FCurrWeap
;
5925 FSavedState
.NextWeap
:= FNextWeap
;
5926 FSavedState
.NextWeapDelay
:= FNextWeapDelay
;
5929 FSavedState
.Ammo
[i
] := FAmmo
[i
];
5931 FSavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5933 FSavedState
.Rulez
:= FRulez
;
5934 FSavedState
.WaitRecall
:= True;
5937 procedure TPlayer
.RecallState();
5941 if not FSavedState
.WaitRecall
then Exit
;
5943 FHealth
:= FSavedState
.Health
;
5944 FArmor
:= FSavedState
.Armor
;
5945 FAir
:= FSavedState
.Air
;
5946 FJetFuel
:= FSavedState
.JetFuel
;
5947 FCurrWeap
:= FSavedState
.CurrWeap
;
5948 //FNetForceWeap := FCurrWeap;
5949 FNextWeap
:= FSavedState
.NextWeap
;
5950 FNextWeapDelay
:= FSavedState
.NextWeapDelay
;
5953 FAmmo
[i
] := FSavedState
.Ammo
[i
];
5955 FMaxAmmo
[i
] := FSavedState
.MaxAmmo
[i
];
5957 FRulez
:= FSavedState
.Rulez
;
5958 FSavedState
.WaitRecall
:= False;
5960 if gGameSettings
.GameType
= GT_SERVER
then
5961 MH_SEND_PlayerStats(FUID
);
5964 procedure TPlayer
.SaveState (st
: TStream
);
5970 utils
.writeSign(st
, 'PLYR');
5971 utils
.writeInt(st
, Byte(PLR_SAVE_VERSION
)); // version
5973 utils
.writeBool(st
, FIamBot
);
5975 utils
.writeInt(st
, Word(FUID
));
5977 utils
.writeStr(st
, FName
);
5979 utils
.writeInt(st
, Byte(FTeam
));
5981 utils
.writeBool(st
, FAlive
);
5982 // Èçðàñõîäîâàë ëè âñå æèçíè
5983 utils
.writeBool(st
, FNoRespawn
);
5985 if FDirection
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
5986 utils
.writeInt(st
, Byte(b
));
5988 utils
.writeInt(st
, LongInt(FHealth
));
5990 utils
.writeInt(st
, Byte(FLives
));
5992 utils
.writeInt(st
, LongInt(FArmor
));
5994 utils
.writeInt(st
, LongInt(FAir
));
5996 utils
.writeInt(st
, LongInt(FJetFuel
));
5998 utils
.writeInt(st
, LongInt(FPain
));
6000 utils
.writeInt(st
, LongInt(FKills
));
6002 utils
.writeInt(st
, LongInt(FMonsterKills
));
6004 utils
.writeInt(st
, LongInt(FFrags
));
6006 utils
.writeInt(st
, Byte(FFragCombo
));
6007 // Âðåìÿ ïîñëåäíåãî ôðàãà
6008 utils
.writeInt(st
, LongWord(FLastFrag
));
6010 utils
.writeInt(st
, LongInt(FDeath
));
6012 utils
.writeInt(st
, Byte(FFlag
));
6014 utils
.writeInt(st
, LongInt(FSecrets
));
6016 utils
.writeInt(st
, Byte(FCurrWeap
));
6018 utils
.writeInt(st
, Word(FNextWeap
));
6020 utils
.writeInt(st
, Byte(FNextWeapDelay
));
6021 // Âðåìÿ çàðÿäêè BFG
6022 utils
.writeInt(st
, SmallInt(FBFGFireCounter
));
6024 utils
.writeInt(st
, LongInt(FDamageBuffer
));
6025 // Ïîñëåäíèé óäàðèâøèé
6026 utils
.writeInt(st
, Word(FLastSpawnerUID
));
6027 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6028 utils
.writeInt(st
, Byte(FLastHit
));
6030 Obj_SaveState(st
, @FObj
);
6031 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6032 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FAmmo
[i
]));
6033 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6034 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FMaxAmmo
[i
]));
6036 for i
:= WP_FIRST
to WP_LAST
do utils
.writeBool(st
, FWeapon
[i
]);
6037 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6038 for i
:= WP_FIRST
to WP_LAST
do utils
.writeInt(st
, Word(FReloading
[i
]));
6040 utils
.writeBool(st
, (R_ITEM_BACKPACK
in FRulez
));
6041 // Íàëè÷èå êðàñíîãî êëþ÷à
6042 utils
.writeBool(st
, (R_KEY_RED
in FRulez
));
6043 // Íàëè÷èå çåëåíîãî êëþ÷à
6044 utils
.writeBool(st
, (R_KEY_GREEN
in FRulez
));
6045 // Íàëè÷èå ñèíåãî êëþ÷à
6046 utils
.writeBool(st
, (R_KEY_BLUE
in FRulez
));
6048 utils
.writeBool(st
, (R_BERSERK
in FRulez
));
6049 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6050 for i
:= MR_SUIT
to MR_MAX
do utils
.writeInt(st
, LongWord(FMegaRulez
[i
]));
6051 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6052 for i
:= T_RESPAWN
to T_FLAGCAP
do utils
.writeInt(st
, LongWord(FTime
[i
]));
6054 utils
.writeStr(st
, FModel
.Name
);
6056 utils
.writeInt(st
, Byte(FColor
.R
));
6057 utils
.writeInt(st
, Byte(FColor
.G
));
6058 utils
.writeInt(st
, Byte(FColor
.B
));
6062 procedure TPlayer
.LoadState (st
: TStream
);
6071 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
6072 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
6074 FIamBot
:= utils
.readBool(st
);
6076 FUID
:= utils
.readWord(st
);
6078 str
:= utils
.readStr(st
);
6079 if (self
<> gPlayer1
) and (self
<> gPlayer2
) then FName
:= str
;
6081 FTeam
:= utils
.readByte(st
);
6083 FAlive
:= utils
.readBool(st
);
6084 // Èçðàñõîäîâàë ëè âñå æèçíè
6085 FNoRespawn
:= utils
.readBool(st
);
6087 b
:= utils
.readByte(st
);
6088 if b
= 1 then FDirection
:= TDirection
.D_LEFT
else FDirection
:= TDirection
.D_RIGHT
; // b = 2
6090 FHealth
:= utils
.readLongInt(st
);
6092 FLives
:= utils
.readByte(st
);
6094 FArmor
:= utils
.readLongInt(st
);
6096 FAir
:= utils
.readLongInt(st
);
6098 FJetFuel
:= utils
.readLongInt(st
);
6100 FPain
:= utils
.readLongInt(st
);
6102 FKills
:= utils
.readLongInt(st
);
6104 FMonsterKills
:= utils
.readLongInt(st
);
6106 FFrags
:= utils
.readLongInt(st
);
6108 FFragCombo
:= utils
.readByte(st
);
6109 // Âðåìÿ ïîñëåäíåãî ôðàãà
6110 FLastFrag
:= utils
.readLongWord(st
);
6112 FDeath
:= utils
.readLongInt(st
);
6114 FFlag
:= utils
.readByte(st
);
6116 FSecrets
:= utils
.readLongInt(st
);
6118 FCurrWeap
:= utils
.readByte(st
);
6119 //FNetForceWeap := FCurrWeap;
6121 FNextWeap
:= utils
.readWord(st
);
6123 FNextWeapDelay
:= utils
.readByte(st
);
6124 // Âðåìÿ çàðÿäêè BFG
6125 FBFGFireCounter
:= utils
.readSmallInt(st
);
6127 FDamageBuffer
:= utils
.readLongInt(st
);
6128 // Ïîñëåäíèé óäàðèâøèé
6129 FLastSpawnerUID
:= utils
.readWord(st
);
6130 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6131 FLastHit
:= utils
.readByte(st
);
6133 Obj_LoadState(@FObj
, st
);
6134 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6135 for i
:= A_BULLETS
to A_HIGH
do FAmmo
[i
] := utils
.readWord(st
);
6136 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6137 for i
:= A_BULLETS
to A_HIGH
do FMaxAmmo
[i
] := utils
.readWord(st
);
6139 for i
:= WP_FIRST
to WP_LAST
do FWeapon
[i
] := utils
.readBool(st
);
6140 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6141 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := utils
.readWord(st
);
6143 if utils
.readBool(st
) then Include(FRulez
, R_ITEM_BACKPACK
);
6144 // Íàëè÷èå êðàñíîãî êëþ÷à
6145 if utils
.readBool(st
) then Include(FRulez
, R_KEY_RED
);
6146 // Íàëè÷èå çåëåíîãî êëþ÷à
6147 if utils
.readBool(st
) then Include(FRulez
, R_KEY_GREEN
);
6148 // Íàëè÷èå ñèíåãî êëþ÷à
6149 if utils
.readBool(st
) then Include(FRulez
, R_KEY_BLUE
);
6151 if utils
.readBool(st
) then Include(FRulez
, R_BERSERK
);
6152 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6153 for i
:= MR_SUIT
to MR_MAX
do FMegaRulez
[i
] := utils
.readLongWord(st
);
6154 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6155 for i
:= T_RESPAWN
to T_FLAGCAP
do FTime
[i
] := utils
.readLongWord(st
);
6157 str
:= utils
.readStr(st
);
6159 FColor
.R
:= utils
.readByte(st
);
6160 FColor
.G
:= utils
.readByte(st
);
6161 FColor
.B
:= utils
.readByte(st
);
6162 if (self
= gPlayer1
) then
6164 str
:= gPlayer1Settings
.Model
;
6165 FColor
:= gPlayer1Settings
.Color
;
6167 else if (self
= gPlayer2
) then
6169 str
:= gPlayer2Settings
.Model
;
6170 FColor
:= gPlayer2Settings
.Color
;
6172 // Îáíîâëÿåì ìîäåëü èãðîêà
6174 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
6175 FModel
.Color
:= TEAMCOLOR
[FTeam
]
6177 FModel
.Color
:= FColor
;
6181 procedure TPlayer
.AllRulez(Health
: Boolean);
6187 FHealth
:= PLAYER_HP_LIMIT
;
6188 FArmor
:= PLAYER_AP_LIMIT
;
6192 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
6193 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
6194 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
6197 procedure TPlayer
.RestoreHealthArmor();
6199 FHealth
:= PLAYER_HP_LIMIT
;
6200 FArmor
:= PLAYER_AP_LIMIT
;
6203 procedure TPlayer
.FragCombo();
6207 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
6209 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
6211 if FFragCombo
< 5 then
6213 Param
:= FUID
or (FFragCombo
shl 16);
6214 if (FComboEvnt
>= Low(gDelayedEvents
)) and
6215 (FComboEvnt
<= High(gDelayedEvents
)) and
6216 gDelayedEvents
[FComboEvnt
].Pending
and
6217 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
6218 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
6220 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
6221 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
6224 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
6232 procedure TPlayer
.GiveItem(ItemType
: Byte);
6236 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
6238 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
6242 if FAir
< AIR_MAX
then
6249 if not (R_BERSERK
in FRulez
) then
6251 Include(FRulez
, R_BERSERK
);
6252 if FBFGFireCounter
< 1 then
6254 FCurrWeap
:= WEAPON_KASTET
;
6255 //FNetForceWeap := FCurrWeap;
6257 FModel
.SetWeapon(WEAPON_KASTET
);
6261 FBerserk
:= gTime
+30000;
6263 if FHealth
< PLAYER_HP_SOFT
then
6265 FHealth
:= PLAYER_HP_SOFT
;
6266 FBerserk
:= gTime
+30000;
6271 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
6273 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
6277 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
6279 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
6283 if FJetFuel
< JET_MAX
then
6285 FJetFuel
:= JET_MAX
;
6288 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
6289 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
6291 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
6292 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6294 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
6296 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
6298 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
6299 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6302 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
6303 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
6304 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
6305 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
6306 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
6307 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
6308 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
6309 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
6310 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
6312 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6313 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
6314 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6315 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
6316 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6317 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
6318 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6319 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
6320 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
6323 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
6324 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
6325 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
6326 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
6327 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
6329 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
6330 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
6331 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
6332 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
6333 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
6335 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6336 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6337 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6338 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6340 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
6343 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
6344 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
6345 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
6347 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
6348 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
6353 if g_Game_IsNet
and g_Game_IsServer
then
6354 MH_SEND_PlayerStats(FUID
);
6357 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
6362 if (Random(5) = 1) and (Times
= 1) then
6365 if BodyInLiquid(0, 0) then
6367 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
6368 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
6369 if Random(2) = 0 then
6370 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
6372 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
6376 if g_Frames_Get(id
, 'FRAMES_SMOKE') 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
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6389 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
6394 if (Random(10) = 1) and (Times
= 1) then
6397 if g_Frames_Get(id
, 'FRAMES_FLAME') then
6399 for i
:= 1 to Times
do
6401 Anim
:= TAnimation
.Create(id
, False, 3);
6403 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6404 Obj
.Y
+8+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6410 procedure TPlayer
.PauseSounds(Enable
: Boolean);
6412 FSawSound
.Pause(Enable
);
6413 FSawSoundIdle
.Pause(Enable
);
6414 FSawSoundHit
.Pause(Enable
);
6415 FSawSoundSelect
.Pause(Enable
);
6420 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
6425 FObj
.Rect
:= PLAYER_CORPSERECT
;
6426 FModelName
:= ModelName
;
6431 FState
:= CORPSE_STATE_MESS
;
6432 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
6436 FState
:= CORPSE_STATE_NORMAL
;
6437 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
6441 destructor TCorpse
.Destroy();
6448 function TCorpse
.ObjPtr (): PObj
; inline; begin result
:= @FObj
; end;
6450 procedure TCorpse
.positionChanged (); inline; begin end;
6452 procedure TCorpse
.moveBy (dx
, dy
: Integer); inline;
6454 if (dx
<> 0) or (dy
<> 0) then
6463 procedure TCorpse
.getMapBox (out x
, y
, w
, h
: Integer); inline;
6465 x
:= FObj
.X
+PLAYER_CORPSERECT
.X
;
6466 y
:= FObj
.Y
+PLAYER_CORPSERECT
.Y
;
6467 w
:= PLAYER_CORPSERECT
.Width
;
6468 h
:= PLAYER_CORPSERECT
.Height
;
6472 procedure TCorpse
.Damage(Value
: Word; vx
, vy
: Integer);
6477 if FState
= CORPSE_STATE_REMOVEME
then
6480 FDamage
:= FDamage
+ Value
;
6482 if FDamage
> 150 then
6484 if FAnimation
<> nil then
6489 FState
:= CORPSE_STATE_REMOVEME
;
6491 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
6492 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
6493 FModelName
, FColor
);
6494 // Çâóê ìÿñà îò òðóïà:
6495 pm
:= g_PlayerModel_Get(FModelName
);
6496 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
6500 if (gBodyKillEvent
<> -1)
6501 and gDelayedEvents
[gBodyKillEvent
].Pending
then
6502 gDelayedEvents
[gBodyKillEvent
].Pending
:= False;
6503 gBodyKillEvent
:= g_Game_DelayEvent(DE_BODYKILL
, 1050, 0);
6508 Blood
:= g_PlayerModel_GetBlood(FModelName
);
6509 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
6510 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
6511 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
6512 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
6513 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
6514 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
6518 procedure TCorpse
.Draw();
6520 if FState
= CORPSE_STATE_REMOVEME
then
6523 if FAnimation
<> nil then
6524 FAnimation
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6526 if FAnimationMask
<> nil then
6529 FAnimationMask
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6536 procedure TCorpse
.Update();
6540 if FState
= CORPSE_STATE_REMOVEME
then
6543 if gTime
mod (GAME_TICK
*2) <> 0 then
6545 g_Obj_Move(@FObj
, True, True, True);
6546 positionChanged(); // this updates spatial accelerators
6550 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6551 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
6553 st
:= g_Obj_Move(@FObj
, True, True, True);
6554 positionChanged(); // this updates spatial accelerators
6556 if WordBool(st
and MOVE_FALLOUT
) then
6558 FState
:= CORPSE_STATE_REMOVEME
;
6562 if FAnimation
<> nil then
6563 FAnimation
.Update();
6564 if FAnimationMask
<> nil then
6565 FAnimationMask
.Update();
6569 procedure TCorpse
.SaveState (st
: TStream
);
6576 utils
.writeSign(st
, 'CORP');
6577 utils
.writeInt(st
, Byte(0));
6579 utils
.writeInt(st
, Byte(FState
));
6581 utils
.writeInt(st
, Byte(FDamage
));
6583 utils
.writeInt(st
, Byte(FColor
.R
));
6584 utils
.writeInt(st
, Byte(FColor
.G
));
6585 utils
.writeInt(st
, Byte(FColor
.B
));
6587 Obj_SaveState(st
, @FObj
);
6588 utils
.writeInt(st
, Word(FPlayerUID
));
6590 anim
:= (FAnimation
<> nil);
6591 utils
.writeBool(st
, anim
);
6592 // Åñëè åñòü - ñîõðàíÿåì
6593 if anim
then FAnimation
.SaveState(st
);
6594 // Åñòü ëè ìàñêà àíèìàöèè
6595 anim
:= (FAnimationMask
<> nil);
6596 utils
.writeBool(st
, anim
);
6597 // Åñëè åñòü - ñîõðàíÿåì
6598 if anim
then FAnimationMask
.SaveState(st
);
6602 procedure TCorpse
.LoadState (st
: TStream
);
6609 if not utils
.checkSign(st
, 'CORP') then raise XStreamError
.Create('invalid corpse signature');
6610 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid corpse version');
6612 FState
:= utils
.readByte(st
);
6614 FDamage
:= utils
.readByte(st
);
6616 FColor
.R
:= utils
.readByte(st
);
6617 FColor
.G
:= utils
.readByte(st
);
6618 FColor
.B
:= utils
.readByte(st
);
6620 Obj_LoadState(@FObj
, st
);
6621 FPlayerUID
:= utils
.readWord(st
);
6623 anim
:= utils
.readBool(st
);
6624 // Åñëè åñòü - çàãðóæàåì
6627 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6628 FAnimation
.LoadState(st
);
6630 // Åñòü ëè ìàñêà àíèìàöèè
6631 anim
:= utils
.readBool(st
);
6632 // Åñëè åñòü - çàãðóæàåì
6635 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6636 FAnimationMask
.LoadState(st
);
6642 constructor TBot
.Create();
6649 FSpectator
:= False;
6656 for a
:= WP_FIRST
to WP_LAST
do
6658 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6659 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6660 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6664 destructor TBot
.Destroy();
6667 inherited Destroy();
6670 procedure TBot
.Draw();
6674 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6675 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6678 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6680 inherited Respawn(Silent
, Force
);
6683 FSelectedWeapon
:= FCurrWeap
;
6688 procedure TBot
.UpdateCombat();
6701 TTargetRecord
= array of TTarget
;
6703 function Compare(a
, b
: TTarget
): Integer;
6705 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6708 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6710 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6711 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6713 if a
.Dist
> b
.Dist
then // B áëèæå
6715 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6718 else // Ñòðàííî -> A
6723 a
, x1
, y1
, x2
, y2
: Integer;
6724 targets
: TTargetRecord
;
6726 Target
, BestTarget
: TTarget
;
6727 firew
, fireh
: Integer;
6731 vsPlayer
, vsMonster
, ok
: Boolean;
6734 function monsUpdate (mon
: TMonster
): Boolean;
6736 result
:= false; // don't stop
6737 if mon
.alive
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6739 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6741 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6742 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6744 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6745 if g_TraceVector(x1
, y1
, x2
, y2
) then
6747 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6748 SetLength(targets
, Length(targets
)+1);
6749 with targets
[High(targets
)] do
6756 Rect
:= mon
.Obj
.Rect
;
6757 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6758 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6759 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6768 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6769 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6771 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6772 if FCurrWeap
<> FSelectedWeapon
then
6775 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6776 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6778 RemoveAIFlag('NEEDFIRE');
6781 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6782 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6783 else PressKey(KEY_FIRE
);
6787 // Êîîðäèíàòû ñòâîëà:
6788 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6789 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6791 Target
.UID
:= FTargetUID
;
6794 if Target
.UID
<> 0 then
6795 begin // Öåëü åñòü - íàñòðàèâàåì
6796 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6799 tpla
:= g_Player_Get(Target
.UID
);
6803 if (@FObj
) <> nil then
6810 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6811 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6812 Target
.Rect
:= PLAYER_RECT
;
6813 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6814 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6815 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6816 Target
.IsPlayer
:= True;
6820 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6823 mon
:= g_Monsters_ByUID(Target
.UID
);
6826 Target
.X
:= mon
.Obj
.X
;
6827 Target
.Y
:= mon
.Obj
.Y
;
6829 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6830 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6831 Target
.Rect
:= mon
.Obj
.Rect
;
6832 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6833 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6834 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6835 Target
.IsPlayer
:= False;
6842 begin // Öåëè íåò - îáíóëÿåì
6847 Target
.Visible
:= False;
6848 Target
.Line
:= False;
6849 Target
.IsPlayer
:= False;
6854 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6855 if (not Target
.Line
) or (not Target
.Visible
) then
6859 for a
:= 0 to High(gPlayers
) do
6860 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].alive
) and
6861 (gPlayers
[a
].FUID
<> FUID
) and
6862 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6863 (not gPlayers
[a
].NoTarget
) and
6864 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6866 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6867 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6870 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6871 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6873 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6874 if g_TraceVector(x1
, y1
, x2
, y2
) then
6876 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6877 SetLength(targets
, Length(targets
)+1);
6878 with targets
[High(targets
)] do
6880 UID
:= gPlayers
[a
].FUID
;
6881 X
:= gPlayers
[a
].FObj
.X
;
6882 Y
:= gPlayers
[a
].FObj
.Y
;
6885 Rect
:= PLAYER_RECT
;
6886 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6887 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6888 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6896 if vsMonster
then g_Mons_ForEach(monsUpdate
);
6899 // Åñëè åñòü âîçìîæíûå öåëè:
6900 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6901 if targets
<> nil then
6903 // Âûáèðàåì íàèëó÷øóþ öåëü:
6904 BestTarget
:= targets
[0];
6905 if Length(targets
) > 1 then
6906 for a
:= 1 to High(targets
) do
6907 if Compare(BestTarget
, targets
[a
]) = 1 then
6908 BestTarget
:= targets
[a
];
6910 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6911 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6912 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6914 Target
:= BestTarget
;
6916 if (Healthy() = 3) or ((Healthy() = 2)) then
6917 begin // Åñëè çäîðîâû - äîãîíÿåì
6918 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6919 SetAIFlag('GORIGHT', '1');
6920 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6921 SetAIFlag('GOLEFT', '1');
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 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6932 SelectWeapon(Abs(x1
-Target
.cX
));
6937 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6938 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6939 if Target
.UID
<> 0 then
6941 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6942 Target
.Y
+ Target
.Rect
.Y
) then
6943 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6944 if (Healthy() = 3) or ((Healthy() = 2)) then
6945 begin // Åñëè çäîðîâû - äîãîíÿåì
6946 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6947 SetAIFlag('GORIGHT', '1');
6948 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6949 SetAIFlag('GOLEFT', '1');
6952 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6954 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6955 SetAIFlag('GORIGHT', '1');
6956 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6957 SetAIFlag('GOLEFT', '1');
6961 begin // Öåëü ïîêà íà "ýêðàíå"
6962 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
6963 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6964 FLastVisible
:= gTime
;
6965 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
6966 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6968 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6969 SetAIFlag('GORIGHT', '1');
6970 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6971 SetAIFlag('GOLEFT', '1');
6975 // Âûáèðàåì óãîë ââåðõ:
6976 if FDirection
= TDirection
.D_LEFT
then
6977 angle
:= ANGLE_LEFTUP
6979 angle
:= ANGLE_RIGHTUP
;
6981 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6982 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6984 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6985 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6986 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6987 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6988 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6989 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6990 begin // òî íóæíî ñòðåëÿòü ââåðõ
6991 SetAIFlag('NEEDFIRE', '1');
6992 SetAIFlag('NEEDSEEUP', '1');
6995 // Âûáèðàåì óãîë âíèç:
6996 if FDirection
= TDirection
.D_LEFT
then
6997 angle
:= ANGLE_LEFTDOWN
6999 angle
:= ANGLE_RIGHTDOWN
;
7001 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7002 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7004 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
7005 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7006 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7007 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7008 Target
.Rect
.Width
, Target
.Rect
.Height
) and
7009 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
7010 begin // òî íóæíî ñòðåëÿòü âíèç
7011 SetAIFlag('NEEDFIRE', '1');
7012 SetAIFlag('NEEDSEEDOWN', '1');
7015 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
7016 if Target
.Visible
and
7017 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
7018 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
7020 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
7021 if ((FDirection
= TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) or
7022 ((FDirection
= TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
7023 begin // òî íóæíî ñòðåëÿòü âïåðåä
7024 SetAIFlag('NEEDFIRE', '1');
7025 SetAIFlag('NEEDSEEDOWN', '');
7026 SetAIFlag('NEEDSEEUP', '');
7028 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
7029 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
7030 if GetRnd(FDifficult
.CloseJump
) then
7031 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
7032 if Abs(FObj
.X
-Target
.X
) < 128 then
7036 if Random(a
) = 0 then
7037 SetAIFlag('NEEDJUMP', '1');
7041 // Åñëè öåëü âñå åùå åñòü:
7042 if Target
.UID
<> 0 then
7043 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
7044 Target
.UID
:= 0 // òî çàáûòü öåëü
7045 else // Åñëè âèäåëè íåäàâíî
7046 begin // íî öåëü óáèëè
7047 if Target
.IsPlayer
then
7048 begin // Öåëü - èãðîê
7049 pla
:= g_Player_Get(Target
.UID
);
7050 if (pla
= nil) or (not pla
.alive
) or pla
.NoTarget
or
7051 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
7052 Target
.UID
:= 0; // òî çàáûòü öåëü
7055 begin // Öåëü - ìîíñòð
7056 mon
:= g_Monsters_ByUID(Target
.UID
);
7057 if (mon
= nil) or (not mon
.alive
) then
7058 Target
.UID
:= 0; // òî çàáûòü öåëü
7061 end; // if Target.UID <> 0
7063 FTargetUID
:= Target
.UID
;
7065 // Åñëè âîçìîæíûõ öåëåé íåò:
7066 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
7067 if targets
= nil then
7068 if GetAIFlag('ATTACKLEFT') <> '' then
7069 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
7070 RemoveAIFlag('ATTACKLEFT');
7072 SetAIFlag('NEEDJUMP', '1');
7074 if RunDirection() = TDirection
.D_RIGHT
then
7075 begin // Èäåì íå â òó ñòîðîíó
7076 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7077 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
7078 SetAIFlag('NEEDFIRE', '1');
7079 SetAIFlag('GOLEFT', '1');
7083 begin // Èäåì â íóæíóþ ñòîðîíó
7084 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7085 SetAIFlag('NEEDFIRE', '1');
7086 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7087 SetAIFlag('GORIGHT', '1');
7091 if GetAIFlag('ATTACKRIGHT') <> '' then
7092 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
7093 RemoveAIFlag('ATTACKRIGHT');
7095 SetAIFlag('NEEDJUMP', '1');
7097 if RunDirection() = TDirection
.D_LEFT
then
7098 begin // Èäåì íå â òó ñòîðîíó
7099 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7100 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
7101 SetAIFlag('NEEDFIRE', '1');
7102 SetAIFlag('GORIGHT', '1');
7107 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7108 SetAIFlag('NEEDFIRE', '1');
7109 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7110 SetAIFlag('GOLEFT', '1');
7114 //HACK! (does it belong there?)
7115 RealizeCurrentWeapon();
7117 // Åñëè åñòü âîçìîæíûå öåëè:
7118 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
7119 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
7120 for a
:= 0 to High(targets
) do
7122 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
7123 if GetRnd(FDifficult
.DiagFire
) then
7125 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
7126 if FDirection
= TDirection
.D_LEFT
then
7127 angle
:= ANGLE_LEFTUP
7129 angle
:= ANGLE_RIGHTUP
;
7131 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7132 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7134 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7135 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7136 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7137 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7138 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7140 SetAIFlag('NEEDFIRE', '1');
7141 SetAIFlag('NEEDSEEUP', '1');
7144 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
7145 if FDirection
= TDirection
.D_LEFT
then
7146 angle
:= ANGLE_LEFTDOWN
7148 angle
:= ANGLE_RIGHTDOWN
;
7150 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7151 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7153 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7154 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7155 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7156 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7157 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7159 SetAIFlag('NEEDFIRE', '1');
7160 SetAIFlag('NEEDSEEDOWN', '1');
7164 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
7165 if targets
[a
].Line
and targets
[a
].Visible
and
7166 (((FDirection
= TDirection
.D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
7167 ((FDirection
= TDirection
.D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
7169 SetAIFlag('NEEDFIRE', '1');
7174 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
7175 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
7176 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
7177 40+GetInterval(FDifficult
.Cover
, 40)) then
7178 SetAIFlag('NEEDJUMP', '1');
7180 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
7181 ammo
:= GetAmmoByWeapon(FCurrWeap
);
7182 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
7183 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
7185 SetAIFlag('SELECTWEAPON', '1');
7187 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
7188 if GetAIFlag('SELECTWEAPON') = '1' then
7191 RemoveAIFlag('SELECTWEAPON');
7195 procedure TBot
.Update();
7208 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
7209 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
7211 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
7213 if g_debug_BotAIOff
= 3 then
7223 RealizeCurrentWeapon();
7230 procedure TBot
.ReleaseKey(Key
: Byte);
7239 function TBot
.KeyPressed(Key
: Word): Boolean;
7241 Result
:= FKeys
[Key
].Pressed
;
7244 function TBot
.GetAIFlag(aName
: String20
): String20
;
7250 aName
:= LowerCase(aName
);
7252 if FAIFlags
<> nil then
7253 for a
:= 0 to High(FAIFlags
) do
7254 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7256 Result
:= FAIFlags
[a
].Value
;
7261 procedure TBot
.RemoveAIFlag(aName
: String20
);
7265 if FAIFlags
= nil then Exit
;
7267 aName
:= LowerCase(aName
);
7269 for a
:= 0 to High(FAIFlags
) do
7270 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7272 if a
<> High(FAIFlags
) then
7273 for b
:= a
to High(FAIFlags
)-1 do
7274 FAIFlags
[b
] := FAIFlags
[b
+1];
7276 SetLength(FAIFlags
, Length(FAIFlags
)-1);
7281 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
7289 aName
:= LowerCase(aName
);
7291 if FAIFlags
<> nil then
7292 for a
:= 0 to High(FAIFlags
) do
7293 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7299 if ok
then FAIFlags
[a
].Value
:= fValue
7302 SetLength(FAIFlags
, Length(FAIFlags
)+1);
7303 with FAIFlags
[High(FAIFlags
)] do
7311 procedure TBot
.UpdateMove
;
7313 procedure GoLeft(Time
: Word = 1);
7315 ReleaseKey(KEY_LEFT
);
7316 ReleaseKey(KEY_RIGHT
);
7317 PressKey(KEY_LEFT
, Time
);
7318 SetDirection(TDirection
.D_LEFT
);
7321 procedure GoRight(Time
: Word = 1);
7323 ReleaseKey(KEY_LEFT
);
7324 ReleaseKey(KEY_RIGHT
);
7325 PressKey(KEY_RIGHT
, Time
);
7326 SetDirection(TDirection
.D_RIGHT
);
7329 function Rnd(a
: Word): Boolean;
7331 Result
:= Random(a
) = 0;
7334 procedure Turn(Time
: Word = 1200);
7336 if RunDirection() = TDirection
.D_LEFT
then GoRight(Time
) else GoLeft(Time
);
7341 ReleaseKey(KEY_LEFT
);
7342 ReleaseKey(KEY_RIGHT
);
7345 function CanRunLeft(): Boolean;
7347 Result
:= not CollideLevel(-1, 0);
7350 function CanRunRight(): Boolean;
7352 Result
:= not CollideLevel(1, 0);
7355 function CanRun(): Boolean;
7357 if RunDirection() = TDirection
.D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
7360 procedure Jump(Time
: Word = 30);
7362 PressKey(KEY_JUMP
, Time
);
7365 function NearHole(): Boolean;
7369 { TODO 5 : Ëåñòíèöû }
7370 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7371 for x
:= 1 to PLAYER_RECT
.Width
do
7372 if (not StayOnStep(x
*sx
, 0)) and
7373 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7374 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7383 function BorderHole(): Boolean;
7387 { TODO 5 : Ëåñòíèöû }
7388 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7389 for x
:= 1 to PLAYER_RECT
.Width
do
7390 if (not StayOnStep(x
*sx
, 0)) and
7391 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7392 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7394 for xx
:= x
to x
+32 do
7395 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
7405 function NearDeepHole(): Boolean;
7411 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7414 for x
:= 1 to PLAYER_RECT
.Width
do
7415 if (not StayOnStep(x
*sx
, 0)) and
7416 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7417 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7419 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7421 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
7426 end else Result
:= False;
7429 function OverDeepHole(): Boolean;
7436 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7438 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
7445 function OnGround(): Boolean;
7447 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
7450 function OnLadder(): Boolean;
7452 Result
:= FullInStep(0, 0);
7455 function BelowLadder(): Boolean;
7457 Result
:= (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
7458 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7459 (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
7460 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7463 function BelowLiftUp(): Boolean;
7465 Result
:= ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
7466 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7467 ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
7468 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7471 function OnTopLift(): Boolean;
7473 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7476 function CanJumpOver(): Boolean;
7480 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7484 if not CollideLevel(sx
, 0) then Exit
;
7486 for y
:= 1 to BOT_MAXJUMP
do
7487 if CollideLevel(0, -y
) then Exit
else
7488 if not CollideLevel(sx
, -y
) then
7495 function CanJumpUp(Dist
: ShortInt): Boolean;
7502 if CollideLevel(Dist
, 0) then Exit
;
7505 for y
:= 0 to BOT_MAXJUMP
do
7506 if CollideLevel(Dist
, -y
) then
7515 for yy
:= y
+1 to BOT_MAXJUMP
do
7516 if not CollideLevel(Dist
, -yy
) then
7525 for y
:= 0 to BOT_MAXJUMP
do
7526 if CollideLevel(0, -y
) then
7534 if y
< yy
then Exit
;
7539 function IsSafeTrigger(): Boolean;
7544 if gTriggers
= nil then
7546 for a
:= 0 to High(gTriggers
) do
7547 if Collide(gTriggers
[a
].X
,
7550 gTriggers
[a
].Height
) and
7551 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
7552 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
7553 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
7554 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
7555 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
7560 // Âîçìîæíî, íàæèìàåì êíîïêó:
7561 if Rnd(16) and IsSafeTrigger() then
7564 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7565 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7567 ReleaseKey(KEY_LEFT
);
7568 ReleaseKey(KEY_RIGHT
);
7572 // Èäåì âëåâî, åñëè íàäî áûëî:
7573 if GetAIFlag('GOLEFT') <> '' then
7575 RemoveAIFlag('GOLEFT');
7576 if CanRunLeft() then
7580 // Èäåì âïðàâî, åñëè íàäî áûëî:
7581 if GetAIFlag('GORIGHT') <> '' then
7583 RemoveAIFlag('GORIGHT');
7584 if CanRunRight() then
7588 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7589 if FObj
.X
< -32 then
7592 if FObj
.X
+32 > gMapInfo
.Width
then
7595 // Ïðûãàåì, åñëè íàäî áûëî:
7596 if GetAIFlag('NEEDJUMP') <> '' then
7599 RemoveAIFlag('NEEDJUMP');
7602 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7603 if GetAIFlag('NEEDSEEUP') <> '' then
7606 ReleaseKey(KEY_DOWN
);
7607 PressKey(KEY_UP
, 20);
7608 RemoveAIFlag('NEEDSEEUP');
7611 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7612 if GetAIFlag('NEEDSEEDOWN') <> '' then
7615 ReleaseKey(KEY_DOWN
);
7616 PressKey(KEY_DOWN
, 20);
7617 RemoveAIFlag('NEEDSEEDOWN');
7620 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7621 if GetAIFlag('GOINHOLE') <> '' then
7622 if not OnGround() then
7624 ReleaseKey(KEY_LEFT
);
7625 ReleaseKey(KEY_RIGHT
);
7626 RemoveAIFlag('GOINHOLE');
7627 SetAIFlag('FALLINHOLE', '1');
7630 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7631 if GetAIFlag('FALLINHOLE') <> '' then
7633 RemoveAIFlag('FALLINHOLE');
7635 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7636 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7637 if GetAIFlag('FALLINHOLE') = '' then
7638 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7644 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7646 CanJumpUp(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*32) and
7650 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7651 if OnGround() and NearHole() then
7652 if NearDeepHole() then // Åñëè ýòî áåçäíà
7654 0..3: Turn(); // Áåæèì îáðàòíî
7655 4: Jump(); // Ïðûãàåì
7656 5: begin // Ïðûãàåì îáðàòíî
7661 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7662 if GetAIFlag('GOINHOLE') = '' then
7664 0: Turn(); // Íå íóæíî òóäà
7665 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7666 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7667 if BorderHole() then
7668 SetAIFlag('GOINHOLE', '1');
7671 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7672 if (not CanRun()) and OnGround() then
7674 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7675 if CanJumpOver() or OnLadder() then
7677 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7678 if Random(2) = 0 then
7680 if IsSafeTrigger() then
7686 // Îñòàëîñü ìàëî âîçäóõà:
7687 if FAir
< 36 * 2 then
7690 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7691 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7692 if BodyInAcid(0, 0) then
7696 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7698 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7699 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7702 {function TBot.NeedItem(Item: Byte): Byte;
7707 procedure TBot
.SelectWeapon(Dist
: Integer);
7711 function HaveAmmo(weapon
: Byte): Boolean;
7714 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7715 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7716 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7717 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7718 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7719 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7720 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7721 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7722 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7723 else Result
:= True;
7728 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7730 if Dist
> BOT_LONGDIST
then
7731 begin // Äàëüíèé áîé
7733 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7735 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7739 else //if Dist > BOT_UNSAFEDIST then
7740 begin // Áëèæíèé áîé
7742 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7744 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7751 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7753 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7759 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7761 Result
:= inherited PickItem(ItemType
, force
, remove
);
7763 if Result
then SetAIFlag('SELECTWEAPON', '1');
7766 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7768 Result
:= inherited Heal(value
, Soft
);
7771 function TBot
.Healthy(): Byte;
7773 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7774 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7775 else if (FHealth
> 50) then Result
:= 2
7776 else if (FHealth
> 20) then Result
:= 1
7780 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7782 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7783 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7786 procedure TBot
.OnDamage(Angle
: SmallInt);
7794 if (Angle
= 0) or (Angle
= 180) then
7797 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7798 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7800 pla
:= g_Player_Get(FLastSpawnerUID
);
7801 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7802 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7805 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7806 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7808 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
7809 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7810 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7815 SetAIFlag('ATTACKLEFT', '1')
7817 SetAIFlag('ATTACKRIGHT', '1');
7821 function TBot
.RunDirection(): TDirection
;
7823 if Abs(Vel
.X
) >= 1 then
7825 if Vel
.X
> 0 then Result
:= TDirection
.D_RIGHT
else Result
:= TDirection
.D_LEFT
;
7827 Result
:= FDirection
;
7830 function TBot
.GetRnd(a
: Byte): Boolean;
7832 if a
= 0 then Result
:= False
7833 else if a
= 255 then Result
:= True
7834 else Result
:= Random(256) > 255-a
;
7837 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7839 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7843 procedure TDifficult
.save (st
: TStream
);
7845 utils
.writeInt(st
, Byte(DiagFire
));
7846 utils
.writeInt(st
, Byte(InvisFire
));
7847 utils
.writeInt(st
, Byte(DiagPrecision
));
7848 utils
.writeInt(st
, Byte(FlyPrecision
));
7849 utils
.writeInt(st
, Byte(Cover
));
7850 utils
.writeInt(st
, Byte(CloseJump
));
7851 st
.WriteBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7852 st
.WriteBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7855 procedure TDifficult
.load (st
: TStream
);
7857 DiagFire
:= utils
.readByte(st
);
7858 InvisFire
:= utils
.readByte(st
);
7859 DiagPrecision
:= utils
.readByte(st
);
7860 FlyPrecision
:= utils
.readByte(st
);
7861 Cover
:= utils
.readByte(st
);
7862 CloseJump
:= utils
.readByte(st
);
7863 st
.ReadBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7864 st
.ReadBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7868 procedure TBot
.SaveState (st
: TStream
);
7873 inherited SaveState(st
);
7874 utils
.writeSign(st
, 'BOT0');
7876 utils
.writeInt(st
, Byte(FSelectedWeapon
));
7878 utils
.writeInt(st
, Word(FTargetUID
));
7879 // Âðåìÿ ïîòåðè öåëè
7880 utils
.writeInt(st
, LongWord(FLastVisible
));
7881 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7882 dw
:= Length(FAIFlags
);
7883 utils
.writeInt(st
, LongInt(dw
));
7885 for i
:= 0 to dw
-1 do
7887 utils
.writeStr(st
, FAIFlags
[i
].Name
, 20);
7888 utils
.writeStr(st
, FAIFlags
[i
].Value
, 20);
7890 // Íàñòðîéêè ñëîæíîñòè
7891 FDifficult
.save(st
);
7895 procedure TBot
.LoadState (st
: TStream
);
7900 inherited LoadState(st
);
7901 if not utils
.checkSign(st
, 'BOT0') then raise XStreamError
.Create('invalid bot signature');
7903 FSelectedWeapon
:= utils
.readByte(st
);
7905 FTargetUID
:= utils
.readWord(st
);
7906 // Âðåìÿ ïîòåðè öåëè
7907 FLastVisible
:= utils
.readLongWord(st
);
7908 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7909 dw
:= utils
.readLongInt(st
);
7910 if (dw
< 0) or (dw
> 16384) then raise XStreamError
.Create('invalid number of bot AI flags');
7911 SetLength(FAIFlags
, dw
);
7913 for i
:= 0 to dw
-1 do
7915 FAIFlags
[i
].Name
:= utils
.readStr(st
, 20);
7916 FAIFlags
[i
].Value
:= utils
.readStr(st
, 20);
7918 // Íàñòðîéêè ñëîæíîñòè
7919 FDifficult
.load(st
);
7924 conRegVar('cheat_berserk_autoswitch', @gBerserkAutoswitch
, 'autoswitch to fist when berserk pack taken', '', true, true);