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 g_Game_IsNet
then
4484 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4485 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4487 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4488 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4493 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4496 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4497 else if (not NoMove
) then
4499 GameX
:= gMapInfo
.Width
div 2;
4500 GameY
:= gMapInfo
.Height
div 2;
4509 FWantsInGame
:= False;
4514 if Self
= gPlayer1
then
4519 if Self
= gPlayer2
then
4526 if g_Game_IsNet
then
4527 MH_SEND_PlayerStats(FUID
);
4530 procedure TPlayer
.SwitchNoClip
;
4534 FGhost
:= not FGhost
;
4535 FPhysics
:= not FGhost
;
4547 procedure TPlayer
.Run(Direction
: TDirection
);
4551 if MAX_RUNVEL
> 8 then
4555 if Direction
= TDirection
.D_LEFT
then
4557 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4558 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4561 if FObj
.Vel
.X
< MAX_RUNVEL
then
4562 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4564 // Âîçìîæíî, ïèíàåì êóñêè:
4565 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4567 b
:= Abs(FObj
.Vel
.X
);
4568 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4569 for a
:= 0 to High(gGibs
) do
4571 if gGibs
[a
].alive
and
4572 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4573 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4576 if FObj
.Vel
.X
< 0 then
4578 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4582 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4584 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4592 procedure TPlayer
.SeeDown();
4594 SetAction(A_SEEDOWN
);
4596 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4598 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4601 procedure TPlayer
.SeeUp();
4605 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4607 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4610 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4618 A_ATTACK
: Prior
:= 2;
4619 A_SEEUP
: Prior
:= 1;
4620 A_SEEDOWN
: Prior
:= 1;
4621 A_ATTACKUP
: Prior
:= 2;
4622 A_ATTACKDOWN
: Prior
:= 2;
4627 if (Prior
> FActionPrior
) or Force
then
4628 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4630 FActionPrior
:= Prior
;
4631 FActionAnim
:= Action
;
4632 FActionForce
:= Force
;
4633 FActionChanged
:= True;
4636 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4639 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4641 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4642 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4643 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4644 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4647 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4654 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4656 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4657 if g_Game_IsServer
and g_Game_IsNet
then
4658 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4662 FJustTeleported
:= True;
4667 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4669 Anim
:= TAnimation
.Create(ID
, False, 3);
4672 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4673 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4674 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4675 if g_Game_IsServer
and g_Game_IsNet
then
4676 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4677 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4681 FObj
.X
:= X
-PLAYER_RECT
.X
;
4682 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4683 if FAlive
and FGhost
then
4689 if not g_Game_IsNet
then
4693 SetDirection(TDirection
.D_LEFT
);
4699 SetDirection(TDirection
.D_RIGHT
);
4705 if FDirection
= TDirection
.D_RIGHT
then
4707 SetDirection(TDirection
.D_LEFT
);
4712 SetDirection(TDirection
.D_RIGHT
);
4718 if not silent
and (Anim
<> nil) then
4720 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4721 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4724 if g_Game_IsServer
and g_Game_IsNet
then
4725 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4726 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4733 function nonz(a
: Single): Single;
4741 procedure TPlayer
.Update();
4744 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
4745 blockmon
, headwater
, dospawn
: Boolean;
4750 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
4751 AnyServer
:= g_Game_IsServer
;
4753 if g_Game_IsClient
and (NetInterpLevel
> 0) then
4754 DoLerp(NetInterpLevel
+ 1)
4760 if FClientID
>= 0 then
4762 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
4763 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
4764 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
4773 if FAlive
and (FPunchAnim
<> nil) then
4774 FPunchAnim
.Update();
4776 if FAlive
and (gFly
or FJetpack
) then
4779 if FDirection
= TDirection
.D_LEFT
then
4784 if FAlive
and (not FGhost
) then
4786 if FKeys
[KEY_UP
].Pressed
then
4788 if FKeys
[KEY_DOWN
].Pressed
then
4792 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
4795 i
:= g_basic
.Sign(FIncCam
);
4796 FIncCam
:= Abs(FIncCam
);
4797 DecMin(FIncCam
, 5, 0);
4798 FIncCam
:= FIncCam
*i
;
4801 // no need to do that each second frame, weapon queue will take care of it
4802 if FAlive
and FKeys
[KEY_NEXTWEAPON
].Pressed
and AnyServer
then NextWeapon();
4803 if FAlive
and FKeys
[KEY_PREVWEAPON
].Pressed
and AnyServer
then PrevWeapon();
4805 if gTime
mod (GAME_TICK
*2) <> 0 then
4807 if (FObj
.Vel
.X
= 0) and FAlive
then
4809 if FKeys
[KEY_LEFT
].Pressed
then
4810 Run(TDirection
.D_LEFT
);
4811 if FKeys
[KEY_RIGHT
].Pressed
then
4812 Run(TDirection
.D_RIGHT
);
4817 g_Obj_Move(@FObj
, True, True, True);
4818 positionChanged(); // this updates spatial accelerators
4824 FActionChanged
:= False;
4828 // Let alive player do some actions
4829 if FKeys
[KEY_LEFT
].Pressed
then Run(TDirection
.D_LEFT
);
4830 if FKeys
[KEY_RIGHT
].Pressed
then Run(TDirection
.D_RIGHT
);
4831 //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
4832 //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
4833 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire();
4834 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
4835 if FKeys
[KEY_JUMP
].Pressed
then Jump()
4838 if AnyServer
and FJetpack
then
4842 if NetServer
then MH_SEND_PlayerStats(FUID
);
4844 FCanJetpack
:= True;
4851 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
4853 if FKeys
[k
].Pressed
then
4861 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
4864 if (FTime
[T_RESPAWN
] <= gTime
) and
4865 gGameOn
and (not FAlive
) then
4867 if (g_Player_GetCount() > 1) then
4871 gExit
:= EXIT_RESTART
;
4876 // Dead spectator actions
4879 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
4880 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
4884 if (FSpectatePlayer
>= High(gPlayers
)) then
4885 FSpectatePlayer
:= -1
4889 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
4890 if gPlayers
[I
] <> nil then
4891 if gPlayers
[I
].alive
then
4892 if gPlayers
[I
].UID
<> FUID
then
4894 FSpectatePlayer
:= I
;
4899 if not SetSpect
then FSpectatePlayer
:= -1;
4910 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
4912 FYTo
:= FObj
.Y
- 32;
4913 FSpectatePlayer
:= -1;
4915 if FKeys
[KEY_DOWN
].Pressed
then
4917 FYTo
:= FObj
.Y
+ 32;
4918 FSpectatePlayer
:= -1;
4920 if FKeys
[KEY_LEFT
].Pressed
then
4922 FXTo
:= FObj
.X
- 32;
4923 FSpectatePlayer
:= -1;
4925 if FKeys
[KEY_RIGHT
].Pressed
then
4927 FXTo
:= FObj
.X
+ 32;
4928 FSpectatePlayer
:= -1;
4931 if (FXTo
< -64) then
4933 else if (FXTo
> gMapInfo
.Width
+ 32) then
4934 FXTo
:= gMapInfo
.Width
+ 32;
4935 if (FYTo
< -72) then
4937 else if (FYTo
> gMapInfo
.Height
+ 32) then
4938 FYTo
:= gMapInfo
.Height
+ 32;
4943 g_Obj_Move(@FObj
, True, True, True);
4944 positionChanged(); // this updates spatial accelerators
4951 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
4952 if gPlayers
[FSpectatePlayer
] <> nil then
4953 if gPlayers
[FSpectatePlayer
].alive
then
4955 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
4956 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
4960 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
4961 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
4962 PANEL_BLOCKMON
, True);
4963 headwater
:= HeadInLiquid(0, 0);
4965 // Ñîïðîòèâëåíèå âîçäóõà:
4966 if (not FAlive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
4967 if FObj
.Vel
.X
<> 0 then
4968 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
4970 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
4971 DecMin(FPain
, 5, 0);
4972 DecMin(FPickup
, 1, 0);
4974 if FAlive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
4976 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
4977 FMegaRulez
[MR_SUIT
] := 0;
4978 FMegaRulez
[MR_INVUL
] := 0;
4979 FMegaRulez
[MR_INVIS
] := 0;
4980 Kill(K_FALLKILL
, 0, HIT_FALL
);
4987 if FCurrWeap
= WEAPON_SAW
then
4988 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
4989 FSawSoundSelect
.IsPlaying()) then
4990 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
4993 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
4994 (not FJetSoundOff
.IsPlaying()) then
4996 FJetSoundFly
.SetPosition(0);
4997 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
5000 for b
:= WP_FIRST
to WP_LAST
do
5001 if FReloading
[b
] > 0 then
5007 if FShellTimer
> -1 then
5008 if FShellTimer
= 0 then
5010 if FShellType
= SHELL_SHELL
then
5011 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5012 GameVelX
, GameVelY
-2, SHELL_SHELL
)
5013 else if FShellType
= SHELL_DBLSHELL
then
5015 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5016 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
5017 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5018 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
5021 end else Dec(FShellTimer
);
5023 if (FBFGFireCounter
> -1) then
5024 if FBFGFireCounter
= 0 then
5028 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
5029 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
5030 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
5031 yd
:= wy
+firediry();
5032 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
5033 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
5034 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5035 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5036 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5039 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
5040 FBFGFireCounter
:= -1;
5043 FBFGFireCounter
:= 0
5045 Dec(FBFGFireCounter
);
5047 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
5049 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
5051 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
5054 if (headwater
or blockmon
) then
5060 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
5063 else if (FAir
mod 31 = 0) and not blockmon
then
5065 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
5066 if Random(2) = 0 then
5067 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5069 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5071 end else if FAir
< AIR_DEF
then
5074 if FFireTime
> 0 then
5076 if BodyInLiquid(0, 0) then
5081 else if FMegaRulez
[MR_SUIT
] >= gTime
then
5083 if FMegaRulez
[MR_SUIT
] = gTime
then
5090 if FFirePainTime
<= 0 then
5092 if g_Game_IsServer
then
5093 Damage(5, FFireAttacker
, 0, 0, HIT_FLAME
);
5094 FFirePainTime
:= 18;
5096 FFirePainTime
:= FFirePainTime
- 1;
5097 FFireTime
:= FFireTime
- 1;
5098 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
5099 MH_SEND_PlayerStats(FUID
);
5103 if FDamageBuffer
> 0 then
5105 if FDamageBuffer
>= 9 then
5109 if FDamageBuffer
< 30 then i
:= 9
5110 else if FDamageBuffer
< 100 then i
:= 18
5114 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
5115 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
5116 FHealth
:= FHealth
-ii
;
5119 FHealth
:= FHealth
+FArmor
;
5124 if FHealth
<= 0 then
5125 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
5126 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
5127 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
5131 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
5132 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
5133 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
5134 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
5141 end; // if FAlive then ...
5143 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
5145 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
5146 FModel
.GetCurrentAnimation
.MinLength
:= i
;
5147 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
5148 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
5150 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
5151 then SetAction(A_STAND
, True);
5153 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
5155 for b
:= Low(FKeys
) to High(FKeys
) do
5156 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
5160 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5162 x
:= FObj
.X
+PLAYER_RECT
.X
;
5163 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
5164 w
:= PLAYER_RECT
.Width
;
5165 h
:= PLAYER_RECT
.Height
;
5169 procedure TPlayer
.moveBy (dx
, dy
: Integer); inline;
5171 if (dx
<> 0) or (dy
<> 0) then
5180 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
5182 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5183 FObj
.Y
+PLAYER_RECT
.Y
,
5190 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
5192 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5193 FObj
.Y
+PLAYER_RECT
.Y
,
5197 Panel
.Width
, Panel
.Height
);
5200 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
5202 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
5203 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
5204 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
5205 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
5208 function g_Player_ValidName(Name
: string): Boolean;
5214 if gPlayers
= nil then Exit
;
5216 for a
:= 0 to High(gPlayers
) do
5217 if gPlayers
[a
] <> nil then
5218 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
5225 procedure TPlayer
.SetDirection(Direction
: TDirection
);
5229 d
:= FModel
.Direction
;
5231 FModel
.Direction
:= Direction
;
5232 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
5234 FDirection
:= Direction
;
5237 function TPlayer
.GetKeys(): Byte;
5241 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
5242 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
5243 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
5245 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
5246 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
5249 procedure TPlayer
.Use();
5253 if FTime
[T_USE
] > gTime
then Exit
;
5255 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
5256 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
5258 for a
:= 0 to High(gPlayers
) do
5259 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
5260 gPlayers
[a
].alive
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
5261 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5262 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
5264 gPlayers
[a
].Touch();
5265 if g_Game_IsNet
and g_Game_IsServer
then
5266 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
5269 FTime
[T_USE
] := gTime
+120;
5272 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
5276 WX
, WY
, XD
, YD
: Integer;
5287 if R_BERSERK
in FRulez
then
5289 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5290 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
5291 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
5294 locobj
.rect
.Width
:= 39;
5295 locobj
.rect
.Height
:= 52;
5296 locobj
.Vel
.X
:= (xd
-wx
) div 2;
5297 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
5298 locobj
.Accel
.X
:= xd
-wx
;
5299 locobj
.Accel
.y
:= yd
-wy
;
5303 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
5304 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
5306 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
5310 FPain
:= min(FPain
+ 25, 50);
5312 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
5317 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5318 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
5320 FSawSoundSelect
.Stop();
5322 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
5324 else if not FSawSoundHit
.IsPlaying() then
5326 FSawSoundSelect
.Stop();
5327 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
5334 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
5335 FFireAngle
:= FAngle
;
5337 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5338 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5343 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5344 FFireAngle
:= FAngle
;
5347 FShellType
:= SHELL_SHELL
;
5352 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5353 FFireAngle
:= FAngle
;
5356 FShellType
:= SHELL_DBLSHELL
;
5361 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5362 FFireAngle
:= FAngle
;
5364 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5365 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5368 WEAPON_ROCKETLAUNCHER
:
5370 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5371 FFireAngle
:= FAngle
;
5377 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5378 FFireAngle
:= FAngle
;
5384 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5385 FFireAngle
:= FAngle
;
5389 WEAPON_SUPERPULEMET
:
5391 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5392 FFireAngle
:= FAngle
;
5394 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5395 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5398 WEAPON_FLAMETHROWER
:
5400 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
5401 FFireAngle
:= FAngle
;
5408 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5409 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5410 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5413 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5415 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5416 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5419 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5423 if NetInterpLevel
< 1 then
5433 AX
:= Abs(FXTo
- FObj
.X
);
5434 AY
:= Abs(FYTo
- FObj
.Y
);
5435 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5437 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5442 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5444 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5445 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5446 PANEL_LIFTUP
, False) then Result
:= -1
5448 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5449 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5450 PANEL_LIFTDOWN
, False) then Result
:= 1
5454 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5461 if Flag
= FLAG_NONE
then
5464 if not g_Game_IsServer
then Exit
;
5466 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5467 if (Flag
= FTeam
) and
5468 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5469 (FFlag
<> FLAG_NONE
) then
5471 if FFlag
= FLAG_RED
then
5472 s
:= _lc
[I_PLAYER_FLAG_RED
]
5474 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5476 evtype
:= FLAG_STATE_SCORED
;
5478 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5479 Insert('.', ts
, Length(ts
) + 1 - 3);
5480 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5482 g_Map_ResetFlag(FFlag
);
5483 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5485 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5488 if g_Game_IsNet
then
5490 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5494 gFlags
[FFlag
].CaptureTime
:= 0;
5499 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5500 if (Flag
= FTeam
) and
5501 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5503 if Flag
= FLAG_RED
then
5504 s
:= _lc
[I_PLAYER_FLAG_RED
]
5506 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5508 evtype
:= FLAG_STATE_RETURNED
;
5509 gFlags
[Flag
].CaptureTime
:= 0;
5511 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5513 g_Map_ResetFlag(Flag
);
5514 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5517 if g_Game_IsNet
then
5519 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5525 // Ïîäîáðàë ÷óæîé ôëàã:
5526 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5530 if Flag
= FLAG_RED
then
5531 s
:= _lc
[I_PLAYER_FLAG_RED
]
5533 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5535 evtype
:= FLAG_STATE_CAPTURED
;
5537 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5539 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5541 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5544 if g_Game_IsNet
then
5546 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5552 procedure TPlayer
.SetFlag(Flag
: Byte);
5555 if FModel
<> nil then
5556 FModel
.SetFlag(FFlag
);
5559 function TPlayer
.DropFlag(): Boolean;
5564 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5566 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5567 with gFlags
[FFlag
] do
5571 Direction
:= FDirection
;
5572 State
:= FLAG_STATE_DROPPED
;
5574 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5575 (FObj
.Vel
.Y
div 2)-2+Random(5));
5576 positionChanged(); // this updates spatial accelerators
5578 if FFlag
= FLAG_RED
then
5579 s
:= _lc
[I_PLAYER_FLAG_RED
]
5581 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5583 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5584 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5586 if g_Game_IsNet
then
5587 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5593 procedure TPlayer
.GetSecret();
5598 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5600 Assert(Key
<= High(FKeys
));
5602 FKeys
[Key
].Pressed
:= True;
5603 FKeys
[Key
].Time
:= Time
;
5606 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5608 Result
:= FKeys
[K
].Pressed
;
5611 procedure TPlayer
.ReleaseKeys();
5615 for a
:= Low(FKeys
) to High(FKeys
) do
5617 FKeys
[a
].Pressed
:= False;
5622 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5626 function TPlayer
.firediry(): Integer;
5628 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5629 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5633 procedure TPlayer
.RememberState();
5637 FSavedState
.Health
:= FHealth
;
5638 FSavedState
.Armor
:= FArmor
;
5639 FSavedState
.Air
:= FAir
;
5640 FSavedState
.JetFuel
:= FJetFuel
;
5641 FSavedState
.CurrWeap
:= FCurrWeap
;
5642 FSavedState
.NextWeap
:= FNextWeap
;
5643 FSavedState
.NextWeapDelay
:= FNextWeapDelay
;
5646 FSavedState
.Ammo
[i
] := FAmmo
[i
];
5648 FSavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5650 FSavedState
.Rulez
:= FRulez
;
5651 FSavedState
.WaitRecall
:= True;
5654 procedure TPlayer
.RecallState();
5658 if not FSavedState
.WaitRecall
then Exit
;
5660 FHealth
:= FSavedState
.Health
;
5661 FArmor
:= FSavedState
.Armor
;
5662 FAir
:= FSavedState
.Air
;
5663 FJetFuel
:= FSavedState
.JetFuel
;
5664 FCurrWeap
:= FSavedState
.CurrWeap
;
5665 FNextWeap
:= FSavedState
.NextWeap
;
5666 FNextWeapDelay
:= FSavedState
.NextWeapDelay
;
5669 FAmmo
[i
] := FSavedState
.Ammo
[i
];
5671 FMaxAmmo
[i
] := FSavedState
.MaxAmmo
[i
];
5673 FRulez
:= FSavedState
.Rulez
;
5674 FSavedState
.WaitRecall
:= False;
5676 if gGameSettings
.GameType
= GT_SERVER
then
5677 MH_SEND_PlayerStats(FUID
);
5680 procedure TPlayer
.SaveState (st
: TStream
);
5686 utils
.writeSign(st
, 'PLYR');
5687 utils
.writeInt(st
, Byte(PLR_SAVE_VERSION
)); // version
5689 utils
.writeBool(st
, FIamBot
);
5691 utils
.writeInt(st
, Word(FUID
));
5693 utils
.writeStr(st
, FName
);
5695 utils
.writeInt(st
, Byte(FTeam
));
5697 utils
.writeBool(st
, FAlive
);
5698 // Èçðàñõîäîâàë ëè âñå æèçíè
5699 utils
.writeBool(st
, FNoRespawn
);
5701 if FDirection
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
5702 utils
.writeInt(st
, Byte(b
));
5704 utils
.writeInt(st
, LongInt(FHealth
));
5706 utils
.writeInt(st
, Byte(FLives
));
5708 utils
.writeInt(st
, LongInt(FArmor
));
5710 utils
.writeInt(st
, LongInt(FAir
));
5712 utils
.writeInt(st
, LongInt(FJetFuel
));
5714 utils
.writeInt(st
, LongInt(FPain
));
5716 utils
.writeInt(st
, LongInt(FKills
));
5718 utils
.writeInt(st
, LongInt(FMonsterKills
));
5720 utils
.writeInt(st
, LongInt(FFrags
));
5722 utils
.writeInt(st
, Byte(FFragCombo
));
5723 // Âðåìÿ ïîñëåäíåãî ôðàãà
5724 utils
.writeInt(st
, LongWord(FLastFrag
));
5726 utils
.writeInt(st
, LongInt(FDeath
));
5728 utils
.writeInt(st
, Byte(FFlag
));
5730 utils
.writeInt(st
, LongInt(FSecrets
));
5732 utils
.writeInt(st
, Byte(FCurrWeap
));
5734 utils
.writeInt(st
, Word(FNextWeap
));
5736 utils
.writeInt(st
, Byte(FNextWeapDelay
));
5737 // Âðåìÿ çàðÿäêè BFG
5738 utils
.writeInt(st
, SmallInt(FBFGFireCounter
));
5740 utils
.writeInt(st
, LongInt(FDamageBuffer
));
5741 // Ïîñëåäíèé óäàðèâøèé
5742 utils
.writeInt(st
, Word(FLastSpawnerUID
));
5743 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
5744 utils
.writeInt(st
, Byte(FLastHit
));
5746 Obj_SaveState(st
, @FObj
);
5747 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
5748 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FAmmo
[i
]));
5749 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
5750 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FMaxAmmo
[i
]));
5752 for i
:= WP_FIRST
to WP_LAST
do utils
.writeBool(st
, FWeapon
[i
]);
5753 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
5754 for i
:= WP_FIRST
to WP_LAST
do utils
.writeInt(st
, Word(FReloading
[i
]));
5756 utils
.writeBool(st
, (R_ITEM_BACKPACK
in FRulez
));
5757 // Íàëè÷èå êðàñíîãî êëþ÷à
5758 utils
.writeBool(st
, (R_KEY_RED
in FRulez
));
5759 // Íàëè÷èå çåëåíîãî êëþ÷à
5760 utils
.writeBool(st
, (R_KEY_GREEN
in FRulez
));
5761 // Íàëè÷èå ñèíåãî êëþ÷à
5762 utils
.writeBool(st
, (R_KEY_BLUE
in FRulez
));
5764 utils
.writeBool(st
, (R_BERSERK
in FRulez
));
5765 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
5766 for i
:= MR_SUIT
to MR_MAX
do utils
.writeInt(st
, LongWord(FMegaRulez
[i
]));
5767 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
5768 for i
:= T_RESPAWN
to T_FLAGCAP
do utils
.writeInt(st
, LongWord(FTime
[i
]));
5770 utils
.writeStr(st
, FModel
.Name
);
5772 utils
.writeInt(st
, Byte(FColor
.R
));
5773 utils
.writeInt(st
, Byte(FColor
.G
));
5774 utils
.writeInt(st
, Byte(FColor
.B
));
5778 procedure TPlayer
.LoadState (st
: TStream
);
5787 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
5788 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
5790 FIamBot
:= utils
.readBool(st
);
5792 FUID
:= utils
.readWord(st
);
5794 str
:= utils
.readStr(st
);
5795 if (self
<> gPlayer1
) and (self
<> gPlayer2
) then FName
:= str
;
5797 FTeam
:= utils
.readByte(st
);
5799 FAlive
:= utils
.readBool(st
);
5800 // Èçðàñõîäîâàë ëè âñå æèçíè
5801 FNoRespawn
:= utils
.readBool(st
);
5803 b
:= utils
.readByte(st
);
5804 if b
= 1 then FDirection
:= TDirection
.D_LEFT
else FDirection
:= TDirection
.D_RIGHT
; // b = 2
5806 FHealth
:= utils
.readLongInt(st
);
5808 FLives
:= utils
.readByte(st
);
5810 FArmor
:= utils
.readLongInt(st
);
5812 FAir
:= utils
.readLongInt(st
);
5814 FJetFuel
:= utils
.readLongInt(st
);
5816 FPain
:= utils
.readLongInt(st
);
5818 FKills
:= utils
.readLongInt(st
);
5820 FMonsterKills
:= utils
.readLongInt(st
);
5822 FFrags
:= utils
.readLongInt(st
);
5824 FFragCombo
:= utils
.readByte(st
);
5825 // Âðåìÿ ïîñëåäíåãî ôðàãà
5826 FLastFrag
:= utils
.readLongWord(st
);
5828 FDeath
:= utils
.readLongInt(st
);
5830 FFlag
:= utils
.readByte(st
);
5832 FSecrets
:= utils
.readLongInt(st
);
5834 FCurrWeap
:= utils
.readByte(st
);
5836 FNextWeap
:= utils
.readWord(st
);
5838 FNextWeapDelay
:= utils
.readByte(st
);
5839 // Âðåìÿ çàðÿäêè BFG
5840 FBFGFireCounter
:= utils
.readSmallInt(st
);
5842 FDamageBuffer
:= utils
.readLongInt(st
);
5843 // Ïîñëåäíèé óäàðèâøèé
5844 FLastSpawnerUID
:= utils
.readWord(st
);
5845 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
5846 FLastHit
:= utils
.readByte(st
);
5848 Obj_LoadState(@FObj
, st
);
5849 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
5850 for i
:= A_BULLETS
to A_HIGH
do FAmmo
[i
] := utils
.readWord(st
);
5851 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
5852 for i
:= A_BULLETS
to A_HIGH
do FMaxAmmo
[i
] := utils
.readWord(st
);
5854 for i
:= WP_FIRST
to WP_LAST
do FWeapon
[i
] := utils
.readBool(st
);
5855 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
5856 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := utils
.readWord(st
);
5858 if utils
.readBool(st
) then Include(FRulez
, R_ITEM_BACKPACK
);
5859 // Íàëè÷èå êðàñíîãî êëþ÷à
5860 if utils
.readBool(st
) then Include(FRulez
, R_KEY_RED
);
5861 // Íàëè÷èå çåëåíîãî êëþ÷à
5862 if utils
.readBool(st
) then Include(FRulez
, R_KEY_GREEN
);
5863 // Íàëè÷èå ñèíåãî êëþ÷à
5864 if utils
.readBool(st
) then Include(FRulez
, R_KEY_BLUE
);
5866 if utils
.readBool(st
) then Include(FRulez
, R_BERSERK
);
5867 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
5868 for i
:= MR_SUIT
to MR_MAX
do FMegaRulez
[i
] := utils
.readLongWord(st
);
5869 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
5870 for i
:= T_RESPAWN
to T_FLAGCAP
do FTime
[i
] := utils
.readLongWord(st
);
5872 str
:= utils
.readStr(st
);
5874 FColor
.R
:= utils
.readByte(st
);
5875 FColor
.G
:= utils
.readByte(st
);
5876 FColor
.B
:= utils
.readByte(st
);
5877 if (self
= gPlayer1
) then
5879 str
:= gPlayer1Settings
.Model
;
5880 FColor
:= gPlayer1Settings
.Color
;
5882 else if (self
= gPlayer2
) then
5884 str
:= gPlayer2Settings
.Model
;
5885 FColor
:= gPlayer2Settings
.Color
;
5887 // Îáíîâëÿåì ìîäåëü èãðîêà
5889 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
5890 FModel
.Color
:= TEAMCOLOR
[FTeam
]
5892 FModel
.Color
:= FColor
;
5896 procedure TPlayer
.AllRulez(Health
: Boolean);
5902 FHealth
:= PLAYER_HP_LIMIT
;
5903 FArmor
:= PLAYER_AP_LIMIT
;
5907 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
5908 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
5909 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
5912 procedure TPlayer
.RestoreHealthArmor();
5914 FHealth
:= PLAYER_HP_LIMIT
;
5915 FArmor
:= PLAYER_AP_LIMIT
;
5918 procedure TPlayer
.FragCombo();
5922 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
5924 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
5926 if FFragCombo
< 5 then
5928 Param
:= FUID
or (FFragCombo
shl 16);
5929 if (FComboEvnt
>= Low(gDelayedEvents
)) and
5930 (FComboEvnt
<= High(gDelayedEvents
)) and
5931 gDelayedEvents
[FComboEvnt
].Pending
and
5932 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
5933 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
5935 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
5936 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
5939 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
5947 procedure TPlayer
.GiveItem(ItemType
: Byte);
5951 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
5953 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
5957 if FAir
< AIR_MAX
then
5964 if not (R_BERSERK
in FRulez
) then
5966 Include(FRulez
, R_BERSERK
);
5967 if FBFGFireCounter
< 1 then
5969 FCurrWeap
:= WEAPON_KASTET
;
5971 FModel
.SetWeapon(WEAPON_KASTET
);
5975 FBerserk
:= gTime
+30000;
5977 if FHealth
< PLAYER_HP_SOFT
then
5979 FHealth
:= PLAYER_HP_SOFT
;
5980 FBerserk
:= gTime
+30000;
5985 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
5987 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
5991 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
5993 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
5997 if FJetFuel
< JET_MAX
then
5999 FJetFuel
:= JET_MAX
;
6002 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
6003 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
6005 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
6006 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6008 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
6010 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
6012 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
6013 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6016 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
6017 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
6018 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
6019 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
6020 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
6021 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
6022 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
6023 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
6024 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
6026 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6027 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
6028 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6029 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
6030 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6031 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
6032 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6033 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
6034 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
6037 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
6038 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
6039 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
6040 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
6041 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
6043 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
6044 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
6045 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
6046 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
6047 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
6049 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6050 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6051 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6052 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6054 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
6057 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
6058 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
6059 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
6061 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
6062 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
6067 if g_Game_IsNet
and g_Game_IsServer
then
6068 MH_SEND_PlayerStats(FUID
);
6071 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
6076 if (Random(5) = 1) and (Times
= 1) then
6079 if BodyInLiquid(0, 0) then
6081 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
6082 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
6083 if Random(2) = 0 then
6084 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
6086 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
6090 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
6092 for i
:= 1 to Times
do
6094 Anim
:= TAnimation
.Create(id
, False, 3);
6096 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6097 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6103 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
6108 if (Random(10) = 1) and (Times
= 1) then
6111 if g_Frames_Get(id
, 'FRAMES_FLAME') then
6113 for i
:= 1 to Times
do
6115 Anim
:= TAnimation
.Create(id
, False, 3);
6117 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6118 Obj
.Y
+8+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6124 procedure TPlayer
.PauseSounds(Enable
: Boolean);
6126 FSawSound
.Pause(Enable
);
6127 FSawSoundIdle
.Pause(Enable
);
6128 FSawSoundHit
.Pause(Enable
);
6129 FSawSoundSelect
.Pause(Enable
);
6134 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
6139 FObj
.Rect
:= PLAYER_CORPSERECT
;
6140 FModelName
:= ModelName
;
6145 FState
:= CORPSE_STATE_MESS
;
6146 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
6150 FState
:= CORPSE_STATE_NORMAL
;
6151 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
6155 destructor TCorpse
.Destroy();
6162 function TCorpse
.ObjPtr (): PObj
; inline; begin result
:= @FObj
; end;
6164 procedure TCorpse
.positionChanged (); inline; begin end;
6166 procedure TCorpse
.moveBy (dx
, dy
: Integer); inline;
6168 if (dx
<> 0) or (dy
<> 0) then
6177 procedure TCorpse
.getMapBox (out x
, y
, w
, h
: Integer); inline;
6179 x
:= FObj
.X
+PLAYER_CORPSERECT
.X
;
6180 y
:= FObj
.Y
+PLAYER_CORPSERECT
.Y
;
6181 w
:= PLAYER_CORPSERECT
.Width
;
6182 h
:= PLAYER_CORPSERECT
.Height
;
6186 procedure TCorpse
.Damage(Value
: Word; vx
, vy
: Integer);
6190 if FState
= CORPSE_STATE_REMOVEME
then
6193 FDamage
:= FDamage
+ Value
;
6195 if FDamage
> 150 then
6197 if FAnimation
<> nil then
6202 FState
:= CORPSE_STATE_REMOVEME
;
6204 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
6205 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
6206 FModelName
, FColor
);
6207 // Çâóê ìÿñà îò òðóïà:
6208 pm
:= g_PlayerModel_Get(FModelName
);
6209 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
6215 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
6216 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
6217 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
6218 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
6219 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
6224 procedure TCorpse
.Draw();
6226 if FState
= CORPSE_STATE_REMOVEME
then
6229 if FAnimation
<> nil then
6230 FAnimation
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6232 if FAnimationMask
<> nil then
6235 FAnimationMask
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6242 procedure TCorpse
.Update();
6246 if FState
= CORPSE_STATE_REMOVEME
then
6249 if gTime
mod (GAME_TICK
*2) <> 0 then
6251 g_Obj_Move(@FObj
, True, True, True);
6252 positionChanged(); // this updates spatial accelerators
6256 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6257 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
6259 st
:= g_Obj_Move(@FObj
, True, True, True);
6260 positionChanged(); // this updates spatial accelerators
6262 if WordBool(st
and MOVE_FALLOUT
) then
6264 FState
:= CORPSE_STATE_REMOVEME
;
6268 if FAnimation
<> nil then
6269 FAnimation
.Update();
6270 if FAnimationMask
<> nil then
6271 FAnimationMask
.Update();
6275 procedure TCorpse
.SaveState (st
: TStream
);
6282 utils
.writeSign(st
, 'CORP');
6283 utils
.writeInt(st
, Byte(0));
6285 utils
.writeInt(st
, Byte(FState
));
6287 utils
.writeInt(st
, Byte(FDamage
));
6289 utils
.writeInt(st
, Byte(FColor
.R
));
6290 utils
.writeInt(st
, Byte(FColor
.G
));
6291 utils
.writeInt(st
, Byte(FColor
.B
));
6293 Obj_SaveState(st
, @FObj
);
6295 anim
:= (FAnimation
<> nil);
6296 utils
.writeBool(st
, anim
);
6297 // Åñëè åñòü - ñîõðàíÿåì
6298 if anim
then FAnimation
.SaveState(st
);
6299 // Åñòü ëè ìàñêà àíèìàöèè
6300 anim
:= (FAnimationMask
<> nil);
6301 utils
.writeBool(st
, anim
);
6302 // Åñëè åñòü - ñîõðàíÿåì
6303 if anim
then FAnimationMask
.SaveState(st
);
6307 procedure TCorpse
.LoadState (st
: TStream
);
6314 if not utils
.checkSign(st
, 'CORP') then raise XStreamError
.Create('invalid corpse signature');
6315 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid corpse version');
6317 FState
:= utils
.readByte(st
);
6319 FDamage
:= utils
.readByte(st
);
6321 FColor
.R
:= utils
.readByte(st
);
6322 FColor
.G
:= utils
.readByte(st
);
6323 FColor
.B
:= utils
.readByte(st
);
6325 Obj_LoadState(@FObj
, st
);
6327 anim
:= utils
.readBool(st
);
6328 // Åñëè åñòü - çàãðóæàåì
6331 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6332 FAnimation
.LoadState(st
);
6334 // Åñòü ëè ìàñêà àíèìàöèè
6335 anim
:= utils
.readBool(st
);
6336 // Åñëè åñòü - çàãðóæàåì
6339 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6340 FAnimationMask
.LoadState(st
);
6346 constructor TBot
.Create();
6353 FSpectator
:= False;
6360 for a
:= WP_FIRST
to WP_LAST
do
6362 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6363 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6364 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6368 destructor TBot
.Destroy();
6371 inherited Destroy();
6374 procedure TBot
.Draw();
6378 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6379 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6382 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6384 inherited Respawn(Silent
, Force
);
6387 FSelectedWeapon
:= FCurrWeap
;
6392 procedure TBot
.UpdateCombat();
6405 TTargetRecord
= array of TTarget
;
6407 function Compare(a
, b
: TTarget
): Integer;
6409 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6412 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6414 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6415 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6417 if a
.Dist
> b
.Dist
then // B áëèæå
6419 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6422 else // Ñòðàííî -> A
6427 a
, x1
, y1
, x2
, y2
: Integer;
6428 targets
: TTargetRecord
;
6430 Target
, BestTarget
: TTarget
;
6431 firew
, fireh
: Integer;
6435 vsPlayer
, vsMonster
, ok
: Boolean;
6438 function monsUpdate (mon
: TMonster
): Boolean;
6440 result
:= false; // don't stop
6441 if mon
.alive
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6443 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6445 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6446 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6448 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6449 if g_TraceVector(x1
, y1
, x2
, y2
) then
6451 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6452 SetLength(targets
, Length(targets
)+1);
6453 with targets
[High(targets
)] do
6460 Rect
:= mon
.Obj
.Rect
;
6461 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6462 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6463 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6472 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6473 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6475 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6476 if FCurrWeap
<> FSelectedWeapon
then
6479 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6480 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6482 RemoveAIFlag('NEEDFIRE');
6485 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6486 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6487 else PressKey(KEY_FIRE
);
6491 // Êîîðäèíàòû ñòâîëà:
6492 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6493 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6495 Target
.UID
:= FTargetUID
;
6498 if Target
.UID
<> 0 then
6499 begin // Öåëü åñòü - íàñòðàèâàåì
6500 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6503 tpla
:= g_Player_Get(Target
.UID
);
6507 if (@FObj
) <> nil then
6514 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6515 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6516 Target
.Rect
:= PLAYER_RECT
;
6517 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6518 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6519 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6520 Target
.IsPlayer
:= True;
6524 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6527 mon
:= g_Monsters_ByUID(Target
.UID
);
6530 Target
.X
:= mon
.Obj
.X
;
6531 Target
.Y
:= mon
.Obj
.Y
;
6533 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6534 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6535 Target
.Rect
:= mon
.Obj
.Rect
;
6536 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6537 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6538 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6539 Target
.IsPlayer
:= False;
6546 begin // Öåëè íåò - îáíóëÿåì
6551 Target
.Visible
:= False;
6552 Target
.Line
:= False;
6553 Target
.IsPlayer
:= False;
6558 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6559 if (not Target
.Line
) or (not Target
.Visible
) then
6563 for a
:= 0 to High(gPlayers
) do
6564 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].alive
) and
6565 (gPlayers
[a
].FUID
<> FUID
) and
6566 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6567 (not gPlayers
[a
].NoTarget
) and
6568 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6570 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6571 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6574 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6575 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6577 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6578 if g_TraceVector(x1
, y1
, x2
, y2
) then
6580 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6581 SetLength(targets
, Length(targets
)+1);
6582 with targets
[High(targets
)] do
6584 UID
:= gPlayers
[a
].FUID
;
6585 X
:= gPlayers
[a
].FObj
.X
;
6586 Y
:= gPlayers
[a
].FObj
.Y
;
6589 Rect
:= PLAYER_RECT
;
6590 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6591 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6592 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6600 if vsMonster
then g_Mons_ForEach(monsUpdate
);
6603 // Åñëè åñòü âîçìîæíûå öåëè:
6604 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6605 if targets
<> nil then
6607 // Âûáèðàåì íàèëó÷øóþ öåëü:
6608 BestTarget
:= targets
[0];
6609 if Length(targets
) > 1 then
6610 for a
:= 1 to High(targets
) do
6611 if Compare(BestTarget
, targets
[a
]) = 1 then
6612 BestTarget
:= targets
[a
];
6614 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6615 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6616 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6618 Target
:= BestTarget
;
6620 if (Healthy() = 3) or ((Healthy() = 2)) then
6621 begin // Åñëè çäîðîâû - äîãîíÿåì
6622 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6623 SetAIFlag('GORIGHT', '1');
6624 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6625 SetAIFlag('GOLEFT', '1');
6628 begin // Åñëè ïîáèòû - óáåãàåì
6629 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6630 SetAIFlag('GORIGHT', '1');
6631 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6632 SetAIFlag('GOLEFT', '1');
6635 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6636 SelectWeapon(Abs(x1
-Target
.cX
));
6641 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6642 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6643 if Target
.UID
<> 0 then
6645 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6646 Target
.Y
+ Target
.Rect
.Y
) then
6647 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6648 if (Healthy() = 3) or ((Healthy() = 2)) then
6649 begin // Åñëè çäîðîâû - äîãîíÿåì
6650 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6651 SetAIFlag('GORIGHT', '1');
6652 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6653 SetAIFlag('GOLEFT', '1');
6656 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6658 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6659 SetAIFlag('GORIGHT', '1');
6660 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6661 SetAIFlag('GOLEFT', '1');
6665 begin // Öåëü ïîêà íà "ýêðàíå"
6666 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
6667 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6668 FLastVisible
:= gTime
;
6669 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
6670 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6672 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6673 SetAIFlag('GORIGHT', '1');
6674 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6675 SetAIFlag('GOLEFT', '1');
6679 // Âûáèðàåì óãîë ââåðõ:
6680 if FDirection
= TDirection
.D_LEFT
then
6681 angle
:= ANGLE_LEFTUP
6683 angle
:= ANGLE_RIGHTUP
;
6685 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6686 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6688 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6689 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6690 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6691 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6692 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6693 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6694 begin // òî íóæíî ñòðåëÿòü ââåðõ
6695 SetAIFlag('NEEDFIRE', '1');
6696 SetAIFlag('NEEDSEEUP', '1');
6699 // Âûáèðàåì óãîë âíèç:
6700 if FDirection
= TDirection
.D_LEFT
then
6701 angle
:= ANGLE_LEFTDOWN
6703 angle
:= ANGLE_RIGHTDOWN
;
6705 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6706 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6708 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6709 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6710 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6711 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6712 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6713 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6714 begin // òî íóæíî ñòðåëÿòü âíèç
6715 SetAIFlag('NEEDFIRE', '1');
6716 SetAIFlag('NEEDSEEDOWN', '1');
6719 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
6720 if Target
.Visible
and
6721 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
6722 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
6724 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
6725 if ((FDirection
= TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) or
6726 ((FDirection
= TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6727 begin // òî íóæíî ñòðåëÿòü âïåðåä
6728 SetAIFlag('NEEDFIRE', '1');
6729 SetAIFlag('NEEDSEEDOWN', '');
6730 SetAIFlag('NEEDSEEUP', '');
6732 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
6733 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
6734 if GetRnd(FDifficult
.CloseJump
) then
6735 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
6736 if Abs(FObj
.X
-Target
.X
) < 128 then
6740 if Random(a
) = 0 then
6741 SetAIFlag('NEEDJUMP', '1');
6745 // Åñëè öåëü âñå åùå åñòü:
6746 if Target
.UID
<> 0 then
6747 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
6748 Target
.UID
:= 0 // òî çàáûòü öåëü
6749 else // Åñëè âèäåëè íåäàâíî
6750 begin // íî öåëü óáèëè
6751 if Target
.IsPlayer
then
6752 begin // Öåëü - èãðîê
6753 pla
:= g_Player_Get(Target
.UID
);
6754 if (pla
= nil) or (not pla
.alive
) or pla
.NoTarget
or
6755 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
6756 Target
.UID
:= 0; // òî çàáûòü öåëü
6759 begin // Öåëü - ìîíñòð
6760 mon
:= g_Monsters_ByUID(Target
.UID
);
6761 if (mon
= nil) or (not mon
.alive
) then
6762 Target
.UID
:= 0; // òî çàáûòü öåëü
6765 end; // if Target.UID <> 0
6767 FTargetUID
:= Target
.UID
;
6769 // Åñëè âîçìîæíûõ öåëåé íåò:
6770 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
6771 if targets
= nil then
6772 if GetAIFlag('ATTACKLEFT') <> '' then
6773 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
6774 RemoveAIFlag('ATTACKLEFT');
6776 SetAIFlag('NEEDJUMP', '1');
6778 if RunDirection() = TDirection
.D_RIGHT
then
6779 begin // Èäåì íå â òó ñòîðîíó
6780 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6781 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
6782 SetAIFlag('NEEDFIRE', '1');
6783 SetAIFlag('GOLEFT', '1');
6787 begin // Èäåì â íóæíóþ ñòîðîíó
6788 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6789 SetAIFlag('NEEDFIRE', '1');
6790 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6791 SetAIFlag('GORIGHT', '1');
6795 if GetAIFlag('ATTACKRIGHT') <> '' then
6796 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
6797 RemoveAIFlag('ATTACKRIGHT');
6799 SetAIFlag('NEEDJUMP', '1');
6801 if RunDirection() = TDirection
.D_LEFT
then
6802 begin // Èäåì íå â òó ñòîðîíó
6803 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6804 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
6805 SetAIFlag('NEEDFIRE', '1');
6806 SetAIFlag('GORIGHT', '1');
6811 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6812 SetAIFlag('NEEDFIRE', '1');
6813 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6814 SetAIFlag('GOLEFT', '1');
6818 //HACK! (does it belongs there?)
6819 RealizeCurrentWeapon();
6821 // Åñëè åñòü âîçìîæíûå öåëè:
6822 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
6823 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
6824 for a
:= 0 to High(targets
) do
6826 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
6827 if GetRnd(FDifficult
.DiagFire
) then
6829 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
6830 if FDirection
= TDirection
.D_LEFT
then
6831 angle
:= ANGLE_LEFTUP
6833 angle
:= ANGLE_RIGHTUP
;
6835 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6836 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6838 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6839 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6840 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6841 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6842 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6844 SetAIFlag('NEEDFIRE', '1');
6845 SetAIFlag('NEEDSEEUP', '1');
6848 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
6849 if FDirection
= TDirection
.D_LEFT
then
6850 angle
:= ANGLE_LEFTDOWN
6852 angle
:= ANGLE_RIGHTDOWN
;
6854 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6855 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6857 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6858 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6859 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6860 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6861 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6863 SetAIFlag('NEEDFIRE', '1');
6864 SetAIFlag('NEEDSEEDOWN', '1');
6868 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
6869 if targets
[a
].Line
and targets
[a
].Visible
and
6870 (((FDirection
= TDirection
.D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
6871 ((FDirection
= TDirection
.D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
6873 SetAIFlag('NEEDFIRE', '1');
6878 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
6879 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
6880 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
6881 40+GetInterval(FDifficult
.Cover
, 40)) then
6882 SetAIFlag('NEEDJUMP', '1');
6884 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
6885 ammo
:= GetAmmoByWeapon(FCurrWeap
);
6886 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
6887 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
6889 SetAIFlag('SELECTWEAPON', '1');
6891 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
6892 if GetAIFlag('SELECTWEAPON') = '1' then
6895 RemoveAIFlag('SELECTWEAPON');
6899 procedure TBot
.Update();
6912 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
6913 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
6915 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
6917 if g_debug_BotAIOff
= 3 then
6927 RealizeCurrentWeapon();
6934 procedure TBot
.ReleaseKey(Key
: Byte);
6943 function TBot
.KeyPressed(Key
: Word): Boolean;
6945 Result
:= FKeys
[Key
].Pressed
;
6948 function TBot
.GetAIFlag(aName
: String20
): String20
;
6954 aName
:= LowerCase(aName
);
6956 if FAIFlags
<> nil then
6957 for a
:= 0 to High(FAIFlags
) do
6958 if LowerCase(FAIFlags
[a
].Name
) = aName
then
6960 Result
:= FAIFlags
[a
].Value
;
6965 procedure TBot
.RemoveAIFlag(aName
: String20
);
6969 if FAIFlags
= nil then Exit
;
6971 aName
:= LowerCase(aName
);
6973 for a
:= 0 to High(FAIFlags
) do
6974 if LowerCase(FAIFlags
[a
].Name
) = aName
then
6976 if a
<> High(FAIFlags
) then
6977 for b
:= a
to High(FAIFlags
)-1 do
6978 FAIFlags
[b
] := FAIFlags
[b
+1];
6980 SetLength(FAIFlags
, Length(FAIFlags
)-1);
6985 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
6993 aName
:= LowerCase(aName
);
6995 if FAIFlags
<> nil then
6996 for a
:= 0 to High(FAIFlags
) do
6997 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7003 if ok
then FAIFlags
[a
].Value
:= fValue
7006 SetLength(FAIFlags
, Length(FAIFlags
)+1);
7007 with FAIFlags
[High(FAIFlags
)] do
7015 procedure TBot
.UpdateMove
;
7017 procedure GoLeft(Time
: Word = 1);
7019 ReleaseKey(KEY_LEFT
);
7020 ReleaseKey(KEY_RIGHT
);
7021 PressKey(KEY_LEFT
, Time
);
7022 SetDirection(TDirection
.D_LEFT
);
7025 procedure GoRight(Time
: Word = 1);
7027 ReleaseKey(KEY_LEFT
);
7028 ReleaseKey(KEY_RIGHT
);
7029 PressKey(KEY_RIGHT
, Time
);
7030 SetDirection(TDirection
.D_RIGHT
);
7033 function Rnd(a
: Word): Boolean;
7035 Result
:= Random(a
) = 0;
7038 procedure Turn(Time
: Word = 1200);
7040 if RunDirection() = TDirection
.D_LEFT
then GoRight(Time
) else GoLeft(Time
);
7045 ReleaseKey(KEY_LEFT
);
7046 ReleaseKey(KEY_RIGHT
);
7049 function CanRunLeft(): Boolean;
7051 Result
:= not CollideLevel(-1, 0);
7054 function CanRunRight(): Boolean;
7056 Result
:= not CollideLevel(1, 0);
7059 function CanRun(): Boolean;
7061 if RunDirection() = TDirection
.D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
7064 procedure Jump(Time
: Word = 30);
7066 PressKey(KEY_JUMP
, Time
);
7069 function NearHole(): Boolean;
7073 { TODO 5 : Ëåñòíèöû }
7074 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7075 for x
:= 1 to PLAYER_RECT
.Width
do
7076 if (not StayOnStep(x
*sx
, 0)) and
7077 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7078 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7087 function BorderHole(): Boolean;
7091 { TODO 5 : Ëåñòíèöû }
7092 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7093 for x
:= 1 to PLAYER_RECT
.Width
do
7094 if (not StayOnStep(x
*sx
, 0)) and
7095 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7096 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7098 for xx
:= x
to x
+32 do
7099 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
7109 function NearDeepHole(): Boolean;
7115 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7118 for x
:= 1 to PLAYER_RECT
.Width
do
7119 if (not StayOnStep(x
*sx
, 0)) and
7120 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7121 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7123 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7125 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
7130 end else Result
:= False;
7133 function OverDeepHole(): Boolean;
7140 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7142 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
7149 function OnGround(): Boolean;
7151 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
7154 function OnLadder(): Boolean;
7156 Result
:= FullInStep(0, 0);
7159 function BelowLadder(): Boolean;
7161 Result
:= (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
7162 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7163 (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
7164 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7167 function BelowLiftUp(): Boolean;
7169 Result
:= ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
7170 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7171 ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
7172 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7175 function OnTopLift(): Boolean;
7177 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7180 function CanJumpOver(): Boolean;
7184 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7188 if not CollideLevel(sx
, 0) then Exit
;
7190 for y
:= 1 to BOT_MAXJUMP
do
7191 if CollideLevel(0, -y
) then Exit
else
7192 if not CollideLevel(sx
, -y
) then
7199 function CanJumpUp(Dist
: ShortInt): Boolean;
7206 if CollideLevel(Dist
, 0) then Exit
;
7209 for y
:= 0 to BOT_MAXJUMP
do
7210 if CollideLevel(Dist
, -y
) then
7219 for yy
:= y
+1 to BOT_MAXJUMP
do
7220 if not CollideLevel(Dist
, -yy
) then
7229 for y
:= 0 to BOT_MAXJUMP
do
7230 if CollideLevel(0, -y
) then
7238 if y
< yy
then Exit
;
7243 function IsSafeTrigger(): Boolean;
7248 if gTriggers
= nil then
7250 for a
:= 0 to High(gTriggers
) do
7251 if Collide(gTriggers
[a
].X
,
7254 gTriggers
[a
].Height
) and
7255 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
7256 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
7257 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
7258 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
7259 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
7264 // Âîçìîæíî, íàæèìàåì êíîïêó:
7265 if Rnd(16) and IsSafeTrigger() then
7268 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7269 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7271 ReleaseKey(KEY_LEFT
);
7272 ReleaseKey(KEY_RIGHT
);
7276 // Èäåì âëåâî, åñëè íàäî áûëî:
7277 if GetAIFlag('GOLEFT') <> '' then
7279 RemoveAIFlag('GOLEFT');
7280 if CanRunLeft() then
7284 // Èäåì âïðàâî, åñëè íàäî áûëî:
7285 if GetAIFlag('GORIGHT') <> '' then
7287 RemoveAIFlag('GORIGHT');
7288 if CanRunRight() then
7292 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7293 if FObj
.X
< -32 then
7296 if FObj
.X
+32 > gMapInfo
.Width
then
7299 // Ïðûãàåì, åñëè íàäî áûëî:
7300 if GetAIFlag('NEEDJUMP') <> '' then
7303 RemoveAIFlag('NEEDJUMP');
7306 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7307 if GetAIFlag('NEEDSEEUP') <> '' then
7310 ReleaseKey(KEY_DOWN
);
7311 PressKey(KEY_UP
, 20);
7312 RemoveAIFlag('NEEDSEEUP');
7315 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7316 if GetAIFlag('NEEDSEEDOWN') <> '' then
7319 ReleaseKey(KEY_DOWN
);
7320 PressKey(KEY_DOWN
, 20);
7321 RemoveAIFlag('NEEDSEEDOWN');
7324 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7325 if GetAIFlag('GOINHOLE') <> '' then
7326 if not OnGround() then
7328 ReleaseKey(KEY_LEFT
);
7329 ReleaseKey(KEY_RIGHT
);
7330 RemoveAIFlag('GOINHOLE');
7331 SetAIFlag('FALLINHOLE', '1');
7334 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7335 if GetAIFlag('FALLINHOLE') <> '' then
7337 RemoveAIFlag('FALLINHOLE');
7339 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7340 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7341 if GetAIFlag('FALLINHOLE') = '' then
7342 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7348 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7350 CanJumpUp(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*32) and
7354 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7355 if OnGround() and NearHole() then
7356 if NearDeepHole() then // Åñëè ýòî áåçäíà
7358 0..3: Turn(); // Áåæèì îáðàòíî
7359 4: Jump(); // Ïðûãàåì
7360 5: begin // Ïðûãàåì îáðàòíî
7365 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7366 if GetAIFlag('GOINHOLE') = '' then
7368 0: Turn(); // Íå íóæíî òóäà
7369 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7370 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7371 if BorderHole() then
7372 SetAIFlag('GOINHOLE', '1');
7375 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7376 if (not CanRun()) and OnGround() then
7378 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7379 if CanJumpOver() or OnLadder() then
7381 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7382 if Random(2) = 0 then
7384 if IsSafeTrigger() then
7390 // Îñòàëîñü ìàëî âîçäóõà:
7391 if FAir
< 36 * 2 then
7394 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7395 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7396 if BodyInAcid(0, 0) then
7400 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7402 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7403 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7406 {function TBot.NeedItem(Item: Byte): Byte;
7411 procedure TBot
.SelectWeapon(Dist
: Integer);
7415 function HaveAmmo(weapon
: Byte): Boolean;
7418 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7419 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7420 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7421 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7422 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7423 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7424 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7425 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7426 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7427 else Result
:= True;
7432 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7434 if Dist
> BOT_LONGDIST
then
7435 begin // Äàëüíèé áîé
7437 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7439 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7443 else //if Dist > BOT_UNSAFEDIST then
7444 begin // Áëèæíèé áîé
7446 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7448 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7455 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7457 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7463 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7465 Result
:= inherited PickItem(ItemType
, force
, remove
);
7467 if Result
then SetAIFlag('SELECTWEAPON', '1');
7470 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7472 Result
:= inherited Heal(value
, Soft
);
7475 function TBot
.Healthy(): Byte;
7477 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7478 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7479 else if (FHealth
> 50) then Result
:= 2
7480 else if (FHealth
> 20) then Result
:= 1
7484 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7486 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7487 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7490 procedure TBot
.OnDamage(Angle
: SmallInt);
7498 if (Angle
= 0) or (Angle
= 180) then
7501 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7502 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7504 pla
:= g_Player_Get(FLastSpawnerUID
);
7505 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7506 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7509 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7510 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7512 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
7513 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7514 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7519 SetAIFlag('ATTACKLEFT', '1')
7521 SetAIFlag('ATTACKRIGHT', '1');
7525 function TBot
.RunDirection(): TDirection
;
7527 if Abs(Vel
.X
) >= 1 then
7529 if Vel
.X
> 0 then Result
:= TDirection
.D_RIGHT
else Result
:= TDirection
.D_LEFT
;
7531 Result
:= FDirection
;
7534 function TBot
.GetRnd(a
: Byte): Boolean;
7536 if a
= 0 then Result
:= False
7537 else if a
= 255 then Result
:= True
7538 else Result
:= Random(256) > 255-a
;
7541 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7543 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7547 procedure TDifficult
.save (st
: TStream
);
7549 utils
.writeInt(st
, Byte(DiagFire
));
7550 utils
.writeInt(st
, Byte(InvisFire
));
7551 utils
.writeInt(st
, Byte(DiagPrecision
));
7552 utils
.writeInt(st
, Byte(FlyPrecision
));
7553 utils
.writeInt(st
, Byte(Cover
));
7554 utils
.writeInt(st
, Byte(CloseJump
));
7555 st
.WriteBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7556 st
.WriteBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7559 procedure TDifficult
.load (st
: TStream
);
7561 DiagFire
:= utils
.readByte(st
);
7562 InvisFire
:= utils
.readByte(st
);
7563 DiagPrecision
:= utils
.readByte(st
);
7564 FlyPrecision
:= utils
.readByte(st
);
7565 Cover
:= utils
.readByte(st
);
7566 CloseJump
:= utils
.readByte(st
);
7567 st
.ReadBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7568 st
.ReadBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7572 procedure TBot
.SaveState (st
: TStream
);
7577 inherited SaveState(st
);
7578 utils
.writeSign(st
, 'BOT0');
7580 utils
.writeInt(st
, Byte(FSelectedWeapon
));
7582 utils
.writeInt(st
, Word(FTargetUID
));
7583 // Âðåìÿ ïîòåðè öåëè
7584 utils
.writeInt(st
, LongWord(FLastVisible
));
7585 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7586 dw
:= Length(FAIFlags
);
7587 utils
.writeInt(st
, LongInt(dw
));
7589 for i
:= 0 to dw
-1 do
7591 utils
.writeStr(st
, FAIFlags
[i
].Name
, 20);
7592 utils
.writeStr(st
, FAIFlags
[i
].Value
, 20);
7594 // Íàñòðîéêè ñëîæíîñòè
7595 FDifficult
.save(st
);
7599 procedure TBot
.LoadState (st
: TStream
);
7604 inherited LoadState(st
);
7605 if not utils
.checkSign(st
, 'BOT0') then raise XStreamError
.Create('invalid bot signature');
7607 FSelectedWeapon
:= utils
.readByte(st
);
7609 FTargetUID
:= utils
.readWord(st
);
7610 // Âðåìÿ ïîòåðè öåëè
7611 FLastVisible
:= utils
.readLongWord(st
);
7612 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7613 dw
:= utils
.readLongInt(st
);
7614 if (dw
< 0) or (dw
> 16384) then raise XStreamError
.Create('invalid number of bot AI flags');
7615 SetLength(FAIFlags
, dw
);
7617 for i
:= 0 to dw
-1 do
7619 FAIFlags
[i
].Name
:= utils
.readStr(st
, 20);
7620 FAIFlags
[i
].Value
:= utils
.readStr(st
, 20);
7622 // Íàñòðîéêè ñëîæíîñòè
7623 FDifficult
.load(st
);
7628 conRegVar('cheat_berserk_autoswitch', @gBerserkAutoswitch
, 'autoswitch to fist when berserk pack taken', '', true, true);