1 (* Copyright (C) Doom 2D: Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 {$INCLUDE ../shared/a_modes.inc}
24 {$IFDEF USE_MEMPOOL}mempool
,{$ENDIF}
25 e_graphics
, g_playermodel
, g_basic
, g_textures
,
26 g_weapons
, g_phys
, g_sound
, g_saveload
, MAPDEF
,
59 AmmoLimits
: Array [0..1] of Array [A_BULLETS
..A_HIGH
] of Word =
60 ((200, 50, 50, 300, 100),
61 (400, 100, 100, 600, 200));
82 ANGLE_NONE
= Low(SmallInt);
84 CORPSE_STATE_REMOVEME
= 0;
85 CORPSE_STATE_NORMAL
= 1;
86 CORPSE_STATE_MESS
= 2;
88 PLAYER_RECT
: TRectWH
= (X
:15; Y
:12; Width
:34; Height
:52);
89 PLAYER_RECT_CX
= 15+(34 div 2);
90 PLAYER_RECT_CY
= 12+(52 div 2);
91 PLAYER_CORPSERECT
: TRectWH
= (X
:15; Y
:48; Width
:34; Height
:16);
94 PLAYER_HP_LIMIT
= 200;
96 PLAYER_AP_LIMIT
= 200;
99 PLAYER1_DEF_COLOR
: TRGB
= (R
:64; G
:175; B
:48);
100 PLAYER2_DEF_COLOR
: TRGB
= (R
:96; G
:96; B
:96);
116 TPlayerStatArray
= Array of TPlayerStat
;
118 TPlayerSavedState
= record
126 Ammo
: Array [A_BULLETS
..A_HIGH
] of Word;
127 MaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
128 Weapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
129 Rulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
138 TPlayer
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
146 FDirection
: TDirection
;
154 FMonsterKills
: Integer;
160 FCanJetpack
: Boolean;
166 FNextWeapDelay
: Byte; // frames
167 FBFGFireCounter
: SmallInt;
168 FLastSpawnerUID
: Word;
172 FSpectatePlayer
: Integer;
173 FFirePainTime
: Integer;
176 FSavedState
: TPlayerSavedState
;
178 FModel
: TPlayerModel
;
179 FPunchAnim
: TAnimation
;
182 FActionForce
: Boolean;
183 FActionChanged
: Boolean;
185 FFireAngle
: SmallInt;
187 FShellTimer
: Integer;
189 FSawSound
: TPlayableSound
;
190 FSawSoundIdle
: TPlayableSound
;
191 FSawSoundHit
: TPlayableSound
;
192 FSawSoundSelect
: TPlayableSound
;
193 FJetSoundOn
: TPlayableSound
;
194 FJetSoundOff
: TPlayableSound
;
195 FJetSoundFly
: TPlayableSound
;
199 FJustTeleported
: Boolean;
201 mEDamageType
: Integer;
204 function CollideLevel(XInc
, YInc
: Integer): Boolean;
205 function StayOnStep(XInc
, YInc
: Integer): Boolean;
206 function HeadInLiquid(XInc
, YInc
: Integer): Boolean;
207 function BodyInLiquid(XInc
, YInc
: Integer): Boolean;
208 function BodyInAcid(XInc
, YInc
: Integer): Boolean;
209 function FullInLift(XInc
, YInc
: Integer): Integer;
210 {procedure CollideItem();}
211 procedure FlySmoke(Times
: DWORD
= 1);
212 procedure OnFireFlame(Times
: DWORD
= 1);
213 function GetAmmoByWeapon(Weapon
: Byte): Word;
214 procedure SetAction(Action
: Byte; Force
: Boolean = False);
215 procedure OnDamage(Angle
: SmallInt); virtual;
216 function firediry(): Integer;
219 procedure Run(Direction
: TDirection
);
220 procedure NextWeapon();
221 procedure PrevWeapon();
228 function getNextWeaponIndex (): Byte; // return 255 for "no switch"
229 procedure resetWeaponQueue ();
230 function hasAmmoForWeapon (weapon
: Byte): Boolean;
232 procedure doDamage (v
: Integer);
235 FDamageBuffer
: Integer;
237 FAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
238 FMaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
239 FWeapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
240 FRulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
242 FMegaRulez
: Array [MR_SUIT
..MR_MAX
] of DWORD
;
243 FReloading
: Array [WP_FIRST
..WP_LAST
] of Word;
244 FTime
: Array [T_RESPAWN
..T_FLAGCAP
] of DWORD
;
245 FKeys
: Array [KEY_LEFT
..KEY_CHAT
] of TKeyState
;
247 FPreferredTeam
: Byte;
250 FWantsInGame
: Boolean;
254 FActualModelName
: string;
261 // debug: viewport offset
262 viewPortX
, viewPortY
, viewPortW
, viewPortH
: Integer;
264 function isValidViewPort (): Boolean; inline;
266 constructor Create(); virtual;
267 destructor Destroy(); override;
268 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); virtual;
269 function GetRespawnPoint(): Byte;
270 procedure PressKey(Key
: Byte; Time
: Word = 1);
271 procedure ReleaseKeys();
272 procedure SetModel(ModelName
: String);
273 procedure SetColor(Color
: TRGB
);
274 procedure SetWeapon(W
: Byte);
275 function IsKeyPressed(K
: Byte): Boolean;
276 function GetKeys(): Byte;
277 function PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean; virtual;
278 function Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean; overload
;
279 function Collide(Panel
: TPanel
): Boolean; overload
;
280 function Collide(X
, Y
: Integer): Boolean; overload
;
281 procedure SetDirection(Direction
: TDirection
);
282 procedure GetSecret();
283 function TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
285 procedure Push(vx
, vy
: Integer);
286 procedure ChangeModel(ModelName
: String);
287 procedure SwitchTeam
;
288 procedure ChangeTeam(Team
: Byte);
290 function GetFlag(Flag
: Byte): Boolean;
291 procedure SetFlag(Flag
: Byte);
292 function DropFlag(): Boolean;
293 procedure AllRulez(Health
: Boolean);
294 procedure RestoreHealthArmor();
295 procedure FragCombo();
296 procedure GiveItem(ItemType
: Byte);
297 procedure Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte); virtual;
298 function Heal(value
: Word; Soft
: Boolean): Boolean; virtual;
299 procedure MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
300 procedure MakeBloodSimple(Count
: Word);
301 procedure Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
302 procedure Reset(Force
: Boolean);
303 procedure Spectate(NoMove
: Boolean = False);
304 procedure SwitchNoClip
;
305 procedure SoftReset();
306 procedure Draw(); virtual;
307 procedure DrawPain();
308 procedure DrawPickup();
309 procedure DrawRulez();
311 procedure DrawBubble();
313 procedure Update(); virtual;
314 procedure RememberState();
315 procedure RecallState();
316 procedure SaveState (st
: TStream
); virtual;
317 procedure LoadState (st
: TStream
); virtual;
318 procedure PauseSounds(Enable
: Boolean);
319 procedure NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
320 procedure DoLerp(Level
: Integer = 2);
321 procedure SetLerp(XTo
, YTo
: Integer);
322 procedure QueueWeaponSwitch(Weapon
: Byte);
323 procedure RealizeCurrentWeapon();
325 procedure JetpackOff
;
326 procedure CatchFire(Attacker
: Word);
328 //WARNING! this does nothing for now, but still call it!
329 procedure positionChanged (); //WARNING! call this after entity position was changed, or coldet will not work right!
331 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
332 procedure moveBy (dx
, dy
: Integer); inline;
335 property Vel
: TPoint2i read FObj
.Vel
;
336 property Obj
: TObj read FObj
;
338 property Name
: String read FName write FName
;
339 property Model
: TPlayerModel read FModel
;
340 property Health
: Integer read FHealth write FHealth
;
341 property Lives
: Byte read FLives write FLives
;
342 property Armor
: Integer read FArmor write FArmor
;
343 property Air
: Integer read FAir write FAir
;
344 property JetFuel
: Integer read FJetFuel write FJetFuel
;
345 property Frags
: Integer read FFrags write FFrags
;
346 property Death
: Integer read FDeath write FDeath
;
347 property Kills
: Integer read FKills write FKills
;
348 property CurrWeap
: Byte read FCurrWeap write FCurrWeap
;
349 property MonsterKills
: Integer read FMonsterKills write FMonsterKills
;
350 property Secrets
: Integer read FSecrets
;
351 property GodMode
: Boolean read FGodMode write FGodMode
;
352 property NoTarget
: Boolean read FNoTarget write FNoTarget
;
353 property NoReload
: Boolean read FNoReload write FNoReload
;
354 property alive
: Boolean read FAlive write FAlive
;
355 property Flag
: Byte read FFlag
;
356 property Team
: Byte read FTeam write FTeam
;
357 property Direction
: TDirection read FDirection
;
358 property GameX
: Integer read FObj
.X write FObj
.X
;
359 property GameY
: Integer read FObj
.Y write FObj
.Y
;
360 property GameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
361 property GameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
362 property GameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
363 property GameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
364 property IncCam
: Integer read FIncCam write FIncCam
;
365 property UID
: Word read FUID write FUID
;
366 property JustTeleported
: Boolean read FJustTeleported write FJustTeleported
;
367 property NetTime
: LongWord read FNetTime write FNetTime
;
370 property eName
: String read FName write FName
;
371 property eHealth
: Integer read FHealth write FHealth
;
372 property eLives
: Byte read FLives write FLives
;
373 property eArmor
: Integer read FArmor write FArmor
;
374 property eAir
: Integer read FAir write FAir
;
375 property eJetFuel
: Integer read FJetFuel write FJetFuel
;
376 property eFrags
: Integer read FFrags write FFrags
;
377 property eDeath
: Integer read FDeath write FDeath
;
378 property eKills
: Integer read FKills write FKills
;
379 property eCurrWeap
: Byte read FCurrWeap write FCurrWeap
;
380 property eMonsterKills
: Integer read FMonsterKills write FMonsterKills
;
381 property eSecrets
: Integer read FSecrets write FSecrets
;
382 property eGodMode
: Boolean read FGodMode write FGodMode
;
383 property eNoTarget
: Boolean read FNoTarget write FNoTarget
;
384 property eNoReload
: Boolean read FNoReload write FNoReload
;
385 property eAlive
: Boolean read FAlive write FAlive
;
386 property eFlag
: Byte read FFlag
;
387 property eTeam
: Byte read FTeam write FTeam
;
388 property eDirection
: TDirection read FDirection
;
389 property eGameX
: Integer read FObj
.X write FObj
.X
;
390 property eGameY
: Integer read FObj
.Y write FObj
.Y
;
391 property eGameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
392 property eGameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
393 property eGameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
394 property eGameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
395 property eIncCam
: Integer read FIncCam write FIncCam
;
396 property eUID
: Word read FUID
;
397 property eJustTeleported
: Boolean read FJustTeleported
;
398 property eNetTime
: LongWord read FNetTime
;
400 // set this before assigning something to `eDamage`
401 property eDamageType
: Integer read mEDamageType write mEDamageType
;
402 property eDamage
: Integer write doDamage
;
413 WeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
414 CloseWeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
415 //SafeWeaponPrior: Array [WP_FIRST..WP_LAST] of Byte;
418 procedure save (st
: TStream
);
419 procedure load (st
: TStream
);
427 TBot
= class(TPlayer
)
429 FSelectedWeapon
: Byte;
432 FAIFlags
: Array of TAIFlag
;
433 FDifficult
: TDifficult
;
435 function GetRnd(a
: Byte): Boolean;
436 function GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
437 function RunDirection(): TDirection
;
438 function FullInStep(XInc
, YInc
: Integer): Boolean;
439 //function NeedItem(Item: Byte): Byte;
440 procedure SelectWeapon(Dist
: Integer);
441 procedure SetAIFlag(aName
, fValue
: String20
);
442 function GetAIFlag(aName
: String20
): String20
;
443 procedure RemoveAIFlag(aName
: String20
);
444 function Healthy(): Byte;
445 procedure UpdateMove();
446 procedure UpdateCombat();
447 function KeyPressed(Key
: Word): Boolean;
448 procedure ReleaseKey(Key
: Byte);
449 function TargetOnScreen(TX
, TY
: Integer): Boolean;
450 procedure OnDamage(Angle
: SmallInt); override;
453 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); override;
454 constructor Create(); override;
455 destructor Destroy(); override;
456 procedure Draw(); override;
457 function PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean; override;
458 function Heal(value
: Word; Soft
: Boolean): Boolean; override;
459 procedure Update(); override;
460 procedure SaveState (st
: TStream
); override;
461 procedure LoadState (st
: TStream
); override;
473 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
474 procedure moveBy (dx
, dy
: Integer); inline;
476 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
490 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
491 procedure moveBy (dx
, dy
: Integer); inline;
493 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
496 TCorpse
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
504 FAnimation
: TAnimation
;
505 FAnimationMask
: TAnimation
;
508 constructor Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
509 destructor Destroy(); override;
510 procedure Damage(Value
: Word; vx
, vy
: Integer);
513 procedure SaveState (st
: TStream
);
514 procedure LoadState (st
: TStream
);
516 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
517 procedure moveBy (dx
, dy
: Integer); inline;
519 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
521 function ObjPtr (): PObj
; inline;
523 property Obj
: TObj read FObj
; // copies object
524 property State
: Byte read FState
;
525 property Mess
: Boolean read FMess
;
528 TTeamStat
= Array [TEAM_RED
..TEAM_BLUE
] of
534 gPlayers
: Array of TPlayer
;
535 gCorpses
: Array of TCorpse
;
536 gGibs
: Array of TGib
;
537 gShells
: Array of TShell
;
538 gTeamStat
: TTeamStat
;
539 gFly
: Boolean = False;
540 gAimLine
: Boolean = False;
541 gChatBubble
: Byte = 0;
545 MAX_RUNVEL
: Integer = 8;
546 VEL_JUMP
: Integer = 10;
547 SHELL_TIMEOUT
: Cardinal = 60000;
549 function Lerp(X
, Y
, Factor
: Integer): Integer;
551 procedure g_Gibs_SetMax(Count
: Word);
552 function g_Gibs_GetMax(): Word;
553 procedure g_Corpses_SetMax(Count
: Word);
554 function g_Corpses_GetMax(): Word;
555 procedure g_Shells_SetMax(Count
: Word);
556 function g_Shells_GetMax(): Word;
558 procedure g_Player_Init();
559 procedure g_Player_Free();
560 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
561 function g_Player_CreateFromState (st
: TStream
): Word;
562 procedure g_Player_Remove(UID
: Word);
563 procedure g_Player_ResetTeams();
564 procedure g_Player_UpdateAll();
565 procedure g_Player_DrawAll();
566 procedure g_Player_DrawDebug(p
: TPlayer
);
567 procedure g_Player_DrawHealth();
568 procedure g_Player_RememberAll();
569 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
570 function g_Player_Get(UID
: Word): TPlayer
;
571 function g_Player_GetCount(): Byte;
572 function g_Player_GetStats(): TPlayerStatArray
;
573 function g_Player_ValidName(Name
: String): Boolean;
574 procedure g_Player_CreateCorpse(Player
: TPlayer
);
575 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: String; fColor
: TRGB
);
576 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
577 procedure g_Player_UpdatePhysicalObjects();
578 procedure g_Player_DrawCorpses();
579 procedure g_Player_DrawShells();
580 procedure g_Player_RemoveAllCorpses();
581 procedure g_Player_Corpses_SaveState (st
: TStream
);
582 procedure g_Player_Corpses_LoadState (st
: TStream
);
583 procedure g_Bot_Add(Team
, Difficult
: Byte);
584 procedure g_Bot_AddList(Team
: Byte; lname
: ShortString; num
: Integer = -1);
585 procedure g_Bot_MixNames();
586 procedure g_Bot_RemoveAll();
591 e_log
, g_map
, g_items
, g_console
, g_gfx
, Math
,
592 g_options
, g_triggers
, g_menu
, g_game
, g_grid
,
593 wadreader
, g_main
, g_monsters
, CONFIG
, g_language
,
594 g_net
, g_netmsg
, g_window
, GL
, g_holmes
,
597 const PLR_SAVE_VERSION
= 0;
607 diag_precision
: Byte;
611 w_prior1
: Array [WP_FIRST
..WP_LAST
] of Byte;
612 w_prior2
: Array [WP_FIRST
..WP_LAST
] of Byte;
613 w_prior3
: Array [WP_FIRST
..WP_LAST
] of Byte;
617 TIME_RESPAWN1
= 1500;
618 TIME_RESPAWN2
= 2000;
619 TIME_RESPAWN3
= 3000;
622 JET_MAX
= 540; // ~30 sec
623 PLAYER_SUIT_TIME
= 30000;
624 PLAYER_INVUL_TIME
= 30000;
625 PLAYER_INVIS_TIME
= 35000;
626 FRAG_COMBO_TIME
= 3000;
630 ANGLE_RIGHTDOWN
= -35;
632 ANGLE_LEFTDOWN
= -145;
633 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
634 WEAPONPOINT
: Array [TDirection
] of TDFPoint
= ((X
:16; Y
:32), (X
:47; Y
:32));
637 BOT_UNSAFEDIST
= 128;
638 TEAMCOLOR
: Array [TEAM_RED
..TEAM_BLUE
] of TRGB
= ((R
:255; G
:0; B
:0),
640 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
641 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
642 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
643 DIFFICULT_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
644 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
645 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
646 DIFFICULT_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
647 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
648 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
649 WEAPON_PRIOR1
: Array [WP_FIRST
..WP_LAST
] of Byte =
650 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
651 WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
652 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
653 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
654 WEAPON_PRIOR2
: Array [WP_FIRST
..WP_LAST
] of Byte =
655 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
656 WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
657 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
658 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
659 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
660 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
661 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
662 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
663 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
664 WEAPON_RELOAD
: Array [WP_FIRST
..WP_LAST
] of Byte =
665 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
667 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
668 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
670 BOTNAMES_FILENAME
= 'botnames.txt';
671 BOTLIST_FILENAME
= 'botlist.txt';
675 MaxCorpses
: Word = 20;
676 MaxShells
: Word = 300;
677 CurrentGib
: Integer = 0;
678 CurrentShell
: Integer = 0;
679 BotNames
: Array of String;
680 BotList
: Array of TBotProfile
;
683 function Lerp(X
, Y
, Factor
: Integer): Integer;
685 Result
:= X
+ ((Y
- X
) div Factor
);
688 function SameTeam(UID1
, UID2
: Word): Boolean;
692 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
693 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
695 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
697 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
698 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
700 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
703 procedure g_Gibs_SetMax(Count
: Word);
706 SetLength(gGibs
, Count
);
708 if CurrentGib
>= Count
then
712 function g_Gibs_GetMax(): Word;
717 procedure g_Shells_SetMax(Count
: Word);
720 SetLength(gShells
, Count
);
722 if CurrentShell
>= Count
then
726 function g_Shells_GetMax(): Word;
732 procedure g_Corpses_SetMax(Count
: Word);
735 SetLength(gCorpses
, Count
);
738 function g_Corpses_GetMax(): Word;
740 Result
:= MaxCorpses
;
743 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
753 // Åñòü ëè ìåñòî â gPlayers:
754 if gPlayers
<> nil then
755 for a
:= 0 to High(gPlayers
) do
756 if gPlayers
[a
] = nil then
762 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
765 SetLength(gPlayers
, Length(gPlayers
)+1);
769 // Ñîçäàåì îáúåêò èãðîêà:
771 gPlayers
[a
] := TBot
.Create()
773 gPlayers
[a
] := TPlayer
.Create();
776 gPlayers
[a
].FActualModelName
:= ModelName
;
777 gPlayers
[a
].SetModel(ModelName
);
779 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
780 if gPlayers
[a
].FModel
= nil then
784 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
788 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
789 if Random(2) = 0 then
793 gPlayers
[a
].FPreferredTeam
:= Team
;
795 case gGameSettings
.GameMode
of
796 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
798 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
800 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
803 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
804 gPlayers
[a
].FColor
:= Color
;
805 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
806 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
808 gPlayers
[a
].FModel
.Color
:= Color
;
810 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
811 gPlayers
[a
].FAlive
:= False;
813 Result
:= gPlayers
[a
].FUID
;
816 function g_Player_CreateFromState (st
: TStream
): Word;
823 if (st
= nil) then exit
; //???
826 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
827 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
830 Bot
:= utils
.readBool(st
);
835 // Åñòü ëè ìåñòî â gPlayers:
836 for a
:= 0 to High(gPlayers
) do if (gPlayers
[a
] = nil) then begin ok
:= true; break
; end;
838 // Íåò ìåñòà - ðàñøèðÿåì gPlayers
841 SetLength(gPlayers
, Length(gPlayers
)+1);
845 // Ñîçäàåì îáúåêò èãðîêà
847 gPlayers
[a
] := TBot
.Create()
849 gPlayers
[a
] := TPlayer
.Create();
850 gPlayers
[a
].FIamBot
:= Bot
;
851 gPlayers
[a
].FPhysics
:= True;
854 gPlayers
[a
].FUID
:= utils
.readWord(st
);
856 gPlayers
[a
].FName
:= utils
.readStr(st
);
858 gPlayers
[a
].FTeam
:= utils
.readByte(st
);
859 gPlayers
[a
].FPreferredTeam
:= gPlayers
[a
].FTeam
;
861 gPlayers
[a
].FAlive
:= utils
.readBool(st
);
862 // Èçðàñõîäîâàë ëè âñå æèçíè
863 gPlayers
[a
].FNoRespawn
:= utils
.readBool(st
);
865 b
:= utils
.readByte(st
);
866 if b
= 1 then gPlayers
[a
].FDirection
:= TDirection
.D_LEFT
else gPlayers
[a
].FDirection
:= TDirection
.D_RIGHT
; // b = 2
868 gPlayers
[a
].FHealth
:= utils
.readLongInt(st
);
870 gPlayers
[a
].FLives
:= utils
.readByte(st
);
872 gPlayers
[a
].FArmor
:= utils
.readLongInt(st
);
874 gPlayers
[a
].FAir
:= utils
.readLongInt(st
);
876 gPlayers
[a
].FJetFuel
:= utils
.readLongInt(st
);
878 gPlayers
[a
].FPain
:= utils
.readLongInt(st
);
880 gPlayers
[a
].FKills
:= utils
.readLongInt(st
);
882 gPlayers
[a
].FMonsterKills
:= utils
.readLongInt(st
);
884 gPlayers
[a
].FFrags
:= utils
.readLongInt(st
);
886 gPlayers
[a
].FFragCombo
:= utils
.readByte(st
);
887 // Âðåìÿ ïîñëåäíåãî ôðàãà
888 gPlayers
[a
].FLastFrag
:= utils
.readLongWord(st
);
890 gPlayers
[a
].FDeath
:= utils
.readLongInt(st
);
892 gPlayers
[a
].FFlag
:= utils
.readByte(st
);
894 gPlayers
[a
].FSecrets
:= utils
.readLongInt(st
);
896 gPlayers
[a
].FCurrWeap
:= utils
.readByte(st
);
897 // Ñëåäóþùåå æåëàåìîå îðóæèå
898 gPlayers
[a
].FNextWeap
:= utils
.readWord(st
);
900 gPlayers
[a
].FNextWeapDelay
:= utils
.readByte(st
);
902 gPlayers
[a
].FBFGFireCounter
:= utils
.readSmallInt(st
);
904 gPlayers
[a
].FDamageBuffer
:= utils
.readLongInt(st
);
905 // Ïîñëåäíèé óäàðèâøèé
906 gPlayers
[a
].FLastSpawnerUID
:= utils
.readWord(st
);
907 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
908 gPlayers
[a
].FLastHit
:= utils
.readByte(st
);
910 Obj_LoadState(@gPlayers
[a
].FObj
, st
);
911 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
912 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FAmmo
[i
] := utils
.readWord(st
);
913 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
914 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FMaxAmmo
[i
] := utils
.readWord(st
);
916 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FWeapon
[i
] := utils
.readBool(st
);
917 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
918 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FReloading
[i
] := utils
.readWord(st
);
920 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_ITEM_BACKPACK
);
921 // Íàëè÷èå êðàñíîãî êëþ÷à
922 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_RED
);
923 // Íàëè÷èå çåëåíîãî êëþ÷à
924 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_GREEN
);
925 // Íàëè÷èå ñèíåãî êëþ÷à
926 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_BLUE
);
928 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_BERSERK
);
929 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
930 for i
:= MR_SUIT
to MR_MAX
do gPlayers
[a
].FMegaRulez
[i
] := utils
.readLongWord(st
);
931 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
932 for i
:= T_RESPAWN
to T_FLAGCAP
do gPlayers
[a
].FTime
[i
] := utils
.readLongWord(st
);
935 gPlayers
[a
].FActualModelName
:= utils
.readStr(st
);
937 gPlayers
[a
].FColor
.R
:= utils
.readByte(st
);
938 gPlayers
[a
].FColor
.G
:= utils
.readByte(st
);
939 gPlayers
[a
].FColor
.B
:= utils
.readByte(st
);
940 // Îáíîâëÿåì ìîäåëü èãðîêà
941 gPlayers
[a
].SetModel(gPlayers
[a
].FActualModelName
);
943 // Íåò ìîäåëè - ñîçäàíèå íåâîçìîæíî
944 if (gPlayers
[a
].FModel
= nil) then
948 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [gPlayers
[a
].FActualModelName
]));
952 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû
953 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
954 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
956 gPlayers
[a
].FModel
.Color
:= gPlayers
[a
].FColor
;
958 result
:= gPlayers
[a
].FUID
;
962 procedure g_Player_ResetTeams();
966 if g_Game_IsClient
then
968 if gPlayers
= nil then
970 for a
:= Low(gPlayers
) to High(gPlayers
) do
971 if gPlayers
[a
] <> nil then
972 case gGameSettings
.GameMode
of
974 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
976 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
977 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
978 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
981 gPlayers
[a
].ChangeTeam(TEAM_RED
)
983 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
986 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
990 procedure g_Bot_Add(Team
, Difficult
: Byte);
993 _name
, _model
: String;
996 if not g_Game_IsServer
then Exit
;
998 // Ñïèñîê íàçâàíèé ìîäåëåé:
999 m
:= g_PlayerModel_GetNames();
1004 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1005 Team
:= TEAM_COOP
// COOP
1007 if gGameSettings
.GameMode
= GM_DM
then
1008 Team
:= TEAM_NONE
// DM
1010 if Team
= TEAM_NONE
then // CTF / TDM
1012 // Àâòîáàëàíñ êîìàíä:
1016 for a
:= 0 to High(gPlayers
) do
1017 if gPlayers
[a
] <> nil then
1019 if gPlayers
[a
].Team
= TEAM_RED
then
1022 if gPlayers
[a
].Team
= TEAM_BLUE
then
1032 if Random(2) = 0 then
1038 // Âûáèðàåì áîòó èìÿ:
1040 if BotNames
<> nil then
1041 for a
:= 0 to High(BotNames
) do
1042 if g_Player_ValidName(BotNames
[a
]) then
1044 _name
:= BotNames
[a
];
1048 // Èìåíè íåò, çàäàåì ñëó÷àéíîå:
1051 _name
:= Format('DFBOT%.2d', [Random(100)]);
1052 until g_Player_ValidName(_name
);
1054 // Âûáèðàåì ñëó÷àéíóþ ìîäåëü:
1055 _model
:= m
[Random(Length(m
))];
1058 with g_Player_Get(g_Player_Create(_model
,
1059 _RGB(Min(Random(9)*32, 255),
1060 Min(Random(9)*32, 255),
1061 Min(Random(9)*32, 255)),
1062 Team
, True)) as TBot
do
1067 1: FDifficult
:= DIFFICULT_EASY
;
1068 2: FDifficult
:= DIFFICULT_MEDIUM
;
1069 else FDifficult
:= DIFFICULT_HARD
;
1072 for a
:= WP_FIRST
to WP_LAST
do
1074 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1075 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1076 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1079 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1081 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1082 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1087 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString; num
: Integer = -1);
1090 _name
, _model
: String;
1093 if not g_Game_IsServer
then Exit
;
1095 // Ñïèñîê íàçâàíèé ìîäåëåé:
1096 m
:= g_PlayerModel_GetNames();
1101 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1102 Team
:= TEAM_COOP
// COOP
1104 if gGameSettings
.GameMode
= GM_DM
then
1105 Team
:= TEAM_NONE
// DM
1107 if Team
= TEAM_NONE
then
1108 Team
:= BotList
[num
].team
; // CTF / TDM
1110 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1111 lName
:= AnsiLowerCase(lName
);
1112 if (num
< 0) or (num
> Length(BotList
)-1) then
1114 if (num
= -1) and (lName
<> '') and (BotList
<> nil) then
1115 for a
:= 0 to High(BotList
) do
1116 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1125 _name
:= BotList
[num
].name
;
1126 // Çàíÿòî - âûáèðàåì ñëó÷àéíîå:
1127 if not g_Player_ValidName(_name
) then
1129 _name
:= Format('DFBOT%.2d', [Random(100)]);
1130 until g_Player_ValidName(_name
);
1133 _model
:= BotList
[num
].model
;
1134 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1135 if not InSArray(_model
, m
) then
1136 _model
:= m
[Random(Length(m
))];
1139 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1143 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1144 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1145 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1146 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1147 FDifficult
.Cover
:= BotList
[num
].cover
;
1148 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1150 for a
:= WP_FIRST
to WP_LAST
do
1152 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1153 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1154 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1157 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1159 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1163 procedure g_Bot_RemoveAll();
1167 if not g_Game_IsServer
then Exit
;
1168 if gPlayers
= nil then Exit
;
1170 for a
:= 0 to High(gPlayers
) do
1171 if gPlayers
[a
] <> nil then
1172 if gPlayers
[a
] is TBot
then
1174 gPlayers
[a
].Lives
:= 0;
1175 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1176 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1177 g_Player_Remove(gPlayers
[a
].FUID
);
1183 procedure g_Bot_MixNames();
1188 if BotNames
<> nil then
1189 for a
:= 0 to High(BotNames
) do
1191 b
:= Random(Length(BotNames
));
1193 Botnames
[a
] := BotNames
[b
];
1198 procedure g_Player_Remove(UID
: Word);
1202 if gPlayers
= nil then Exit
;
1204 if g_Game_IsServer
and g_Game_IsNet
then
1205 MH_SEND_PlayerDelete(UID
);
1207 for i
:= 0 to High(gPlayers
) do
1208 if gPlayers
[i
] <> nil then
1209 if gPlayers
[i
].FUID
= UID
then
1211 if gPlayers
[i
] is TPlayer
then
1212 TPlayer(gPlayers
[i
]).Free()
1214 TBot(gPlayers
[i
]).Free();
1220 procedure g_Player_Init();
1230 if not FileExists(DataDir
+ BOTNAMES_FILENAME
) then
1233 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1234 AssignFile(F
, DataDir
+ BOTNAMES_FILENAME
);
1245 SetLength(BotNames
, Length(BotNames
)+1);
1246 BotNames
[High(BotNames
)] := s
;
1254 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1255 config
:= TConfig
.CreateFile(DataDir
+ BOTLIST_FILENAME
);
1259 while config
.SectionExists(IntToStr(a
)) do
1261 SetLength(BotList
, Length(BotList
)+1);
1263 with BotList
[High(BotList
)] do
1266 name
:= config
.ReadStr(IntToStr(a
), 'name', '');
1268 model
:= config
.ReadStr(IntToStr(a
), 'model', '');
1270 if config
.ReadStr(IntToStr(a
), 'team', 'red') = 'red' then
1275 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1276 color
.R
:= StrToIntDef(sa
[0], 0);
1277 color
.G
:= StrToIntDef(sa
[1], 0);
1278 color
.B
:= StrToIntDef(sa
[2], 0);
1279 // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì:
1280 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0);
1281 // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó:
1282 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0);
1283 // Òî÷íîñòü ñòðåëüáû ïîä óãëîì:
1284 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0);
1285 // Òî÷íîñòü ñòðåëüáû â ïîëåòå:
1286 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0);
1287 // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ:
1288 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0);
1289 // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà:
1290 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0);
1291 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ:
1292 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1293 if Length(sa
) = 10 then
1295 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1296 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ:
1297 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1298 if Length(sa
) = 10 then
1300 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1302 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1303 if Length(sa) = 10 then
1305 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1314 procedure g_Player_Free();
1318 if gPlayers
<> nil then
1320 for i
:= 0 to High(gPlayers
) do
1321 if gPlayers
[i
] <> nil then
1323 if gPlayers
[i
] is TPlayer
then
1324 TPlayer(gPlayers
[i
]).Free()
1326 TBot(gPlayers
[i
]).Free();
1337 procedure g_Player_UpdateAll();
1341 if gPlayers
= nil then Exit
;
1343 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1344 for i
:= 0 to High(gPlayers
) do
1346 if gPlayers
[i
] <> nil then
1348 if gPlayers
[i
] is TPlayer
then
1350 gPlayers
[i
].Update();
1351 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1355 // bot updates weapons in `UpdateCombat()`
1356 TBot(gPlayers
[i
]).Update();
1360 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1363 procedure g_Player_DrawAll();
1367 if gPlayers
= nil then Exit
;
1369 for i
:= 0 to High(gPlayers
) do
1370 if gPlayers
[i
] <> nil then
1371 if gPlayers
[i
] is TPlayer
then gPlayers
[i
].Draw()
1372 else TBot(gPlayers
[i
]).Draw();
1375 procedure g_Player_DrawDebug(p
: TPlayer
);
1379 if p
= nil then Exit
;
1380 if (@p
.FObj
) = nil then Exit
;
1382 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1384 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p
.FObj
.X
), gStdFont
);
1385 e_TextureFontPrint(0, fH
, 'Pos Y: ' + IntToStr(p
.FObj
.Y
), gStdFont
);
1386 e_TextureFontPrint(0, fH
* 2, 'Vel X: ' + IntToStr(p
.FObj
.Vel
.X
), gStdFont
);
1387 e_TextureFontPrint(0, fH
* 3, 'Vel Y: ' + IntToStr(p
.FObj
.Vel
.Y
), gStdFont
);
1388 e_TextureFontPrint(0, fH
* 4, 'Acc X: ' + IntToStr(p
.FObj
.Accel
.X
), gStdFont
);
1389 e_TextureFontPrint(0, fH
* 5, 'Acc Y: ' + IntToStr(p
.FObj
.Accel
.Y
), gStdFont
);
1392 procedure g_Player_DrawHealth();
1397 if gPlayers
= nil then Exit
;
1398 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1400 for i
:= 0 to High(gPlayers
) do
1401 if gPlayers
[i
] <> nil then
1403 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1404 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
* 2,
1405 IntToStr(gPlayers
[i
].FHealth
), gStdFont
);
1406 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1407 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
,
1408 IntToStr(gPlayers
[i
].FArmor
), gStdFont
);
1412 function g_Player_Get(UID
: Word): TPlayer
;
1418 if gPlayers
= nil then
1421 for a
:= 0 to High(gPlayers
) do
1422 if gPlayers
[a
] <> nil then
1423 if gPlayers
[a
].FUID
= UID
then
1425 Result
:= gPlayers
[a
];
1430 function g_Player_GetCount(): Byte;
1436 if gPlayers
= nil then
1439 for a
:= 0 to High(gPlayers
) do
1440 if gPlayers
[a
] <> nil then
1441 Result
:= Result
+ 1;
1444 function g_Player_GetStats(): TPlayerStatArray
;
1450 if gPlayers
= nil then Exit
;
1452 for a
:= 0 to High(gPlayers
) do
1453 if gPlayers
[a
] <> nil then
1455 SetLength(Result
, Length(Result
)+1);
1456 with Result
[High(Result
)] do
1458 Ping
:= gPlayers
[a
].FPing
;
1459 Loss
:= gPlayers
[a
].FLoss
;
1460 Name
:= gPlayers
[a
].FName
;
1461 Team
:= gPlayers
[a
].FTeam
;
1462 Frags
:= gPlayers
[a
].FFrags
;
1463 Deaths
:= gPlayers
[a
].FDeath
;
1464 Kills
:= gPlayers
[a
].FKills
;
1465 Color
:= gPlayers
[a
].FModel
.Color
;
1466 Lives
:= gPlayers
[a
].FLives
;
1467 Spectator
:= gPlayers
[a
].FSpectator
;
1472 procedure g_Player_RememberAll
;
1476 for i
:= Low(gPlayers
) to High(gPlayers
) do
1477 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
then
1478 gPlayers
[i
].RememberState
;
1481 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1485 gTeamStat
[TEAM_RED
].Goals
:= 0;
1486 gTeamStat
[TEAM_BLUE
].Goals
:= 0;
1488 if gPlayers
<> nil then
1489 for i
:= 0 to High(gPlayers
) do
1490 if gPlayers
[i
] <> nil then
1492 gPlayers
[i
].Reset(Force
);
1494 if gPlayers
[i
] is TPlayer
then
1496 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1497 gPlayers
[i
].Respawn(Silent
)
1499 gPlayers
[i
].Spectate();
1502 TBot(gPlayers
[i
]).Respawn(Silent
);
1506 procedure g_Player_CreateCorpse(Player
: TPlayer
);
1511 if Player
.alive
then
1513 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1518 if (FHealth
>= -50) or (gGibsCount
= 0) then
1520 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1524 for find_id
:= 0 to High(gCorpses
) do
1525 if gCorpses
[find_id
] = nil then
1532 find_id
:= Random(Length(gCorpses
));
1534 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.Name
, FHealth
< -20);
1535 gCorpses
[find_id
].FColor
:= FModel
.Color
;
1536 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1537 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1540 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
,
1541 FObj
.Y
+ PLAYER_RECT_CY
,
1542 FModel
.Name
, FModel
.Color
);
1546 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1550 if (gShells
= nil) or (Length(gShells
) = 0) then
1553 with gShells
[CurrentShell
] do
1559 if T
= SHELL_BULLET
then
1561 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID
) then
1565 Obj
.Rect
.Width
:= 4;
1566 Obj
.Rect
.Height
:= 2;
1570 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID
) then
1574 Obj
.Rect
.Width
:= 7;
1575 Obj
.Rect
.Height
:= 3;
1581 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1582 positionChanged(); // this updates spatial accelerators
1583 RAngle
:= Random(360);
1584 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1586 if CurrentShell
>= High(gShells
) then
1593 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: string; fColor
: TRGB
);
1596 GibsArray
: TGibsArray
;
1598 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1600 if not g_PlayerModel_GetGibs(ModelName
, GibsArray
) then
1603 for a
:= 0 to High(GibsArray
) do
1604 with gGibs
[CurrentGib
] do
1607 ID
:= GibsArray
[a
].ID
;
1608 MaskID
:= GibsArray
[a
].MaskID
;
1611 Obj
.Rect
:= GibsArray
[a
].Rect
;
1612 Obj
.X
:= fX
-GibsArray
[a
].Rect
.X
-(GibsArray
[a
].Rect
.Width
div 2);
1613 Obj
.Y
:= fY
-GibsArray
[a
].Rect
.Y
-(GibsArray
[a
].Rect
.Height
div 2);
1614 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1615 positionChanged(); // this updates spatial accelerators
1616 RAngle
:= Random(360);
1618 if gBloodCount
> 0 then
1619 g_GFX_Blood(fX
, fY
, 16*gBloodCount
+Random(5*gBloodCount
), -16+Random(33), -16+Random(33),
1620 Random(48), Random(48), 150, 0, 0);
1622 if CurrentGib
>= High(gGibs
) then
1629 procedure g_Player_UpdatePhysicalObjects();
1635 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1640 if T
= SHELL_BULLET
then
1641 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1643 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1648 if gGibs
<> nil then
1649 for i
:= 0 to High(gGibs
) do
1650 if gGibs
[i
].alive
then
1654 mr
:= g_Obj_Move(@Obj
, True, False, True);
1655 positionChanged(); // this updates spatial accelerators
1657 if WordBool(mr
and MOVE_FALLOUT
) then
1663 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1664 if WordBool(mr
and MOVE_HITWALL
) then
1665 Obj
.Vel
.X
:= -(vel
.X
div 2);
1666 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1667 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1669 if (Obj
.Vel
.X
>= 0) then
1671 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1672 if RAngle
>= 360 then
1673 RAngle
:= RAngle
mod 360;
1674 end else begin // Counter-clockwise
1675 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1677 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1680 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1681 if gTime
mod (GAME_TICK
*3) = 0 then
1682 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1686 if gCorpses
<> nil then
1687 for i
:= 0 to High(gCorpses
) do
1688 if gCorpses
[i
] <> nil then
1689 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1695 gCorpses
[i
].Update();
1698 if gShells
<> nil then
1699 for i
:= 0 to High(gShells
) do
1700 if gShells
[i
].alive
then
1704 mr
:= g_Obj_Move(@Obj
, True, False, True);
1705 positionChanged(); // this updates spatial accelerators
1707 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1713 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1714 if WordBool(mr
and MOVE_HITWALL
) then
1716 Obj
.Vel
.X
:= -(vel
.X
div 2);
1717 if not WordBool(mr
and MOVE_INWATER
) then
1718 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1720 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1722 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1723 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1724 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1726 if RAngle
mod 90 <> 0 then
1727 RAngle
:= (RAngle
div 90) * 90;
1729 else if not WordBool(mr
and MOVE_INWATER
) then
1730 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1733 if (Obj
.Vel
.X
>= 0) then
1735 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1736 if RAngle
>= 360 then
1737 RAngle
:= RAngle
mod 360;
1738 end else begin // Counter-clockwise
1739 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1741 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1747 procedure TGib
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1749 x
:= Obj
.X
+Obj
.Rect
.X
;
1750 y
:= Obj
.Y
+Obj
.Rect
.Y
;
1751 w
:= Obj
.Rect
.Width
;
1752 h
:= Obj
.Rect
.Height
;
1755 procedure TGib
.moveBy (dx
, dy
: Integer); inline;
1757 if (dx
<> 0) or (dy
<> 0) then
1766 procedure TShell
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1770 w
:= Obj
.Rect
.Width
;
1771 h
:= Obj
.Rect
.Height
;
1774 procedure TShell
.moveBy (dx
, dy
: Integer); inline;
1776 if (dx
<> 0) or (dy
<> 0) then
1785 procedure TGib
.positionChanged (); inline; begin end;
1786 procedure TShell
.positionChanged (); inline; begin end;
1789 procedure g_Player_DrawCorpses();
1794 if gGibs
<> nil then
1795 for i
:= 0 to High(gGibs
) do
1796 if gGibs
[i
].alive
then
1799 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1802 a
.X
:= Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2);
1803 a
.y
:= Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2);
1805 e_DrawAdv(ID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1808 e_DrawAdv(MaskID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1814 if gCorpses
<> nil then
1815 for i
:= 0 to High(gCorpses
) do
1816 if gCorpses
[i
] <> nil then
1820 procedure g_Player_DrawShells();
1825 if gShells
<> nil then
1826 for i
:= 0 to High(gShells
) do
1827 if gShells
[i
].alive
then
1830 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1836 e_DrawAdv(SpriteID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1840 procedure g_Player_RemoveAllCorpses();
1846 SetLength(gGibs
, MaxGibs
);
1847 SetLength(gShells
, MaxGibs
);
1851 if gCorpses
<> nil then
1852 for i
:= 0 to High(gCorpses
) do
1856 SetLength(gCorpses
, MaxCorpses
);
1859 procedure g_Player_Corpses_SaveState (st
: TStream
);
1863 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ
1865 for i
:= 0 to High(gCorpses
) do if (gCorpses
[i
] <> nil) then Inc(count
);
1867 // Êîëè÷åñòâî òðóïîâ
1868 utils
.writeInt(st
, LongInt(count
));
1870 if (count
= 0) then exit
;
1873 for i
:= 0 to High(gCorpses
) do
1875 if gCorpses
[i
] <> nil then
1878 utils
.writeStr(st
, gCorpses
[i
].FModelName
);
1880 utils
.writeBool(st
, gCorpses
[i
].Mess
);
1881 // Ñîõðàíÿåì äàííûå òðóïà:
1882 gCorpses
[i
].SaveState(st
);
1888 procedure g_Player_Corpses_LoadState (st
: TStream
);
1896 g_Player_RemoveAllCorpses();
1898 // Êîëè÷åñòâî òðóïîâ:
1899 count
:= utils
.readLongInt(st
);
1900 if (count
< 0) or (count
> Length(gCorpses
)) then raise XStreamError
.Create('invalid number of corpses');
1902 if (count
= 0) then exit
;
1905 for i
:= 0 to count
-1 do
1908 str
:= utils
.readStr(st
);
1910 b
:= utils
.readBool(st
);
1912 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1913 // Çàãðóæàåì äàííûå òðóïà
1914 gCorpses
[i
].LoadState(st
);
1921 function TPlayer
.isValidViewPort (): Boolean; inline; begin result
:= (viewPortW
> 0) and (viewPortH
> 0); end;
1923 procedure TPlayer
.BFGHit();
1925 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1926 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
1927 if g_Game_IsServer
and g_Game_IsNet
then
1928 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1929 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
1933 procedure TPlayer
.ChangeModel(ModelName
: string);
1935 locModel
: TPlayerModel
;
1937 locModel
:= g_PlayerModel_Get(ModelName
);
1938 if locModel
= nil then Exit
;
1944 procedure TPlayer
.SetModel(ModelName
: string);
1948 m
:= g_PlayerModel_Get(ModelName
);
1951 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
1952 m
:= g_PlayerModel_Get('doomer');
1955 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
1960 if FModel
<> nil then
1965 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1966 FModel
.Color
:= FColor
1968 FModel
.Color
:= TEAMCOLOR
[FTeam
];
1969 FModel
.SetWeapon(FCurrWeap
);
1970 FModel
.SetFlag(FFlag
);
1971 SetDirection(FDirection
);
1974 procedure TPlayer
.SetColor(Color
: TRGB
);
1977 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1978 if FModel
<> nil then FModel
.Color
:= Color
;
1981 procedure TPlayer
.SwitchTeam
;
1983 if g_Game_IsClient
then
1985 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
1987 if gGameOn
and FAlive
then
1988 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
1990 if FTeam
= TEAM_RED
then
1992 ChangeTeam(TEAM_BLUE
);
1993 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
1994 if g_Game_IsNet
then
1995 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
1999 ChangeTeam(TEAM_RED
);
2000 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
2001 if g_Game_IsNet
then
2002 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
2004 FPreferredTeam
:= FTeam
;
2007 procedure TPlayer
.ChangeTeam(Team
: Byte);
2014 TEAM_RED
, TEAM_BLUE
:
2015 FModel
.Color
:= TEAMCOLOR
[Team
];
2017 FModel
.Color
:= FColor
;
2019 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
2020 MH_SEND_PlayerStats(FUID
);
2024 procedure TPlayer.CollideItem();
2029 if gItems = nil then Exit;
2030 if not FAlive then Exit;
2032 for i := 0 to High(gItems) do
2035 if (ItemType <> ITEM_NONE) and alive then
2036 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
2037 PLAYER_RECT.Height, @Obj) then
2039 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
2041 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
2042 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
2043 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
2044 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
2045 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
2047 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
2048 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
2049 (gGameSettings.GameType = GT_SINGLE) and
2050 (g_Player_GetCount() > 1)) then
2051 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
2057 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
2059 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
2060 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
2064 constructor TPlayer
.Create();
2070 mEDamageType
:= HIT_SOME
;
2076 FSawSound
:= TPlayableSound
.Create();
2077 FSawSoundIdle
:= TPlayableSound
.Create();
2078 FSawSoundHit
:= TPlayableSound
.Create();
2079 FSawSoundSelect
:= TPlayableSound
.Create();
2080 FJetSoundFly
:= TPlayableSound
.Create();
2081 FJetSoundOn
:= TPlayableSound
.Create();
2082 FJetSoundOff
:= TPlayableSound
.Create();
2084 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
2085 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
2086 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
2087 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
2088 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
2089 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
2090 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
2092 FSpectatePlayer
:= -1;
2096 FSavedState
.WaitRecall
:= False;
2102 FActualModelName
:= 'doomer';
2105 FObj
.Rect
:= PLAYER_RECT
;
2107 FBFGFireCounter
:= -1;
2108 FJustTeleported
:= False;
2114 procedure TPlayer
.positionChanged (); inline;
2118 procedure TPlayer
.doDamage (v
: Integer);
2120 if (v
<= 0) then exit
;
2121 if (v
> 32767) then v
:= 32767;
2122 Damage(v
, 0, 0, 0, mEDamageType
);
2125 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
2129 if (not g_Game_IsClient
) and (not FAlive
) then
2134 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2135 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2137 if not g_Game_IsClient
then
2140 if t
= HIT_TRAP
then
2142 // Ëîâóøêà óáèâàåò ñðàçó:
2144 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2146 if t
= HIT_SELF
then
2150 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2153 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2154 FMegaRulez
[MR_SUIT
] := 0;
2155 FMegaRulez
[MR_INVUL
] := 0;
2156 FMegaRulez
[MR_INVIS
] := 0;
2160 // Íî îò îñòàëüíîãî ñïàñàåò:
2161 if FMegaRulez
[MR_INVUL
] >= gTime
then
2168 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2169 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2170 (SpawnerUID
= FUID
) or
2171 (not SameTeam(FUID
, SpawnerUID
)) then
2173 FLastSpawnerUID
:= SpawnerUID
;
2175 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2176 if gBloodCount
> 0 then
2178 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2179 if value
div 4 <= c
then
2180 c
:= c
- (value
div 4)
2184 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2188 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2189 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2192 if t
= HIT_WATER
then
2193 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2194 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2199 Inc(FDamageBuffer
, value
);
2203 FPain
:= FPain
+ value
;
2206 if g_Game_IsServer
and g_Game_IsNet
then
2208 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2209 MH_SEND_PlayerStats(FUID
);
2210 MH_SEND_PlayerPos(False, FUID
);
2214 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2217 if g_Game_IsClient
then
2222 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2224 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2227 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2229 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2233 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2234 MH_SEND_PlayerStats(FUID
);
2237 destructor TPlayer
.Destroy();
2239 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2241 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2245 FSawSoundIdle
.Free();
2246 FSawSoundHit
.Free();
2247 FJetSoundFly
.Free();
2249 FJetSoundOff
.Free();
2251 if FPunchAnim
<> nil then
2257 procedure TPlayer
.DrawBubble();
2259 bubX
, bubY
: Integer;
2262 Rw
, Gw
, Bw
: SmallInt;
2265 bubX
:= FObj
.X
+FObj
.Rect
.X
+ IfThen(FDirection
= TDirection
.D_LEFT
, -4, 18);
2266 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 18;
2274 1: // simple textual non-bubble
2276 bubX
:= FObj
.X
+FObj
.Rect
.X
- 11;
2277 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 17;
2278 e_TextureFontPrint(bubX
, bubY
, '[...]', gStdFont
);
2281 2: // advanced pixel-perfect bubble
2283 if FTeam
= TEAM_RED
then
2286 if FTeam
= TEAM_BLUE
then
2289 3: // colored bubble
2291 Rb
:= FModel
.Color
.R
;
2292 Gb
:= FModel
.Color
.G
;
2293 Bb
:= FModel
.Color
.B
;
2294 Rw
:= Min(Rb
* 2 + 64, 255);
2295 Gw
:= Min(Gb
* 2 + 64, 255);
2296 Bw
:= Min(Bb
* 2 + 64, 255);
2297 if (Abs(Rw
- Rb
) < 32)
2298 or (Abs(Gw
- Gb
) < 32)
2299 or (Abs(Bw
- Bb
) < 32) then
2301 Rb
:= Max(Rw
div 2 - 16, 0);
2302 Gb
:= Max(Gw
div 2 - 16, 0);
2303 Bb
:= Max(Bw
div 2 - 16, 0);
2306 4: // custom textured bubble
2308 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID
) then
2309 if FDirection
= TDirection
.D_RIGHT
then
2310 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False)
2312 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False, TMirrorType
.Horizontal
);
2318 e_DrawQuad(bubX
+ 1, bubY
, bubX
+ 18, bubY
+ 13, Rb
, Gb
, Bb
);
2319 e_DrawQuad(bubX
, bubY
+ 1, bubX
+ 19, bubY
+ 12, Rb
, Gb
, Bb
);
2321 e_DrawFillQuad(bubX
+ 1, bubY
+ 1, bubX
+ 18, bubY
+ 12, Rw
, Gw
, Bw
, 0);
2324 Dot
:= IfThen(FDirection
= TDirection
.D_LEFT
, 14, 5);
2325 e_DrawLine(1, bubX
+ Dot
, bubY
+ 14, bubX
+ Dot
, bubY
+ 16, Rb
, Gb
, Bb
);
2326 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
);
2327 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
);
2328 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
);
2329 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
);
2333 e_DrawFillQuad(bubX
+ Dot
, bubY
+ 8, bubX
+ Dot
+ 1, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2334 e_DrawFillQuad(bubX
+ Dot
+ 3, bubY
+ 8, bubX
+ Dot
+ 4, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2335 e_DrawFillQuad(bubX
+ Dot
+ 6, bubY
+ 8, bubX
+ Dot
+ 7, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2338 procedure TPlayer
.Draw();
2343 Mirror
: TMirrorType
;
2347 if Direction
= TDirection
.D_RIGHT
then
2348 Mirror
:= TMirrorType
.None
2350 Mirror
:= TMirrorType
.Horizontal
;
2352 if FPunchAnim
<> nil then
2353 FPunchAnim
.Draw(FObj
.X
+IfThen(Direction
= TDirection
.D_LEFT
, 15-FObj
.Rect
.X
, FObj
.Rect
.X
-15),
2354 FObj
.Y
+FObj
.Rect
.Y
-11, Mirror
);
2356 if (FMegaRulez
[MR_INVUL
] > gTime
) and (gPlayerDrawn
<> Self
) then
2357 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID
) then
2359 e_GetTextureSize(ID
, @w
, @h
);
2360 if FDirection
= TDirection
.D_LEFT
then
2361 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)+4,
2362 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False)
2364 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)-2,
2365 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False);
2368 if FMegaRulez
[MR_INVIS
] > gTime
then
2370 if (gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2371 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
))) then
2373 if (FMegaRulez
[MR_INVIS
] - gTime
) <= 2100 then
2374 dr
:= not Odd((FMegaRulez
[MR_INVIS
] - gTime
) div 300)
2378 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 200)
2380 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2383 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 254);
2386 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2389 if g_debug_Frames
then
2391 e_DrawQuad(FObj
.X
+FObj
.Rect
.X
,
2393 FObj
.X
+FObj
.Rect
.X
+FObj
.Rect
.Width
-1,
2394 FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-1,
2398 if (gChatBubble
> 0) and (FKeys
[KEY_CHAT
].Pressed
) and not FGhost
then
2400 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2401 if gAimLine
and alive
and
2402 ((Self
= gPlayer1
) or (Self
= gPlayer2
)) then
2407 procedure TPlayer
.DrawAim();
2408 procedure drawCast (sz
: Integer; ax0
, ay0
, ax1
, ay1
: Integer);
2412 if isValidViewPort
and (self
= gPlayer1
) then
2414 g_Holmes_plrLaser(ax0
, ay0
, ax1
, ay1
);
2417 e_DrawLine(sz
, ax0
, ay0
, ax1
, ay1
, 255, 0, 0, 96);
2418 if (g_Map_traceToNearestWall(ax0
, ay0
, ax1
, ay1
, @ex
, @ey
) <> nil) then
2420 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 255, 0, 96);
2424 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 0, 255, 96);
2429 wx
, wy
, xx
, yy
: Integer;
2433 wx
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
+ IfThen(FDirection
= TDirection
.D_LEFT
, 7, -7);
2434 wy
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
2443 1: begin // Chainsaw
2450 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2451 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2452 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2453 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2458 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2459 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2460 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2461 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2463 4: begin // Double Shotgun
2466 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2467 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2468 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2469 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2471 5: begin // Chaingun
2474 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2475 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2476 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2477 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2479 6: begin // Rocket Launcher
2482 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 2);
2483 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2484 if angle
= ANGLE_LEFTUP
then Dec(angle
, 2);
2485 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2487 7: begin // Plasmagun
2490 if angle
= ANGLE_RIGHTUP
then Inc(angle
);
2491 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 3);
2492 if angle
= ANGLE_LEFTUP
then Dec(angle
);
2493 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 3);
2498 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 1);
2499 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 2);
2500 if angle
= ANGLE_LEFTUP
then Dec(angle
, 1);
2501 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 2);
2503 9: begin // Super Chaingun
2506 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2507 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2508 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2509 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2512 xx
:= Trunc(Cos(-DegToRad(angle
)) * len
) + wx
;
2513 yy
:= Trunc(Sin(-DegToRad(angle
)) * len
) + wy
;
2514 {$IF DEFINED(D2F_DEBUG)}
2515 drawCast(sz
, wx
, wy
, xx
, yy
);
2517 e_DrawLine(sz
, wx
, wy
, xx
, yy
, 255, 0, 0, 96);
2521 procedure TPlayer
.DrawGUI();
2524 X
, Y
, SY
, a
, p
, m
: Integer;
2528 stat
: TPlayerStatArray
;
2530 X
:= gPlayerScreenSize
.X
;
2531 SY
:= gPlayerScreenSize
.Y
;
2534 if gShowGoals
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2536 if gGameSettings
.GameMode
= GM_CTF
then
2540 if gGameSettings
.GameMode
= GM_CTF
then
2542 s
:= 'TEXTURE_PLAYER_REDFLAG';
2543 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2544 s
:= 'TEXTURE_PLAYER_REDFLAG_S';
2545 if gFlags
[FLAG_RED
].State
= FLAG_STATE_DROPPED
then
2546 s
:= 'TEXTURE_PLAYER_REDFLAG_D';
2547 if g_Texture_Get(s
, ID
) then
2548 e_Draw(ID
, X
-16-32, 240-72-4, 0, True, False);
2551 s
:= IntToStr(gTeamStat
[TEAM_RED
].Goals
);
2552 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2553 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-72-4, s
, TEAMCOLOR
[TEAM_RED
]);
2555 if gGameSettings
.GameMode
= GM_CTF
then
2557 s
:= 'TEXTURE_PLAYER_BLUEFLAG';
2558 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2559 s
:= 'TEXTURE_PLAYER_BLUEFLAG_S';
2560 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_DROPPED
then
2561 s
:= 'TEXTURE_PLAYER_BLUEFLAG_D';
2562 if g_Texture_Get(s
, ID
) then
2563 e_Draw(ID
, X
-16-32, 240-32-4, 0, True, False);
2566 s
:= IntToStr(gTeamStat
[TEAM_BLUE
].Goals
);
2567 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2568 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-32-4, s
, TEAMCOLOR
[TEAM_BLUE
]);
2571 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID
) then
2572 e_DrawFill(ID
, X
, 0, 1, (gPlayerScreenSize
.Y
div 256)+IfThen(gPlayerScreenSize
.Y
mod 256 > 0, 1, 0),
2575 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID
) then
2576 e_Draw(ID
, X
+2, Y
, 0, True, False);
2578 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
2582 s
:= IntToStr(Frags
);
2583 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2584 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, Y
, s
, _RGB(255, 0, 0));
2589 stat
:= g_Player_GetStats();
2594 for a
:= 0 to High(stat
) do
2595 if stat
[a
].Name
<> Name
then
2597 if stat
[a
].Frags
> m
then m
:= stat
[a
].Frags
;
2598 if stat
[a
].Frags
> Frags
then p
:= p
+1;
2602 s
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2603 if Frags
>= m
then s
:= s
+'+' else s
:= s
+'-';
2604 s
:= s
+IntToStr(Abs(Frags
-m
));
2606 e_CharFont_GetSize(gMenuSmallFont
, s
, tw
, th
);
2607 e_CharFont_PrintEx(gMenuSmallFont
, X
-16-tw
, Y
+32, s
, _RGB(255, 0, 0));
2610 if gShowLives
and (gGameSettings
.MaxLives
> 0) then
2612 s
:= IntToStr(Lives
);
2613 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2614 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, SY
-32, s
, _RGB(0, 255, 0));
2618 e_CharFont_GetSize(gMenuSmallFont
, FName
, tw
, th
);
2619 e_CharFont_PrintEx(gMenuSmallFont
, X
+98-(tw
div 2), Y
+8, FName
, _RGB(255, 0, 0));
2621 if R_BERSERK
in FRulez
then
2622 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_BLACK
], X
+37, Y
+45, 0, True, False)
2624 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_LARGE
], X
+37, Y
+45, 0, True, False);
2626 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID
) then
2627 e_Draw(ID
, X
+36, Y
+77, 0, True, False);
2629 s
:= IntToStr(IfThen(FHealth
> 0, FHealth
, 0));
2630 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2631 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+40, s
, _RGB(255, 0, 0));
2633 s
:= IntToStr(FArmor
);
2634 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2635 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+68, s
, _RGB(255, 0, 0));
2637 s
:= IntToStr(GetAmmoByWeapon(FCurrWeap
));
2643 ID
:= gItemsTexturesID
[ITEM_WEAPON_KASTET
];
2648 ID
:= gItemsTexturesID
[ITEM_WEAPON_SAW
];
2650 WEAPON_PISTOL
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PISTOL
];
2651 WEAPON_CHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
];
2652 WEAPON_SHOTGUN1
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
];
2653 WEAPON_SHOTGUN2
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
];
2654 WEAPON_SUPERPULEMET
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SUPERPULEMET
];
2655 WEAPON_ROCKETLAUNCHER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
];
2656 WEAPON_PLASMA
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PLASMA
];
2657 WEAPON_BFG
: ID
:= gItemsTexturesID
[ITEM_WEAPON_BFG
];
2658 WEAPON_FLAMETHROWER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_FLAMETHROWER
];
2661 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2662 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+158, s
, _RGB(255, 0, 0));
2663 e_Draw(ID
, X
+20, Y
+160, 0, True, False);
2665 if R_KEY_RED
in FRulez
then
2666 e_Draw(gItemsTexturesID
[ITEM_KEY_RED
], X
+78, Y
+214, 0, True, False);
2668 if R_KEY_GREEN
in FRulez
then
2669 e_Draw(gItemsTexturesID
[ITEM_KEY_GREEN
], X
+95, Y
+214, 0, True, False);
2671 if R_KEY_BLUE
in FRulez
then
2672 e_Draw(gItemsTexturesID
[ITEM_KEY_BLUE
], X
+112, Y
+214, 0, True, False);
2674 if FJetFuel
> 0 then
2676 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2677 e_Draw(ID
, X
+2, Y
+116, 0, True, False);
2678 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID
) then
2679 e_Draw(ID
, X
+2, Y
+126, 0, True, False);
2680 e_DrawLine(4, X
+16, Y
+122, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+122, 0, 0, 196);
2681 e_DrawLine(4, X
+16, Y
+132, X
+16+Trunc(168*FJetFuel
/JET_MAX
), Y
+132, 208, 0, 0);
2685 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2686 e_Draw(ID
, X
+2, Y
+124, 0, True, False);
2687 e_DrawLine(4, X
+16, Y
+130, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+130, 0, 0, 196);
2690 if gShowPing
and g_Game_IsClient
then
2692 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
2693 e_TextureFontPrint(X
+ 4, Y
+ 242, s
, gStdFont
);
2699 e_TextureFontPrint(X
+ 4, Y
+ 242, _lc
[I_PLAYER_SPECT
], gStdFont
);
2700 e_TextureFontPrint(X
+ 4, Y
+ 258, _lc
[I_PLAYER_SPECT2
], gStdFont
);
2701 e_TextureFontPrint(X
+ 4, Y
+ 274, _lc
[I_PLAYER_SPECT1
], gStdFont
);
2704 e_TextureFontGetSize(gStdFont
, cw
, ch
);
2705 s
:= _lc
[I_PLAYER_SPECT4
];
2706 e_TextureFontPrintEx(gScreenWidth
div 2 - cw
*(Length(s
) div 2),
2707 gScreenHeight
-4-ch
, s
, gStdFont
, 255, 255, 255, 1, True);
2708 e_TextureFontPrint(X
+ 4, Y
+ 290, _lc
[I_PLAYER_SPECT1S
], gStdFont
);
2714 procedure TPlayer
.DrawRulez();
2718 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2719 if FMegaRulez
[MR_INVUL
] >= gTime
then
2721 if (FMegaRulez
[MR_INVUL
]-gTime
) <= 2100 then
2722 dr
:= not Odd((FMegaRulez
[MR_INVUL
]-gTime
) div 300)
2727 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2728 191, 191, 191, 0, TBlending
.Invert
);
2731 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2732 if FMegaRulez
[MR_SUIT
] >= gTime
then
2734 if (FMegaRulez
[MR_SUIT
]-gTime
) <= 2100 then
2735 dr
:= not Odd((FMegaRulez
[MR_SUIT
]-gTime
) div 300)
2740 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2741 0, 96, 0, 200, TBlending
.None
);
2744 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2745 if (FBerserk
>= 0) and (LongWord(FBerserk
) >= gTime
) and (gFlash
= 2) then
2747 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2748 255, 0, 0, 200, TBlending
.None
);
2752 procedure TPlayer
.DrawPain();
2756 if FPain
= 0 then Exit
;
2760 if a
< 15 then h
:= 0
2761 else if a
< 35 then h
:= 1
2762 else if a
< 55 then h
:= 2
2763 else if a
< 75 then h
:= 3
2764 else if a
< 95 then h
:= 4
2767 //if a > 255 then a := 255;
2769 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 255, 0, 0, 255-h
*50);
2770 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2773 procedure TPlayer
.DrawPickup();
2777 if FPickup
= 0 then Exit
;
2781 if a
< 15 then h
:= 1
2782 else if a
< 35 then h
:= 2
2783 else if a
< 55 then h
:= 3
2784 else if a
< 75 then h
:= 4
2787 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 150, 200, 150, 255-h
*50);
2790 procedure TPlayer
.DoPunch();
2794 if FPunchAnim
= nil then begin
2795 g_Frames_Get(id
, 'FRAMES_PUNCH');
2796 FPunchAnim
:= TAnimation
.Create(id
, False, 1);
2801 procedure TPlayer
.Fire();
2803 f
, DidFire
: Boolean;
2804 wx
, wy
, xd
, yd
: Integer;
2807 if g_Game_IsClient
then Exit
;
2808 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
2809 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
2817 if FReloading
[FCurrWeap
] <> 0 then Exit
;
2822 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
2823 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
2824 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
2825 yd
:= wy
+firediry();
2830 if R_BERSERK
in FRulez
then
2832 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2833 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
2834 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
2837 locobj
.rect
.Width
:= 39;
2838 locobj
.rect
.Height
:= 52;
2839 locobj
.Vel
.X
:= (xd
-wx
) div 2;
2840 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
2841 locobj
.Accel
.X
:= xd
-wx
;
2842 locobj
.Accel
.y
:= yd
-wy
;
2846 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
2847 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
2849 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
2851 if (gFlash
= 1) and (FPain
< 50) then FPain
:= min(FPain
+ 25, 50);
2855 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
2859 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2864 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
2865 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
2867 FSawSoundSelect
.Stop();
2869 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
2871 else if not FSawSoundHit
.IsPlaying() then
2873 FSawSoundSelect
.Stop();
2874 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
2877 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2883 if FAmmo
[A_BULLETS
] > 0 then
2885 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
2886 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2887 Dec(FAmmo
[A_BULLETS
]);
2888 FFireAngle
:= FAngle
;
2891 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2892 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2896 if FAmmo
[A_SHELLS
] > 0 then
2898 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2899 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
2900 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2901 Dec(FAmmo
[A_SHELLS
]);
2902 FFireAngle
:= FAngle
;
2906 FShellType
:= SHELL_SHELL
;
2910 if FAmmo
[A_SHELLS
] >= 2 then
2912 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
2913 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2914 Dec(FAmmo
[A_SHELLS
], 2);
2915 FFireAngle
:= FAngle
;
2919 FShellType
:= SHELL_DBLSHELL
;
2923 if FAmmo
[A_BULLETS
] > 0 then
2925 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
2926 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
2927 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2928 Dec(FAmmo
[A_BULLETS
]);
2929 FFireAngle
:= FAngle
;
2932 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2933 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2936 WEAPON_ROCKETLAUNCHER
:
2937 if FAmmo
[A_ROCKETS
] > 0 then
2939 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
2940 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2941 Dec(FAmmo
[A_ROCKETS
]);
2942 FFireAngle
:= FAngle
;
2948 if FAmmo
[A_CELLS
] > 0 then
2950 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
2951 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2952 Dec(FAmmo
[A_CELLS
]);
2953 FFireAngle
:= FAngle
;
2959 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
2961 FBFGFireCounter
:= 17;
2962 if not FNoReload
then
2963 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
2964 Dec(FAmmo
[A_CELLS
], 40);
2968 WEAPON_SUPERPULEMET
:
2969 if FAmmo
[A_SHELLS
] > 0 then
2971 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2972 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
2973 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2974 Dec(FAmmo
[A_SHELLS
]);
2975 FFireAngle
:= FAngle
;
2978 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2979 GameVelX
, GameVelY
-2, SHELL_SHELL
);
2982 WEAPON_FLAMETHROWER
:
2983 if FAmmo
[A_FUEL
] > 0 then
2985 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
2986 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2988 FFireAngle
:= FAngle
;
2994 if g_Game_IsNet
then
2998 if FCurrWeap
<> WEAPON_BFG
then
2999 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
3001 if not FNoReload
then
3002 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
3005 MH_SEND_PlayerStats(FUID
);
3010 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
3011 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
3012 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
3015 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
3018 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
3019 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
3020 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
3021 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
3022 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
3027 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
3029 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
3030 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
3031 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
3034 procedure TPlayer
.JetpackOn
;
3038 FJetSoundOn
.SetPosition(0);
3039 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3043 procedure TPlayer
.JetpackOff
;
3047 FJetSoundOff
.SetPosition(0);
3048 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3051 procedure TPlayer
.CatchFire(Attacker
: Word);
3054 FFireAttacker
:= Attacker
;
3055 if g_Game_IsNet
and g_Game_IsServer
then
3056 MH_SEND_PlayerStats(FUID
);
3059 procedure TPlayer
.Jump();
3061 if gFly
or FJetpack
then
3063 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
3064 if FObj
.Vel
.Y
> -VEL_FLY
then
3065 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
3068 if FJetFuel
> 0 then
3070 if (FJetFuel
< 1) and g_Game_IsServer
then
3074 if g_Game_IsNet
then
3075 MH_SEND_PlayerStats(FUID
);
3081 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
3083 FCanJetpack
:= False;
3085 // Ïðûãàåì èëè âñïëûâàåì:
3086 if (CollideLevel(0, 1) or
3087 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
3088 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
3089 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
3091 FObj
.Vel
.Y
:= -VEL_JUMP
;
3092 FCanJetpack
:= False;
3096 if BodyInLiquid(0, 0) then
3097 FObj
.Vel
.Y
:= -VEL_SW
3098 else if (FJetFuel
> 0) and FCanJetpack
and
3099 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
3103 if g_Game_IsNet
then
3104 MH_SEND_PlayerStats(FUID
);
3109 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
3111 a
, i
, k
, ab
, ar
: Byte;
3115 srv
, netsrv
: Boolean;
3121 procedure PushItem(t
: Byte);
3125 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
3126 it
:= g_Items_ByIdx(id
);
3127 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
3129 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
3130 (FObj
.Vel
.Y
div 2)-Random(9));
3131 it
.positionChanged(); // this updates spatial accelerators
3135 if KillType
= K_HARDKILL
then // -5..+5; -5..0
3137 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
3138 (FObj
.Vel
.Y
div 2)-Random(6));
3140 else // -3..+3; -3..0
3142 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
3143 (FObj
.Vel
.Y
div 2)-Random(4));
3145 it
.positionChanged(); // this updates spatial accelerators
3148 if g_Game_IsNet
and g_Game_IsServer
then
3149 MH_SEND_ItemSpawn(True, id
);
3153 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
3154 Srv
:= g_Game_IsServer
;
3155 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
3156 if Srv
then FDeath
:= FDeath
+ 1;
3161 if not FPhysics
then
3167 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3169 if FLives
> 0 then FLives
:= FLives
- 1;
3170 if FLives
= 0 then FNoRespawn
:= True;
3173 // Íîìåð òèïà ñìåðòè:
3176 K_SIMPLEKILL
: a
:= 1;
3178 K_EXTRAHARDKILL
: a
:= 3;
3183 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
3185 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
3192 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
3194 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
3195 K_EXTRAHARDKILL
, K_FALLKILL
:
3196 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
3199 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3203 K_HARDKILL
, K_EXTRAHARDKILL
:
3207 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3208 if (KillType
<> K_FALLKILL
) and (Srv
) then
3209 g_Monsters_killedp();
3211 if SpawnerUID
= FUID
then
3213 if Srv
and (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3218 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3221 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
3222 begin // Óáèò äðóãèì èãðîêîì
3223 KP
:= g_Player_Get(SpawnerUID
);
3224 if (KP
<> nil) and Srv
then
3226 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3227 if SameTeam(FUID
, SpawnerUID
) then
3237 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3238 Inc(gTeamStat
[KP
.Team
].Goals
,
3239 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3241 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3244 plr
:= g_Player_Get(SpawnerUID
);
3252 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3256 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3260 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3265 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3266 begin // Óáèò ìîíñòðîì
3267 mon
:= g_Monsters_ByUID(SpawnerUID
);
3271 s
:= g_Mons_GetKilledByTypeId(mon
.MonsterType
);
3275 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3279 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3283 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3288 else // Îñîáûå òèïû ñìåðòè
3291 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3292 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3293 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3294 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3295 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3296 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3302 for a
:= WP_FIRST
to WP_LAST
do
3306 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3307 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3308 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3309 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3310 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3311 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3312 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3313 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
3314 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
3323 if R_ITEM_BACKPACK
in FRulez
then
3324 PushItem(ITEM_AMMO_BACKPACK
);
3326 // Âûáðîñ ðàêåòíîãî ðàíöà:
3327 if FJetFuel
> 0 then
3328 PushItem(ITEM_JETPACK
);
3331 if not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
3333 if R_KEY_RED
in FRulez
then
3334 PushItem(ITEM_KEY_RED
);
3336 if R_KEY_GREEN
in FRulez
then
3337 PushItem(ITEM_KEY_GREEN
);
3339 if R_KEY_BLUE
in FRulez
then
3340 PushItem(ITEM_KEY_BLUE
);
3347 g_Player_CreateCorpse(Self
);
3349 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3350 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3356 for i
:= Low(gPlayers
) to High(gPlayers
) do
3358 if gPlayers
[i
] = nil then continue
;
3359 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3362 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3363 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3368 OldLR
:= gLMSRespawn
;
3369 if (gGameSettings
.GameMode
= GM_COOP
) then
3373 // everyone is dead, restart the map
3374 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3376 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3377 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3378 gLMSRespawnTime
:= gTime
+ 5000;
3380 else if (a
= 1) then
3382 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3383 if (gPlayers
[k
] = gPlayer1
) or
3384 (gPlayers
[k
] = gPlayer2
) then
3385 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3386 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3387 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3390 else if (gGameSettings
.GameMode
= GM_TDM
) then
3392 if (ab
= 0) and (ar
<> 0) then
3395 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3397 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3398 Inc(gTeamStat
[TEAM_RED
].Goals
);
3399 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3400 gLMSRespawnTime
:= gTime
+ 5000;
3402 else if (ar
= 0) and (ab
<> 0) then
3405 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3407 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3408 Inc(gTeamStat
[TEAM_BLUE
].Goals
);
3409 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3410 gLMSRespawnTime
:= gTime
+ 5000;
3412 else if (ar
= 0) and (ab
= 0) then
3415 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3417 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3418 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3419 gLMSRespawnTime
:= gTime
+ 5000;
3422 else if (gGameSettings
.GameMode
= GM_DM
) then
3426 if gPlayers
[k
] <> nil then
3429 // survivor is the winner
3430 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3432 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3435 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3436 gLMSRespawnTime
:= gTime
+ 5000;
3438 else if (a
= 0) then
3440 // everyone is dead, restart the map
3441 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3443 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3444 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3445 gLMSRespawnTime
:= gTime
+ 5000;
3448 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3450 if NetMode
= NET_SERVER
then
3451 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
3453 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3459 MH_SEND_PlayerStats(FUID
);
3460 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3461 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3464 if srv
and FNoRespawn
then Spectate(True);
3465 FWantsInGame
:= True;
3468 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3470 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3471 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3474 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3476 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3477 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3480 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3482 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3483 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3484 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3486 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3487 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3488 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3492 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3494 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3495 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3496 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3500 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3502 if g_Game_IsClient
then Exit
;
3503 if Weapon
> High(FWeapon
) then Exit
;
3504 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3507 procedure TPlayer
.resetWeaponQueue ();
3510 FNextWeapDelay
:= 0;
3513 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3517 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3518 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
: result
:= (FAmmo
[A_SHELLS
] > 0);
3519 WEAPON_PISTOL
, WEAPON_CHAINGUN
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_BULLETS
] > 0);
3520 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3521 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3522 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3523 else result
:= (weapon
< length(FWeapon
));
3527 // return 255 for "no switch"
3528 function TPlayer
.getNextWeaponIndex (): Byte;
3531 wantThisWeapon
: array[0..64] of Boolean;
3532 wwc
: Integer = 0; //HACK!
3535 result
:= 255; // default result: "no switch"
3536 // had weapon cycling on previous frame? remove that flag
3537 if (FNextWeap
and $2000) <> 0 then
3539 FNextWeap
:= FNextWeap
and $1FFF;
3540 FNextWeapDelay
:= 0;
3542 // cycling has priority
3543 if (FNextWeap
and $C000) <> 0 then
3545 if (FNextWeap
and $8000) <> 0 then
3549 FNextWeap
:= FNextWeap
or $2000; // we need this
3550 if FNextWeapDelay
> 0 then
3551 exit
; // cooldown time
3553 for i
:= 0 to High(FWeapon
) do
3555 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3556 if FWeapon
[cwi
] then
3558 //e_WriteLog(Format(' SWITCH: cur=%d; new=%d', [FCurrWeap, cwi]), MSG_WARNING);
3559 result
:= Byte(cwi
);
3560 FNextWeapDelay
:= 10;
3568 for i
:= 0 to High(wantThisWeapon
) do
3569 wantThisWeapon
[i
] := false;
3570 for i
:= 0 to High(FWeapon
) do
3571 if (FNextWeap
and (1 shl i
)) <> 0 then
3573 wantThisWeapon
[i
] := true;
3576 // exclude currently selected weapon from the set
3577 wantThisWeapon
[FCurrWeap
] := false;
3578 // slow down alterations a little
3581 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3582 // more than one weapon requested, assume "alteration" and check alteration delay
3583 if FNextWeapDelay
> 0 then
3589 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3590 // but clear all counters if no weapon should be switched
3596 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3597 // try weapons in descending order
3598 for i
:= High(FWeapon
) downto 0 do
3600 if wantThisWeapon
[i
] and FWeapon
[i
] and ((wwc
= 1) or hasAmmoForWeapon(i
)) then
3605 FNextWeapDelay
:= 10; // anyway, 'cause why not
3609 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3613 procedure TPlayer
.RealizeCurrentWeapon();
3614 function switchAllowed (): Boolean;
3619 if FBFGFireCounter
<> -1 then
3621 if FTime
[T_SWITCH
] > gTime
then
3623 for i
:= WP_FIRST
to WP_LAST
do
3624 if FReloading
[i
] > 0 then
3632 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3633 //FNextWeap := FNextWeap and $1FFF;
3634 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
3636 if not switchAllowed
then
3638 //HACK for weapon cycling
3639 if (FNextWeap
and $7000) <> 0 then FNextWeap
:= 0;
3643 nw
:= getNextWeaponIndex();
3644 if nw
= 255 then exit
; // don't reset anything here
3645 if nw
> High(FWeapon
) then
3647 // don't forget to reset queue here!
3648 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
3656 FTime
[T_SWITCH
] := gTime
+156;
3657 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3658 FModel
.SetWeapon(FCurrWeap
);
3659 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3663 procedure TPlayer
.NextWeapon();
3665 if g_Game_IsClient
then Exit
;
3669 procedure TPlayer
.PrevWeapon();
3671 if g_Game_IsClient
then Exit
;
3675 procedure TPlayer
.SetWeapon(W
: Byte);
3677 if FCurrWeap
<> W
then
3678 if W
= WEAPON_SAW
then
3679 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3682 FModel
.SetWeapon(CurrWeap
);
3686 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
3688 function allowBerserkSwitching (): Boolean;
3690 if (FBFGFireCounter
<> -1) then begin result
:= false; exit
; end;
3692 if gBerserkAutoswitch
then exit
;
3693 if not conIsCheatsEnabled
then exit
;
3701 if g_Game_IsClient
then Exit
;
3703 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3704 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
3709 if FHealth
< PLAYER_HP_SOFT
then
3711 IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3715 if gFlash
= 2 then Inc(FPickup
, 5);
3719 if FHealth
< PLAYER_HP_SOFT
then
3721 IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3725 if gFlash
= 2 then Inc(FPickup
, 5);
3729 if FArmor
< PLAYER_AP_SOFT
then
3731 FArmor
:= PLAYER_AP_SOFT
;
3734 if gFlash
= 2 then Inc(FPickup
, 5);
3738 if FArmor
< PLAYER_AP_LIMIT
then
3740 FArmor
:= PLAYER_AP_LIMIT
;
3743 if gFlash
= 2 then Inc(FPickup
, 5);
3747 if FHealth
< PLAYER_HP_LIMIT
then
3749 IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3753 if gFlash
= 2 then Inc(FPickup
, 5);
3757 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
3759 if FHealth
< PLAYER_HP_LIMIT
then
3760 FHealth
:= PLAYER_HP_LIMIT
;
3761 if FArmor
< PLAYER_AP_LIMIT
then
3762 FArmor
:= PLAYER_AP_LIMIT
;
3766 if gFlash
= 2 then Inc(FPickup
, 5);
3770 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3772 FWeapon
[WEAPON_SAW
] := True;
3774 if gFlash
= 2 then Inc(FPickup
, 5);
3775 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3778 ITEM_WEAPON_SHOTGUN1
:
3779 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3781 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
3782 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3784 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3785 FWeapon
[WEAPON_SHOTGUN1
] := True;
3787 if gFlash
= 2 then Inc(FPickup
, 5);
3788 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3791 ITEM_WEAPON_SHOTGUN2
:
3792 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
3794 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
3796 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3797 FWeapon
[WEAPON_SHOTGUN2
] := True;
3799 if gFlash
= 2 then Inc(FPickup
, 5);
3800 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3803 ITEM_WEAPON_CHAINGUN
:
3804 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
3806 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
3808 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3809 FWeapon
[WEAPON_CHAINGUN
] := True;
3811 if gFlash
= 2 then Inc(FPickup
, 5);
3812 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3815 ITEM_WEAPON_ROCKETLAUNCHER
:
3816 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
3818 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
3820 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
3821 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
3823 if gFlash
= 2 then Inc(FPickup
, 5);
3824 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3828 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
3830 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
3832 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3833 FWeapon
[WEAPON_PLASMA
] := True;
3835 if gFlash
= 2 then Inc(FPickup
, 5);
3836 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3840 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
3842 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
3844 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3845 FWeapon
[WEAPON_BFG
] := True;
3847 if gFlash
= 2 then Inc(FPickup
, 5);
3848 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3851 ITEM_WEAPON_SUPERPULEMET
:
3852 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
3854 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
3856 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3857 FWeapon
[WEAPON_SUPERPULEMET
] := True;
3859 if gFlash
= 2 then Inc(FPickup
, 5);
3860 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3863 ITEM_WEAPON_FLAMETHROWER
:
3864 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
3866 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
3868 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
3869 FWeapon
[WEAPON_FLAMETHROWER
] := True;
3871 if gFlash
= 2 then Inc(FPickup
, 5);
3872 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3876 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3878 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3881 if gFlash
= 2 then Inc(FPickup
, 5);
3884 ITEM_AMMO_BULLETS_BOX
:
3885 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3887 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3890 if gFlash
= 2 then Inc(FPickup
, 5);
3894 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3896 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3899 if gFlash
= 2 then Inc(FPickup
, 5);
3902 ITEM_AMMO_SHELLS_BOX
:
3903 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3905 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
3908 if gFlash
= 2 then Inc(FPickup
, 5);
3912 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3914 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3917 if gFlash
= 2 then Inc(FPickup
, 5);
3920 ITEM_AMMO_ROCKET_BOX
:
3921 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3923 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
3926 if gFlash
= 2 then Inc(FPickup
, 5);
3930 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3932 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3935 if gFlash
= 2 then Inc(FPickup
, 5);
3939 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3941 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
3944 if gFlash
= 2 then Inc(FPickup
, 5);
3948 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
3950 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
3953 if gFlash
= 2 then Inc(FPickup
, 5);
3957 if not(R_ITEM_BACKPACK
in FRulez
) or
3958 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
3959 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
3960 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
3961 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
3962 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
3964 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
3965 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
3966 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
3967 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
3968 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
3970 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3971 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3972 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3973 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3974 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3975 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3976 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3977 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3979 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
3982 if gFlash
= 2 then Inc(FPickup
, 5);
3986 if not(R_KEY_RED
in FRulez
) then
3988 Include(FRulez
, R_KEY_RED
);
3990 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3991 if gFlash
= 2 then Inc(FPickup
, 5);
3992 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3996 if not(R_KEY_GREEN
in FRulez
) then
3998 Include(FRulez
, R_KEY_GREEN
);
4000 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4001 if gFlash
= 2 then Inc(FPickup
, 5);
4002 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4006 if not(R_KEY_BLUE
in FRulez
) then
4008 Include(FRulez
, R_KEY_BLUE
);
4010 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4011 if gFlash
= 2 then Inc(FPickup
, 5);
4012 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4016 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
4018 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
4022 if gFlash
= 2 then Inc(FPickup
, 5);
4026 if FAir
< AIR_MAX
then
4031 if gFlash
= 2 then Inc(FPickup
, 5);
4036 if not (R_BERSERK
in FRulez
) then
4038 Include(FRulez
, R_BERSERK
);
4039 if allowBerserkSwitching
then
4041 FCurrWeap
:= WEAPON_KASTET
;
4043 FModel
.SetWeapon(WEAPON_KASTET
);
4048 if gFlash
= 2 then Inc(FPickup
, 5);
4050 FBerserk
:= gTime
+30000;
4055 if FHealth
< PLAYER_HP_SOFT
then
4057 FHealth
:= PLAYER_HP_SOFT
;
4058 FBerserk
:= gTime
+30000;
4066 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
4068 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
4071 if gFlash
= 2 then Inc(FPickup
, 5);
4075 if FHealth
< PLAYER_HP_LIMIT
then
4077 IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
4081 if gFlash
= 2 then Inc(FPickup
, 5);
4085 if FArmor
< PLAYER_AP_LIMIT
then
4087 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
4090 if gFlash
= 2 then Inc(FPickup
, 5);
4094 if FJetFuel
< JET_MAX
then
4096 FJetFuel
:= JET_MAX
;
4099 if gFlash
= 2 then Inc(FPickup
, 5);
4103 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
4105 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
4108 if gFlash
= 2 then Inc(FPickup
, 5);
4113 procedure TPlayer
.Touch();
4117 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4120 // Áðîñèòü ôëàã òîâàðèùó:
4121 if gGameSettings
.GameMode
= GM_CTF
then
4126 procedure TPlayer
.Push(vx
, vy
: Integer);
4128 if (not FPhysics
) and FGhost
then
4130 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
4131 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
4132 if g_Game_IsNet
and g_Game_IsServer
then
4133 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4136 procedure TPlayer
.Reset(Force
: Boolean);
4142 FTime
[T_RESPAWN
] := 0;
4143 FTime
[T_FLAGCAP
] := 0;
4156 FSpectator
:= False;
4159 FSpectatePlayer
:= -1;
4160 FNoRespawn
:= False;
4162 FLives
:= gGameSettings
.MaxLives
;
4167 procedure TPlayer
.SoftReset();
4173 FBFGFireCounter
:= -1;
4181 SetAction(A_STAND
, True);
4184 function TPlayer
.GetRespawnPoint(): Byte;
4189 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4191 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4192 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
4194 if (Self
= gPlayer1
) or (Self
= gPlayer2
) then
4196 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
4197 if Self
= gPlayer1
then
4198 c
:= RESPAWNPOINT_PLAYER1
4200 c
:= RESPAWNPOINT_PLAYER2
;
4201 if g_Map_GetPointCount(c
) > 0 then
4207 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
4208 if Self
= gPlayer1
then
4209 c
:= RESPAWNPOINT_PLAYER2
4211 c
:= RESPAWNPOINT_PLAYER1
;
4212 if g_Map_GetPointCount(c
) > 0 then
4219 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
4220 if Random(2) = 0 then
4221 c
:= RESPAWNPOINT_PLAYER1
4223 c
:= RESPAWNPOINT_PLAYER2
;
4224 if g_Map_GetPointCount(c
) > 0 then
4231 // Òî÷êà ëþáîé èç êîìàíä
4232 if Random(2) = 0 then
4233 c
:= RESPAWNPOINT_RED
4235 c
:= RESPAWNPOINT_BLUE
;
4236 if g_Map_GetPointCount(c
) > 0 then
4243 c
:= RESPAWNPOINT_DM
;
4244 if g_Map_GetPointCount(c
) > 0 then
4252 if gGameSettings
.GameMode
= GM_DM
then
4255 c
:= RESPAWNPOINT_DM
;
4256 if g_Map_GetPointCount(c
) > 0 then
4262 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4263 if Random(2) = 0 then
4264 c
:= RESPAWNPOINT_PLAYER1
4266 c
:= RESPAWNPOINT_PLAYER2
;
4267 if g_Map_GetPointCount(c
) > 0 then
4273 // Òî÷êà ëþáîé èç êîìàíä
4274 if Random(2) = 0 then
4275 c
:= RESPAWNPOINT_RED
4277 c
:= RESPAWNPOINT_BLUE
;
4278 if g_Map_GetPointCount(c
) > 0 then
4286 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4288 // Òî÷êà ñâîåé êîìàíäû
4289 c
:= RESPAWNPOINT_DM
;
4290 if FTeam
= TEAM_RED
then
4291 c
:= RESPAWNPOINT_RED
;
4292 if FTeam
= TEAM_BLUE
then
4293 c
:= RESPAWNPOINT_BLUE
;
4294 if g_Map_GetPointCount(c
) > 0 then
4301 c
:= RESPAWNPOINT_DM
;
4302 if g_Map_GetPointCount(c
) > 0 then
4308 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4309 if Random(2) = 0 then
4310 c
:= RESPAWNPOINT_PLAYER1
4312 c
:= RESPAWNPOINT_PLAYER2
;
4313 if g_Map_GetPointCount(c
) > 0 then
4319 // Òî÷êà äðóãîé êîìàíäû
4320 c
:= RESPAWNPOINT_DM
;
4321 if FTeam
= TEAM_RED
then
4322 c
:= RESPAWNPOINT_BLUE
;
4323 if FTeam
= TEAM_BLUE
then
4324 c
:= RESPAWNPOINT_RED
;
4325 if g_Map_GetPointCount(c
) > 0 then
4333 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4335 RespawnPoint
: TRespawnPoint
;
4340 if not g_Game_IsServer
then
4344 FWantsInGame
:= True;
4345 FJustTeleported
:= True;
4348 FTime
[T_RESPAWN
] := 0;
4352 // if server changes MaxLives we gotta be ready
4353 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4355 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4356 if FTime
[T_RESPAWN
] > gTime
then
4359 // Ïðîñðàë âñå æèçíè:
4362 if not FSpectator
then Spectate(True);
4363 FWantsInGame
:= True;
4367 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4368 begin // "Ñâîÿ èãðà"
4369 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4370 FRulez
:= FRulez
-[R_BERSERK
];
4372 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4374 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4375 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4378 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4379 c
:= GetRespawnPoint();
4384 // Âîñêðåøåíèå áåç îðóæèÿ:
4387 FHealth
:= PLAYER_HP_SOFT
;
4393 for a
:= WP_FIRST
to WP_LAST
do
4395 FWeapon
[a
] := False;
4399 FWeapon
[WEAPON_PISTOL
] := True;
4400 FWeapon
[WEAPON_KASTET
] := True;
4401 FCurrWeap
:= WEAPON_PISTOL
;
4404 FModel
.SetWeapon(FCurrWeap
);
4406 for b
:= A_BULLETS
to A_HIGH
do
4409 FAmmo
[A_BULLETS
] := 50;
4411 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
4412 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
4413 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
4414 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
4415 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
4417 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
4418 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4423 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4424 if not g_Map_GetPoint(c
, RespawnPoint
) then
4426 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4430 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4431 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4432 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4438 FDirection
:= RespawnPoint
.Direction
;
4439 if FDirection
= TDirection
.D_LEFT
then
4445 FBFGFireCounter
:= -1;
4450 SetAction(A_STAND
, True);
4451 FModel
.Direction
:= FDirection
;
4453 for a
:= Low(FTime
) to High(FTime
) do
4456 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4461 FCanJetpack
:= False;
4466 // Àíèìàöèÿ âîçðîæäåíèÿ:
4467 if (not gLoadGameMode
) and (not Silent
) then
4468 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4470 Anim
:= TAnimation
.Create(ID
, False, 3);
4471 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4472 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4476 FSpectator
:= False;
4479 FSpectatePlayer
:= -1;
4482 if (gPlayer1
= nil) and (gLMSPID1
= FUID
) then
4484 if (gPlayer2
= nil) and (gLMSPID2
= FUID
) then
4487 if g_Game_IsNet
then
4489 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4490 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4492 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4493 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4498 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4501 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4502 else if (not NoMove
) then
4504 GameX
:= gMapInfo
.Width
div 2;
4505 GameY
:= gMapInfo
.Height
div 2;
4514 FWantsInGame
:= False;
4519 if Self
= gPlayer1
then
4524 if Self
= gPlayer2
then
4531 if g_Game_IsNet
then
4532 MH_SEND_PlayerStats(FUID
);
4535 procedure TPlayer
.SwitchNoClip
;
4539 FGhost
:= not FGhost
;
4540 FPhysics
:= not FGhost
;
4552 procedure TPlayer
.Run(Direction
: TDirection
);
4556 if MAX_RUNVEL
> 8 then
4560 if Direction
= TDirection
.D_LEFT
then
4562 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4563 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4566 if FObj
.Vel
.X
< MAX_RUNVEL
then
4567 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4569 // Âîçìîæíî, ïèíàåì êóñêè:
4570 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4572 b
:= Abs(FObj
.Vel
.X
);
4573 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4574 for a
:= 0 to High(gGibs
) do
4576 if gGibs
[a
].alive
and
4577 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4578 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4581 if FObj
.Vel
.X
< 0 then
4583 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4587 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4589 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4597 procedure TPlayer
.SeeDown();
4599 SetAction(A_SEEDOWN
);
4601 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4603 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4606 procedure TPlayer
.SeeUp();
4610 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4612 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4615 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4623 A_ATTACK
: Prior
:= 2;
4624 A_SEEUP
: Prior
:= 1;
4625 A_SEEDOWN
: Prior
:= 1;
4626 A_ATTACKUP
: Prior
:= 2;
4627 A_ATTACKDOWN
: Prior
:= 2;
4632 if (Prior
> FActionPrior
) or Force
then
4633 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4635 FActionPrior
:= Prior
;
4636 FActionAnim
:= Action
;
4637 FActionForce
:= Force
;
4638 FActionChanged
:= True;
4641 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4644 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4646 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4647 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4648 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4649 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4652 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4659 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4661 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4662 if g_Game_IsServer
and g_Game_IsNet
then
4663 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4667 FJustTeleported
:= True;
4672 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4674 Anim
:= TAnimation
.Create(ID
, False, 3);
4677 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4678 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4679 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4680 if g_Game_IsServer
and g_Game_IsNet
then
4681 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4682 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4686 FObj
.X
:= X
-PLAYER_RECT
.X
;
4687 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4688 if FAlive
and FGhost
then
4694 if not g_Game_IsNet
then
4698 SetDirection(TDirection
.D_LEFT
);
4704 SetDirection(TDirection
.D_RIGHT
);
4710 if FDirection
= TDirection
.D_RIGHT
then
4712 SetDirection(TDirection
.D_LEFT
);
4717 SetDirection(TDirection
.D_RIGHT
);
4723 if not silent
and (Anim
<> nil) then
4725 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4726 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4729 if g_Game_IsServer
and g_Game_IsNet
then
4730 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4731 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4738 function nonz(a
: Single): Single;
4746 procedure TPlayer
.Update();
4749 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
4750 blockmon
, headwater
, dospawn
: Boolean;
4755 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
4756 AnyServer
:= g_Game_IsServer
;
4758 if g_Game_IsClient
and (NetInterpLevel
> 0) then
4759 DoLerp(NetInterpLevel
+ 1)
4765 if FClientID
>= 0 then
4767 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
4768 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
4769 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
4778 if FAlive
and (FPunchAnim
<> nil) then
4779 FPunchAnim
.Update();
4781 if FAlive
and (gFly
or FJetpack
) then
4784 if FDirection
= TDirection
.D_LEFT
then
4789 if FAlive
and (not FGhost
) then
4791 if FKeys
[KEY_UP
].Pressed
then
4793 if FKeys
[KEY_DOWN
].Pressed
then
4797 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
4800 i
:= g_basic
.Sign(FIncCam
);
4801 FIncCam
:= Abs(FIncCam
);
4802 DecMin(FIncCam
, 5, 0);
4803 FIncCam
:= FIncCam
*i
;
4806 // no need to do that each second frame, weapon queue will take care of it
4807 if FAlive
and FKeys
[KEY_NEXTWEAPON
].Pressed
and AnyServer
then NextWeapon();
4808 if FAlive
and FKeys
[KEY_PREVWEAPON
].Pressed
and AnyServer
then PrevWeapon();
4810 if gTime
mod (GAME_TICK
*2) <> 0 then
4812 if (FObj
.Vel
.X
= 0) and FAlive
then
4814 if FKeys
[KEY_LEFT
].Pressed
then
4815 Run(TDirection
.D_LEFT
);
4816 if FKeys
[KEY_RIGHT
].Pressed
then
4817 Run(TDirection
.D_RIGHT
);
4822 g_Obj_Move(@FObj
, True, True, True);
4823 positionChanged(); // this updates spatial accelerators
4829 FActionChanged
:= False;
4833 // Let alive player do some actions
4834 if FKeys
[KEY_LEFT
].Pressed
then Run(TDirection
.D_LEFT
);
4835 if FKeys
[KEY_RIGHT
].Pressed
then Run(TDirection
.D_RIGHT
);
4836 //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
4837 //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
4838 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire();
4839 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
4840 if FKeys
[KEY_JUMP
].Pressed
then Jump()
4843 if AnyServer
and FJetpack
then
4847 if NetServer
then MH_SEND_PlayerStats(FUID
);
4849 FCanJetpack
:= True;
4856 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
4858 if FKeys
[k
].Pressed
then
4866 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
4869 if (FTime
[T_RESPAWN
] <= gTime
) and
4870 gGameOn
and (not FAlive
) then
4872 if (g_Player_GetCount() > 1) then
4876 gExit
:= EXIT_RESTART
;
4881 // Dead spectator actions
4884 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
4885 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
4889 if (FSpectatePlayer
>= High(gPlayers
)) then
4890 FSpectatePlayer
:= -1
4894 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
4895 if gPlayers
[I
] <> nil then
4896 if gPlayers
[I
].alive
then
4897 if gPlayers
[I
].UID
<> FUID
then
4899 FSpectatePlayer
:= I
;
4904 if not SetSpect
then FSpectatePlayer
:= -1;
4915 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
4917 FYTo
:= FObj
.Y
- 32;
4918 FSpectatePlayer
:= -1;
4920 if FKeys
[KEY_DOWN
].Pressed
then
4922 FYTo
:= FObj
.Y
+ 32;
4923 FSpectatePlayer
:= -1;
4925 if FKeys
[KEY_LEFT
].Pressed
then
4927 FXTo
:= FObj
.X
- 32;
4928 FSpectatePlayer
:= -1;
4930 if FKeys
[KEY_RIGHT
].Pressed
then
4932 FXTo
:= FObj
.X
+ 32;
4933 FSpectatePlayer
:= -1;
4936 if (FXTo
< -64) then
4938 else if (FXTo
> gMapInfo
.Width
+ 32) then
4939 FXTo
:= gMapInfo
.Width
+ 32;
4940 if (FYTo
< -72) then
4942 else if (FYTo
> gMapInfo
.Height
+ 32) then
4943 FYTo
:= gMapInfo
.Height
+ 32;
4948 g_Obj_Move(@FObj
, True, True, True);
4949 positionChanged(); // this updates spatial accelerators
4956 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
4957 if gPlayers
[FSpectatePlayer
] <> nil then
4958 if gPlayers
[FSpectatePlayer
].alive
then
4960 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
4961 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
4965 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
4966 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
4967 PANEL_BLOCKMON
, True);
4968 headwater
:= HeadInLiquid(0, 0);
4970 // Ñîïðîòèâëåíèå âîçäóõà:
4971 if (not FAlive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
4972 if FObj
.Vel
.X
<> 0 then
4973 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
4975 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
4976 DecMin(FPain
, 5, 0);
4977 DecMin(FPickup
, 1, 0);
4979 if FAlive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
4981 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
4982 FMegaRulez
[MR_SUIT
] := 0;
4983 FMegaRulez
[MR_INVUL
] := 0;
4984 FMegaRulez
[MR_INVIS
] := 0;
4985 Kill(K_FALLKILL
, 0, HIT_FALL
);
4992 if FCurrWeap
= WEAPON_SAW
then
4993 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
4994 FSawSoundSelect
.IsPlaying()) then
4995 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
4998 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
4999 (not FJetSoundOff
.IsPlaying()) then
5001 FJetSoundFly
.SetPosition(0);
5002 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
5005 for b
:= WP_FIRST
to WP_LAST
do
5006 if FReloading
[b
] > 0 then
5012 if FShellTimer
> -1 then
5013 if FShellTimer
= 0 then
5015 if FShellType
= SHELL_SHELL
then
5016 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5017 GameVelX
, GameVelY
-2, SHELL_SHELL
)
5018 else if FShellType
= SHELL_DBLSHELL
then
5020 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5021 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
5022 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5023 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
5026 end else Dec(FShellTimer
);
5028 if (FBFGFireCounter
> -1) then
5029 if FBFGFireCounter
= 0 then
5033 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
5034 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
5035 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
5036 yd
:= wy
+firediry();
5037 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
5038 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
5039 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5040 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5041 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5044 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
5045 FBFGFireCounter
:= -1;
5048 FBFGFireCounter
:= 0
5050 Dec(FBFGFireCounter
);
5052 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
5054 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
5056 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
5059 if (headwater
or blockmon
) then
5065 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
5068 else if (FAir
mod 31 = 0) and not blockmon
then
5070 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
5071 if Random(2) = 0 then
5072 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5074 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5076 end else if FAir
< AIR_DEF
then
5079 if FFireTime
> 0 then
5081 if BodyInLiquid(0, 0) then
5086 else if FMegaRulez
[MR_SUIT
] >= gTime
then
5088 if FMegaRulez
[MR_SUIT
] = gTime
then
5095 if FFirePainTime
<= 0 then
5097 if g_Game_IsServer
then
5098 Damage(5, FFireAttacker
, 0, 0, HIT_FLAME
);
5099 FFirePainTime
:= 18;
5101 FFirePainTime
:= FFirePainTime
- 1;
5102 FFireTime
:= FFireTime
- 1;
5103 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
5104 MH_SEND_PlayerStats(FUID
);
5108 if FDamageBuffer
> 0 then
5110 if FDamageBuffer
>= 9 then
5114 if FDamageBuffer
< 30 then i
:= 9
5115 else if FDamageBuffer
< 100 then i
:= 18
5119 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
5120 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
5121 FHealth
:= FHealth
-ii
;
5124 FHealth
:= FHealth
+FArmor
;
5129 if FHealth
<= 0 then
5130 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
5131 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
5132 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
5136 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
5137 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
5138 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
5139 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
5146 end; // if FAlive then ...
5148 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
5150 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
5151 FModel
.GetCurrentAnimation
.MinLength
:= i
;
5152 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
5153 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
5155 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
5156 then SetAction(A_STAND
, True);
5158 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
5160 for b
:= Low(FKeys
) to High(FKeys
) do
5161 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
5165 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5167 x
:= FObj
.X
+PLAYER_RECT
.X
;
5168 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
5169 w
:= PLAYER_RECT
.Width
;
5170 h
:= PLAYER_RECT
.Height
;
5174 procedure TPlayer
.moveBy (dx
, dy
: Integer); inline;
5176 if (dx
<> 0) or (dy
<> 0) then
5185 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
5187 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5188 FObj
.Y
+PLAYER_RECT
.Y
,
5195 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
5197 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5198 FObj
.Y
+PLAYER_RECT
.Y
,
5202 Panel
.Width
, Panel
.Height
);
5205 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
5207 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
5208 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
5209 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
5210 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
5213 function g_Player_ValidName(Name
: string): Boolean;
5219 if gPlayers
= nil then Exit
;
5221 for a
:= 0 to High(gPlayers
) do
5222 if gPlayers
[a
] <> nil then
5223 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
5230 procedure TPlayer
.SetDirection(Direction
: TDirection
);
5234 d
:= FModel
.Direction
;
5236 FModel
.Direction
:= Direction
;
5237 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
5239 FDirection
:= Direction
;
5242 function TPlayer
.GetKeys(): Byte;
5246 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
5247 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
5248 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
5250 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
5251 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
5254 procedure TPlayer
.Use();
5258 if FTime
[T_USE
] > gTime
then Exit
;
5260 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
5261 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
5263 for a
:= 0 to High(gPlayers
) do
5264 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
5265 gPlayers
[a
].alive
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
5266 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5267 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
5269 gPlayers
[a
].Touch();
5270 if g_Game_IsNet
and g_Game_IsServer
then
5271 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
5274 FTime
[T_USE
] := gTime
+120;
5277 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
5281 WX
, WY
, XD
, YD
: Integer;
5292 if R_BERSERK
in FRulez
then
5294 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5295 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
5296 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
5299 locobj
.rect
.Width
:= 39;
5300 locobj
.rect
.Height
:= 52;
5301 locobj
.Vel
.X
:= (xd
-wx
) div 2;
5302 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
5303 locobj
.Accel
.X
:= xd
-wx
;
5304 locobj
.Accel
.y
:= yd
-wy
;
5308 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
5309 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
5311 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
5315 FPain
:= min(FPain
+ 25, 50);
5317 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
5322 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5323 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
5325 FSawSoundSelect
.Stop();
5327 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
5329 else if not FSawSoundHit
.IsPlaying() then
5331 FSawSoundSelect
.Stop();
5332 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
5339 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
5340 FFireAngle
:= FAngle
;
5342 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5343 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5348 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5349 FFireAngle
:= FAngle
;
5352 FShellType
:= SHELL_SHELL
;
5357 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5358 FFireAngle
:= FAngle
;
5361 FShellType
:= SHELL_DBLSHELL
;
5366 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5367 FFireAngle
:= FAngle
;
5369 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5370 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5373 WEAPON_ROCKETLAUNCHER
:
5375 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5376 FFireAngle
:= FAngle
;
5382 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5383 FFireAngle
:= FAngle
;
5389 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5390 FFireAngle
:= FAngle
;
5394 WEAPON_SUPERPULEMET
:
5396 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5397 FFireAngle
:= FAngle
;
5399 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5400 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5403 WEAPON_FLAMETHROWER
:
5405 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
5406 FFireAngle
:= FAngle
;
5413 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5414 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5415 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5418 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5420 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5421 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5424 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5428 if NetInterpLevel
< 1 then
5438 AX
:= Abs(FXTo
- FObj
.X
);
5439 AY
:= Abs(FYTo
- FObj
.Y
);
5440 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5442 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5447 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5449 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5450 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5451 PANEL_LIFTUP
, False) then Result
:= -1
5453 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5454 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5455 PANEL_LIFTDOWN
, False) then Result
:= 1
5459 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5466 if Flag
= FLAG_NONE
then
5469 if not g_Game_IsServer
then Exit
;
5471 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5472 if (Flag
= FTeam
) and
5473 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5474 (FFlag
<> FLAG_NONE
) then
5476 if FFlag
= FLAG_RED
then
5477 s
:= _lc
[I_PLAYER_FLAG_RED
]
5479 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5481 evtype
:= FLAG_STATE_SCORED
;
5483 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5484 Insert('.', ts
, Length(ts
) + 1 - 3);
5485 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5487 g_Map_ResetFlag(FFlag
);
5488 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5490 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5493 if g_Game_IsNet
then
5495 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5499 gFlags
[FFlag
].CaptureTime
:= 0;
5504 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5505 if (Flag
= FTeam
) and
5506 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5508 if Flag
= FLAG_RED
then
5509 s
:= _lc
[I_PLAYER_FLAG_RED
]
5511 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5513 evtype
:= FLAG_STATE_RETURNED
;
5514 gFlags
[Flag
].CaptureTime
:= 0;
5516 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5518 g_Map_ResetFlag(Flag
);
5519 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5522 if g_Game_IsNet
then
5524 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5530 // Ïîäîáðàë ÷óæîé ôëàã:
5531 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5535 if Flag
= FLAG_RED
then
5536 s
:= _lc
[I_PLAYER_FLAG_RED
]
5538 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5540 evtype
:= FLAG_STATE_CAPTURED
;
5542 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5544 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5546 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5549 if g_Game_IsNet
then
5551 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5557 procedure TPlayer
.SetFlag(Flag
: Byte);
5560 if FModel
<> nil then
5561 FModel
.SetFlag(FFlag
);
5564 function TPlayer
.DropFlag(): Boolean;
5569 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5571 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5572 with gFlags
[FFlag
] do
5576 Direction
:= FDirection
;
5577 State
:= FLAG_STATE_DROPPED
;
5579 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5580 (FObj
.Vel
.Y
div 2)-2+Random(5));
5581 positionChanged(); // this updates spatial accelerators
5583 if FFlag
= FLAG_RED
then
5584 s
:= _lc
[I_PLAYER_FLAG_RED
]
5586 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5588 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5589 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5591 if g_Game_IsNet
then
5592 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5598 procedure TPlayer
.GetSecret();
5603 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5605 Assert(Key
<= High(FKeys
));
5607 FKeys
[Key
].Pressed
:= True;
5608 FKeys
[Key
].Time
:= Time
;
5611 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5613 Result
:= FKeys
[K
].Pressed
;
5616 procedure TPlayer
.ReleaseKeys();
5620 for a
:= Low(FKeys
) to High(FKeys
) do
5622 FKeys
[a
].Pressed
:= False;
5627 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5631 function TPlayer
.firediry(): Integer;
5633 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5634 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5638 procedure TPlayer
.RememberState();
5642 FSavedState
.Health
:= FHealth
;
5643 FSavedState
.Armor
:= FArmor
;
5644 FSavedState
.Air
:= FAir
;
5645 FSavedState
.JetFuel
:= FJetFuel
;
5646 FSavedState
.CurrWeap
:= FCurrWeap
;
5647 FSavedState
.NextWeap
:= FNextWeap
;
5648 FSavedState
.NextWeapDelay
:= FNextWeapDelay
;
5651 FSavedState
.Ammo
[i
] := FAmmo
[i
];
5653 FSavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5655 FSavedState
.Rulez
:= FRulez
;
5656 FSavedState
.WaitRecall
:= True;
5659 procedure TPlayer
.RecallState();
5663 if not FSavedState
.WaitRecall
then Exit
;
5665 FHealth
:= FSavedState
.Health
;
5666 FArmor
:= FSavedState
.Armor
;
5667 FAir
:= FSavedState
.Air
;
5668 FJetFuel
:= FSavedState
.JetFuel
;
5669 FCurrWeap
:= FSavedState
.CurrWeap
;
5670 FNextWeap
:= FSavedState
.NextWeap
;
5671 FNextWeapDelay
:= FSavedState
.NextWeapDelay
;
5674 FAmmo
[i
] := FSavedState
.Ammo
[i
];
5676 FMaxAmmo
[i
] := FSavedState
.MaxAmmo
[i
];
5678 FRulez
:= FSavedState
.Rulez
;
5679 FSavedState
.WaitRecall
:= False;
5681 if gGameSettings
.GameType
= GT_SERVER
then
5682 MH_SEND_PlayerStats(FUID
);
5685 procedure TPlayer
.SaveState (st
: TStream
);
5691 utils
.writeSign(st
, 'PLYR');
5692 utils
.writeInt(st
, Byte(PLR_SAVE_VERSION
)); // version
5694 utils
.writeBool(st
, FIamBot
);
5696 utils
.writeInt(st
, Word(FUID
));
5698 utils
.writeStr(st
, FName
);
5700 utils
.writeInt(st
, Byte(FTeam
));
5702 utils
.writeBool(st
, FAlive
);
5703 // Èçðàñõîäîâàë ëè âñå æèçíè
5704 utils
.writeBool(st
, FNoRespawn
);
5706 if FDirection
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
5707 utils
.writeInt(st
, Byte(b
));
5709 utils
.writeInt(st
, LongInt(FHealth
));
5711 utils
.writeInt(st
, Byte(FLives
));
5713 utils
.writeInt(st
, LongInt(FArmor
));
5715 utils
.writeInt(st
, LongInt(FAir
));
5717 utils
.writeInt(st
, LongInt(FJetFuel
));
5719 utils
.writeInt(st
, LongInt(FPain
));
5721 utils
.writeInt(st
, LongInt(FKills
));
5723 utils
.writeInt(st
, LongInt(FMonsterKills
));
5725 utils
.writeInt(st
, LongInt(FFrags
));
5727 utils
.writeInt(st
, Byte(FFragCombo
));
5728 // Âðåìÿ ïîñëåäíåãî ôðàãà
5729 utils
.writeInt(st
, LongWord(FLastFrag
));
5731 utils
.writeInt(st
, LongInt(FDeath
));
5733 utils
.writeInt(st
, Byte(FFlag
));
5735 utils
.writeInt(st
, LongInt(FSecrets
));
5737 utils
.writeInt(st
, Byte(FCurrWeap
));
5739 utils
.writeInt(st
, Word(FNextWeap
));
5741 utils
.writeInt(st
, Byte(FNextWeapDelay
));
5742 // Âðåìÿ çàðÿäêè BFG
5743 utils
.writeInt(st
, SmallInt(FBFGFireCounter
));
5745 utils
.writeInt(st
, LongInt(FDamageBuffer
));
5746 // Ïîñëåäíèé óäàðèâøèé
5747 utils
.writeInt(st
, Word(FLastSpawnerUID
));
5748 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
5749 utils
.writeInt(st
, Byte(FLastHit
));
5751 Obj_SaveState(st
, @FObj
);
5752 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
5753 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FAmmo
[i
]));
5754 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
5755 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FMaxAmmo
[i
]));
5757 for i
:= WP_FIRST
to WP_LAST
do utils
.writeBool(st
, FWeapon
[i
]);
5758 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
5759 for i
:= WP_FIRST
to WP_LAST
do utils
.writeInt(st
, Word(FReloading
[i
]));
5761 utils
.writeBool(st
, (R_ITEM_BACKPACK
in FRulez
));
5762 // Íàëè÷èå êðàñíîãî êëþ÷à
5763 utils
.writeBool(st
, (R_KEY_RED
in FRulez
));
5764 // Íàëè÷èå çåëåíîãî êëþ÷à
5765 utils
.writeBool(st
, (R_KEY_GREEN
in FRulez
));
5766 // Íàëè÷èå ñèíåãî êëþ÷à
5767 utils
.writeBool(st
, (R_KEY_BLUE
in FRulez
));
5769 utils
.writeBool(st
, (R_BERSERK
in FRulez
));
5770 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
5771 for i
:= MR_SUIT
to MR_MAX
do utils
.writeInt(st
, LongWord(FMegaRulez
[i
]));
5772 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
5773 for i
:= T_RESPAWN
to T_FLAGCAP
do utils
.writeInt(st
, LongWord(FTime
[i
]));
5775 utils
.writeStr(st
, FModel
.Name
);
5777 utils
.writeInt(st
, Byte(FColor
.R
));
5778 utils
.writeInt(st
, Byte(FColor
.G
));
5779 utils
.writeInt(st
, Byte(FColor
.B
));
5783 procedure TPlayer
.LoadState (st
: TStream
);
5792 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
5793 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
5795 FIamBot
:= utils
.readBool(st
);
5797 FUID
:= utils
.readWord(st
);
5799 str
:= utils
.readStr(st
);
5800 if (self
<> gPlayer1
) and (self
<> gPlayer2
) then FName
:= str
;
5802 FTeam
:= utils
.readByte(st
);
5804 FAlive
:= utils
.readBool(st
);
5805 // Èçðàñõîäîâàë ëè âñå æèçíè
5806 FNoRespawn
:= utils
.readBool(st
);
5808 b
:= utils
.readByte(st
);
5809 if b
= 1 then FDirection
:= TDirection
.D_LEFT
else FDirection
:= TDirection
.D_RIGHT
; // b = 2
5811 FHealth
:= utils
.readLongInt(st
);
5813 FLives
:= utils
.readByte(st
);
5815 FArmor
:= utils
.readLongInt(st
);
5817 FAir
:= utils
.readLongInt(st
);
5819 FJetFuel
:= utils
.readLongInt(st
);
5821 FPain
:= utils
.readLongInt(st
);
5823 FKills
:= utils
.readLongInt(st
);
5825 FMonsterKills
:= utils
.readLongInt(st
);
5827 FFrags
:= utils
.readLongInt(st
);
5829 FFragCombo
:= utils
.readByte(st
);
5830 // Âðåìÿ ïîñëåäíåãî ôðàãà
5831 FLastFrag
:= utils
.readLongWord(st
);
5833 FDeath
:= utils
.readLongInt(st
);
5835 FFlag
:= utils
.readByte(st
);
5837 FSecrets
:= utils
.readLongInt(st
);
5839 FCurrWeap
:= utils
.readByte(st
);
5841 FNextWeap
:= utils
.readWord(st
);
5843 FNextWeapDelay
:= utils
.readByte(st
);
5844 // Âðåìÿ çàðÿäêè BFG
5845 FBFGFireCounter
:= utils
.readSmallInt(st
);
5847 FDamageBuffer
:= utils
.readLongInt(st
);
5848 // Ïîñëåäíèé óäàðèâøèé
5849 FLastSpawnerUID
:= utils
.readWord(st
);
5850 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
5851 FLastHit
:= utils
.readByte(st
);
5853 Obj_LoadState(@FObj
, st
);
5854 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
5855 for i
:= A_BULLETS
to A_HIGH
do FAmmo
[i
] := utils
.readWord(st
);
5856 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
5857 for i
:= A_BULLETS
to A_HIGH
do FMaxAmmo
[i
] := utils
.readWord(st
);
5859 for i
:= WP_FIRST
to WP_LAST
do FWeapon
[i
] := utils
.readBool(st
);
5860 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
5861 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := utils
.readWord(st
);
5863 if utils
.readBool(st
) then Include(FRulez
, R_ITEM_BACKPACK
);
5864 // Íàëè÷èå êðàñíîãî êëþ÷à
5865 if utils
.readBool(st
) then Include(FRulez
, R_KEY_RED
);
5866 // Íàëè÷èå çåëåíîãî êëþ÷à
5867 if utils
.readBool(st
) then Include(FRulez
, R_KEY_GREEN
);
5868 // Íàëè÷èå ñèíåãî êëþ÷à
5869 if utils
.readBool(st
) then Include(FRulez
, R_KEY_BLUE
);
5871 if utils
.readBool(st
) then Include(FRulez
, R_BERSERK
);
5872 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
5873 for i
:= MR_SUIT
to MR_MAX
do FMegaRulez
[i
] := utils
.readLongWord(st
);
5874 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
5875 for i
:= T_RESPAWN
to T_FLAGCAP
do FTime
[i
] := utils
.readLongWord(st
);
5877 str
:= utils
.readStr(st
);
5879 FColor
.R
:= utils
.readByte(st
);
5880 FColor
.G
:= utils
.readByte(st
);
5881 FColor
.B
:= utils
.readByte(st
);
5882 if (self
= gPlayer1
) then
5884 str
:= gPlayer1Settings
.Model
;
5885 FColor
:= gPlayer1Settings
.Color
;
5887 else if (self
= gPlayer2
) then
5889 str
:= gPlayer2Settings
.Model
;
5890 FColor
:= gPlayer2Settings
.Color
;
5892 // Îáíîâëÿåì ìîäåëü èãðîêà
5894 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
5895 FModel
.Color
:= TEAMCOLOR
[FTeam
]
5897 FModel
.Color
:= FColor
;
5901 procedure TPlayer
.AllRulez(Health
: Boolean);
5907 FHealth
:= PLAYER_HP_LIMIT
;
5908 FArmor
:= PLAYER_AP_LIMIT
;
5912 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
5913 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
5914 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
5917 procedure TPlayer
.RestoreHealthArmor();
5919 FHealth
:= PLAYER_HP_LIMIT
;
5920 FArmor
:= PLAYER_AP_LIMIT
;
5923 procedure TPlayer
.FragCombo();
5927 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
5929 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
5931 if FFragCombo
< 5 then
5933 Param
:= FUID
or (FFragCombo
shl 16);
5934 if (FComboEvnt
>= Low(gDelayedEvents
)) and
5935 (FComboEvnt
<= High(gDelayedEvents
)) and
5936 gDelayedEvents
[FComboEvnt
].Pending
and
5937 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
5938 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
5940 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
5941 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
5944 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
5952 procedure TPlayer
.GiveItem(ItemType
: Byte);
5956 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
5958 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
5962 if FAir
< AIR_MAX
then
5969 if not (R_BERSERK
in FRulez
) then
5971 Include(FRulez
, R_BERSERK
);
5972 if FBFGFireCounter
< 1 then
5974 FCurrWeap
:= WEAPON_KASTET
;
5976 FModel
.SetWeapon(WEAPON_KASTET
);
5980 FBerserk
:= gTime
+30000;
5982 if FHealth
< PLAYER_HP_SOFT
then
5984 FHealth
:= PLAYER_HP_SOFT
;
5985 FBerserk
:= gTime
+30000;
5990 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
5992 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
5996 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
5998 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
6002 if FJetFuel
< JET_MAX
then
6004 FJetFuel
:= JET_MAX
;
6007 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
6008 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
6010 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
6011 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6013 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
6015 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
6017 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
6018 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6021 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
6022 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
6023 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
6024 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
6025 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
6026 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
6027 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
6028 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
6029 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
6031 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6032 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
6033 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6034 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
6035 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6036 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
6037 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6038 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
6039 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
6042 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
6043 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
6044 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
6045 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
6046 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
6048 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
6049 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
6050 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
6051 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
6052 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
6054 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6055 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6056 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6057 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6059 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
6062 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
6063 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
6064 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
6066 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
6067 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
6072 if g_Game_IsNet
and g_Game_IsServer
then
6073 MH_SEND_PlayerStats(FUID
);
6076 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
6081 if (Random(5) = 1) and (Times
= 1) then
6084 if BodyInLiquid(0, 0) then
6086 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
6087 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
6088 if Random(2) = 0 then
6089 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
6091 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
6095 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
6097 for i
:= 1 to Times
do
6099 Anim
:= TAnimation
.Create(id
, False, 3);
6101 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6102 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6108 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
6113 if (Random(10) = 1) and (Times
= 1) then
6116 if g_Frames_Get(id
, 'FRAMES_FLAME') then
6118 for i
:= 1 to Times
do
6120 Anim
:= TAnimation
.Create(id
, False, 3);
6122 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6123 Obj
.Y
+8+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6129 procedure TPlayer
.PauseSounds(Enable
: Boolean);
6131 FSawSound
.Pause(Enable
);
6132 FSawSoundIdle
.Pause(Enable
);
6133 FSawSoundHit
.Pause(Enable
);
6134 FSawSoundSelect
.Pause(Enable
);
6139 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
6144 FObj
.Rect
:= PLAYER_CORPSERECT
;
6145 FModelName
:= ModelName
;
6150 FState
:= CORPSE_STATE_MESS
;
6151 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
6155 FState
:= CORPSE_STATE_NORMAL
;
6156 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
6160 destructor TCorpse
.Destroy();
6167 function TCorpse
.ObjPtr (): PObj
; inline; begin result
:= @FObj
; end;
6169 procedure TCorpse
.positionChanged (); inline; begin end;
6171 procedure TCorpse
.moveBy (dx
, dy
: Integer); inline;
6173 if (dx
<> 0) or (dy
<> 0) then
6182 procedure TCorpse
.getMapBox (out x
, y
, w
, h
: Integer); inline;
6184 x
:= FObj
.X
+PLAYER_CORPSERECT
.X
;
6185 y
:= FObj
.Y
+PLAYER_CORPSERECT
.Y
;
6186 w
:= PLAYER_CORPSERECT
.Width
;
6187 h
:= PLAYER_CORPSERECT
.Height
;
6191 procedure TCorpse
.Damage(Value
: Word; vx
, vy
: Integer);
6195 if FState
= CORPSE_STATE_REMOVEME
then
6198 FDamage
:= FDamage
+ Value
;
6200 if FDamage
> 150 then
6202 if FAnimation
<> nil then
6207 FState
:= CORPSE_STATE_REMOVEME
;
6209 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
6210 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
6211 FModelName
, FColor
);
6212 // Çâóê ìÿñà îò òðóïà:
6213 pm
:= g_PlayerModel_Get(FModelName
);
6214 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
6220 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
6221 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
6222 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
6223 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
6224 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
6229 procedure TCorpse
.Draw();
6231 if FState
= CORPSE_STATE_REMOVEME
then
6234 if FAnimation
<> nil then
6235 FAnimation
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6237 if FAnimationMask
<> nil then
6240 FAnimationMask
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6247 procedure TCorpse
.Update();
6251 if FState
= CORPSE_STATE_REMOVEME
then
6254 if gTime
mod (GAME_TICK
*2) <> 0 then
6256 g_Obj_Move(@FObj
, True, True, True);
6257 positionChanged(); // this updates spatial accelerators
6261 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6262 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
6264 st
:= g_Obj_Move(@FObj
, True, True, True);
6265 positionChanged(); // this updates spatial accelerators
6267 if WordBool(st
and MOVE_FALLOUT
) then
6269 FState
:= CORPSE_STATE_REMOVEME
;
6273 if FAnimation
<> nil then
6274 FAnimation
.Update();
6275 if FAnimationMask
<> nil then
6276 FAnimationMask
.Update();
6280 procedure TCorpse
.SaveState (st
: TStream
);
6287 utils
.writeSign(st
, 'CORP');
6288 utils
.writeInt(st
, Byte(0));
6290 utils
.writeInt(st
, Byte(FState
));
6292 utils
.writeInt(st
, Byte(FDamage
));
6294 utils
.writeInt(st
, Byte(FColor
.R
));
6295 utils
.writeInt(st
, Byte(FColor
.G
));
6296 utils
.writeInt(st
, Byte(FColor
.B
));
6298 Obj_SaveState(st
, @FObj
);
6300 anim
:= (FAnimation
<> nil);
6301 utils
.writeBool(st
, anim
);
6302 // Åñëè åñòü - ñîõðàíÿåì
6303 if anim
then FAnimation
.SaveState(st
);
6304 // Åñòü ëè ìàñêà àíèìàöèè
6305 anim
:= (FAnimationMask
<> nil);
6306 utils
.writeBool(st
, anim
);
6307 // Åñëè åñòü - ñîõðàíÿåì
6308 if anim
then FAnimationMask
.SaveState(st
);
6312 procedure TCorpse
.LoadState (st
: TStream
);
6319 if not utils
.checkSign(st
, 'CORP') then raise XStreamError
.Create('invalid corpse signature');
6320 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid corpse version');
6322 FState
:= utils
.readByte(st
);
6324 FDamage
:= utils
.readByte(st
);
6326 FColor
.R
:= utils
.readByte(st
);
6327 FColor
.G
:= utils
.readByte(st
);
6328 FColor
.B
:= utils
.readByte(st
);
6330 Obj_LoadState(@FObj
, st
);
6332 anim
:= utils
.readBool(st
);
6333 // Åñëè åñòü - çàãðóæàåì
6336 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6337 FAnimation
.LoadState(st
);
6339 // Åñòü ëè ìàñêà àíèìàöèè
6340 anim
:= utils
.readBool(st
);
6341 // Åñëè åñòü - çàãðóæàåì
6344 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6345 FAnimationMask
.LoadState(st
);
6351 constructor TBot
.Create();
6358 FSpectator
:= False;
6365 for a
:= WP_FIRST
to WP_LAST
do
6367 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6368 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6369 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6373 destructor TBot
.Destroy();
6376 inherited Destroy();
6379 procedure TBot
.Draw();
6383 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6384 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6387 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6389 inherited Respawn(Silent
, Force
);
6392 FSelectedWeapon
:= FCurrWeap
;
6397 procedure TBot
.UpdateCombat();
6410 TTargetRecord
= array of TTarget
;
6412 function Compare(a
, b
: TTarget
): Integer;
6414 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6417 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6419 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6420 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6422 if a
.Dist
> b
.Dist
then // B áëèæå
6424 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6427 else // Ñòðàííî -> A
6432 a
, x1
, y1
, x2
, y2
: Integer;
6433 targets
: TTargetRecord
;
6435 Target
, BestTarget
: TTarget
;
6436 firew
, fireh
: Integer;
6440 vsPlayer
, vsMonster
, ok
: Boolean;
6443 function monsUpdate (mon
: TMonster
): Boolean;
6445 result
:= false; // don't stop
6446 if mon
.alive
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6448 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6450 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6451 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6453 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6454 if g_TraceVector(x1
, y1
, x2
, y2
) then
6456 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6457 SetLength(targets
, Length(targets
)+1);
6458 with targets
[High(targets
)] do
6465 Rect
:= mon
.Obj
.Rect
;
6466 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6467 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6468 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6477 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6478 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6480 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6481 if FCurrWeap
<> FSelectedWeapon
then
6484 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6485 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6487 RemoveAIFlag('NEEDFIRE');
6490 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6491 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6492 else PressKey(KEY_FIRE
);
6496 // Êîîðäèíàòû ñòâîëà:
6497 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6498 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6500 Target
.UID
:= FTargetUID
;
6503 if Target
.UID
<> 0 then
6504 begin // Öåëü åñòü - íàñòðàèâàåì
6505 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6508 tpla
:= g_Player_Get(Target
.UID
);
6512 if (@FObj
) <> nil then
6519 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6520 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6521 Target
.Rect
:= PLAYER_RECT
;
6522 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6523 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6524 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6525 Target
.IsPlayer
:= True;
6529 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6532 mon
:= g_Monsters_ByUID(Target
.UID
);
6535 Target
.X
:= mon
.Obj
.X
;
6536 Target
.Y
:= mon
.Obj
.Y
;
6538 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6539 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6540 Target
.Rect
:= mon
.Obj
.Rect
;
6541 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6542 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6543 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6544 Target
.IsPlayer
:= False;
6551 begin // Öåëè íåò - îáíóëÿåì
6556 Target
.Visible
:= False;
6557 Target
.Line
:= False;
6558 Target
.IsPlayer
:= False;
6563 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6564 if (not Target
.Line
) or (not Target
.Visible
) then
6568 for a
:= 0 to High(gPlayers
) do
6569 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].alive
) and
6570 (gPlayers
[a
].FUID
<> FUID
) and
6571 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6572 (not gPlayers
[a
].NoTarget
) and
6573 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6575 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6576 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6579 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6580 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6582 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6583 if g_TraceVector(x1
, y1
, x2
, y2
) then
6585 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6586 SetLength(targets
, Length(targets
)+1);
6587 with targets
[High(targets
)] do
6589 UID
:= gPlayers
[a
].FUID
;
6590 X
:= gPlayers
[a
].FObj
.X
;
6591 Y
:= gPlayers
[a
].FObj
.Y
;
6594 Rect
:= PLAYER_RECT
;
6595 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6596 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6597 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6605 if vsMonster
then g_Mons_ForEach(monsUpdate
);
6608 // Åñëè åñòü âîçìîæíûå öåëè:
6609 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6610 if targets
<> nil then
6612 // Âûáèðàåì íàèëó÷øóþ öåëü:
6613 BestTarget
:= targets
[0];
6614 if Length(targets
) > 1 then
6615 for a
:= 1 to High(targets
) do
6616 if Compare(BestTarget
, targets
[a
]) = 1 then
6617 BestTarget
:= targets
[a
];
6619 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6620 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6621 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6623 Target
:= BestTarget
;
6625 if (Healthy() = 3) or ((Healthy() = 2)) then
6626 begin // Åñëè çäîðîâû - äîãîíÿåì
6627 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6628 SetAIFlag('GORIGHT', '1');
6629 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6630 SetAIFlag('GOLEFT', '1');
6633 begin // Åñëè ïîáèòû - óáåãàåì
6634 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6635 SetAIFlag('GORIGHT', '1');
6636 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6637 SetAIFlag('GOLEFT', '1');
6640 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6641 SelectWeapon(Abs(x1
-Target
.cX
));
6646 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6647 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6648 if Target
.UID
<> 0 then
6650 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6651 Target
.Y
+ Target
.Rect
.Y
) then
6652 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6653 if (Healthy() = 3) or ((Healthy() = 2)) then
6654 begin // Åñëè çäîðîâû - äîãîíÿåì
6655 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6656 SetAIFlag('GORIGHT', '1');
6657 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6658 SetAIFlag('GOLEFT', '1');
6661 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6663 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6664 SetAIFlag('GORIGHT', '1');
6665 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6666 SetAIFlag('GOLEFT', '1');
6670 begin // Öåëü ïîêà íà "ýêðàíå"
6671 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
6672 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6673 FLastVisible
:= gTime
;
6674 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
6675 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6677 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6678 SetAIFlag('GORIGHT', '1');
6679 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6680 SetAIFlag('GOLEFT', '1');
6684 // Âûáèðàåì óãîë ââåðõ:
6685 if FDirection
= TDirection
.D_LEFT
then
6686 angle
:= ANGLE_LEFTUP
6688 angle
:= ANGLE_RIGHTUP
;
6690 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6691 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6693 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6694 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6695 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6696 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6697 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6698 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6699 begin // òî íóæíî ñòðåëÿòü ââåðõ
6700 SetAIFlag('NEEDFIRE', '1');
6701 SetAIFlag('NEEDSEEUP', '1');
6704 // Âûáèðàåì óãîë âíèç:
6705 if FDirection
= TDirection
.D_LEFT
then
6706 angle
:= ANGLE_LEFTDOWN
6708 angle
:= ANGLE_RIGHTDOWN
;
6710 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6711 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6713 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6714 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6715 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6716 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6717 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6718 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6719 begin // òî íóæíî ñòðåëÿòü âíèç
6720 SetAIFlag('NEEDFIRE', '1');
6721 SetAIFlag('NEEDSEEDOWN', '1');
6724 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
6725 if Target
.Visible
and
6726 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
6727 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
6729 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
6730 if ((FDirection
= TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) or
6731 ((FDirection
= TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6732 begin // òî íóæíî ñòðåëÿòü âïåðåä
6733 SetAIFlag('NEEDFIRE', '1');
6734 SetAIFlag('NEEDSEEDOWN', '');
6735 SetAIFlag('NEEDSEEUP', '');
6737 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
6738 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
6739 if GetRnd(FDifficult
.CloseJump
) then
6740 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
6741 if Abs(FObj
.X
-Target
.X
) < 128 then
6745 if Random(a
) = 0 then
6746 SetAIFlag('NEEDJUMP', '1');
6750 // Åñëè öåëü âñå åùå åñòü:
6751 if Target
.UID
<> 0 then
6752 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
6753 Target
.UID
:= 0 // òî çàáûòü öåëü
6754 else // Åñëè âèäåëè íåäàâíî
6755 begin // íî öåëü óáèëè
6756 if Target
.IsPlayer
then
6757 begin // Öåëü - èãðîê
6758 pla
:= g_Player_Get(Target
.UID
);
6759 if (pla
= nil) or (not pla
.alive
) or pla
.NoTarget
or
6760 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
6761 Target
.UID
:= 0; // òî çàáûòü öåëü
6764 begin // Öåëü - ìîíñòð
6765 mon
:= g_Monsters_ByUID(Target
.UID
);
6766 if (mon
= nil) or (not mon
.alive
) then
6767 Target
.UID
:= 0; // òî çàáûòü öåëü
6770 end; // if Target.UID <> 0
6772 FTargetUID
:= Target
.UID
;
6774 // Åñëè âîçìîæíûõ öåëåé íåò:
6775 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
6776 if targets
= nil then
6777 if GetAIFlag('ATTACKLEFT') <> '' then
6778 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
6779 RemoveAIFlag('ATTACKLEFT');
6781 SetAIFlag('NEEDJUMP', '1');
6783 if RunDirection() = TDirection
.D_RIGHT
then
6784 begin // Èäåì íå â òó ñòîðîíó
6785 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6786 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
6787 SetAIFlag('NEEDFIRE', '1');
6788 SetAIFlag('GOLEFT', '1');
6792 begin // Èäåì â íóæíóþ ñòîðîíó
6793 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6794 SetAIFlag('NEEDFIRE', '1');
6795 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6796 SetAIFlag('GORIGHT', '1');
6800 if GetAIFlag('ATTACKRIGHT') <> '' then
6801 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
6802 RemoveAIFlag('ATTACKRIGHT');
6804 SetAIFlag('NEEDJUMP', '1');
6806 if RunDirection() = TDirection
.D_LEFT
then
6807 begin // Èäåì íå â òó ñòîðîíó
6808 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6809 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
6810 SetAIFlag('NEEDFIRE', '1');
6811 SetAIFlag('GORIGHT', '1');
6816 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6817 SetAIFlag('NEEDFIRE', '1');
6818 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6819 SetAIFlag('GOLEFT', '1');
6823 //HACK! (does it belongs there?)
6824 RealizeCurrentWeapon();
6826 // Åñëè åñòü âîçìîæíûå öåëè:
6827 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
6828 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
6829 for a
:= 0 to High(targets
) do
6831 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
6832 if GetRnd(FDifficult
.DiagFire
) then
6834 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
6835 if FDirection
= TDirection
.D_LEFT
then
6836 angle
:= ANGLE_LEFTUP
6838 angle
:= ANGLE_RIGHTUP
;
6840 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6841 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6843 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6844 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6845 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6846 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6847 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6849 SetAIFlag('NEEDFIRE', '1');
6850 SetAIFlag('NEEDSEEUP', '1');
6853 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
6854 if FDirection
= TDirection
.D_LEFT
then
6855 angle
:= ANGLE_LEFTDOWN
6857 angle
:= ANGLE_RIGHTDOWN
;
6859 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6860 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6862 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6863 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6864 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6865 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6866 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6868 SetAIFlag('NEEDFIRE', '1');
6869 SetAIFlag('NEEDSEEDOWN', '1');
6873 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
6874 if targets
[a
].Line
and targets
[a
].Visible
and
6875 (((FDirection
= TDirection
.D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
6876 ((FDirection
= TDirection
.D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
6878 SetAIFlag('NEEDFIRE', '1');
6883 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
6884 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
6885 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
6886 40+GetInterval(FDifficult
.Cover
, 40)) then
6887 SetAIFlag('NEEDJUMP', '1');
6889 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
6890 ammo
:= GetAmmoByWeapon(FCurrWeap
);
6891 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
6892 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
6894 SetAIFlag('SELECTWEAPON', '1');
6896 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
6897 if GetAIFlag('SELECTWEAPON') = '1' then
6900 RemoveAIFlag('SELECTWEAPON');
6904 procedure TBot
.Update();
6917 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
6918 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
6920 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
6922 if g_debug_BotAIOff
= 3 then
6932 RealizeCurrentWeapon();
6939 procedure TBot
.ReleaseKey(Key
: Byte);
6948 function TBot
.KeyPressed(Key
: Word): Boolean;
6950 Result
:= FKeys
[Key
].Pressed
;
6953 function TBot
.GetAIFlag(aName
: String20
): String20
;
6959 aName
:= LowerCase(aName
);
6961 if FAIFlags
<> nil then
6962 for a
:= 0 to High(FAIFlags
) do
6963 if LowerCase(FAIFlags
[a
].Name
) = aName
then
6965 Result
:= FAIFlags
[a
].Value
;
6970 procedure TBot
.RemoveAIFlag(aName
: String20
);
6974 if FAIFlags
= nil then Exit
;
6976 aName
:= LowerCase(aName
);
6978 for a
:= 0 to High(FAIFlags
) do
6979 if LowerCase(FAIFlags
[a
].Name
) = aName
then
6981 if a
<> High(FAIFlags
) then
6982 for b
:= a
to High(FAIFlags
)-1 do
6983 FAIFlags
[b
] := FAIFlags
[b
+1];
6985 SetLength(FAIFlags
, Length(FAIFlags
)-1);
6990 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
6998 aName
:= LowerCase(aName
);
7000 if FAIFlags
<> nil then
7001 for a
:= 0 to High(FAIFlags
) do
7002 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7008 if ok
then FAIFlags
[a
].Value
:= fValue
7011 SetLength(FAIFlags
, Length(FAIFlags
)+1);
7012 with FAIFlags
[High(FAIFlags
)] do
7020 procedure TBot
.UpdateMove
;
7022 procedure GoLeft(Time
: Word = 1);
7024 ReleaseKey(KEY_LEFT
);
7025 ReleaseKey(KEY_RIGHT
);
7026 PressKey(KEY_LEFT
, Time
);
7027 SetDirection(TDirection
.D_LEFT
);
7030 procedure GoRight(Time
: Word = 1);
7032 ReleaseKey(KEY_LEFT
);
7033 ReleaseKey(KEY_RIGHT
);
7034 PressKey(KEY_RIGHT
, Time
);
7035 SetDirection(TDirection
.D_RIGHT
);
7038 function Rnd(a
: Word): Boolean;
7040 Result
:= Random(a
) = 0;
7043 procedure Turn(Time
: Word = 1200);
7045 if RunDirection() = TDirection
.D_LEFT
then GoRight(Time
) else GoLeft(Time
);
7050 ReleaseKey(KEY_LEFT
);
7051 ReleaseKey(KEY_RIGHT
);
7054 function CanRunLeft(): Boolean;
7056 Result
:= not CollideLevel(-1, 0);
7059 function CanRunRight(): Boolean;
7061 Result
:= not CollideLevel(1, 0);
7064 function CanRun(): Boolean;
7066 if RunDirection() = TDirection
.D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
7069 procedure Jump(Time
: Word = 30);
7071 PressKey(KEY_JUMP
, Time
);
7074 function NearHole(): Boolean;
7078 { TODO 5 : Ëåñòíèöû }
7079 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7080 for x
:= 1 to PLAYER_RECT
.Width
do
7081 if (not StayOnStep(x
*sx
, 0)) and
7082 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7083 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7092 function BorderHole(): Boolean;
7096 { TODO 5 : Ëåñòíèöû }
7097 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7098 for x
:= 1 to PLAYER_RECT
.Width
do
7099 if (not StayOnStep(x
*sx
, 0)) and
7100 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7101 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7103 for xx
:= x
to x
+32 do
7104 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
7114 function NearDeepHole(): Boolean;
7120 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7123 for x
:= 1 to PLAYER_RECT
.Width
do
7124 if (not StayOnStep(x
*sx
, 0)) and
7125 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7126 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7128 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7130 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
7135 end else Result
:= False;
7138 function OverDeepHole(): Boolean;
7145 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7147 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
7154 function OnGround(): Boolean;
7156 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
7159 function OnLadder(): Boolean;
7161 Result
:= FullInStep(0, 0);
7164 function BelowLadder(): Boolean;
7166 Result
:= (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
7167 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7168 (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
7169 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7172 function BelowLiftUp(): Boolean;
7174 Result
:= ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
7175 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7176 ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
7177 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7180 function OnTopLift(): Boolean;
7182 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7185 function CanJumpOver(): Boolean;
7189 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7193 if not CollideLevel(sx
, 0) then Exit
;
7195 for y
:= 1 to BOT_MAXJUMP
do
7196 if CollideLevel(0, -y
) then Exit
else
7197 if not CollideLevel(sx
, -y
) then
7204 function CanJumpUp(Dist
: ShortInt): Boolean;
7211 if CollideLevel(Dist
, 0) then Exit
;
7214 for y
:= 0 to BOT_MAXJUMP
do
7215 if CollideLevel(Dist
, -y
) then
7224 for yy
:= y
+1 to BOT_MAXJUMP
do
7225 if not CollideLevel(Dist
, -yy
) then
7234 for y
:= 0 to BOT_MAXJUMP
do
7235 if CollideLevel(0, -y
) then
7243 if y
< yy
then Exit
;
7248 function IsSafeTrigger(): Boolean;
7253 if gTriggers
= nil then
7255 for a
:= 0 to High(gTriggers
) do
7256 if Collide(gTriggers
[a
].X
,
7259 gTriggers
[a
].Height
) and
7260 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
7261 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
7262 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
7263 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
7264 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
7269 // Âîçìîæíî, íàæèìàåì êíîïêó:
7270 if Rnd(16) and IsSafeTrigger() then
7273 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7274 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7276 ReleaseKey(KEY_LEFT
);
7277 ReleaseKey(KEY_RIGHT
);
7281 // Èäåì âëåâî, åñëè íàäî áûëî:
7282 if GetAIFlag('GOLEFT') <> '' then
7284 RemoveAIFlag('GOLEFT');
7285 if CanRunLeft() then
7289 // Èäåì âïðàâî, åñëè íàäî áûëî:
7290 if GetAIFlag('GORIGHT') <> '' then
7292 RemoveAIFlag('GORIGHT');
7293 if CanRunRight() then
7297 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7298 if FObj
.X
< -32 then
7301 if FObj
.X
+32 > gMapInfo
.Width
then
7304 // Ïðûãàåì, åñëè íàäî áûëî:
7305 if GetAIFlag('NEEDJUMP') <> '' then
7308 RemoveAIFlag('NEEDJUMP');
7311 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7312 if GetAIFlag('NEEDSEEUP') <> '' then
7315 ReleaseKey(KEY_DOWN
);
7316 PressKey(KEY_UP
, 20);
7317 RemoveAIFlag('NEEDSEEUP');
7320 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7321 if GetAIFlag('NEEDSEEDOWN') <> '' then
7324 ReleaseKey(KEY_DOWN
);
7325 PressKey(KEY_DOWN
, 20);
7326 RemoveAIFlag('NEEDSEEDOWN');
7329 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7330 if GetAIFlag('GOINHOLE') <> '' then
7331 if not OnGround() then
7333 ReleaseKey(KEY_LEFT
);
7334 ReleaseKey(KEY_RIGHT
);
7335 RemoveAIFlag('GOINHOLE');
7336 SetAIFlag('FALLINHOLE', '1');
7339 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7340 if GetAIFlag('FALLINHOLE') <> '' then
7342 RemoveAIFlag('FALLINHOLE');
7344 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7345 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7346 if GetAIFlag('FALLINHOLE') = '' then
7347 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7353 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7355 CanJumpUp(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*32) and
7359 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7360 if OnGround() and NearHole() then
7361 if NearDeepHole() then // Åñëè ýòî áåçäíà
7363 0..3: Turn(); // Áåæèì îáðàòíî
7364 4: Jump(); // Ïðûãàåì
7365 5: begin // Ïðûãàåì îáðàòíî
7370 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7371 if GetAIFlag('GOINHOLE') = '' then
7373 0: Turn(); // Íå íóæíî òóäà
7374 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7375 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7376 if BorderHole() then
7377 SetAIFlag('GOINHOLE', '1');
7380 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7381 if (not CanRun()) and OnGround() then
7383 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7384 if CanJumpOver() or OnLadder() then
7386 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7387 if Random(2) = 0 then
7389 if IsSafeTrigger() then
7395 // Îñòàëîñü ìàëî âîçäóõà:
7396 if FAir
< 36 * 2 then
7399 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7400 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7401 if BodyInAcid(0, 0) then
7405 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7407 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7408 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7411 {function TBot.NeedItem(Item: Byte): Byte;
7416 procedure TBot
.SelectWeapon(Dist
: Integer);
7420 function HaveAmmo(weapon
: Byte): Boolean;
7423 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7424 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7425 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7426 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7427 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7428 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7429 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7430 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7431 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7432 else Result
:= True;
7437 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7439 if Dist
> BOT_LONGDIST
then
7440 begin // Äàëüíèé áîé
7442 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7444 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7448 else //if Dist > BOT_UNSAFEDIST then
7449 begin // Áëèæíèé áîé
7451 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7453 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7460 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7462 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7468 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7470 Result
:= inherited PickItem(ItemType
, force
, remove
);
7472 if Result
then SetAIFlag('SELECTWEAPON', '1');
7475 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7477 Result
:= inherited Heal(value
, Soft
);
7480 function TBot
.Healthy(): Byte;
7482 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7483 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7484 else if (FHealth
> 50) then Result
:= 2
7485 else if (FHealth
> 20) then Result
:= 1
7489 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7491 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7492 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7495 procedure TBot
.OnDamage(Angle
: SmallInt);
7503 if (Angle
= 0) or (Angle
= 180) then
7506 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7507 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7509 pla
:= g_Player_Get(FLastSpawnerUID
);
7510 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7511 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7514 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7515 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7517 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
7518 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7519 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7524 SetAIFlag('ATTACKLEFT', '1')
7526 SetAIFlag('ATTACKRIGHT', '1');
7530 function TBot
.RunDirection(): TDirection
;
7532 if Abs(Vel
.X
) >= 1 then
7534 if Vel
.X
> 0 then Result
:= TDirection
.D_RIGHT
else Result
:= TDirection
.D_LEFT
;
7536 Result
:= FDirection
;
7539 function TBot
.GetRnd(a
: Byte): Boolean;
7541 if a
= 0 then Result
:= False
7542 else if a
= 255 then Result
:= True
7543 else Result
:= Random(256) > 255-a
;
7546 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7548 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7552 procedure TDifficult
.save (st
: TStream
);
7554 utils
.writeInt(st
, Byte(DiagFire
));
7555 utils
.writeInt(st
, Byte(InvisFire
));
7556 utils
.writeInt(st
, Byte(DiagPrecision
));
7557 utils
.writeInt(st
, Byte(FlyPrecision
));
7558 utils
.writeInt(st
, Byte(Cover
));
7559 utils
.writeInt(st
, Byte(CloseJump
));
7560 st
.WriteBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7561 st
.WriteBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7564 procedure TDifficult
.load (st
: TStream
);
7566 DiagFire
:= utils
.readByte(st
);
7567 InvisFire
:= utils
.readByte(st
);
7568 DiagPrecision
:= utils
.readByte(st
);
7569 FlyPrecision
:= utils
.readByte(st
);
7570 Cover
:= utils
.readByte(st
);
7571 CloseJump
:= utils
.readByte(st
);
7572 st
.ReadBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7573 st
.ReadBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7577 procedure TBot
.SaveState (st
: TStream
);
7582 inherited SaveState(st
);
7583 utils
.writeSign(st
, 'BOT0');
7585 utils
.writeInt(st
, Byte(FSelectedWeapon
));
7587 utils
.writeInt(st
, Word(FTargetUID
));
7588 // Âðåìÿ ïîòåðè öåëè
7589 utils
.writeInt(st
, LongWord(FLastVisible
));
7590 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7591 dw
:= Length(FAIFlags
);
7592 utils
.writeInt(st
, LongInt(dw
));
7594 for i
:= 0 to dw
-1 do
7596 utils
.writeStr(st
, FAIFlags
[i
].Name
, 20);
7597 utils
.writeStr(st
, FAIFlags
[i
].Value
, 20);
7599 // Íàñòðîéêè ñëîæíîñòè
7600 FDifficult
.save(st
);
7604 procedure TBot
.LoadState (st
: TStream
);
7609 inherited LoadState(st
);
7610 if not utils
.checkSign(st
, 'BOT0') then raise XStreamError
.Create('invalid bot signature');
7612 FSelectedWeapon
:= utils
.readByte(st
);
7614 FTargetUID
:= utils
.readWord(st
);
7615 // Âðåìÿ ïîòåðè öåëè
7616 FLastVisible
:= utils
.readLongWord(st
);
7617 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7618 dw
:= utils
.readLongInt(st
);
7619 if (dw
< 0) or (dw
> 16384) then raise XStreamError
.Create('invalid number of bot AI flags');
7620 SetLength(FAIFlags
, dw
);
7622 for i
:= 0 to dw
-1 do
7624 FAIFlags
[i
].Name
:= utils
.readStr(st
, 20);
7625 FAIFlags
[i
].Value
:= utils
.readStr(st
, 20);
7627 // Íàñòðîéêè ñëîæíîñòè
7628 FDifficult
.load(st
);
7633 conRegVar('cheat_berserk_autoswitch', @gBerserkAutoswitch
, 'autoswitch to fist when berserk pack taken', '', true, true);