DEADSOFTWARE

f80d72195105d1d96dcbffd5a0f7a63dd8efb2fd
[d2df-sdl.git] / src / game / g_player.pas
1 (* Copyright (C) Doom 2D: Forever Developers
2 *
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, version 3 of the License ONLY.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 *)
15 {$INCLUDE ../shared/a_modes.inc}
16 {$M+}
17 unit g_player;
19 interface
21 uses
22 SysUtils, Classes,
23 {$IFDEF USE_MEMPOOL}mempool,{$ENDIF}
24 e_graphics, g_playermodel, g_basic, g_textures,
25 g_weapons, g_phys, g_sound, g_saveload, MAPDEF,
26 g_panel;
28 const
29 KEY_LEFT = 1;
30 KEY_RIGHT = 2;
31 KEY_UP = 3;
32 KEY_DOWN = 4;
33 KEY_FIRE = 5;
34 KEY_OPEN = 6;
35 KEY_JUMP = 7;
36 KEY_CHAT = 8;
38 WP_PREV = 0;
39 WP_NEXT = 1;
40 WP_FACT = WP_PREV;
41 WP_LACT = WP_NEXT;
43 R_ITEM_BACKPACK = 0;
44 R_KEY_RED = 1;
45 R_KEY_GREEN = 2;
46 R_KEY_BLUE = 3;
47 R_BERSERK = 4;
49 MR_SUIT = 0;
50 MR_INVUL = 1;
51 MR_INVIS = 2;
52 MR_MAX = 2;
54 A_BULLETS = 0;
55 A_SHELLS = 1;
56 A_ROCKETS = 2;
57 A_CELLS = 3;
58 A_FUEL = 4;
59 A_HIGH = 4;
61 AmmoLimits: Array [0..1] of Array [A_BULLETS..A_HIGH] of Word =
62 ((200, 50, 50, 300, 100),
63 (400, 100, 100, 600, 200));
65 K_SIMPLEKILL = 0;
66 K_HARDKILL = 1;
67 K_EXTRAHARDKILL = 2;
68 K_FALLKILL = 3;
70 T_RESPAWN = 0;
71 T_SWITCH = 1;
72 T_USE = 2;
73 T_FLAGCAP = 3;
75 TEAM_NONE = 0;
76 TEAM_RED = 1;
77 TEAM_BLUE = 2;
78 TEAM_COOP = 3;
80 SHELL_BULLET = 0;
81 SHELL_SHELL = 1;
82 SHELL_DBLSHELL = 2;
84 ANGLE_NONE = Low(SmallInt);
86 CORPSE_STATE_REMOVEME = 0;
87 CORPSE_STATE_NORMAL = 1;
88 CORPSE_STATE_MESS = 2;
90 PLAYER_RECT: TRectWH = (X:15; Y:12; Width:34; Height:52);
91 PLAYER_RECT_CX = 15+(34 div 2);
92 PLAYER_RECT_CY = 12+(52 div 2);
93 PLAYER_CORPSERECT: TRectWH = (X:15; Y:48; Width:34; Height:16);
95 PLAYER_HP_SOFT = 100;
96 PLAYER_HP_LIMIT = 200;
97 PLAYER_AP_SOFT = 100;
98 PLAYER_AP_LIMIT = 200;
99 SUICIDE_DAMAGE = 112;
100 WEAPON_DELAY = 5;
102 PLAYER_BURN_TIME = 110;
104 PLAYER1_DEF_COLOR: TRGB = (R:64; G:175; B:48);
105 PLAYER2_DEF_COLOR: TRGB = (R:96; G:96; B:96);
107 type
108 TPlayerStat = record
109 Num: Integer;
110 Ping: Word;
111 Loss: Byte;
112 Name: String;
113 Team: Byte;
114 Frags: SmallInt;
115 Deaths: SmallInt;
116 Lives: Byte;
117 Kills: Word;
118 Color: TRGB;
119 Spectator: Boolean;
120 UID: Word;
121 end;
123 TPlayerStatArray = Array of TPlayerStat;
125 TPlayerSavedState = record
126 Health: Integer;
127 Armor: Integer;
128 Air: Integer;
129 JetFuel: Integer;
130 CurrWeap: Byte;
131 NextWeap: WORD;
132 NextWeapDelay: Byte;
133 Ammo: Array [A_BULLETS..A_HIGH] of Word;
134 MaxAmmo: Array [A_BULLETS..A_HIGH] of Word;
135 Weapon: Array [WP_FIRST..WP_LAST] of Boolean;
136 Rulez: Set of R_ITEM_BACKPACK..R_BERSERK;
137 Used: Boolean;
138 end;
140 TKeyState = record
141 Pressed: Boolean;
142 Time: Word;
143 end;
145 TPlayer = class{$IFDEF USE_MEMPOOL}(TPoolObject){$ENDIF}
146 private
147 FIamBot: Boolean;
148 FUID: Word;
149 FName: String;
150 FTeam: Byte;
151 FAlive: Boolean;
152 FSpawned: Boolean;
153 FDirection: TDirection;
154 FHealth: Integer;
155 FLives: Byte;
156 FArmor: Integer;
157 FAir: Integer;
158 FPain: Integer;
159 FPickup: Integer;
160 FKills: Integer;
161 FMonsterKills: Integer;
162 FFrags: Integer;
163 FFragCombo: Byte;
164 FLastFrag: LongWord;
165 FComboEvnt: Integer;
166 FDeath: Integer;
167 FCanJetpack: Boolean;
168 FJetFuel: Integer;
169 FFlag: Byte;
170 FSecrets: Integer;
171 FCurrWeap: Byte;
172 FNextWeap: WORD;
173 FNextWeapDelay: Byte; // frames
174 FBFGFireCounter: SmallInt;
175 FLastSpawnerUID: Word;
176 FLastHit: Byte;
177 FObj: TObj;
178 FXTo, FYTo: Integer;
179 FSpectatePlayer: Integer;
180 FFirePainTime: Integer;
181 FFireAttacker: Word;
183 FSavedStateNum: Integer;
185 FModel: TPlayerModel;
186 FPunchAnim: TAnimation;
187 FActionPrior: Byte;
188 FActionAnim: Byte;
189 FActionForce: Boolean;
190 FActionChanged: Boolean;
191 FAngle: SmallInt;
192 FFireAngle: SmallInt;
193 FIncCamOld: Integer;
194 FIncCam: Integer;
195 FSlopeOld: Integer;
196 FShellTimer: Integer;
197 FShellType: Byte;
198 FSawSound: TPlayableSound;
199 FSawSoundIdle: TPlayableSound;
200 FSawSoundHit: TPlayableSound;
201 FSawSoundSelect: TPlayableSound;
202 FFlameSoundOn: TPlayableSound;
203 FFlameSoundOff: TPlayableSound;
204 FFlameSoundWork: TPlayableSound;
205 FJetSoundOn: TPlayableSound;
206 FJetSoundOff: TPlayableSound;
207 FJetSoundFly: TPlayableSound;
208 FGodMode: Boolean;
209 FNoTarget: Boolean;
210 FNoReload: Boolean;
211 FJustTeleported: Boolean;
212 FNetTime: LongWord;
213 mEDamageType: Integer;
216 function CollideLevel(XInc, YInc: Integer): Boolean;
217 function StayOnStep(XInc, YInc: Integer): Boolean;
218 function HeadInLiquid(XInc, YInc: Integer): Boolean;
219 function BodyInLiquid(XInc, YInc: Integer): Boolean;
220 function BodyInAcid(XInc, YInc: Integer): Boolean;
221 function FullInLift(XInc, YInc: Integer): Integer;
222 {procedure CollideItem();}
223 procedure FlySmoke(Times: DWORD = 1);
224 procedure OnFireFlame(Times: DWORD = 1);
225 function GetAmmoByWeapon(Weapon: Byte): Word;
226 procedure SetAction(Action: Byte; Force: Boolean = False);
227 procedure OnDamage(Angle: SmallInt); virtual;
228 function firediry(): Integer;
229 procedure DoPunch();
231 procedure Run(Direction: TDirection);
232 procedure NextWeapon();
233 procedure PrevWeapon();
234 procedure SeeUp();
235 procedure SeeDown();
236 procedure Fire();
237 procedure Jump();
238 procedure Use();
240 function getNextWeaponIndex (): Byte; // return 255 for "no switch"
241 procedure resetWeaponQueue ();
242 function hasAmmoForWeapon (weapon: Byte): Boolean;
243 function shouldSwitch (weapon: Byte; hadWeapon: Boolean) : Boolean;
245 procedure doDamage (v: Integer);
247 function refreshCorpse(): Boolean;
249 public
250 FDamageBuffer: Integer;
252 FAmmo: Array [A_BULLETS..A_HIGH] of Word;
253 FMaxAmmo: Array [A_BULLETS..A_HIGH] of Word;
254 FWeapon: Array [WP_FIRST..WP_LAST] of Boolean;
255 FRulez: Set of R_ITEM_BACKPACK..R_BERSERK;
256 FBerserk: Integer;
257 FMegaRulez: Array [MR_SUIT..MR_MAX] of DWORD;
258 FReloading: Array [WP_FIRST..WP_LAST] of Word;
259 FTime: Array [T_RESPAWN..T_FLAGCAP] of DWORD;
260 FKeys: Array [KEY_LEFT..KEY_CHAT] of TKeyState;
261 FWeapSwitchMode: Byte;
262 FWeapPreferences: Array [WP_FIRST .. WP_LAST+1] of Byte;
263 FSwitchToEmpty: Byte;
264 FSkipFist: Byte;
265 FColor: TRGB;
266 FPreferredTeam: Byte;
267 FSpectator: Boolean;
268 FNoRespawn: Boolean;
269 FWantsInGame: Boolean;
270 FGhost: Boolean;
271 FPhysics: Boolean;
272 FFlaming: Boolean;
273 FJetpack: Boolean;
274 FActualModelName: string;
275 FClientID: SmallInt;
276 FPing: Word;
277 FLoss: Byte;
278 FReady: Boolean;
279 FDummy: Boolean;
280 FFireTime: Integer;
281 FSpawnInvul: Integer;
282 FHandicap: Integer;
283 FWaitForFirstSpawn: Boolean; // set to `true` in server, used to spawn a player on first full state request
284 FCorpse: Integer;
286 // debug: viewport offset
287 viewPortX, viewPortY, viewPortW, viewPortH: Integer;
289 function isValidViewPort (): Boolean; inline;
291 constructor Create(); virtual;
292 destructor Destroy(); override;
293 procedure Respawn(Silent: Boolean; Force: Boolean = False); virtual;
294 function GetRespawnPoint(): Byte;
295 procedure PressKey(Key: Byte; Time: Word = 1);
296 procedure ReleaseKeys();
297 procedure SetModel(ModelName: String);
298 procedure SetColor(Color: TRGB);
299 function GetColor(): TRGB;
300 procedure SetWeapon(W: Byte);
301 function IsKeyPressed(K: Byte): Boolean;
302 function GetKeys(): Byte;
303 function PickItem(ItemType: Byte; arespawn: Boolean; var remove: Boolean): Boolean; virtual;
304 procedure SetWeaponPrefs(Prefs: Array of Byte);
305 procedure SetWeaponPref(Weapon, Pref: Byte);
306 function GetWeaponPref(Weapon: Byte) : Byte;
307 function GetMorePrefered() : Byte;
308 function MaySwitch(Weapon: Byte) : Boolean;
309 function Collide(X, Y: Integer; Width, Height: Word): Boolean; overload;
310 function Collide(Panel: TPanel): Boolean; overload;
311 function Collide(X, Y: Integer): Boolean; overload;
312 procedure SetDirection(Direction: TDirection);
313 procedure GetSecret();
314 function TeleportTo(X, Y: Integer; silent: Boolean; dir: Byte): Boolean;
315 procedure Touch();
316 procedure Push(vx, vy: Integer);
317 procedure ChangeModel(ModelName: String);
318 procedure SwitchTeam;
319 procedure ChangeTeam(Team: Byte);
320 procedure BFGHit();
321 function GetFlag(Flag: Byte): Boolean;
322 procedure SetFlag(Flag: Byte);
323 function DropFlag(Silent: Boolean = True; DoThrow: Boolean = False): Boolean;
324 function TryDropFlag(): Boolean;
325 procedure AllRulez(Health: Boolean);
326 procedure RestoreHealthArmor();
327 procedure FragCombo();
328 procedure GiveItem(ItemType: Byte);
329 procedure Damage(value: Word; SpawnerUID: Word; vx, vy: Integer; t: Byte); virtual;
330 function Heal(value: Word; Soft: Boolean): Boolean; virtual;
331 procedure MakeBloodVector(Count: Word; VelX, VelY: Integer);
332 procedure MakeBloodSimple(Count: Word);
333 procedure Kill(KillType: Byte; SpawnerUID: Word; t: Byte);
334 procedure Reset(Force: Boolean);
335 procedure Spectate(NoMove: Boolean = False);
336 procedure SwitchNoClip;
337 procedure SoftReset();
338 procedure Draw(); virtual;
339 procedure DrawPain();
340 procedure DrawPickup();
341 procedure DrawRulez();
342 procedure DrawAim();
343 procedure DrawIndicator(Color: TRGB);
344 procedure DrawBubble();
345 procedure DrawGUI();
346 procedure PreUpdate();
347 procedure Update(); virtual;
348 procedure RememberState();
349 procedure RecallState();
350 procedure SaveState (st: TStream); virtual;
351 procedure LoadState (st: TStream); virtual;
352 procedure PauseSounds(Enable: Boolean);
353 procedure NetFire(Wpn: Byte; X, Y, AX, AY: Integer; WID: Integer = -1);
354 procedure DoLerp(Level: Integer = 2);
355 procedure SetLerp(XTo, YTo: Integer);
356 procedure ProcessWeaponAction(Action: Byte);
357 procedure QueueWeaponSwitch(Weapon: Byte);
358 procedure RealizeCurrentWeapon();
359 procedure FlamerOn;
360 procedure FlamerOff;
361 procedure JetpackOn;
362 procedure JetpackOff;
363 procedure CatchFire(Attacker: Word; Timeout: Integer = PLAYER_BURN_TIME);
365 //WARNING! this does nothing for now, but still call it!
366 procedure positionChanged (); //WARNING! call this after entity position was changed, or coldet will not work right!
368 procedure getMapBox (out x, y, w, h: Integer); inline;
369 procedure moveBy (dx, dy: Integer); inline;
371 function getCameraObj(): TObj;
373 public
374 property Vel: TPoint2i read FObj.Vel;
375 property Obj: TObj read FObj;
377 property Name: String read FName write FName;
378 property Model: TPlayerModel read FModel;
379 property Health: Integer read FHealth write FHealth;
380 property Lives: Byte read FLives write FLives;
381 property Armor: Integer read FArmor write FArmor;
382 property Air: Integer read FAir write FAir;
383 property JetFuel: Integer read FJetFuel write FJetFuel;
384 property Frags: Integer read FFrags write FFrags;
385 property Death: Integer read FDeath write FDeath;
386 property Kills: Integer read FKills write FKills;
387 property CurrWeap: Byte read FCurrWeap write FCurrWeap;
388 property WeapSwitchMode: Byte read FWeapSwitchMode write FWeapSwitchMode;
389 property SwitchToEmpty: Byte read FSwitchToEmpty write FSwitchToEmpty;
390 property SkipFist: Byte read FSkipFist write FSkipFist;
391 property MonsterKills: Integer read FMonsterKills write FMonsterKills;
392 property Secrets: Integer read FSecrets;
393 property GodMode: Boolean read FGodMode write FGodMode;
394 property NoTarget: Boolean read FNoTarget write FNoTarget;
395 property NoReload: Boolean read FNoReload write FNoReload;
396 property alive: Boolean read FAlive write FAlive;
397 property Flag: Byte read FFlag;
398 property Team: Byte read FTeam write FTeam;
399 property Direction: TDirection read FDirection;
400 property GameX: Integer read FObj.X write FObj.X;
401 property GameY: Integer read FObj.Y write FObj.Y;
402 property GameVelX: Integer read FObj.Vel.X write FObj.Vel.X;
403 property GameVelY: Integer read FObj.Vel.Y write FObj.Vel.Y;
404 property GameAccelX: Integer read FObj.Accel.X write FObj.Accel.X;
405 property GameAccelY: Integer read FObj.Accel.Y write FObj.Accel.Y;
406 property IncCam: Integer read FIncCam write FIncCam;
407 property IncCamOld: Integer read FIncCamOld write FIncCamOld;
408 property SlopeOld: Integer read FSlopeOld write FSlopeOld;
409 property UID: Word read FUID write FUID;
410 property JustTeleported: Boolean read FJustTeleported write FJustTeleported;
411 property NetTime: LongWord read FNetTime write FNetTime;
413 published
414 property eName: String read FName write FName;
415 property eHealth: Integer read FHealth write FHealth;
416 property eLives: Byte read FLives write FLives;
417 property eArmor: Integer read FArmor write FArmor;
418 property eAir: Integer read FAir write FAir;
419 property eJetFuel: Integer read FJetFuel write FJetFuel;
420 property eFrags: Integer read FFrags write FFrags;
421 property eDeath: Integer read FDeath write FDeath;
422 property eKills: Integer read FKills write FKills;
423 property eCurrWeap: Byte read FCurrWeap write FCurrWeap;
424 property eMonsterKills: Integer read FMonsterKills write FMonsterKills;
425 property eSecrets: Integer read FSecrets write FSecrets;
426 property eGodMode: Boolean read FGodMode write FGodMode;
427 property eNoTarget: Boolean read FNoTarget write FNoTarget;
428 property eNoReload: Boolean read FNoReload write FNoReload;
429 property eAlive: Boolean read FAlive write FAlive;
430 property eFlag: Byte read FFlag;
431 property eTeam: Byte read FTeam write FTeam;
432 property eDirection: TDirection read FDirection;
433 property eGameX: Integer read FObj.X write FObj.X;
434 property eGameY: Integer read FObj.Y write FObj.Y;
435 property eGameVelX: Integer read FObj.Vel.X write FObj.Vel.X;
436 property eGameVelY: Integer read FObj.Vel.Y write FObj.Vel.Y;
437 property eGameAccelX: Integer read FObj.Accel.X write FObj.Accel.X;
438 property eGameAccelY: Integer read FObj.Accel.Y write FObj.Accel.Y;
439 property eIncCam: Integer read FIncCam write FIncCam;
440 property eUID: Word read FUID;
441 property eJustTeleported: Boolean read FJustTeleported;
442 property eNetTime: LongWord read FNetTime;
444 // set this before assigning something to `eDamage`
445 property eDamageType: Integer read mEDamageType write mEDamageType;
446 property eDamage: Integer write doDamage;
447 end;
449 TDifficult = record
450 public
451 DiagFire: Byte;
452 InvisFire: Byte;
453 DiagPrecision: Byte;
454 FlyPrecision: Byte;
455 Cover: Byte;
456 CloseJump: Byte;
457 WeaponPrior: packed array [WP_FIRST..WP_LAST] of Byte;
458 CloseWeaponPrior: packed array [WP_FIRST..WP_LAST] of Byte;
459 //SafeWeaponPrior: Array [WP_FIRST..WP_LAST] of Byte;
461 public
462 procedure save (st: TStream);
463 procedure load (st: TStream);
464 end;
466 TAIFlag = record
467 Name: String;
468 Value: String;
469 end;
471 TBot = class(TPlayer)
472 private
473 FSelectedWeapon: Byte;
474 FTargetUID: Word;
475 FLastVisible: DWORD;
476 FAIFlags: Array of TAIFlag;
477 FDifficult: TDifficult;
479 function GetRnd(a: Byte): Boolean;
480 function GetInterval(a: Byte; radius: SmallInt): SmallInt;
481 function RunDirection(): TDirection;
482 function FullInStep(XInc, YInc: Integer): Boolean;
483 //function NeedItem(Item: Byte): Byte;
484 procedure SelectWeapon(Dist: Integer);
485 procedure SetAIFlag(aName, fValue: String20);
486 function GetAIFlag(aName: String20): String20;
487 procedure RemoveAIFlag(aName: String20);
488 function Healthy(): Byte;
489 procedure UpdateMove();
490 procedure UpdateCombat();
491 function KeyPressed(Key: Word): Boolean;
492 procedure ReleaseKey(Key: Byte);
493 function TargetOnScreen(TX, TY: Integer): Boolean;
494 procedure OnDamage(Angle: SmallInt); override;
496 public
497 procedure Respawn(Silent: Boolean; Force: Boolean = False); override;
498 constructor Create(); override;
499 destructor Destroy(); override;
500 procedure Draw(); override;
501 function PickItem(ItemType: Byte; force: Boolean; var remove: Boolean): Boolean; override;
502 function Heal(value: Word; Soft: Boolean): Boolean; override;
503 procedure Update(); override;
504 procedure SaveState (st: TStream); override;
505 procedure LoadState (st: TStream); override;
506 end;
508 PGib = ^TGib;
509 TGib = record
510 alive: Boolean;
511 ID: DWORD;
512 MaskID: DWORD;
513 RAngle: Integer;
514 Color: TRGB;
515 Obj: TObj;
517 procedure getMapBox (out x, y, w, h: Integer); inline;
518 procedure moveBy (dx, dy: Integer); inline;
520 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
521 end;
524 PShell = ^TShell;
525 TShell = record
526 SpriteID: DWORD;
527 alive: Boolean;
528 SType: Byte;
529 RAngle: Integer;
530 Timeout: Cardinal;
531 CX, CY: Integer;
532 Obj: TObj;
534 procedure getMapBox (out x, y, w, h: Integer); inline;
535 procedure moveBy (dx, dy: Integer); inline;
537 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
538 end;
540 TCorpse = class{$IFDEF USE_MEMPOOL}(TPoolObject){$ENDIF}
541 private
542 FModelName: String;
543 FMess: Boolean;
544 FState: Byte;
545 FDamage: Byte;
546 FColor: TRGB;
547 FObj: TObj;
548 FPlayerUID: Word;
549 FAnimation: TAnimation;
550 FAnimationMask: TAnimation;
552 public
553 constructor Create(X, Y: Integer; ModelName: String; aMess: Boolean);
554 destructor Destroy(); override;
555 procedure Damage(Value: Word; SpawnerUID: Word; vx, vy: Integer);
556 procedure Update();
557 procedure Draw();
558 procedure SaveState (st: TStream);
559 procedure LoadState (st: TStream);
561 procedure getMapBox (out x, y, w, h: Integer); inline;
562 procedure moveBy (dx, dy: Integer); inline;
564 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
566 function ObjPtr (): PObj; inline;
568 property Obj: TObj read FObj; // copies object
569 property State: Byte read FState;
570 property Mess: Boolean read FMess;
571 end;
573 TTeamStat = Array [TEAM_RED..TEAM_BLUE] of
574 record
575 Goals: SmallInt;
576 end;
578 var
579 gPlayers: Array of TPlayer;
580 gCorpses: Array of TCorpse;
581 gGibs: Array of TGib;
582 gShells: Array of TShell;
583 gTeamStat: TTeamStat;
584 gFly: Boolean = False;
585 gAimLine: Boolean = False;
586 gChatBubble: Integer = 0;
587 gPlayerIndicator: Integer = 1;
588 gPlayerIndicatorStyle: Integer = 0;
589 gNumBots: Word = 0;
590 gSpectLatchPID1: Word = 0;
591 gSpectLatchPID2: Word = 0;
592 MAX_RUNVEL: Integer = 8;
593 VEL_JUMP: Integer = 10;
594 SHELL_TIMEOUT: Cardinal = 60000;
596 function Lerp(X, Y, Factor: Integer): Integer;
598 procedure g_Gibs_SetMax(Count: Word);
599 function g_Gibs_GetMax(): Word;
600 procedure g_Corpses_SetMax(Count: Word);
601 function g_Corpses_GetMax(): Word;
602 procedure g_Shells_SetMax(Count: Word);
603 function g_Shells_GetMax(): Word;
605 procedure g_Player_Init();
606 procedure g_Player_Free();
607 function g_Player_Create(ModelName: String; Color: TRGB; Team: Byte; Bot: Boolean): Word;
608 function g_Player_CreateFromState (st: TStream): Word;
609 procedure g_Player_Remove(UID: Word);
610 procedure g_Player_ResetTeams();
611 procedure g_Player_PreUpdate();
612 procedure g_Player_UpdateAll();
613 procedure g_Player_DrawAll();
614 procedure g_Player_DrawDebug(p: TPlayer);
615 procedure g_Player_DrawHealth();
616 procedure g_Player_RememberAll();
617 procedure g_Player_ResetAll(Force, Silent: Boolean);
618 function g_Player_Get(UID: Word): TPlayer;
619 function g_Player_GetCount(): Byte;
620 function g_Player_GetStats(): TPlayerStatArray;
621 function g_Player_ValidName(Name: String): Boolean;
622 function g_Player_CreateCorpse(Player: TPlayer): Integer;
623 procedure g_Player_CreateGibs(fX, fY: Integer; ModelName: String; fColor: TRGB);
624 procedure g_Player_CreateShell(fX, fY, dX, dY: Integer; T: Byte);
625 procedure g_Player_UpdatePhysicalObjects();
626 procedure g_Player_DrawCorpses();
627 procedure g_Player_DrawShells();
628 procedure g_Player_RemoveAllCorpses();
629 procedure g_Player_Corpses_SaveState (st: TStream);
630 procedure g_Player_Corpses_LoadState (st: TStream);
631 procedure g_Player_ResetReady();
632 procedure g_Bot_Add(Team, Difficult: Byte; Handicap: Integer = 100);
633 procedure g_Bot_AddList(Team: Byte; lname: ShortString; num: Integer = -1; Handicap: Integer = 100);
634 procedure g_Bot_MixNames();
635 procedure g_Bot_RemoveAll();
637 implementation
639 uses
640 {$INCLUDE ../nogl/noGLuses.inc}
641 {$IFDEF ENABLE_HOLMES}
642 g_holmes,
643 {$ENDIF}
644 e_log, g_map, g_items, g_console, g_gfx, Math,
645 g_options, g_triggers, g_menu, g_game, g_grid, e_res,
646 wadreader, g_main, g_monsters, CONFIG, g_language,
647 g_net, g_netmsg, g_window,
648 utils, xstreams;
650 const PLR_SAVE_VERSION = 0;
652 type
653 TBotProfile = record
654 name: ShortString;
655 model: ShortString;
656 team: Byte;
657 color: TRGB;
658 diag_fire: Byte;
659 invis_fire: Byte;
660 diag_precision: Byte;
661 fly_precision: Byte;
662 cover: Byte;
663 close_jump: Byte;
664 w_prior1: Array [WP_FIRST..WP_LAST] of Byte;
665 w_prior2: Array [WP_FIRST..WP_LAST] of Byte;
666 w_prior3: Array [WP_FIRST..WP_LAST] of Byte;
667 end;
669 const
670 TIME_RESPAWN1 = 1500;
671 TIME_RESPAWN2 = 2000;
672 TIME_RESPAWN3 = 3000;
673 AIR_DEF = 360;
674 AIR_MAX = 1091;
675 JET_MAX = 540; // ~30 sec
676 PLAYER_SUIT_TIME = 30000;
677 PLAYER_INVUL_TIME = 30000;
678 PLAYER_INVIS_TIME = 35000;
679 FRAG_COMBO_TIME = 3000;
680 VEL_SW = 4;
681 VEL_FLY = 6;
682 ANGLE_RIGHTUP = 55;
683 ANGLE_RIGHTDOWN = -35;
684 ANGLE_LEFTUP = 125;
685 ANGLE_LEFTDOWN = -145;
686 PLAYER_HEADRECT: TRectWH = (X:24; Y:12; Width:20; Height:12);
687 WEAPONPOINT: Array [TDirection] of TDFPoint = ((X:16; Y:32), (X:47; Y:32));
688 BOT_MAXJUMP = 84;
689 BOT_LONGDIST = 300;
690 BOT_UNSAFEDIST = 128;
691 TEAMCOLOR: Array [TEAM_RED..TEAM_BLUE] of TRGB = ((R:255; G:0; B:0),
692 (R:0; G:0; B:255));
693 DIFFICULT_EASY: TDifficult = (DiagFire: 32; InvisFire: 32; DiagPrecision: 32;
694 FlyPrecision: 32; Cover: 32; CloseJump: 32;
695 WeaponPrior:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior:(0,0,0,0,0,0,0,0,0,0,0));
696 DIFFICULT_MEDIUM: TDifficult = (DiagFire: 127; InvisFire: 127; DiagPrecision: 127;
697 FlyPrecision: 127; Cover: 127; CloseJump: 127;
698 WeaponPrior:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior:(0,0,0,0,0,0,0,0,0,0,0));
699 DIFFICULT_HARD: TDifficult = (DiagFire: 255; InvisFire: 255; DiagPrecision: 255;
700 FlyPrecision: 255; Cover: 255; CloseJump: 255;
701 WeaponPrior:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior:(0,0,0,0,0,0,0,0,0,0,0));
702 WEAPON_PRIOR1: Array [WP_FIRST..WP_LAST] of Byte =
703 (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
704 WEAPON_SHOTGUN2, WEAPON_SHOTGUN1,
705 WEAPON_CHAINGUN, WEAPON_PLASMA, WEAPON_ROCKETLAUNCHER,
706 WEAPON_BFG, WEAPON_PISTOL, WEAPON_SAW, WEAPON_KASTET);
707 WEAPON_PRIOR2: Array [WP_FIRST..WP_LAST] of Byte =
708 (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
709 WEAPON_BFG, WEAPON_ROCKETLAUNCHER,
710 WEAPON_SHOTGUN2, WEAPON_PLASMA, WEAPON_SHOTGUN1,
711 WEAPON_CHAINGUN, WEAPON_PISTOL, WEAPON_SAW, WEAPON_KASTET);
712 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
713 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
714 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
715 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
716 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
717 WEAPON_RELOAD: Array [WP_FIRST..WP_LAST] of Byte =
718 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
720 PLAYER_SIGNATURE = $52594C50; // 'PLYR'
721 CORPSE_SIGNATURE = $50524F43; // 'CORP'
723 BOTNAMES_FILENAME = 'botnames.txt';
724 BOTLIST_FILENAME = 'botlist.txt';
726 var
727 MaxGibs: Word = 150;
728 MaxCorpses: Word = 20;
729 MaxShells: Word = 300;
730 CurrentGib: Integer = 0;
731 CurrentShell: Integer = 0;
732 BotNames: Array of String;
733 BotList: Array of TBotProfile;
734 SavedStates: Array of TPlayerSavedState;
737 function Lerp(X, Y, Factor: Integer): Integer;
738 begin
739 Result := X + ((Y - X) div Factor);
740 end;
742 function SameTeam(UID1, UID2: Word): Boolean;
743 begin
744 Result := False;
746 if (UID1 > UID_MAX_PLAYER) or (UID1 <= UID_MAX_GAME) or
747 (UID2 > UID_MAX_PLAYER) or (UID2 <= UID_MAX_GAME) then Exit;
749 if (g_Player_Get(UID1) = nil) or (g_Player_Get(UID2) = nil) then Exit;
751 if ((g_Player_Get(UID1).Team = TEAM_NONE) or
752 (g_Player_Get(UID2).Team = TEAM_NONE)) then Exit;
754 Result := g_Player_Get(UID1).FTeam = g_Player_Get(UID2).FTeam;
755 end;
757 procedure g_Gibs_SetMax(Count: Word);
758 begin
759 MaxGibs := Count;
760 SetLength(gGibs, Count);
762 if CurrentGib >= Count then
763 CurrentGib := 0;
764 end;
766 function g_Gibs_GetMax(): Word;
767 begin
768 Result := MaxGibs;
769 end;
771 procedure g_Shells_SetMax(Count: Word);
772 begin
773 MaxShells := Count;
774 SetLength(gShells, Count);
776 if CurrentShell >= Count then
777 CurrentShell := 0;
778 end;
780 function g_Shells_GetMax(): Word;
781 begin
782 Result := MaxShells;
783 end;
786 procedure g_Corpses_SetMax(Count: Word);
787 begin
788 MaxCorpses := Count;
789 SetLength(gCorpses, Count);
790 end;
792 function g_Corpses_GetMax(): Word;
793 begin
794 Result := MaxCorpses;
795 end;
797 function g_Player_Create(ModelName: String; Color: TRGB; Team: Byte; Bot: Boolean): Word;
798 var
799 a: Integer;
800 ok: Boolean;
801 begin
802 Result := 0;
804 ok := False;
805 a := 0;
807 // Åñòü ëè ìåñòî â gPlayers:
808 if gPlayers <> nil then
809 for a := 0 to High(gPlayers) do
810 if gPlayers[a] = nil then
811 begin
812 ok := True;
813 Break;
814 end;
816 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
817 if not ok then
818 begin
819 SetLength(gPlayers, Length(gPlayers)+1);
820 a := High(gPlayers);
821 end;
823 // Ñîçäàåì îáúåêò èãðîêà:
824 if Bot then
825 gPlayers[a] := TBot.Create()
826 else
827 gPlayers[a] := TPlayer.Create();
830 gPlayers[a].FActualModelName := ModelName;
831 gPlayers[a].SetModel(ModelName);
833 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
834 if gPlayers[a].FModel = nil then
835 begin
836 gPlayers[a].Free();
837 gPlayers[a] := nil;
838 g_FatalError(Format(_lc[I_GAME_ERROR_MODEL], [ModelName]));
839 Exit;
840 end;
842 if not (Team in [TEAM_RED, TEAM_BLUE]) then
843 if Random(2) = 0 then
844 Team := TEAM_RED
845 else
846 Team := TEAM_BLUE;
847 gPlayers[a].FPreferredTeam := Team;
849 case gGameSettings.GameMode of
850 GM_DM: gPlayers[a].FTeam := TEAM_NONE;
851 GM_TDM,
852 GM_CTF: gPlayers[a].FTeam := gPlayers[a].FPreferredTeam;
853 GM_SINGLE,
854 GM_COOP: gPlayers[a].FTeam := TEAM_COOP;
855 end;
857 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
858 gPlayers[a].FColor := Color;
859 if gPlayers[a].FTeam in [TEAM_RED, TEAM_BLUE] then
860 gPlayers[a].FModel.Color := TEAMCOLOR[gPlayers[a].FTeam]
861 else
862 gPlayers[a].FModel.Color := Color;
864 gPlayers[a].FUID := g_CreateUID(UID_PLAYER);
865 gPlayers[a].FAlive := False;
867 Result := gPlayers[a].FUID;
868 end;
870 function g_Player_CreateFromState (st: TStream): Word;
871 var a: Integer; ok, Bot: Boolean; pos: Int64;
872 begin
873 assert(st <> nil);
875 // check signature and entity type
876 pos := st.Position;
877 if not utils.checkSign(st, 'PLYR') then raise XStreamError.Create('invalid player signature');
878 if (utils.readByte(st) <> PLR_SAVE_VERSION) then raise XStreamError.Create('invalid player version');
879 Bot := utils.readBool(st);
880 st.Position := pos;
882 // find free player slot
883 ok := false;
884 for a := 0 to High(gPlayers) do
885 if gPlayers[a] = nil then
886 begin
887 ok := true;
888 break;
889 end;
891 // allocate player slot
892 if not ok then
893 begin
894 SetLength(gPlayers, Length(gPlayers)+1);
895 a := High(gPlayers);
896 end;
898 // create entity and load state
899 if Bot then
900 gPlayers[a] := TBot.Create()
901 else
902 gPlayers[a] := TPlayer.Create();
903 gPlayers[a].FPhysics := True; // ???
904 gPlayers[a].LoadState(st);
906 result := gPlayers[a].FUID;
907 end;
910 procedure g_Player_ResetTeams();
911 var
912 a: Integer;
913 begin
914 if g_Game_IsClient then
915 Exit;
916 if gPlayers = nil then
917 Exit;
918 for a := Low(gPlayers) to High(gPlayers) do
919 if gPlayers[a] <> nil then
920 case gGameSettings.GameMode of
921 GM_DM:
922 gPlayers[a].ChangeTeam(TEAM_NONE);
923 GM_TDM, GM_CTF:
924 if not (gPlayers[a].Team in [TEAM_RED, TEAM_BLUE]) then
925 if gPlayers[a].FPreferredTeam in [TEAM_RED, TEAM_BLUE] then
926 gPlayers[a].ChangeTeam(gPlayers[a].FPreferredTeam)
927 else
928 if a mod 2 = 0 then
929 gPlayers[a].ChangeTeam(TEAM_RED)
930 else
931 gPlayers[a].ChangeTeam(TEAM_BLUE);
932 GM_SINGLE,
933 GM_COOP:
934 gPlayers[a].ChangeTeam(TEAM_COOP);
935 end;
936 end;
938 procedure g_Bot_Add(Team, Difficult: Byte; Handicap: Integer = 100);
939 var
940 m: SSArray;
941 _name, _model: String;
942 a, tr, tb: Integer;
943 begin
944 if not g_Game_IsServer then Exit;
946 // Ñïèñîê íàçâàíèé ìîäåëåé:
947 m := g_PlayerModel_GetNames();
948 if m = nil then
949 Exit;
951 // Êîìàíäà:
952 if (gGameSettings.GameType = GT_SINGLE) or (gGameSettings.GameMode = GM_COOP) then
953 Team := TEAM_COOP // COOP
954 else
955 if gGameSettings.GameMode = GM_DM then
956 Team := TEAM_NONE // DM
957 else
958 if Team = TEAM_NONE then // CTF / TDM
959 begin
960 // Àâòîáàëàíñ êîìàíä:
961 tr := 0;
962 tb := 0;
964 for a := 0 to High(gPlayers) do
965 if gPlayers[a] <> nil then
966 begin
967 if gPlayers[a].Team = TEAM_RED then
968 Inc(tr)
969 else
970 if gPlayers[a].Team = TEAM_BLUE then
971 Inc(tb);
972 end;
974 if tr > tb then
975 Team := TEAM_BLUE
976 else
977 if tb > tr then
978 Team := TEAM_RED
979 else // tr = tb
980 if Random(2) = 0 then
981 Team := TEAM_RED
982 else
983 Team := TEAM_BLUE;
984 end;
986 // Âûáèðàåì áîòó èìÿ:
987 _name := '';
988 if BotNames <> nil then
989 for a := 0 to High(BotNames) do
990 if g_Player_ValidName(BotNames[a]) then
991 begin
992 _name := BotNames[a];
993 Break;
994 end;
996 // Âûáèðàåì ñëó÷àéíóþ ìîäåëü:
997 _model := m[Random(Length(m))];
999 // Ñîçäàåì áîòà:
1000 with g_Player_Get(g_Player_Create(_model,
1001 _RGB(Min(Random(9)*32, 255),
1002 Min(Random(9)*32, 255),
1003 Min(Random(9)*32, 255)),
1004 Team, True)) as TBot do
1005 begin
1006 // Åñëè èìåíè íåò, äåëàåì åãî èç UID áîòà
1007 if _name = '' then
1008 Name := Format('DFBOT%.5d', [UID])
1009 else
1010 Name := _name;
1012 case Difficult of
1013 1: FDifficult := DIFFICULT_EASY;
1014 2: FDifficult := DIFFICULT_MEDIUM;
1015 else FDifficult := DIFFICULT_HARD;
1016 end;
1018 for a := WP_FIRST to WP_LAST do
1019 begin
1020 FDifficult.WeaponPrior[a] := WEAPON_PRIOR1[a];
1021 FDifficult.CloseWeaponPrior[a] := WEAPON_PRIOR2[a];
1022 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1023 end;
1025 FHandicap := Handicap;
1027 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [Name]), True);
1029 if g_Game_IsNet then MH_SEND_PlayerCreate(UID);
1030 if g_Game_IsServer and (gGameSettings.MaxLives > 0) then
1031 Spectate();
1032 end;
1033 end;
1035 procedure g_Bot_AddList(Team: Byte; lName: ShortString; num: Integer = -1; Handicap: Integer = 100);
1036 var
1037 m: SSArray;
1038 _name, _model: String;
1039 a: Integer;
1040 begin
1041 if not g_Game_IsServer then Exit;
1043 // Ñïèñîê íàçâàíèé ìîäåëåé:
1044 m := g_PlayerModel_GetNames();
1045 if m = nil then
1046 Exit;
1048 // Êîìàíäà:
1049 if (gGameSettings.GameType = GT_SINGLE) or (gGameSettings.GameMode = GM_COOP) then
1050 Team := TEAM_COOP // COOP
1051 else
1052 if gGameSettings.GameMode = GM_DM then
1053 Team := TEAM_NONE // DM
1054 else
1055 if Team = TEAM_NONE then
1056 Team := BotList[num].team; // CTF / TDM
1058 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1059 lName := AnsiLowerCase(lName);
1060 if (num < 0) or (num > Length(BotList)-1) then
1061 num := -1;
1062 if (num = -1) and (lName <> '') and (BotList <> nil) then
1063 for a := 0 to High(BotList) do
1064 if AnsiLowerCase(BotList[a].name) = lName then
1065 begin
1066 num := a;
1067 Break;
1068 end;
1069 if num = -1 then
1070 Exit;
1072 // Èìÿ áîòà:
1073 _name := BotList[num].name;
1074 // Çàíÿòî - âûáèðàåì ñëó÷àéíîå:
1075 if not g_Player_ValidName(_name) then
1076 repeat
1077 _name := Format('DFBOT%.2d', [Random(100)]);
1078 until g_Player_ValidName(_name);
1080 // Ìîäåëü:
1081 _model := BotList[num].model;
1082 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1083 if not InSArray(_model, m) then
1084 _model := m[Random(Length(m))];
1086 // Ñîçäàåì áîòà:
1087 with g_Player_Get(g_Player_Create(_model, BotList[num].color, Team, True)) as TBot do
1088 begin
1089 Name := _name;
1091 FDifficult.DiagFire := BotList[num].diag_fire;
1092 FDifficult.InvisFire := BotList[num].invis_fire;
1093 FDifficult.DiagPrecision := BotList[num].diag_precision;
1094 FDifficult.FlyPrecision := BotList[num].fly_precision;
1095 FDifficult.Cover := BotList[num].cover;
1096 FDifficult.CloseJump := BotList[num].close_jump;
1098 FHandicap := Handicap;
1100 for a := WP_FIRST to WP_LAST do
1101 begin
1102 FDifficult.WeaponPrior[a] := BotList[num].w_prior1[a];
1103 FDifficult.CloseWeaponPrior[a] := BotList[num].w_prior2[a];
1104 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1105 end;
1107 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [Name]), True);
1109 if g_Game_IsNet then MH_SEND_PlayerCreate(UID);
1110 end;
1111 end;
1113 procedure g_Bot_RemoveAll();
1114 var
1115 a: Integer;
1116 begin
1117 if not g_Game_IsServer then Exit;
1118 if gPlayers = nil then Exit;
1120 for a := 0 to High(gPlayers) do
1121 if gPlayers[a] <> nil then
1122 if gPlayers[a] is TBot then
1123 begin
1124 gPlayers[a].Lives := 0;
1125 gPlayers[a].Kill(K_SIMPLEKILL, 0, HIT_DISCON);
1126 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [gPlayers[a].Name]), True);
1127 g_Player_Remove(gPlayers[a].FUID);
1128 end;
1130 g_Bot_MixNames();
1131 end;
1133 procedure g_Bot_MixNames();
1134 var
1135 s: String;
1136 a, b: Integer;
1137 begin
1138 if BotNames <> nil then
1139 for a := 0 to High(BotNames) do
1140 begin
1141 b := Random(Length(BotNames));
1142 s := BotNames[a];
1143 Botnames[a] := BotNames[b];
1144 BotNames[b] := s;
1145 end;
1146 end;
1148 procedure g_Player_Remove(UID: Word);
1149 var
1150 i: Integer;
1151 begin
1152 if gPlayers = nil then Exit;
1154 if g_Game_IsServer and g_Game_IsNet then
1155 MH_SEND_PlayerDelete(UID);
1157 for i := 0 to High(gPlayers) do
1158 if gPlayers[i] <> nil then
1159 if gPlayers[i].FUID = UID then
1160 begin
1161 if gPlayers[i] is TPlayer then
1162 TPlayer(gPlayers[i]).Free()
1163 else
1164 TBot(gPlayers[i]).Free();
1165 gPlayers[i] := nil;
1166 Exit;
1167 end;
1168 end;
1170 procedure g_Player_Init();
1171 var
1172 F: TextFile;
1173 s: String;
1174 a, b: Integer;
1175 config: TConfig;
1176 sa: SSArray;
1177 path: AnsiString;
1178 begin
1179 BotNames := nil;
1181 path := BOTNAMES_FILENAME;
1182 if e_FindResource(DataDirs, path) = false then
1183 Exit;
1185 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1186 AssignFile(F, path);
1187 Reset(F);
1189 while not EOF(F) do
1190 begin
1191 ReadLn(F, s);
1193 s := Trim(s);
1194 if s = '' then
1195 Continue;
1197 SetLength(BotNames, Length(BotNames)+1);
1198 BotNames[High(BotNames)] := s;
1199 end;
1201 CloseFile(F);
1203 // Ïåðåìåøèâàåì èõ:
1204 g_Bot_MixNames();
1206 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1207 config := TConfig.CreateFile(path);
1208 BotList := nil;
1209 a := 0;
1211 while config.SectionExists(IntToStr(a)) do
1212 begin
1213 SetLength(BotList, Length(BotList)+1);
1215 with BotList[High(BotList)] do
1216 begin
1217 // Èìÿ áîòà:
1218 name := config.ReadStr(IntToStr(a), 'name', '');
1219 // Ìîäåëü:
1220 model := config.ReadStr(IntToStr(a), 'model', '');
1221 // Êîìàíäà:
1222 if config.ReadStr(IntToStr(a), 'team', 'red') = 'red' then
1223 team := TEAM_RED
1224 else
1225 team := TEAM_BLUE;
1226 // Öâåò ìîäåëè:
1227 sa := parse(config.ReadStr(IntToStr(a), 'color', ''));
1228 color.R := StrToIntDef(sa[0], 0);
1229 color.G := StrToIntDef(sa[1], 0);
1230 color.B := StrToIntDef(sa[2], 0);
1231 // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì:
1232 diag_fire := config.ReadInt(IntToStr(a), 'diag_fire', 0);
1233 // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó:
1234 invis_fire := config.ReadInt(IntToStr(a), 'invis_fire', 0);
1235 // Òî÷íîñòü ñòðåëüáû ïîä óãëîì:
1236 diag_precision := config.ReadInt(IntToStr(a), 'diag_precision', 0);
1237 // Òî÷íîñòü ñòðåëüáû â ïîëåòå:
1238 fly_precision := config.ReadInt(IntToStr(a), 'fly_precision', 0);
1239 // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ:
1240 cover := config.ReadInt(IntToStr(a), 'cover', 0);
1241 // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà:
1242 close_jump := config.ReadInt(IntToStr(a), 'close_jump', 0);
1243 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ:
1244 sa := parse(config.ReadStr(IntToStr(a), 'w_prior1', ''));
1245 if Length(sa) = 10 then
1246 for b := 0 to 9 do
1247 w_prior1[b] := EnsureRange(StrToInt(sa[b]), 0, 9);
1248 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ:
1249 sa := parse(config.ReadStr(IntToStr(a), 'w_prior2', ''));
1250 if Length(sa) = 10 then
1251 for b := 0 to 9 do
1252 w_prior2[b] := EnsureRange(StrToInt(sa[b]), 0, 9);
1254 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1255 if Length(sa) = 10 then
1256 for b := 0 to 9 do
1257 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1258 end;
1260 a := a + 1;
1261 end;
1263 config.Free();
1264 SetLength(SavedStates, 0);
1265 end;
1267 procedure g_Player_Free();
1268 var
1269 i: Integer;
1270 begin
1271 if gPlayers <> nil then
1272 begin
1273 for i := 0 to High(gPlayers) do
1274 if gPlayers[i] <> nil then
1275 begin
1276 if gPlayers[i] is TPlayer then
1277 TPlayer(gPlayers[i]).Free()
1278 else
1279 TBot(gPlayers[i]).Free();
1280 gPlayers[i] := nil;
1281 end;
1283 gPlayers := nil;
1284 end;
1286 gPlayer1 := nil;
1287 gPlayer2 := nil;
1288 SetLength(SavedStates, 0);
1289 end;
1291 procedure g_Player_PreUpdate();
1292 var
1293 i: Integer;
1294 begin
1295 if gPlayers = nil then Exit;
1296 for i := 0 to High(gPlayers) do
1297 if gPlayers[i] <> nil then
1298 gPlayers[i].PreUpdate();
1299 end;
1301 procedure g_Player_UpdateAll();
1302 var
1303 i: Integer;
1304 begin
1305 if gPlayers = nil then Exit;
1307 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1308 for i := 0 to High(gPlayers) do
1309 begin
1310 if gPlayers[i] <> nil then
1311 begin
1312 if gPlayers[i] is TPlayer then
1313 begin
1314 gPlayers[i].Update();
1315 gPlayers[i].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1316 end
1317 else
1318 begin
1319 // bot updates weapons in `UpdateCombat()`
1320 TBot(gPlayers[i]).Update();
1321 end;
1322 end;
1323 end;
1324 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1325 end;
1327 procedure g_Player_DrawAll();
1328 var
1329 i: Integer;
1330 begin
1331 if gPlayers = nil then Exit;
1333 for i := 0 to High(gPlayers) do
1334 if gPlayers[i] <> nil then
1335 if gPlayers[i] is TPlayer then gPlayers[i].Draw()
1336 else TBot(gPlayers[i]).Draw();
1337 end;
1339 procedure g_Player_DrawDebug(p: TPlayer);
1340 var
1341 fW, fH: Byte;
1342 begin
1343 if p = nil then Exit;
1344 if (@p.FObj) = nil then Exit;
1346 e_TextureFontGetSize(gStdFont, fW, fH);
1348 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p.FObj.X), gStdFont);
1349 e_TextureFontPrint(0, fH , 'Pos Y: ' + IntToStr(p.FObj.Y), gStdFont);
1350 e_TextureFontPrint(0, fH * 2, 'Vel X: ' + IntToStr(p.FObj.Vel.X), gStdFont);
1351 e_TextureFontPrint(0, fH * 3, 'Vel Y: ' + IntToStr(p.FObj.Vel.Y), gStdFont);
1352 e_TextureFontPrint(0, fH * 4, 'Acc X: ' + IntToStr(p.FObj.Accel.X), gStdFont);
1353 e_TextureFontPrint(0, fH * 5, 'Acc Y: ' + IntToStr(p.FObj.Accel.Y), gStdFont);
1354 e_TextureFontPrint(0, fH * 6, 'Old X: ' + IntToStr(p.FObj.oldX), gStdFont);
1355 e_TextureFontPrint(0, fH * 7, 'Old Y: ' + IntToStr(p.FObj.oldY), gStdFont);
1356 end;
1358 procedure g_Player_DrawHealth();
1359 var
1360 i: Integer;
1361 fW, fH: Byte;
1362 begin
1363 if gPlayers = nil then Exit;
1364 e_TextureFontGetSize(gStdFont, fW, fH);
1366 for i := 0 to High(gPlayers) do
1367 if gPlayers[i] <> nil then
1368 begin
1369 e_TextureFontPrint(gPlayers[i].FObj.X + gPlayers[i].FObj.Rect.X,
1370 gPlayers[i].FObj.Y + gPlayers[i].FObj.Rect.Y + gPlayers[i].FObj.Rect.Height - fH * 2,
1371 IntToStr(gPlayers[i].FHealth), gStdFont);
1372 e_TextureFontPrint(gPlayers[i].FObj.X + gPlayers[i].FObj.Rect.X,
1373 gPlayers[i].FObj.Y + gPlayers[i].FObj.Rect.Y + gPlayers[i].FObj.Rect.Height - fH,
1374 IntToStr(gPlayers[i].FArmor), gStdFont);
1375 end;
1376 end;
1378 function g_Player_Get(UID: Word): TPlayer;
1379 var
1380 a: Integer;
1381 begin
1382 Result := nil;
1384 if gPlayers = nil then
1385 Exit;
1387 for a := 0 to High(gPlayers) do
1388 if gPlayers[a] <> nil then
1389 if gPlayers[a].FUID = UID then
1390 begin
1391 Result := gPlayers[a];
1392 Exit;
1393 end;
1394 end;
1396 function g_Player_GetCount(): Byte;
1397 var
1398 a: Integer;
1399 begin
1400 Result := 0;
1402 if gPlayers = nil then
1403 Exit;
1405 for a := 0 to High(gPlayers) do
1406 if gPlayers[a] <> nil then
1407 Result := Result + 1;
1408 end;
1410 function g_Player_GetStats(): TPlayerStatArray;
1411 var
1412 a: Integer;
1413 begin
1414 Result := nil;
1416 if gPlayers = nil then Exit;
1418 for a := 0 to High(gPlayers) do
1419 if gPlayers[a] <> nil then
1420 begin
1421 SetLength(Result, Length(Result)+1);
1422 with Result[High(Result)] do
1423 begin
1424 Num := a;
1425 Ping := gPlayers[a].FPing;
1426 Loss := gPlayers[a].FLoss;
1427 Name := gPlayers[a].FName;
1428 Team := gPlayers[a].FTeam;
1429 Frags := gPlayers[a].FFrags;
1430 Deaths := gPlayers[a].FDeath;
1431 Kills := gPlayers[a].FKills;
1432 Color := gPlayers[a].FModel.Color;
1433 Lives := gPlayers[a].FLives;
1434 Spectator := gPlayers[a].FSpectator;
1435 UID := gPlayers[a].FUID;
1436 end;
1437 end;
1438 end;
1440 procedure g_Player_ResetReady();
1441 var
1442 a: Integer;
1443 begin
1444 if not g_Game_IsServer then Exit;
1445 if gPlayers = nil then Exit;
1447 for a := 0 to High(gPlayers) do
1448 if gPlayers[a] <> nil then
1449 begin
1450 gPlayers[a].FReady := False;
1451 if g_Game_IsNet then
1452 MH_SEND_GameEvent(NET_EV_INTER_READY, gPlayers[a].UID, 'N');
1453 end;
1454 end;
1456 procedure g_Player_RememberAll;
1457 var
1458 i: Integer;
1459 begin
1460 for i := Low(gPlayers) to High(gPlayers) do
1461 if (gPlayers[i] <> nil) and gPlayers[i].alive then
1462 gPlayers[i].RememberState;
1463 end;
1465 procedure g_Player_ResetAll(Force, Silent: Boolean);
1466 var
1467 i: Integer;
1468 begin
1469 gTeamStat[TEAM_RED].Goals := 0;
1470 gTeamStat[TEAM_BLUE].Goals := 0;
1472 if gPlayers <> nil then
1473 for i := 0 to High(gPlayers) do
1474 if gPlayers[i] <> nil then
1475 begin
1476 gPlayers[i].Reset(Force);
1478 if gPlayers[i] is TPlayer then
1479 begin
1480 if (not gPlayers[i].FSpectator) or gPlayers[i].FWantsInGame then
1481 gPlayers[i].Respawn(Silent)
1482 else
1483 gPlayers[i].Spectate();
1484 end
1485 else
1486 TBot(gPlayers[i]).Respawn(Silent);
1487 end;
1488 end;
1490 function g_Player_CreateCorpse(Player: TPlayer): Integer;
1491 var
1492 i: Integer;
1493 find_id: DWORD;
1494 ok: Boolean;
1495 begin
1496 Result := -1;
1498 if Player.alive then
1499 Exit;
1501 // Ðàçðûâàåì ñâÿçü ñ ïðåæíèì òðóïîì:
1502 i := Player.FCorpse;
1503 if (i >= 0) and (i < Length(gCorpses)) then
1504 begin
1505 if (gCorpses[i] <> nil) and (gCorpses[i].FPlayerUID = Player.FUID) then
1506 gCorpses[i].FPlayerUID := 0;
1507 end;
1509 if Player.FObj.Y >= gMapInfo.Height+128 then
1510 Exit;
1512 with Player do
1513 begin
1514 if (FHealth >= -50) or (gGibsCount = 0) then
1515 begin
1516 if (gCorpses = nil) or (Length(gCorpses) = 0) then
1517 Exit;
1519 ok := False;
1520 for find_id := 0 to High(gCorpses) do
1521 if gCorpses[find_id] = nil then
1522 begin
1523 ok := True;
1524 Break;
1525 end;
1527 if not ok then
1528 find_id := Random(Length(gCorpses));
1530 gCorpses[find_id] := TCorpse.Create(FObj.X, FObj.Y, FModel.Name, FHealth < -20);
1531 gCorpses[find_id].FColor := FModel.Color;
1532 gCorpses[find_id].FObj.Vel := FObj.Vel;
1533 gCorpses[find_id].FObj.Accel := FObj.Accel;
1534 gCorpses[find_id].FPlayerUID := FUID;
1536 Result := find_id;
1537 end
1538 else
1539 g_Player_CreateGibs(FObj.X + PLAYER_RECT_CX,
1540 FObj.Y + PLAYER_RECT_CY,
1541 FModel.Name, FModel.Color);
1542 end;
1543 end;
1545 procedure g_Player_CreateShell(fX, fY, dX, dY: Integer; T: Byte);
1546 var
1547 SID: DWORD;
1548 begin
1549 if (gShells = nil) or (Length(gShells) = 0) then
1550 Exit;
1552 with gShells[CurrentShell] do
1553 begin
1554 SpriteID := 0;
1555 g_Obj_Init(@Obj);
1556 Obj.Rect.X := 0;
1557 Obj.Rect.Y := 0;
1558 if T = SHELL_BULLET then
1559 begin
1560 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID) then
1561 SpriteID := SID;
1562 CX := 2;
1563 CY := 1;
1564 Obj.Rect.Width := 4;
1565 Obj.Rect.Height := 2;
1566 end
1567 else
1568 begin
1569 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID) then
1570 SpriteID := SID;
1571 CX := 4;
1572 CY := 2;
1573 Obj.Rect.Width := 7;
1574 Obj.Rect.Height := 3;
1575 end;
1576 SType := T;
1577 alive := True;
1578 Obj.X := fX;
1579 Obj.Y := fY;
1580 g_Obj_Push(@Obj, dX + Random(4)-Random(4), dY-Random(4));
1581 positionChanged(); // this updates spatial accelerators
1582 RAngle := Random(360);
1583 Timeout := gTime + SHELL_TIMEOUT;
1585 if CurrentShell >= High(gShells) then
1586 CurrentShell := 0
1587 else
1588 Inc(CurrentShell);
1589 end;
1590 end;
1592 procedure g_Player_CreateGibs(fX, fY: Integer; ModelName: string; fColor: TRGB);
1593 var
1594 a: Integer;
1595 GibsArray: TGibsArray;
1596 Blood: TModelBlood;
1597 begin
1598 if (gGibs = nil) or (Length(gGibs) = 0) then
1599 Exit;
1600 if not g_PlayerModel_GetGibs(ModelName, GibsArray) then
1601 Exit;
1602 Blood := g_PlayerModel_GetBlood(ModelName);
1604 for a := 0 to High(GibsArray) do
1605 with gGibs[CurrentGib] do
1606 begin
1607 Color := fColor;
1608 ID := GibsArray[a].ID;
1609 MaskID := GibsArray[a].MaskID;
1610 alive := True;
1611 g_Obj_Init(@Obj);
1612 Obj.Rect := GibsArray[a].Rect;
1613 Obj.X := fX-GibsArray[a].Rect.X-(GibsArray[a].Rect.Width div 2);
1614 Obj.Y := fY-GibsArray[a].Rect.Y-(GibsArray[a].Rect.Height div 2);
1615 g_Obj_PushA(@Obj, 25 + Random(10), Random(361));
1616 positionChanged(); // this updates spatial accelerators
1617 RAngle := Random(360);
1619 if gBloodCount > 0 then
1620 g_GFX_Blood(fX, fY, 16*gBloodCount+Random(5*gBloodCount), -16+Random(33), -16+Random(33),
1621 Random(48), Random(48), Blood.R, Blood.G, Blood.B, Blood.Kind);
1623 if CurrentGib >= High(gGibs) then
1624 CurrentGib := 0
1625 else
1626 Inc(CurrentGib);
1627 end;
1628 end;
1630 procedure g_Player_UpdatePhysicalObjects();
1631 var
1632 i: Integer;
1633 vel: TPoint2i;
1634 mr: Word;
1636 procedure ShellSound_Bounce(X, Y: Integer; T: Byte);
1637 var
1638 k: Integer;
1639 begin
1640 k := 1 + Random(2);
1641 if T = SHELL_BULLET then
1642 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k), X, Y)
1643 else
1644 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k), X, Y);
1645 end;
1647 begin
1648 // Êóñêè ìÿñà:
1649 if gGibs <> nil then
1650 for i := 0 to High(gGibs) do
1651 if gGibs[i].alive then
1652 with gGibs[i] do
1653 begin
1654 Obj.oldX := Obj.X;
1655 Obj.oldY := Obj.Y;
1657 vel := Obj.Vel;
1658 mr := g_Obj_Move(@Obj, True, False, True);
1659 positionChanged(); // this updates spatial accelerators
1661 if WordBool(mr and MOVE_FALLOUT) then
1662 begin
1663 alive := False;
1664 Continue;
1665 end;
1667 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1668 if WordBool(mr and MOVE_HITWALL) then
1669 Obj.Vel.X := -(vel.X div 2);
1670 if WordBool(mr and (MOVE_HITCEIL or MOVE_HITLAND)) then
1671 Obj.Vel.Y := -(vel.Y div 2);
1673 if (Obj.Vel.X >= 0) then
1674 begin // Clockwise
1675 RAngle := RAngle + Abs(Obj.Vel.X)*6 + Abs(Obj.Vel.Y);
1676 if RAngle >= 360 then
1677 RAngle := RAngle mod 360;
1678 end else begin // Counter-clockwise
1679 RAngle := RAngle - Abs(Obj.Vel.X)*6 - Abs(Obj.Vel.Y);
1680 if RAngle < 0 then
1681 RAngle := (360 - (Abs(RAngle) mod 360)) mod 360;
1682 end;
1684 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1685 if gTime mod (GAME_TICK*3) = 0 then
1686 Obj.Vel.X := z_dec(Obj.Vel.X, 1);
1687 end;
1689 // Òðóïû:
1690 if gCorpses <> nil then
1691 for i := 0 to High(gCorpses) do
1692 if gCorpses[i] <> nil then
1693 if gCorpses[i].State = CORPSE_STATE_REMOVEME then
1694 begin
1695 gCorpses[i].Free();
1696 gCorpses[i] := nil;
1697 end
1698 else
1699 gCorpses[i].Update();
1701 // Ãèëüçû:
1702 if gShells <> nil then
1703 for i := 0 to High(gShells) do
1704 if gShells[i].alive then
1705 with gShells[i] do
1706 begin
1707 Obj.oldX := Obj.X;
1708 Obj.oldY := Obj.Y;
1710 vel := Obj.Vel;
1711 mr := g_Obj_Move(@Obj, True, False, True);
1712 positionChanged(); // this updates spatial accelerators
1714 if WordBool(mr and MOVE_FALLOUT) or (gShells[i].Timeout < gTime) then
1715 begin
1716 alive := False;
1717 Continue;
1718 end;
1720 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1721 if WordBool(mr and MOVE_HITWALL) then
1722 begin
1723 Obj.Vel.X := -(vel.X div 2);
1724 if not WordBool(mr and MOVE_INWATER) then
1725 ShellSound_Bounce(Obj.X, Obj.Y, SType);
1726 end;
1727 if WordBool(mr and (MOVE_HITCEIL or MOVE_HITLAND)) then
1728 begin
1729 Obj.Vel.Y := -(vel.Y div 2);
1730 if Obj.Vel.X <> 0 then Obj.Vel.X := Obj.Vel.X div 2;
1731 if (Obj.Vel.X = 0) and (Obj.Vel.Y = 0) then
1732 begin
1733 if RAngle mod 90 <> 0 then
1734 RAngle := (RAngle div 90) * 90;
1735 end
1736 else if not WordBool(mr and MOVE_INWATER) then
1737 ShellSound_Bounce(Obj.X, Obj.Y, SType);
1738 end;
1740 if (Obj.Vel.X >= 0) then
1741 begin // Clockwise
1742 RAngle := RAngle + Abs(Obj.Vel.X)*8 + Abs(Obj.Vel.Y);
1743 if RAngle >= 360 then
1744 RAngle := RAngle mod 360;
1745 end else begin // Counter-clockwise
1746 RAngle := RAngle - Abs(Obj.Vel.X)*8 - Abs(Obj.Vel.Y);
1747 if RAngle < 0 then
1748 RAngle := (360 - (Abs(RAngle) mod 360)) mod 360;
1749 end;
1750 end;
1751 end;
1754 procedure TGib.getMapBox (out x, y, w, h: Integer); inline;
1755 begin
1756 x := Obj.X+Obj.Rect.X;
1757 y := Obj.Y+Obj.Rect.Y;
1758 w := Obj.Rect.Width;
1759 h := Obj.Rect.Height;
1760 end;
1762 procedure TGib.moveBy (dx, dy: Integer); inline;
1763 begin
1764 if (dx <> 0) or (dy <> 0) then
1765 begin
1766 Obj.X += dx;
1767 Obj.Y += dy;
1768 positionChanged();
1769 end;
1770 end;
1773 procedure TShell.getMapBox (out x, y, w, h: Integer); inline;
1774 begin
1775 x := Obj.X;
1776 y := Obj.Y;
1777 w := Obj.Rect.Width;
1778 h := Obj.Rect.Height;
1779 end;
1781 procedure TShell.moveBy (dx, dy: Integer); inline;
1782 begin
1783 if (dx <> 0) or (dy <> 0) then
1784 begin
1785 Obj.X += dx;
1786 Obj.Y += dy;
1787 positionChanged();
1788 end;
1789 end;
1792 procedure TGib.positionChanged (); inline; begin end;
1793 procedure TShell.positionChanged (); inline; begin end;
1796 procedure g_Player_DrawCorpses();
1797 var
1798 i, fX, fY: Integer;
1799 a: TDFPoint;
1800 begin
1801 if gGibs <> nil then
1802 for i := 0 to High(gGibs) do
1803 if gGibs[i].alive then
1804 with gGibs[i] do
1805 begin
1806 if not g_Obj_Collide(sX, sY, sWidth, sHeight, @Obj) then
1807 Continue;
1809 Obj.lerp(gLerpFactor, fX, fY);
1811 a.X := Obj.Rect.X+(Obj.Rect.Width div 2);
1812 a.y := Obj.Rect.Y+(Obj.Rect.Height div 2);
1814 e_DrawAdv(ID, fX, fY, 0, True, False, RAngle, @a, TMirrorType.None);
1816 e_Colors := Color;
1817 e_DrawAdv(MaskID, fX, fY, 0, True, False, RAngle, @a, TMirrorType.None);
1818 e_Colors.R := 255;
1819 e_Colors.G := 255;
1820 e_Colors.B := 255;
1821 end;
1823 if gCorpses <> nil then
1824 for i := 0 to High(gCorpses) do
1825 if gCorpses[i] <> nil then
1826 gCorpses[i].Draw();
1827 end;
1829 procedure g_Player_DrawShells();
1830 var
1831 i, fX, fY: Integer;
1832 a: TDFPoint;
1833 begin
1834 if gShells <> nil then
1835 for i := 0 to High(gShells) do
1836 if gShells[i].alive then
1837 with gShells[i] do
1838 begin
1839 if not g_Obj_Collide(sX, sY, sWidth, sHeight, @Obj) then
1840 Continue;
1842 Obj.lerp(gLerpFactor, fX, fY);
1844 a.X := CX;
1845 a.Y := CY;
1847 e_DrawAdv(SpriteID, fX, fY, 0, True, False, RAngle, @a, TMirrorType.None);
1848 end;
1849 end;
1851 procedure g_Player_RemoveAllCorpses();
1852 var
1853 i: Integer;
1854 begin
1855 gGibs := nil;
1856 gShells := nil;
1857 SetLength(gGibs, MaxGibs);
1858 SetLength(gShells, MaxGibs);
1859 CurrentGib := 0;
1860 CurrentShell := 0;
1862 if gCorpses <> nil then
1863 for i := 0 to High(gCorpses) do
1864 gCorpses[i].Free();
1866 gCorpses := nil;
1867 SetLength(gCorpses, MaxCorpses);
1868 end;
1870 procedure g_Player_Corpses_SaveState (st: TStream);
1871 var
1872 count, i: Integer;
1873 begin
1874 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ
1875 count := 0;
1876 for i := 0 to High(gCorpses) do if (gCorpses[i] <> nil) then Inc(count);
1878 // Êîëè÷åñòâî òðóïîâ
1879 utils.writeInt(st, LongInt(count));
1881 if (count = 0) then exit;
1883 // Ñîõðàíÿåì òðóïû
1884 for i := 0 to High(gCorpses) do
1885 begin
1886 if gCorpses[i] <> nil then
1887 begin
1888 // Íàçâàíèå ìîäåëè
1889 utils.writeStr(st, gCorpses[i].FModelName);
1890 // Òèï ñìåðòè
1891 utils.writeBool(st, gCorpses[i].Mess);
1892 // Ñîõðàíÿåì äàííûå òðóïà:
1893 gCorpses[i].SaveState(st);
1894 end;
1895 end;
1896 end;
1899 procedure g_Player_Corpses_LoadState (st: TStream);
1900 var
1901 count, i: Integer;
1902 str: String;
1903 b: Boolean;
1904 begin
1905 assert(st <> nil);
1907 g_Player_RemoveAllCorpses();
1909 // Êîëè÷åñòâî òðóïîâ:
1910 count := utils.readLongInt(st);
1911 if (count < 0) or (count > Length(gCorpses)) then raise XStreamError.Create('invalid number of corpses');
1913 if (count = 0) then exit;
1915 // Çàãðóæàåì òðóïû
1916 for i := 0 to count-1 do
1917 begin
1918 // Íàçâàíèå ìîäåëè:
1919 str := utils.readStr(st);
1920 // Òèï ñìåðòè
1921 b := utils.readBool(st);
1922 // Ñîçäàåì òðóï
1923 gCorpses[i] := TCorpse.Create(0, 0, str, b);
1924 // Çàãðóæàåì äàííûå òðóïà
1925 gCorpses[i].LoadState(st);
1926 end;
1927 end;
1930 { T P l a y e r : }
1932 function TPlayer.isValidViewPort (): Boolean; inline; begin result := (viewPortW > 0) and (viewPortH > 0); end;
1934 procedure TPlayer.BFGHit();
1935 begin
1936 g_Weapon_BFGHit(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
1937 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2));
1938 if g_Game_IsServer and g_Game_IsNet then
1939 MH_SEND_Effect(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
1940 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
1941 0, NET_GFX_BFGHIT);
1942 end;
1944 procedure TPlayer.ChangeModel(ModelName: string);
1945 var
1946 locModel: TPlayerModel;
1947 begin
1948 locModel := g_PlayerModel_Get(ModelName);
1949 if locModel = nil then Exit;
1951 FModel.Free();
1952 FModel := locModel;
1953 end;
1955 procedure TPlayer.SetModel(ModelName: string);
1956 var
1957 m: TPlayerModel;
1958 begin
1959 m := g_PlayerModel_Get(ModelName);
1960 if m = nil then
1961 begin
1962 g_SimpleError(Format(_lc[I_GAME_ERROR_MODEL_FALLBACK], [ModelName]));
1963 m := g_PlayerModel_Get('doomer');
1964 if m = nil then
1965 begin
1966 g_FatalError(Format(_lc[I_GAME_ERROR_MODEL], ['doomer']));
1967 Exit;
1968 end;
1969 end;
1971 if FModel <> nil then
1972 FModel.Free();
1974 FModel := m;
1976 if not (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
1977 FModel.Color := FColor
1978 else
1979 FModel.Color := TEAMCOLOR[FTeam];
1980 FModel.SetWeapon(FCurrWeap);
1981 FModel.SetFlag(FFlag);
1982 SetDirection(FDirection);
1983 end;
1985 procedure TPlayer.SetColor(Color: TRGB);
1986 begin
1987 FColor := Color;
1988 if not (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
1989 if FModel <> nil then FModel.Color := Color;
1990 end;
1994 function TPlayer.GetColor(): TRGB;
1995 begin
1996 result := FModel.Color;
1997 end;
1999 procedure TPlayer.SetWeaponPrefs(Prefs: Array of Byte);
2000 var i: Integer;
2001 begin
2002 for i := WP_FIRST to WP_LAST + 1 do
2003 begin
2004 if (Prefs[i] < 0) or (Prefs[i] > WP_LAST + 1) then
2005 FWeapPreferences[i] := 0
2006 else FWeapPreferences[i] := Prefs[i];
2007 end;
2008 end;
2010 procedure TPlayer.SetWeaponPref(Weapon, Pref: Byte);
2011 begin
2012 if (Weapon < 0) or (Weapon > WP_LAST + 1) then
2013 exit
2014 else if (Pref >= 0) and (Pref <= WP_LAST + 1) and (Weapon >= 0) and (Weapon <= WP_LAST + 1) then
2015 FWeapPreferences[Weapon] := Pref
2016 else if (Weapon >= 0) and (Weapon <= WP_LAST + 1) and ((Pref < 0) or (Pref > WP_LAST + 1)) then
2017 FWeapPreferences[Weapon] := 0;
2018 end;
2020 function TPlayer.GetWeaponPref(Weapon: Byte) : Byte;
2021 begin
2022 if (Weapon < 0) or (Weapon > WP_LAST + 1) then
2023 result := 0
2024 else if (FWeapPreferences[Weapon] < 0) or (FWeapPreferences[Weapon] > WP_LAST + 1) then
2025 result := 0
2026 else
2027 result := FWeapPreferences[Weapon];
2028 end;
2030 function TPlayer.GetMorePrefered() : Byte;
2031 var testedWeap, i: Byte;
2032 begin
2033 testedWeap := FCurrWeap;
2034 for i := WP_FIRST to WP_LAST do
2035 if FWeapon[i] and (FWeapPreferences[i] > FWeapPreferences[testedWeap]) then
2036 testedWeap := i;
2037 if (R_BERSERK in FRulez) and (FWeapPreferences[WP_LAST + 1] > FWeapPreferences[testedWeap]) then
2038 testedWeap := WEAPON_KASTET;
2039 result := testedWeap;
2040 end;
2042 function TPlayer.maySwitch(Weapon: Byte) : Boolean;
2043 begin
2044 result := true;
2045 if (Weapon = WEAPON_KASTET) and (FSkipFist <> 0) then
2046 begin
2047 if (FSkipFist = 1) and (not (R_BERSERK in FRulez)) then
2048 result := false;
2049 end
2050 else if (FSwitchToEmpty = 0) and (not hasAmmoForWeapon(Weapon)) then
2051 result := false
2052 end;
2054 procedure TPlayer.SwitchTeam;
2055 begin
2056 if g_Game_IsClient then
2057 Exit;
2058 if not (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then Exit;
2060 if gGameOn and FAlive then
2061 Kill(K_SIMPLEKILL, FUID, HIT_SELF);
2063 if FTeam = TEAM_RED then
2064 begin
2065 ChangeTeam(TEAM_BLUE);
2066 g_Console_Add(Format(_lc[I_PLAYER_CHTEAM_BLUE], [FName]), True);
2067 if g_Game_IsNet then
2068 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM, TEAM_BLUE, FName);
2069 end
2070 else
2071 begin
2072 ChangeTeam(TEAM_RED);
2073 g_Console_Add(Format(_lc[I_PLAYER_CHTEAM_RED], [FName]), True);
2074 if g_Game_IsNet then
2075 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM, TEAM_RED, FName);
2076 end;
2077 FPreferredTeam := FTeam;
2078 end;
2080 procedure TPlayer.ChangeTeam(Team: Byte);
2081 var
2082 OldTeam: Byte;
2083 begin
2084 OldTeam := FTeam;
2085 FTeam := Team;
2086 case Team of
2087 TEAM_RED, TEAM_BLUE:
2088 FModel.Color := TEAMCOLOR[Team];
2089 else
2090 FModel.Color := FColor;
2091 end;
2092 if (FTeam <> OldTeam) and g_Game_IsNet and g_Game_IsServer then
2093 MH_SEND_PlayerStats(FUID);
2094 end;
2097 procedure TPlayer.CollideItem();
2098 var
2099 i: Integer;
2100 r: Boolean;
2101 begin
2102 if gItems = nil then Exit;
2103 if not FAlive then Exit;
2105 for i := 0 to High(gItems) do
2106 with gItems[i] do
2107 begin
2108 if (ItemType <> ITEM_NONE) and alive then
2109 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
2110 PLAYER_RECT.Height, @Obj) then
2111 begin
2112 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
2114 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
2115 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
2116 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
2117 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
2118 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
2120 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
2121 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
2122 (gGameSettings.GameType = GT_SINGLE) and
2123 (g_Player_GetCount() > 1)) then
2124 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
2125 end;
2126 end;
2127 end;
2130 function TPlayer.CollideLevel(XInc, YInc: Integer): Boolean;
2131 begin
2132 Result := g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc,
2133 PLAYER_RECT.Width, PLAYER_RECT.Height, PANEL_WALL,
2134 False);
2135 end;
2137 constructor TPlayer.Create();
2138 begin
2139 viewPortX := 0;
2140 viewPortY := 0;
2141 viewPortW := 0;
2142 viewPortH := 0;
2143 mEDamageType := HIT_SOME;
2145 FIamBot := False;
2146 FDummy := False;
2147 FSpawned := False;
2149 FSawSound := TPlayableSound.Create();
2150 FSawSoundIdle := TPlayableSound.Create();
2151 FSawSoundHit := TPlayableSound.Create();
2152 FSawSoundSelect := TPlayableSound.Create();
2153 FFlameSoundOn := TPlayableSound.Create();
2154 FFlameSoundOff := TPlayableSound.Create();
2155 FFlameSoundWork := TPlayableSound.Create();
2156 FJetSoundFly := TPlayableSound.Create();
2157 FJetSoundOn := TPlayableSound.Create();
2158 FJetSoundOff := TPlayableSound.Create();
2160 FSawSound.SetByName('SOUND_WEAPON_FIRESAW');
2161 FSawSoundIdle.SetByName('SOUND_WEAPON_IDLESAW');
2162 FSawSoundHit.SetByName('SOUND_WEAPON_HITSAW');
2163 FSawSoundSelect.SetByName('SOUND_WEAPON_SELECTSAW');
2164 FFlameSoundOn.SetByName('SOUND_WEAPON_FLAMEON');
2165 FFlameSoundOff.SetByName('SOUND_WEAPON_FLAMEOFF');
2166 FFlameSoundWork.SetByName('SOUND_WEAPON_FLAMEWORK');
2167 FJetSoundFly.SetByName('SOUND_PLAYER_JETFLY');
2168 FJetSoundOn.SetByName('SOUND_PLAYER_JETON');
2169 FJetSoundOff.SetByName('SOUND_PLAYER_JETOFF');
2171 FSpectatePlayer := -1;
2172 FClientID := -1;
2173 FPing := 0;
2174 FLoss := 0;
2175 FSavedStateNum := -1;
2176 FShellTimer := -1;
2177 FFireTime := 0;
2178 FFirePainTime := 0;
2179 FFireAttacker := 0;
2180 FHandicap := 100;
2181 FCorpse := -1;
2183 FActualModelName := 'doomer';
2185 g_Obj_Init(@FObj);
2186 FObj.Rect := PLAYER_RECT;
2188 FBFGFireCounter := -1;
2189 FJustTeleported := False;
2190 FNetTime := 0;
2192 FWaitForFirstSpawn := false;
2194 resetWeaponQueue();
2195 end;
2197 procedure TPlayer.positionChanged (); inline;
2198 begin
2199 end;
2201 procedure TPlayer.doDamage (v: Integer);
2202 begin
2203 if (v <= 0) then exit;
2204 if (v > 32767) then v := 32767;
2205 Damage(v, 0, 0, 0, mEDamageType);
2206 end;
2208 procedure TPlayer.Damage(value: Word; SpawnerUID: Word; vx, vy: Integer; t: Byte);
2209 var
2210 c: Word;
2211 begin
2212 if (not g_Game_IsClient) and (not FAlive) then
2213 Exit;
2215 FLastHit := t;
2217 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2218 if ((t = HIT_TRAP) or (t = HIT_SELF)) and (not FGodMode) then
2219 begin
2220 if not g_Game_IsClient then
2221 begin
2222 FArmor := 0;
2223 if t = HIT_TRAP then
2224 begin
2225 // Ëîâóøêà óáèâàåò ñðàçó:
2226 FHealth := -100;
2227 Kill(K_EXTRAHARDKILL, SpawnerUID, t);
2228 end;
2229 if t = HIT_SELF then
2230 begin
2231 // Ñàìîóáèéñòâî:
2232 FHealth := 0;
2233 Kill(K_SIMPLEKILL, SpawnerUID, t);
2234 end;
2235 end;
2236 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2237 FMegaRulez[MR_SUIT] := 0;
2238 FMegaRulez[MR_INVUL] := 0;
2239 FMegaRulez[MR_INVIS] := 0;
2240 FSpawnInvul := 0;
2241 FBerserk := 0;
2242 end;
2244 // Íî îò îñòàëüíîãî ñïàñàåò:
2245 if FMegaRulez[MR_INVUL] >= gTime then
2246 Exit;
2248 // ×èò-êîä "ÃÎÐÅÖ":
2249 if FGodMode then
2250 Exit;
2252 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2253 if LongBool(gGameSettings.Options and GAME_OPTION_TEAMDAMAGE) or
2254 (SpawnerUID = FUID) or
2255 (not SameTeam(FUID, SpawnerUID)) then
2256 begin
2257 FLastSpawnerUID := SpawnerUID;
2259 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2260 if gBloodCount > 0 then
2261 begin
2262 c := Min(value, 200)*gBloodCount + Random(Min(value, 200) div 2);
2263 if value div 4 <= c then
2264 c := c - (value div 4)
2265 else
2266 c := 0;
2268 if (t = HIT_SOME) and (vx = 0) and (vy = 0) then
2269 MakeBloodSimple(c)
2270 else
2271 case t of
2272 HIT_TRAP, HIT_ACID, HIT_FLAME, HIT_SELF: MakeBloodSimple(c);
2273 HIT_BFG, HIT_ROCKET, HIT_SOME: MakeBloodVector(c, vx, vy);
2274 end;
2276 if t = HIT_WATER then
2277 g_GFX_Bubbles(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2),
2278 FObj.Y+PLAYER_RECT.Y-4, value div 2, 8, 4);
2279 end;
2281 // Áóôåð óðîíà:
2282 if FAlive then
2283 Inc(FDamageBuffer, value);
2285 // Âñïûøêà áîëè:
2286 if gFlash <> 0 then
2287 FPain := FPain + value;
2288 end;
2290 if g_Game_IsServer and g_Game_IsNet then
2291 begin
2292 MH_SEND_PlayerDamage(FUID, t, SpawnerUID, value, vx, vy);
2293 MH_SEND_PlayerStats(FUID);
2294 MH_SEND_PlayerPos(False, FUID);
2295 end;
2296 end;
2298 function TPlayer.Heal(value: Word; Soft: Boolean): Boolean;
2299 begin
2300 Result := False;
2301 if g_Game_IsClient then
2302 Exit;
2303 if not FAlive then
2304 Exit;
2306 if Soft and (FHealth < PLAYER_HP_SOFT) then
2307 begin
2308 IncMax(FHealth, value, PLAYER_HP_SOFT);
2309 Result := True;
2310 end;
2311 if (not Soft) and (FHealth < PLAYER_HP_LIMIT) then
2312 begin
2313 IncMax(FHealth, value, PLAYER_HP_LIMIT);
2314 Result := True;
2315 end;
2317 if Result and g_Game_IsServer and g_Game_IsNet then
2318 MH_SEND_PlayerStats(FUID);
2319 end;
2321 destructor TPlayer.Destroy();
2322 begin
2323 if (gPlayer1 <> nil) and (gPlayer1.FUID = FUID) then
2324 gPlayer1 := nil;
2325 if (gPlayer2 <> nil) and (gPlayer2.FUID = FUID) then
2326 gPlayer2 := nil;
2328 FSawSound.Free();
2329 FSawSoundIdle.Free();
2330 FSawSoundHit.Free();
2331 FSawSoundSelect.Free();
2332 FFlameSoundOn.Free();
2333 FFlameSoundOff.Free();
2334 FFlameSoundWork.Free();
2335 FJetSoundFly.Free();
2336 FJetSoundOn.Free();
2337 FJetSoundOff.Free();
2338 FModel.Free();
2339 if FPunchAnim <> nil then
2340 FPunchAnim.Free();
2342 inherited;
2343 end;
2345 procedure TPlayer.DrawIndicator(Color: TRGB);
2346 var
2347 indX, indY, fX, fY, fSlope: Integer;
2348 indW, indH: Word;
2349 indA: Single;
2350 a: TDFPoint;
2351 nW, nH: Byte;
2352 ID: DWORD;
2353 c: TRGB;
2354 begin
2355 if FAlive then
2356 begin
2357 FObj.lerp(gLerpFactor, fX, fY);
2358 fSlope := nlerp(FSlopeOld, FObj.slopeUpLeft, gLerpFactor);
2360 case gPlayerIndicatorStyle of
2361 0:
2362 begin
2363 if g_Texture_Get('TEXTURE_PLAYER_INDICATOR', ID) then
2364 begin
2365 e_GetTextureSize(ID, @indW, @indH);
2366 a.X := indW div 2;
2367 a.Y := indH div 2;
2369 if (FObj.X + FObj.Rect.X) < 0 then
2370 begin
2371 indA := 90;
2372 indX := fX + FObj.Rect.X + FObj.Rect.Width;
2373 indY := fY + FObj.Rect.Y + (FObj.Rect.Height - indW) div 2;
2374 end
2376 else if (FObj.X + FObj.Rect.X + FObj.Rect.Width) > Max(gMapInfo.Width, gPlayerScreenSize.X) then
2377 begin
2378 indA := 270;
2379 indX := fX + FObj.Rect.X - indH;
2380 indY := fY + FObj.Rect.Y + (FObj.Rect.Height - indW) div 2;
2381 end
2383 else if (FObj.Y - indH) < 0 then
2384 begin
2385 indA := 180;
2386 indX := fX + FObj.Rect.X + (FObj.Rect.Width - indW) div 2;
2387 indY := fY + FObj.Rect.Y + FObj.Rect.Height;
2388 end
2390 else
2391 begin
2392 indA := 0;
2393 indX := fX + FObj.Rect.X + (FObj.Rect.Width - indW) div 2;
2394 indY := fY - indH;
2395 end;
2397 indY := indY + fSlope;
2398 indX := EnsureRange(indX, 0, Max(gMapInfo.Width, gPlayerScreenSize.X) - indW);
2399 indY := EnsureRange(indY, 0, Max(gMapInfo.Height, gPlayerScreenSize.Y) - indH);
2401 c := e_Colors;
2402 e_Colors := Color;
2403 e_DrawAdv(ID, indX, indY, 0, True, False, indA, @a);
2404 e_Colors := c;
2405 end;
2406 end;
2408 1:
2409 begin
2410 e_TextureFontGetSize(gStdFont, nW, nH);
2411 indX := fX + FObj.Rect.X + (FObj.Rect.Width - Length(FName) * nW) div 2;
2412 indY := fY - nH + fSlope;
2413 e_TextureFontPrintEx(indX, indY, FName, gStdFont, Color.R, Color.G, Color.B, 1.0, True);
2414 end;
2415 end;
2416 end;
2417 end;
2419 procedure TPlayer.DrawBubble();
2420 var
2421 bubX, bubY, fX, fY: Integer;
2422 ID: LongWord;
2423 Rb, Gb, Bb,
2424 Rw, Gw, Bw: SmallInt;
2425 Dot: Byte;
2426 CObj: TObj;
2427 begin
2428 CObj := getCameraObj();
2429 CObj.lerp(gLerpFactor, fX, fY);
2430 // NB: _F_Obj.Rect is used to keep the bubble higher; this is not a mistake
2431 bubX := fX+FObj.Rect.X + IfThen(FDirection = TDirection.D_LEFT, -4, 18);
2432 bubY := fY+FObj.Rect.Y - 18;
2433 Rb := 64;
2434 Gb := 64;
2435 Bb := 64;
2436 Rw := 240;
2437 Gw := 240;
2438 Bw := 240;
2439 case gChatBubble of
2440 1: // simple textual non-bubble
2441 begin
2442 bubX := fX+FObj.Rect.X - 11;
2443 bubY := fY+FObj.Rect.Y - 17;
2444 e_TextureFontPrint(bubX, bubY, '[...]', gStdFont);
2445 Exit;
2446 end;
2447 2: // advanced pixel-perfect bubble
2448 begin
2449 if FTeam = TEAM_RED then
2450 Rb := 255
2451 else
2452 if FTeam = TEAM_BLUE then
2453 Bb := 255;
2454 end;
2455 3: // colored bubble
2456 begin
2457 Rb := FModel.Color.R;
2458 Gb := FModel.Color.G;
2459 Bb := FModel.Color.B;
2460 Rw := Min(Rb * 2 + 64, 255);
2461 Gw := Min(Gb * 2 + 64, 255);
2462 Bw := Min(Bb * 2 + 64, 255);
2463 if (Abs(Rw - Rb) < 32)
2464 or (Abs(Gw - Gb) < 32)
2465 or (Abs(Bw - Bb) < 32) then
2466 begin
2467 Rb := Max(Rw div 2 - 16, 0);
2468 Gb := Max(Gw div 2 - 16, 0);
2469 Bb := Max(Bw div 2 - 16, 0);
2470 end;
2471 end;
2472 4: // custom textured bubble
2473 begin
2474 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID) then
2475 if FDirection = TDirection.D_RIGHT then
2476 e_Draw(ID, bubX - 6, bubY - 7, 0, True, False)
2477 else
2478 e_Draw(ID, bubX - 6, bubY - 7, 0, True, False, TMirrorType.Horizontal);
2479 Exit;
2480 end;
2481 end;
2483 // Outer borders
2484 e_DrawQuad(bubX + 1, bubY , bubX + 18, bubY + 13, Rb, Gb, Bb);
2485 e_DrawQuad(bubX , bubY + 1, bubX + 19, bubY + 12, Rb, Gb, Bb);
2486 // Inner box
2487 e_DrawFillQuad(bubX + 1, bubY + 1, bubX + 18, bubY + 12, Rw, Gw, Bw, 0);
2489 // Tail
2490 Dot := IfThen(FDirection = TDirection.D_LEFT, 14, 5);
2491 e_DrawLine(1, bubX + Dot, bubY + 14, bubX + Dot, bubY + 16, Rb, Gb, Bb);
2492 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);
2493 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);
2494 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);
2495 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);
2497 // Dots
2498 Dot := 6;
2499 e_DrawFillQuad(bubX + Dot, bubY + 8, bubX + Dot + 1, bubY + 9, Rb, Gb, Bb, 0);
2500 e_DrawFillQuad(bubX + Dot + 3, bubY + 8, bubX + Dot + 4, bubY + 9, Rb, Gb, Bb, 0);
2501 e_DrawFillQuad(bubX + Dot + 6, bubY + 8, bubX + Dot + 7, bubY + 9, Rb, Gb, Bb, 0);
2502 end;
2504 procedure TPlayer.Draw();
2505 var
2506 ID: DWORD;
2507 w, h: Word;
2508 dr: Boolean;
2509 Mirror: TMirrorType;
2510 fX, fY, fSlope: Integer;
2511 begin
2512 FObj.lerp(gLerpFactor, fX, fY);
2513 fSlope := nlerp(FSlopeOld, FObj.slopeUpLeft, gLerpFactor);
2515 if FAlive then
2516 begin
2517 if Direction = TDirection.D_RIGHT then
2518 Mirror := TMirrorType.None
2519 else
2520 Mirror := TMirrorType.Horizontal;
2522 if FPunchAnim <> nil then
2523 begin
2524 FPunchAnim.Draw(fX+IfThen(Direction = TDirection.D_LEFT, 15-FObj.Rect.X, FObj.Rect.X-15),
2525 fY+fSlope+FObj.Rect.Y-11, Mirror);
2526 if FPunchAnim.played then
2527 begin
2528 FPunchAnim.Free;
2529 FPunchAnim := nil;
2530 end;
2531 end;
2533 if (FMegaRulez[MR_INVUL] > gTime) and ((gPlayerDrawn <> Self) or (FSpawnInvul >= gTime)) then
2534 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID) then
2535 begin
2536 e_GetTextureSize(ID, @w, @h);
2537 if FDirection = TDirection.D_LEFT then
2538 e_Draw(ID, fX+FObj.Rect.X+(FObj.Rect.Width div 2)-(w div 2)+4,
2539 fY+FObj.Rect.Y+(FObj.Rect.Height div 2)-(h div 2)-7+fSlope, 0, True, False)
2540 else
2541 e_Draw(ID, fX+FObj.Rect.X+(FObj.Rect.Width div 2)-(w div 2)-2,
2542 fY+FObj.Rect.Y+(FObj.Rect.Height div 2)-(h div 2)-7+fSlope, 0, True, False);
2543 end;
2545 if FMegaRulez[MR_INVIS] > gTime then
2546 begin
2547 if (gPlayerDrawn <> nil) and ((Self = gPlayerDrawn) or
2548 ((FTeam = gPlayerDrawn.Team) and (gGameSettings.GameMode <> GM_DM))) then
2549 begin
2550 if (FMegaRulez[MR_INVIS] - gTime) <= 2100 then
2551 dr := not Odd((FMegaRulez[MR_INVIS] - gTime) div 300)
2552 else
2553 dr := True;
2554 if dr then
2555 FModel.Draw(fX, fY+fSlope, 200)
2556 else
2557 FModel.Draw(fX, fY+fSlope);
2558 end
2559 else
2560 FModel.Draw(fX, fY+fSlope, 254);
2561 end
2562 else
2563 FModel.Draw(fX, fY+fSlope);
2564 end;
2566 if g_debug_Frames then
2567 begin
2568 e_DrawQuad(FObj.X+FObj.Rect.X,
2569 FObj.Y+FObj.Rect.Y,
2570 FObj.X+FObj.Rect.X+FObj.Rect.Width-1,
2571 FObj.Y+FObj.Rect.Y+FObj.Rect.Height-1,
2572 0, 255, 0);
2573 end;
2575 if (gChatBubble > 0) and (FKeys[KEY_CHAT].Pressed) and not FGhost then
2576 if (FMegaRulez[MR_INVIS] <= gTime) or ((gPlayerDrawn <> nil) and ((Self = gPlayerDrawn) or
2577 ((FTeam = gPlayerDrawn.Team) and (gGameSettings.GameMode <> GM_DM)))) then
2578 DrawBubble();
2579 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2580 if gAimLine and alive and
2581 ((Self = gPlayer1) or (Self = gPlayer2)) then
2582 DrawAim();
2583 end;
2586 procedure TPlayer.DrawAim();
2587 procedure drawCast (sz: Integer; ax0, ay0, ax1, ay1: Integer);
2588 var
2589 ex, ey: Integer;
2590 begin
2592 {$IFDEF ENABLE_HOLMES}
2593 if isValidViewPort and (self = gPlayer1) then
2594 begin
2595 g_Holmes_plrLaser(ax0, ay0, ax1, ay1);
2596 end;
2597 {$ENDIF}
2599 e_DrawLine(sz, ax0, ay0, ax1, ay1, 255, 0, 0, 96);
2600 if (g_Map_traceToNearestWall(ax0, ay0, ax1, ay1, @ex, @ey) <> nil) then
2601 begin
2602 e_DrawLine(sz, ax0, ay0, ex, ey, 0, 255, 0, 96);
2603 end
2604 else
2605 begin
2606 e_DrawLine(sz, ax0, ay0, ex, ey, 0, 0, 255, 96);
2607 end;
2608 end;
2610 var
2611 wx, wy, xx, yy: Integer;
2612 angle: SmallInt;
2613 sz, len: Word;
2614 begin
2615 wx := FObj.X + WEAPONPOINT[FDirection].X + IfThen(FDirection = TDirection.D_LEFT, 7, -7);
2616 wy := FObj.Y + WEAPONPOINT[FDirection].Y;
2617 angle := FAngle;
2618 len := 1024;
2619 sz := 2;
2620 case FCurrWeap of
2621 0: begin // Punch
2622 len := 12;
2623 sz := 4;
2624 end;
2625 1: begin // Chainsaw
2626 len := 24;
2627 sz := 6;
2628 end;
2629 2: begin // Pistol
2630 len := 1024;
2631 sz := 2;
2632 if angle = ANGLE_RIGHTUP then Dec(angle, 2);
2633 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2634 if angle = ANGLE_LEFTUP then Inc(angle, 2);
2635 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2636 end;
2637 3: begin // Shotgun
2638 len := 1024;
2639 sz := 3;
2640 if angle = ANGLE_RIGHTUP then Dec(angle, 2);
2641 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2642 if angle = ANGLE_LEFTUP then Inc(angle, 2);
2643 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2644 end;
2645 4: begin // Double Shotgun
2646 len := 1024;
2647 sz := 4;
2648 if angle = ANGLE_RIGHTUP then Dec(angle, 2);
2649 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2650 if angle = ANGLE_LEFTUP then Inc(angle, 2);
2651 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2652 end;
2653 5: begin // Chaingun
2654 len := 1024;
2655 sz := 3;
2656 if angle = ANGLE_RIGHTUP then Dec(angle, 2);
2657 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2658 if angle = ANGLE_LEFTUP then Inc(angle, 2);
2659 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2660 end;
2661 6: begin // Rocket Launcher
2662 len := 1024;
2663 sz := 7;
2664 if angle = ANGLE_RIGHTUP then Inc(angle, 2);
2665 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2666 if angle = ANGLE_LEFTUP then Dec(angle, 2);
2667 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2668 end;
2669 7: begin // Plasmagun
2670 len := 1024;
2671 sz := 5;
2672 if angle = ANGLE_RIGHTUP then Inc(angle);
2673 if angle = ANGLE_RIGHTDOWN then Inc(angle, 3);
2674 if angle = ANGLE_LEFTUP then Dec(angle);
2675 if angle = ANGLE_LEFTDOWN then Dec(angle, 3);
2676 end;
2677 8: begin // BFG
2678 len := 1024;
2679 sz := 12;
2680 if angle = ANGLE_RIGHTUP then Inc(angle, 1);
2681 if angle = ANGLE_RIGHTDOWN then Inc(angle, 2);
2682 if angle = ANGLE_LEFTUP then Dec(angle, 1);
2683 if angle = ANGLE_LEFTDOWN then Dec(angle, 2);
2684 end;
2685 9: begin // Super Chaingun
2686 len := 1024;
2687 sz := 4;
2688 if angle = ANGLE_RIGHTUP then Dec(angle, 2);
2689 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2690 if angle = ANGLE_LEFTUP then Inc(angle, 2);
2691 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2692 end;
2693 end;
2694 xx := Trunc(Cos(-DegToRad(angle)) * len) + wx;
2695 yy := Trunc(Sin(-DegToRad(angle)) * len) + wy;
2696 {$IF DEFINED(D2F_DEBUG)}
2697 drawCast(sz, wx, wy, xx, yy);
2698 {$ELSE}
2699 e_DrawLine(sz, wx, wy, xx, yy, 255, 0, 0, 96);
2700 {$ENDIF}
2701 end;
2703 procedure TPlayer.DrawGUI();
2704 var
2705 ID: DWORD;
2706 X, Y, SY, a, p, m: Integer;
2707 tw, th: Word;
2708 cw, ch: Byte;
2709 s: string;
2710 stat: TPlayerStatArray;
2711 begin
2712 X := gPlayerScreenSize.X;
2713 SY := gPlayerScreenSize.Y;
2714 Y := 0;
2716 if gShowGoals and (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
2717 begin
2718 if gGameSettings.GameMode = GM_CTF then
2719 a := 32 + 8
2720 else
2721 a := 0;
2722 if gGameSettings.GameMode = GM_CTF then
2723 begin
2724 s := 'TEXTURE_PLAYER_REDFLAG';
2725 if gFlags[FLAG_RED].State = FLAG_STATE_CAPTURED then
2726 s := 'TEXTURE_PLAYER_REDFLAG_S';
2727 if gFlags[FLAG_RED].State = FLAG_STATE_DROPPED then
2728 s := 'TEXTURE_PLAYER_REDFLAG_D';
2729 if g_Texture_Get(s, ID) then
2730 e_Draw(ID, X-16-32, 240-72-4, 0, True, False);
2731 end;
2733 s := IntToStr(gTeamStat[TEAM_RED].Goals);
2734 e_CharFont_GetSize(gMenuFont, s, tw, th);
2735 e_CharFont_PrintEx(gMenuFont, X-16-a-tw, 240-72-4, s, TEAMCOLOR[TEAM_RED]);
2737 if gGameSettings.GameMode = GM_CTF then
2738 begin
2739 s := 'TEXTURE_PLAYER_BLUEFLAG';
2740 if gFlags[FLAG_BLUE].State = FLAG_STATE_CAPTURED then
2741 s := 'TEXTURE_PLAYER_BLUEFLAG_S';
2742 if gFlags[FLAG_BLUE].State = FLAG_STATE_DROPPED then
2743 s := 'TEXTURE_PLAYER_BLUEFLAG_D';
2744 if g_Texture_Get(s, ID) then
2745 e_Draw(ID, X-16-32, 240-32-4, 0, True, False);
2746 end;
2748 s := IntToStr(gTeamStat[TEAM_BLUE].Goals);
2749 e_CharFont_GetSize(gMenuFont, s, tw, th);
2750 e_CharFont_PrintEx(gMenuFont, X-16-a-tw, 240-32-4, s, TEAMCOLOR[TEAM_BLUE]);
2751 end;
2753 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID) then
2754 e_DrawFill(ID, X, 0, 1, (gPlayerScreenSize.Y div 256)+IfThen(gPlayerScreenSize.Y mod 256 > 0, 1, 0),
2755 0, False, False);
2757 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID) then
2758 e_Draw(ID, X+2, Y, 0, True, False);
2760 if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
2761 begin
2762 if gShowStat then
2763 begin
2764 s := IntToStr(Frags);
2765 e_CharFont_GetSize(gMenuFont, s, tw, th);
2766 e_CharFont_PrintEx(gMenuFont, X-16-tw, Y, s, _RGB(255, 0, 0));
2768 s := '';
2769 p := 1;
2770 m := 0;
2771 stat := g_Player_GetStats();
2772 if stat <> nil then
2773 begin
2774 p := 1;
2776 for a := 0 to High(stat) do
2777 if stat[a].Name <> Name then
2778 begin
2779 if stat[a].Frags > m then m := stat[a].Frags;
2780 if stat[a].Frags > Frags then p := p+1;
2781 end;
2782 end;
2784 s := IntToStr(p)+' / '+IntToStr(Length(stat))+' ';
2785 if Frags >= m then s := s+'+' else s := s+'-';
2786 s := s+IntToStr(Abs(Frags-m));
2788 e_CharFont_GetSize(gMenuSmallFont, s, tw, th);
2789 e_CharFont_PrintEx(gMenuSmallFont, X-16-tw, Y+32, s, _RGB(255, 0, 0));
2790 end;
2792 if gLMSRespawn > LMS_RESPAWN_NONE then
2793 begin
2794 s := _lc[I_GAME_WARMUP];
2795 e_CharFont_GetSize(gMenuFont, s, tw, th);
2796 s := s + ': ' + IntToStr((gLMSRespawnTime - gTime) div 1000);
2797 e_CharFont_PrintEx(gMenuFont, X-64-tw, SY-32, s, _RGB(0, 255, 0));
2798 end
2799 else if gShowLives and (gGameSettings.MaxLives > 0) then
2800 begin
2801 s := IntToStr(Lives);
2802 e_CharFont_GetSize(gMenuFont, s, tw, th);
2803 e_CharFont_PrintEx(gMenuFont, X-16-tw, SY-32, s, _RGB(0, 255, 0));
2804 end;
2805 end;
2807 e_CharFont_GetSize(gMenuSmallFont, FName, tw, th);
2808 e_CharFont_PrintEx(gMenuSmallFont, X+98-(tw div 2), Y+8, FName, _RGB(255, 0, 0));
2810 if R_BERSERK in FRulez then
2811 e_Draw(gItemsTexturesID[ITEM_MEDKIT_BLACK], X+37, Y+45, 0, True, False)
2812 else
2813 e_Draw(gItemsTexturesID[ITEM_MEDKIT_LARGE], X+37, Y+45, 0, True, False);
2815 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID) then
2816 e_Draw(ID, X+36, Y+77, 0, True, False);
2818 s := IntToStr(IfThen(FHealth > 0, FHealth, 0));
2819 e_CharFont_GetSize(gMenuFont, s, tw, th);
2820 e_CharFont_PrintEx(gMenuFont, X+178-tw, Y+40, s, _RGB(255, 0, 0));
2822 s := IntToStr(FArmor);
2823 e_CharFont_GetSize(gMenuFont, s, tw, th);
2824 e_CharFont_PrintEx(gMenuFont, X+178-tw, Y+68, s, _RGB(255, 0, 0));
2826 s := IntToStr(GetAmmoByWeapon(FCurrWeap));
2828 case FCurrWeap of
2829 WEAPON_KASTET:
2830 begin
2831 s := '--';
2832 ID := gItemsTexturesID[ITEM_WEAPON_KASTET];
2833 end;
2834 WEAPON_SAW:
2835 begin
2836 s := '--';
2837 ID := gItemsTexturesID[ITEM_WEAPON_SAW];
2838 end;
2839 WEAPON_PISTOL: ID := gItemsTexturesID[ITEM_WEAPON_PISTOL];
2840 WEAPON_CHAINGUN: ID := gItemsTexturesID[ITEM_WEAPON_CHAINGUN];
2841 WEAPON_SHOTGUN1: ID := gItemsTexturesID[ITEM_WEAPON_SHOTGUN1];
2842 WEAPON_SHOTGUN2: ID := gItemsTexturesID[ITEM_WEAPON_SHOTGUN2];
2843 WEAPON_SUPERPULEMET: ID := gItemsTexturesID[ITEM_WEAPON_SUPERPULEMET];
2844 WEAPON_ROCKETLAUNCHER: ID := gItemsTexturesID[ITEM_WEAPON_ROCKETLAUNCHER];
2845 WEAPON_PLASMA: ID := gItemsTexturesID[ITEM_WEAPON_PLASMA];
2846 WEAPON_BFG: ID := gItemsTexturesID[ITEM_WEAPON_BFG];
2847 WEAPON_FLAMETHROWER: ID := gItemsTexturesID[ITEM_WEAPON_FLAMETHROWER];
2848 end;
2850 e_CharFont_GetSize(gMenuFont, s, tw, th);
2851 e_CharFont_PrintEx(gMenuFont, X+178-tw, Y+158, s, _RGB(255, 0, 0));
2852 e_Draw(ID, X+20, Y+160, 0, True, False);
2854 if R_KEY_RED in FRulez then
2855 e_Draw(gItemsTexturesID[ITEM_KEY_RED], X+78, Y+214, 0, True, False);
2857 if R_KEY_GREEN in FRulez then
2858 e_Draw(gItemsTexturesID[ITEM_KEY_GREEN], X+95, Y+214, 0, True, False);
2860 if R_KEY_BLUE in FRulez then
2861 e_Draw(gItemsTexturesID[ITEM_KEY_BLUE], X+112, Y+214, 0, True, False);
2863 if FJetFuel > 0 then
2864 begin
2865 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID) then
2866 e_Draw(ID, X+2, Y+116, 0, True, False);
2867 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID) then
2868 e_Draw(ID, X+2, Y+126, 0, True, False);
2869 e_DrawLine(4, X+16, Y+122, X+16+Trunc(168*IfThen(FAir > 0, FAir, 0)/AIR_MAX), Y+122, 0, 0, 196);
2870 e_DrawLine(4, X+16, Y+132, X+16+Trunc(168*FJetFuel/JET_MAX), Y+132, 208, 0, 0);
2871 end
2872 else
2873 begin
2874 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID) then
2875 e_Draw(ID, X+2, Y+124, 0, True, False);
2876 e_DrawLine(4, X+16, Y+130, X+16+Trunc(168*IfThen(FAir > 0, FAir, 0)/AIR_MAX), Y+130, 0, 0, 196);
2877 end;
2879 if gShowPing and g_Game_IsClient then
2880 begin
2881 s := _lc[I_GAME_PING_HUD] + IntToStr(NetPeer.lastRoundTripTime) + _lc[I_NET_SLIST_PING_MS];
2882 e_TextureFontPrint(X + 4, Y + 242, s, gStdFont);
2883 Y := Y + 16;
2884 end;
2886 if FSpectator then
2887 begin
2888 e_TextureFontPrint(X + 4, Y + 242, _lc[I_PLAYER_SPECT], gStdFont);
2889 e_TextureFontPrint(X + 4, Y + 258, _lc[I_PLAYER_SPECT2], gStdFont);
2890 e_TextureFontPrint(X + 4, Y + 274, _lc[I_PLAYER_SPECT1], gStdFont);
2891 if FNoRespawn then
2892 begin
2893 e_TextureFontGetSize(gStdFont, cw, ch);
2894 s := _lc[I_PLAYER_SPECT4];
2895 e_TextureFontPrintEx(gScreenWidth div 2 - cw*(Length(s) div 2),
2896 gScreenHeight-4-ch, s, gStdFont, 255, 255, 255, 1, True);
2897 e_TextureFontPrint(X + 4, Y + 290, _lc[I_PLAYER_SPECT1S], gStdFont);
2898 end;
2900 end;
2901 end;
2903 procedure TPlayer.DrawRulez();
2904 var
2905 dr: Boolean;
2906 begin
2907 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2908 if (FMegaRulez[MR_INVUL] >= gTime) and (FSpawnInvul < gTime) then
2909 begin
2910 if (FMegaRulez[MR_INVUL]-gTime) <= 2100 then
2911 dr := not Odd((FMegaRulez[MR_INVUL]-gTime) div 300)
2912 else
2913 dr := True;
2915 if dr then
2916 e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1,
2917 191, 191, 191, 0, TBlending.Invert);
2918 end;
2920 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2921 if FMegaRulez[MR_SUIT] >= gTime then
2922 begin
2923 if (FMegaRulez[MR_SUIT]-gTime) <= 2100 then
2924 dr := not Odd((FMegaRulez[MR_SUIT]-gTime) div 300)
2925 else
2926 dr := True;
2928 if dr then
2929 e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1,
2930 0, 96, 0, 200, TBlending.None);
2931 end;
2933 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2934 if (FBerserk >= 0) and (LongWord(FBerserk) >= gTime) and (gFlash = 2) then
2935 begin
2936 e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1,
2937 255, 0, 0, 200, TBlending.None);
2938 end;
2939 end;
2941 procedure TPlayer.DrawPain();
2942 var
2943 a, h: Integer;
2944 begin
2945 if FPain = 0 then Exit;
2947 a := FPain;
2949 if a < 15 then h := 0
2950 else if a < 35 then h := 1
2951 else if a < 55 then h := 2
2952 else if a < 75 then h := 3
2953 else if a < 95 then h := 4
2954 else h := 5;
2956 //if a > 255 then a := 255;
2958 e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255, 0, 0, 255-h*50);
2959 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2960 end;
2962 procedure TPlayer.DrawPickup();
2963 var
2964 a, h: Integer;
2965 begin
2966 if FPickup = 0 then Exit;
2968 a := FPickup;
2970 if a < 15 then h := 1
2971 else if a < 35 then h := 2
2972 else if a < 55 then h := 3
2973 else if a < 75 then h := 4
2974 else h := 5;
2976 e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 150, 200, 150, 255-h*50);
2977 end;
2979 procedure TPlayer.DoPunch();
2980 var
2981 id: DWORD;
2982 st: String;
2983 begin
2984 if FPunchAnim <> nil then begin
2985 FPunchAnim.reset();
2986 FPunchAnim.Free;
2987 FPunchAnim := nil;
2988 end;
2989 st := 'FRAMES_PUNCH';
2990 if R_BERSERK in FRulez then
2991 st := st + '_BERSERK';
2992 if FKeys[KEY_UP].Pressed then
2993 st := st + '_UP'
2994 else if FKeys[KEY_DOWN].Pressed then
2995 st := st + '_DN';
2996 g_Frames_Get(id, st);
2997 FPunchAnim := TAnimation.Create(id, False, 1);
2998 end;
3000 procedure TPlayer.Fire();
3001 var
3002 f, DidFire: Boolean;
3003 wx, wy, xd, yd: Integer;
3004 locobj: TObj;
3005 begin
3006 if g_Game_IsClient then Exit;
3007 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
3008 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
3010 if FSpectator then
3011 begin
3012 Respawn(False);
3013 Exit;
3014 end;
3016 if FReloading[FCurrWeap] <> 0 then Exit;
3018 DidFire := False;
3020 f := False;
3021 wx := FObj.X+WEAPONPOINT[FDirection].X;
3022 wy := FObj.Y+WEAPONPOINT[FDirection].Y;
3023 xd := wx+IfThen(FDirection = TDirection.D_LEFT, -30, 30);
3024 yd := wy+firediry();
3026 case FCurrWeap of
3027 WEAPON_KASTET:
3028 begin
3029 DoPunch();
3030 if R_BERSERK in FRulez then
3031 begin
3032 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
3033 locobj.X := FObj.X+FObj.Rect.X;
3034 locobj.Y := FObj.Y+FObj.Rect.Y;
3035 locobj.rect.X := 0;
3036 locobj.rect.Y := 0;
3037 locobj.rect.Width := 39;
3038 locobj.rect.Height := 52;
3039 locobj.Vel.X := (xd-wx) div 2;
3040 locobj.Vel.Y := (yd-wy) div 2;
3041 locobj.Accel.X := xd-wx;
3042 locobj.Accel.y := yd-wy;
3044 if g_Weapon_Hit(@locobj, 50, FUID, HIT_SOME) <> 0 then
3045 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj.X, FObj.Y)
3046 else
3047 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj.X, FObj.Y);
3049 if (gFlash = 1) and (FPain < 50) then FPain := min(FPain + 25, 50);
3050 end
3051 else
3052 begin
3053 g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 3, FUID);
3054 end;
3056 DidFire := True;
3057 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3058 end;
3060 WEAPON_SAW:
3061 begin
3062 if g_Weapon_chainsaw(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y,
3063 IfThen(gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF], 9, 3), FUID) <> 0 then
3064 begin
3065 FSawSoundSelect.Stop();
3066 FSawSound.Stop();
3067 FSawSoundHit.PlayAt(FObj.X, FObj.Y);
3068 end
3069 else if not FSawSoundHit.IsPlaying() then
3070 begin
3071 FSawSoundSelect.Stop();
3072 FSawSound.PlayAt(FObj.X, FObj.Y);
3073 end;
3075 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3076 DidFire := True;
3077 f := True;
3078 end;
3080 WEAPON_PISTOL:
3081 if FAmmo[A_BULLETS] > 0 then
3082 begin
3083 g_Weapon_pistol(wx, wy, xd, yd, FUID);
3084 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3085 Dec(FAmmo[A_BULLETS]);
3086 FFireAngle := FAngle;
3087 f := True;
3088 DidFire := True;
3089 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
3090 GameVelX, GameVelY-2, SHELL_BULLET);
3091 end;
3093 WEAPON_SHOTGUN1:
3094 if FAmmo[A_SHELLS] > 0 then
3095 begin
3096 g_Weapon_shotgun(wx, wy, xd, yd, FUID);
3097 if not gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx, wy);
3098 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3099 Dec(FAmmo[A_SHELLS]);
3100 FFireAngle := FAngle;
3101 f := True;
3102 DidFire := True;
3103 FShellTimer := 10;
3104 FShellType := SHELL_SHELL;
3105 end;
3107 WEAPON_SHOTGUN2:
3108 if FAmmo[A_SHELLS] >= 2 then
3109 begin
3110 g_Weapon_dshotgun(wx, wy, xd, yd, FUID);
3111 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3112 Dec(FAmmo[A_SHELLS], 2);
3113 FFireAngle := FAngle;
3114 f := True;
3115 DidFire := True;
3116 FShellTimer := 13;
3117 FShellType := SHELL_DBLSHELL;
3118 end;
3120 WEAPON_CHAINGUN:
3121 if FAmmo[A_BULLETS] > 0 then
3122 begin
3123 g_Weapon_mgun(wx, wy, xd, yd, FUID);
3124 if not gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx, wy);
3125 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3126 Dec(FAmmo[A_BULLETS]);
3127 FFireAngle := FAngle;
3128 f := True;
3129 DidFire := True;
3130 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
3131 GameVelX, GameVelY-2, SHELL_BULLET);
3132 end;
3134 WEAPON_ROCKETLAUNCHER:
3135 if FAmmo[A_ROCKETS] > 0 then
3136 begin
3137 g_Weapon_rocket(wx, wy, xd, yd, FUID);
3138 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3139 Dec(FAmmo[A_ROCKETS]);
3140 FFireAngle := FAngle;
3141 f := True;
3142 DidFire := True;
3143 end;
3145 WEAPON_PLASMA:
3146 if FAmmo[A_CELLS] > 0 then
3147 begin
3148 g_Weapon_plasma(wx, wy, xd, yd, FUID);
3149 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3150 Dec(FAmmo[A_CELLS]);
3151 FFireAngle := FAngle;
3152 f := True;
3153 DidFire := True;
3154 end;
3156 WEAPON_BFG:
3157 if (FAmmo[A_CELLS] >= 40) and (FBFGFireCounter = -1) then
3158 begin
3159 FBFGFireCounter := 17;
3160 if not FNoReload then
3161 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj.X, FObj.Y);
3162 Dec(FAmmo[A_CELLS], 40);
3163 DidFire := True;
3164 end;
3166 WEAPON_SUPERPULEMET:
3167 if FAmmo[A_SHELLS] > 0 then
3168 begin
3169 g_Weapon_shotgun(wx, wy, xd, yd, FUID);
3170 if not gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx, wy);
3171 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3172 Dec(FAmmo[A_SHELLS]);
3173 FFireAngle := FAngle;
3174 f := True;
3175 DidFire := True;
3176 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
3177 GameVelX, GameVelY-2, SHELL_SHELL);
3178 end;
3180 WEAPON_FLAMETHROWER:
3181 if FAmmo[A_FUEL] > 0 then
3182 begin
3183 g_Weapon_flame(wx, wy, xd, yd, FUID);
3184 FlamerOn;
3185 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3186 Dec(FAmmo[A_FUEL]);
3187 FFireAngle := FAngle;
3188 f := True;
3189 DidFire := True;
3190 end
3191 else
3192 begin
3193 FlamerOff;
3194 if g_Game_IsNet and g_Game_IsServer then MH_SEND_PlayerStats(FUID);
3195 end;
3196 end;
3198 if g_Game_IsNet then
3199 begin
3200 if DidFire then
3201 begin
3202 if FCurrWeap <> WEAPON_BFG then
3203 MH_SEND_PlayerFire(FUID, FCurrWeap, wx, wy, xd, yd, LastShotID)
3204 else
3205 if not FNoReload then
3206 MH_SEND_Sound(FObj.X, FObj.Y, 'SOUND_WEAPON_STARTFIREBFG');
3207 end;
3209 MH_SEND_PlayerStats(FUID);
3210 end;
3212 if not f then Exit;
3214 if (FAngle = 0) or (FAngle = 180) then SetAction(A_ATTACK)
3215 else if (FAngle = ANGLE_LEFTDOWN) or (FAngle = ANGLE_RIGHTDOWN) then SetAction(A_ATTACKDOWN)
3216 else if (FAngle = ANGLE_LEFTUP) or (FAngle = ANGLE_RIGHTUP) then SetAction(A_ATTACKUP);
3217 end;
3219 function TPlayer.GetAmmoByWeapon(Weapon: Byte): Word;
3220 begin
3221 case Weapon of
3222 WEAPON_PISTOL, WEAPON_CHAINGUN: Result := FAmmo[A_BULLETS];
3223 WEAPON_SHOTGUN1, WEAPON_SHOTGUN2, WEAPON_SUPERPULEMET: Result := FAmmo[A_SHELLS];
3224 WEAPON_ROCKETLAUNCHER: Result := FAmmo[A_ROCKETS];
3225 WEAPON_PLASMA, WEAPON_BFG: Result := FAmmo[A_CELLS];
3226 WEAPON_FLAMETHROWER: Result := FAmmo[A_FUEL];
3227 else Result := 0;
3228 end;
3229 end;
3231 function TPlayer.HeadInLiquid(XInc, YInc: Integer): Boolean;
3232 begin
3233 Result := g_Map_CollidePanel(FObj.X+PLAYER_HEADRECT.X+XInc, FObj.Y+PLAYER_HEADRECT.Y+YInc,
3234 PLAYER_HEADRECT.Width, PLAYER_HEADRECT.Height,
3235 PANEL_WATER or PANEL_ACID1 or PANEL_ACID2, True);
3236 end;
3238 procedure TPlayer.FlamerOn;
3239 begin
3240 FFlameSoundOff.Stop();
3241 FFlameSoundOff.SetPosition(0);
3242 if FFlaming then
3243 begin
3244 if (not FFlameSoundOn.IsPlaying()) and (not FFlameSoundWork.IsPlaying()) then
3245 FFlameSoundWork.PlayAt(FObj.X, FObj.Y);
3246 end
3247 else
3248 begin
3249 FFlameSoundOn.PlayAt(FObj.X, FObj.Y);
3250 FFlaming := True;
3251 end;
3252 end;
3254 procedure TPlayer.FlamerOff;
3255 begin
3256 if FFlaming then
3257 begin
3258 FFlameSoundOn.Stop();
3259 FFlameSoundOn.SetPosition(0);
3260 FFlameSoundWork.Stop();
3261 FFlameSoundWork.SetPosition(0);
3262 FFlameSoundOff.PlayAt(FObj.X, FObj.Y);
3263 FFlaming := False;
3264 end;
3265 end;
3267 procedure TPlayer.JetpackOn;
3268 begin
3269 FJetSoundFly.Stop;
3270 FJetSoundOff.Stop;
3271 FJetSoundOn.SetPosition(0);
3272 FJetSoundOn.PlayAt(FObj.X, FObj.Y);
3273 FlySmoke(8);
3274 end;
3276 procedure TPlayer.JetpackOff;
3277 begin
3278 FJetSoundFly.Stop;
3279 FJetSoundOn.Stop;
3280 FJetSoundOff.SetPosition(0);
3281 FJetSoundOff.PlayAt(FObj.X, FObj.Y);
3282 end;
3284 procedure TPlayer.CatchFire(Attacker: Word; Timeout: Integer = PLAYER_BURN_TIME);
3285 begin
3286 if Timeout <= 0 then
3287 exit;
3288 if (FMegaRulez[MR_SUIT] > gTime) or (FMegaRulez[MR_INVUL] > gTime) then
3289 exit; // Íå çàãîðàåìñÿ êîãäà åñòü çàùèòà
3290 if g_Obj_CollidePanel(@FObj, 0, 0, PANEL_WATER or PANEL_ACID1 or PANEL_ACID2) then
3291 exit; // Íå ïîäãîðàåì â âîäå íà âñÿêèé ñëó÷àé
3292 if FFireTime <= 0 then
3293 g_Sound_PlayExAt('SOUND_IGNITE', FObj.X, FObj.Y);
3294 FFireTime := Timeout;
3295 FFireAttacker := Attacker;
3296 if g_Game_IsNet and g_Game_IsServer then
3297 MH_SEND_PlayerStats(FUID);
3298 end;
3300 procedure TPlayer.Jump();
3301 begin
3302 if gFly or FJetpack then
3303 begin
3304 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
3305 if FObj.Vel.Y > -VEL_FLY then
3306 FObj.Vel.Y := FObj.Vel.Y - 3;
3307 if FJetpack then
3308 begin
3309 if FJetFuel > 0 then
3310 Dec(FJetFuel);
3311 if (FJetFuel < 1) and g_Game_IsServer then
3312 begin
3313 FJetpack := False;
3314 JetpackOff;
3315 if g_Game_IsNet then
3316 MH_SEND_PlayerStats(FUID);
3317 end;
3318 end;
3319 Exit;
3320 end;
3322 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
3323 if FGhost then
3324 FCanJetpack := False;
3326 // Ïðûãàåì èëè âñïëûâàåì:
3327 if (CollideLevel(0, 1) or
3328 g_Map_CollidePanel(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y+36, PLAYER_RECT.Width,
3329 PLAYER_RECT.Height-33, PANEL_STEP, False)
3330 ) and (FObj.Accel.Y = 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
3331 begin
3332 FObj.Vel.Y := -VEL_JUMP;
3333 FCanJetpack := False;
3334 end
3335 else
3336 begin
3337 if BodyInLiquid(0, 0) then
3338 FObj.Vel.Y := -VEL_SW
3339 else if (FJetFuel > 0) and FCanJetpack and
3340 g_Game_IsServer and (not g_Obj_CollideLiquid(@FObj, 0, 0)) then
3341 begin
3342 FJetpack := True;
3343 JetpackOn;
3344 if g_Game_IsNet then
3345 MH_SEND_PlayerStats(FUID);
3346 end;
3347 end;
3348 end;
3350 procedure TPlayer.Kill(KillType: Byte; SpawnerUID: Word; t: Byte);
3351 var
3352 a, i, k, ab, ar: Byte;
3353 s: String;
3354 mon: TMonster;
3355 plr: TPlayer;
3356 srv, netsrv: Boolean;
3357 DoFrags: Boolean;
3358 OldLR: Byte;
3359 KP: TPlayer;
3360 it: PItem;
3362 procedure PushItem(t: Byte);
3363 var
3364 id: DWORD;
3365 begin
3366 id := g_Items_Create(FObj.X, FObj.Y, t, True, False);
3367 it := g_Items_ByIdx(id);
3368 if KillType = K_EXTRAHARDKILL then // -7..+7; -8..0
3369 begin
3370 g_Obj_Push(@it.Obj, (FObj.Vel.X div 2)-7+Random(15),
3371 (FObj.Vel.Y div 2)-Random(9));
3372 it.positionChanged(); // this updates spatial accelerators
3373 end
3374 else
3375 begin
3376 if KillType = K_HARDKILL then // -5..+5; -5..0
3377 begin
3378 g_Obj_Push(@it.Obj, (FObj.Vel.X div 2)-5+Random(11),
3379 (FObj.Vel.Y div 2)-Random(6));
3380 end
3381 else // -3..+3; -3..0
3382 begin
3383 g_Obj_Push(@it.Obj, (FObj.Vel.X div 2)-3+Random(7),
3384 (FObj.Vel.Y div 2)-Random(4));
3385 end;
3386 it.positionChanged(); // this updates spatial accelerators
3387 end;
3389 if g_Game_IsNet and g_Game_IsServer then
3390 MH_SEND_ItemSpawn(True, id);
3391 end;
3393 begin
3394 DoFrags := (gGameSettings.MaxLives = 0) or (gGameSettings.GameMode = GM_COOP);
3395 Srv := g_Game_IsServer;
3396 Netsrv := g_Game_IsServer and g_Game_IsNet;
3397 if Srv then FDeath := FDeath + 1;
3398 if FAlive then
3399 begin
3400 if FGhost then
3401 FGhost := False;
3402 if not FPhysics then
3403 FPhysics := True;
3404 FAlive := False;
3405 end;
3406 FShellTimer := -1;
3408 if (gGameSettings.MaxLives > 0) and Srv and (gLMSRespawn = LMS_RESPAWN_NONE) then
3409 begin
3410 if FLives > 0 then FLives := FLives - 1;
3411 if FLives = 0 then FNoRespawn := True;
3412 end;
3414 // Íîìåð òèïà ñìåðòè:
3415 a := 1;
3416 case KillType of
3417 K_SIMPLEKILL: a := 1;
3418 K_HARDKILL: a := 2;
3419 K_EXTRAHARDKILL: a := 3;
3420 K_FALLKILL: a := 4;
3421 end;
3423 // Çâóê ñìåðòè:
3424 if not FModel.PlaySound(MODELSOUND_DIE, a, FObj.X, FObj.Y) then
3425 for i := 1 to 3 do
3426 if FModel.PlaySound(MODELSOUND_DIE, i, FObj.X, FObj.Y) then
3427 Break;
3429 // Âðåìÿ ðåñïàóíà:
3430 if Srv then
3431 case KillType of
3432 K_SIMPLEKILL:
3433 FTime[T_RESPAWN] := gTime + TIME_RESPAWN1;
3434 K_HARDKILL:
3435 FTime[T_RESPAWN] := gTime + TIME_RESPAWN2;
3436 K_EXTRAHARDKILL, K_FALLKILL:
3437 FTime[T_RESPAWN] := gTime + TIME_RESPAWN3;
3438 end;
3440 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3441 case KillType of
3442 K_SIMPLEKILL:
3443 SetAction(A_DIE1);
3444 K_HARDKILL, K_EXTRAHARDKILL:
3445 SetAction(A_DIE2);
3446 end;
3448 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3449 if (KillType <> K_FALLKILL) and (Srv) then
3450 g_Monsters_killedp();
3452 if SpawnerUID = FUID then
3453 begin // Ñàìîóáèëñÿ
3454 if Srv then
3455 begin
3456 if gGameSettings.GameMode = GM_TDM then
3457 Dec(gTeamStat[FTeam].Goals);
3458 if DoFrags or (gGameSettings.GameMode = GM_TDM) then
3459 begin
3460 Dec(FFrags);
3461 FLastFrag := 0;
3462 end;
3463 end;
3464 g_Console_Add(Format(_lc[I_PLAYER_KILL_SELF], [FName]), True);
3465 end
3466 else
3467 if g_GetUIDType(SpawnerUID) = UID_PLAYER then
3468 begin // Óáèò äðóãèì èãðîêîì
3469 KP := g_Player_Get(SpawnerUID);
3470 if (KP <> nil) and Srv then
3471 begin
3472 if (DoFrags or (gGameSettings.GameMode = GM_TDM)) then
3473 if SameTeam(FUID, SpawnerUID) then
3474 begin
3475 Dec(KP.FFrags);
3476 KP.FLastFrag := 0;
3477 end else
3478 begin
3479 Inc(KP.FFrags);
3480 KP.FragCombo();
3481 end;
3483 if (gGameSettings.GameMode = GM_TDM) and DoFrags then
3484 Inc(gTeamStat[KP.Team].Goals,
3485 IfThen(SameTeam(FUID, SpawnerUID), -1, 1));
3487 if netsrv then MH_SEND_PlayerStats(SpawnerUID);
3488 end;
3490 plr := g_Player_Get(SpawnerUID);
3491 if plr = nil then
3492 s := '?'
3493 else
3494 s := plr.FName;
3496 case KillType of
3497 K_HARDKILL:
3498 g_Console_Add(Format(_lc[I_PLAYER_KILL_EXTRAHARD_2],
3499 [FName, s]),
3500 gShowKillMsg);
3501 K_EXTRAHARDKILL:
3502 g_Console_Add(Format(_lc[I_PLAYER_KILL_EXTRAHARD_1],
3503 [FName, s]),
3504 gShowKillMsg);
3505 else
3506 g_Console_Add(Format(_lc[I_PLAYER_KILL],
3507 [FName, s]),
3508 gShowKillMsg);
3509 end;
3510 end
3511 else if g_GetUIDType(SpawnerUID) = UID_MONSTER then
3512 begin // Óáèò ìîíñòðîì
3513 mon := g_Monsters_ByUID(SpawnerUID);
3514 if mon = nil then
3515 s := '?'
3516 else
3517 s := g_Mons_GetKilledByTypeId(mon.MonsterType);
3519 case KillType of
3520 K_HARDKILL:
3521 g_Console_Add(Format(_lc[I_PLAYER_KILL_EXTRAHARD_2],
3522 [FName, s]),
3523 gShowKillMsg);
3524 K_EXTRAHARDKILL:
3525 g_Console_Add(Format(_lc[I_PLAYER_KILL_EXTRAHARD_1],
3526 [FName, s]),
3527 gShowKillMsg);
3528 else
3529 g_Console_Add(Format(_lc[I_PLAYER_KILL],
3530 [FName, s]),
3531 gShowKillMsg);
3532 end;
3533 end
3534 else // Îñîáûå òèïû ñìåðòè
3535 case t of
3536 HIT_DISCON: ;
3537 HIT_SELF: g_Console_Add(Format(_lc[I_PLAYER_KILL_SELF], [FName]), True);
3538 HIT_FALL: g_Console_Add(Format(_lc[I_PLAYER_KILL_FALL], [FName]), True);
3539 HIT_WATER: g_Console_Add(Format(_lc[I_PLAYER_KILL_WATER], [FName]), True);
3540 HIT_ACID: g_Console_Add(Format(_lc[I_PLAYER_KILL_ACID], [FName]), True);
3541 HIT_TRAP: g_Console_Add(Format(_lc[I_PLAYER_KILL_TRAP], [FName]), True);
3542 else g_Console_Add(Format(_lc[I_PLAYER_DIED], [FName]), True);
3543 end;
3545 if Srv then
3546 begin
3547 // Âûáðîñ îðóæèÿ:
3548 for a := WP_FIRST to WP_LAST do
3549 if FWeapon[a] then
3550 begin
3551 case a of
3552 WEAPON_SAW: i := ITEM_WEAPON_SAW;
3553 WEAPON_SHOTGUN1: i := ITEM_WEAPON_SHOTGUN1;
3554 WEAPON_SHOTGUN2: i := ITEM_WEAPON_SHOTGUN2;
3555 WEAPON_CHAINGUN: i := ITEM_WEAPON_CHAINGUN;
3556 WEAPON_ROCKETLAUNCHER: i := ITEM_WEAPON_ROCKETLAUNCHER;
3557 WEAPON_PLASMA: i := ITEM_WEAPON_PLASMA;
3558 WEAPON_BFG: i := ITEM_WEAPON_BFG;
3559 WEAPON_SUPERPULEMET: i := ITEM_WEAPON_SUPERPULEMET;
3560 WEAPON_FLAMETHROWER: i := ITEM_WEAPON_FLAMETHROWER;
3561 else i := 0;
3562 end;
3564 if i <> 0 then
3565 PushItem(i);
3566 end;
3568 // Âûáðîñ ðþêçàêà:
3569 if R_ITEM_BACKPACK in FRulez then
3570 PushItem(ITEM_AMMO_BACKPACK);
3572 // Âûáðîñ ðàêåòíîãî ðàíöà:
3573 if FJetFuel > 0 then
3574 PushItem(ITEM_JETPACK);
3576 // Âûáðîñ êëþ÷åé:
3577 if (not (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF])) or
3578 (not LongBool(gGameSettings.Options and GAME_OPTION_DMKEYS)) then
3579 begin
3580 if R_KEY_RED in FRulez then
3581 PushItem(ITEM_KEY_RED);
3583 if R_KEY_GREEN in FRulez then
3584 PushItem(ITEM_KEY_GREEN);
3586 if R_KEY_BLUE in FRulez then
3587 PushItem(ITEM_KEY_BLUE);
3588 end;
3590 // Âûáðîñ ôëàãà:
3591 DropFlag(KillType = K_FALLKILL);
3592 end;
3594 FCorpse := g_Player_CreateCorpse(Self);
3596 if Srv and (gGameSettings.MaxLives > 0) and FNoRespawn and
3597 (gLMSRespawn = LMS_RESPAWN_NONE) then
3598 begin
3599 a := 0;
3600 k := 0;
3601 ar := 0;
3602 ab := 0;
3603 for i := Low(gPlayers) to High(gPlayers) do
3604 begin
3605 if gPlayers[i] = nil then continue;
3606 if (not gPlayers[i].FNoRespawn) and (not gPlayers[i].FSpectator) then
3607 begin
3608 Inc(a);
3609 if gPlayers[i].FTeam = TEAM_RED then Inc(ar)
3610 else if gPlayers[i].FTeam = TEAM_BLUE then Inc(ab);
3611 k := i;
3612 end;
3613 end;
3615 OldLR := gLMSRespawn;
3616 if (gGameSettings.GameMode = GM_COOP) then
3617 begin
3618 if (a = 0) then
3619 begin
3620 // everyone is dead, restart the map
3621 g_Game_Message(_lc[I_MESSAGE_LMS_LOSE], 144);
3622 if Netsrv then
3623 MH_SEND_GameEvent(NET_EV_LMS_LOSE);
3624 gLMSRespawn := LMS_RESPAWN_FINAL;
3625 gLMSRespawnTime := gTime + 5000;
3626 end
3627 else if (a = 1) then
3628 begin
3629 if (gPlayers[k] <> nil) and not (gPlayers[k] is TBot) then
3630 if (gPlayers[k] = gPlayer1) or
3631 (gPlayers[k] = gPlayer2) then
3632 g_Console_Add('*** ' + _lc[I_MESSAGE_LMS_SURVIVOR] + ' ***', True)
3633 else if Netsrv and (gPlayers[k].FClientID >= 0) then
3634 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR, 0, 'N', gPlayers[k].FClientID);
3635 end;
3636 end
3637 else if (gGameSettings.GameMode = GM_TDM) then
3638 begin
3639 if (ab = 0) and (ar <> 0) then
3640 begin
3641 // blu team ded
3642 g_Game_Message(Format(_lc[I_MESSAGE_TLMS_WIN], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 144);
3643 if Netsrv then
3644 MH_SEND_GameEvent(NET_EV_TLMS_WIN, TEAM_RED);
3645 Inc(gTeamStat[TEAM_RED].Goals);
3646 gLMSRespawn := LMS_RESPAWN_FINAL;
3647 gLMSRespawnTime := gTime + 5000;
3648 end
3649 else if (ar = 0) and (ab <> 0) then
3650 begin
3651 // red team ded
3652 g_Game_Message(Format(_lc[I_MESSAGE_TLMS_WIN], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 144);
3653 if Netsrv then
3654 MH_SEND_GameEvent(NET_EV_TLMS_WIN, TEAM_BLUE);
3655 Inc(gTeamStat[TEAM_BLUE].Goals);
3656 gLMSRespawn := LMS_RESPAWN_FINAL;
3657 gLMSRespawnTime := gTime + 5000;
3658 end
3659 else if (ar = 0) and (ab = 0) then
3660 begin
3661 // everyone ded
3662 g_Game_Message(_lc[I_GAME_WIN_DRAW], 144);
3663 if Netsrv then
3664 MH_SEND_GameEvent(NET_EV_LMS_DRAW, 0, FName);
3665 gLMSRespawn := LMS_RESPAWN_FINAL;
3666 gLMSRespawnTime := gTime + 5000;
3667 end;
3668 end
3669 else if (gGameSettings.GameMode = GM_DM) then
3670 begin
3671 if (a = 1) then
3672 begin
3673 if gPlayers[k] <> nil then
3674 with gPlayers[k] do
3675 begin
3676 // survivor is the winner
3677 g_Game_Message(Format(_lc[I_MESSAGE_LMS_WIN], [AnsiUpperCase(FName)]), 144);
3678 if Netsrv then
3679 MH_SEND_GameEvent(NET_EV_LMS_WIN, 0, FName);
3680 Inc(FFrags);
3681 end;
3682 gLMSRespawn := LMS_RESPAWN_FINAL;
3683 gLMSRespawnTime := gTime + 5000;
3684 end
3685 else if (a = 0) then
3686 begin
3687 // everyone is dead, restart the map
3688 g_Game_Message(_lc[I_GAME_WIN_DRAW], 144);
3689 if Netsrv then
3690 MH_SEND_GameEvent(NET_EV_LMS_DRAW, 0, FName);
3691 gLMSRespawn := LMS_RESPAWN_FINAL;
3692 gLMSRespawnTime := gTime + 5000;
3693 end;
3694 end;
3695 if srv and (OldLR = LMS_RESPAWN_NONE) and (gLMSRespawn > LMS_RESPAWN_NONE) then
3696 begin
3697 if NetMode = NET_SERVER then
3698 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, gLMSRespawnTime - gTime)
3699 else
3700 g_Console_Add(Format(_lc[I_MSG_WARMUP_START], [(gLMSRespawnTime - gTime) div 1000]), True);
3701 end;
3702 end;
3704 if Netsrv then
3705 begin
3706 MH_SEND_PlayerStats(FUID);
3707 MH_SEND_PlayerDeath(FUID, KillType, t, SpawnerUID);
3708 if gGameSettings.GameMode = GM_TDM then MH_SEND_GameStats;
3709 end;
3711 if srv and FNoRespawn then Spectate(True);
3712 FWantsInGame := True;
3713 end;
3715 function TPlayer.BodyInLiquid(XInc, YInc: Integer): Boolean;
3716 begin
3717 Result := g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc, PLAYER_RECT.Width,
3718 PLAYER_RECT.Height-20, PANEL_WATER or PANEL_ACID1 or PANEL_ACID2, False);
3719 end;
3721 function TPlayer.BodyInAcid(XInc, YInc: Integer): Boolean;
3722 begin
3723 Result := g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc, PLAYER_RECT.Width,
3724 PLAYER_RECT.Height-20, PANEL_ACID1 or PANEL_ACID2, False);
3725 end;
3727 procedure TPlayer.MakeBloodSimple(Count: Word);
3728 begin
3729 g_GFX_Blood(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)+8,
3730 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2),
3731 Count div 2, 3, -1, 16, (PLAYER_RECT.Height*2 div 3),
3732 FModel.Blood.R, FModel.Blood.G, FModel.Blood.B, FModel.Blood.Kind);
3733 g_GFX_Blood(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-8,
3734 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2),
3735 Count div 2, -3, -1, 16, (PLAYER_RECT.Height*2) div 3,
3736 FModel.Blood.R, FModel.Blood.G, FModel.Blood.B, FModel.Blood.Kind);
3737 end;
3739 procedure TPlayer.MakeBloodVector(Count: Word; VelX, VelY: Integer);
3740 begin
3741 g_GFX_Blood(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2),
3742 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2),
3743 Count, VelX, VelY, 16, (PLAYER_RECT.Height*2) div 3,
3744 FModel.Blood.R, FModel.Blood.G, FModel.Blood.B, FModel.Blood.Kind);
3745 end;
3747 procedure TPlayer.ProcessWeaponAction(Action: Byte);
3748 begin
3749 if g_Game_IsClient then Exit;
3750 case Action of
3751 WP_PREV: PrevWeapon();
3752 WP_NEXT: NextWeapon();
3753 end;
3754 end;
3756 procedure TPlayer.QueueWeaponSwitch(Weapon: Byte);
3757 begin
3758 if g_Game_IsClient then Exit;
3759 if Weapon > High(FWeapon) then Exit;
3760 FNextWeap := FNextWeap or (1 shl Weapon);
3761 end;
3763 procedure TPlayer.resetWeaponQueue ();
3764 begin
3765 FNextWeap := 0;
3766 FNextWeapDelay := 0;
3767 end;
3769 function TPlayer.hasAmmoForWeapon (weapon: Byte): Boolean;
3770 begin
3771 result := false;
3772 case weapon of
3773 WEAPON_KASTET, WEAPON_SAW: result := true;
3774 WEAPON_SHOTGUN1, WEAPON_SHOTGUN2, WEAPON_SUPERPULEMET: result := (FAmmo[A_SHELLS] > 0);
3775 WEAPON_PISTOL, WEAPON_CHAINGUN: result := (FAmmo[A_BULLETS] > 0);
3776 WEAPON_ROCKETLAUNCHER: result := (FAmmo[A_ROCKETS] > 0);
3777 WEAPON_PLASMA, WEAPON_BFG: result := (FAmmo[A_CELLS] > 0);
3778 WEAPON_FLAMETHROWER: result := (FAmmo[A_FUEL] > 0);
3779 else result := (weapon < length(FWeapon));
3780 end;
3781 end;
3783 function TPlayer.shouldSwitch (weapon: Byte; hadWeapon: Boolean): Boolean;
3784 begin
3785 result := false;
3786 if (weapon < 0) or (weapon > WP_LAST + 1) then
3787 begin
3788 result := false;
3789 exit;
3790 end;
3791 if (FWeapSwitchMode = 1) and not hadWeapon then
3792 result := true
3793 else if (FWeapSwitchMode = 2) then
3794 result := (FWeapPreferences[weapon] > FWeapPreferences[FCurrWeap]);
3795 end;
3797 // return 255 for "no switch"
3798 function TPlayer.getNextWeaponIndex (): Byte;
3799 var
3800 i: Word;
3801 wantThisWeapon: array[0..64] of Boolean;
3802 wwc: Integer = 0; //HACK!
3803 dir, cwi: Integer;
3804 begin
3805 result := 255; // default result: "no switch"
3806 //e_LogWriteFln('FSWITCHTOEMPTY: %s', [FSwitchToEmpty], TMsgType.Notify);
3807 // had weapon cycling on previous frame? remove that flag
3808 if (FNextWeap and $2000) <> 0 then
3809 begin
3810 FNextWeap := FNextWeap and $1FFF;
3811 FNextWeapDelay := 0;
3812 end;
3813 // cycling has priority
3814 if (FNextWeap and $C000) <> 0 then
3815 begin
3816 if (FNextWeap and $8000) <> 0 then
3817 dir := 1
3818 else
3819 dir := -1;
3820 FNextWeap := FNextWeap or $2000; // we need this
3821 if FNextWeapDelay > 0 then
3822 exit; // cooldown time
3823 cwi := FCurrWeap;
3824 for i := 0 to High(FWeapon) do
3825 begin
3826 cwi := (cwi+length(FWeapon)+dir) mod length(FWeapon);
3827 if FWeapon[cwi] and maySwitch(cwi) then
3828 begin
3829 //e_LogWriteFln(' SWITCH: cur=%d; new=%d %s %s', [FCurrWeap, cwi, FSwitchToEmpty, hasAmmoForWeapon(cwi)], TMsgType.Notify);
3830 result := Byte(cwi);
3831 FNextWeapDelay := WEAPON_DELAY;
3832 exit;
3833 end;
3834 end;
3835 resetWeaponQueue();
3836 exit;
3837 end;
3838 // no cycling
3839 for i := 0 to High(wantThisWeapon) do
3840 wantThisWeapon[i] := false;
3841 for i := 0 to High(FWeapon) do
3842 if (FNextWeap and (1 shl i)) <> 0 then
3843 begin
3844 wantThisWeapon[i] := true;
3845 Inc(wwc);
3846 end;
3848 // exclude currently selected weapon from the set
3849 wantThisWeapon[FCurrWeap] := false;
3850 // slow down alterations a little
3851 if wwc > 1 then
3852 begin
3853 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3854 // more than one weapon requested, assume "alteration" and check alteration delay
3855 if FNextWeapDelay > 0 then
3856 begin
3857 FNextWeap := 0;
3858 exit;
3859 end; // yeah
3860 end;
3861 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3862 // but clear all counters if no weapon should be switched
3863 if wwc < 1 then
3864 begin
3865 resetWeaponQueue();
3866 exit;
3867 end;
3868 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3869 // try weapons in descending order
3870 for i := High(FWeapon) downto 0 do
3871 begin
3872 if wantThisWeapon[i] and FWeapon[i] and ((wwc = 1) or hasAmmoForWeapon(i)) then
3873 begin
3874 // i found her!
3875 result := Byte(i);
3876 resetWeaponQueue();
3877 FNextWeapDelay := WEAPON_DELAY * 2; // anyway, 'cause why not
3878 //e_LogWriteFln('FOUND %s %s %s', [result, FSwitchToEmpty, hasAmmoForWeapon(i)], TMsgType.Notify);
3879 exit;
3880 end;
3881 end;
3882 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3883 resetWeaponQueue();
3884 end;
3886 procedure TPlayer.RealizeCurrentWeapon();
3887 function switchAllowed (): Boolean;
3888 var
3889 i: Byte;
3890 begin
3891 result := false;
3892 if FBFGFireCounter <> -1 then
3893 exit;
3894 if FTime[T_SWITCH] > gTime then
3895 exit;
3896 for i := WP_FIRST to WP_LAST do
3897 if FReloading[i] > 0 then
3898 exit;
3899 result := true;
3900 end;
3902 var
3903 nw: Byte;
3904 begin
3905 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3906 //FNextWeap := FNextWeap and $1FFF;
3907 if FNextWeapDelay > 0 then Dec(FNextWeapDelay); // "alteration delay"
3909 if not switchAllowed then
3910 begin
3911 //HACK for weapon cycling
3912 if (FNextWeap and $E000) <> 0 then FNextWeap := 0;
3913 exit;
3914 end;
3916 nw := getNextWeaponIndex();
3917 //
3918 if nw = 255 then exit; // don't reset anything here
3919 if nw > High(FWeapon) then
3920 begin
3921 // don't forget to reset queue here!
3922 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
3923 resetWeaponQueue();
3924 exit;
3925 end;
3927 if FWeapon[nw] then
3928 begin
3929 FCurrWeap := nw;
3930 FTime[T_SWITCH] := gTime+156;
3931 if FCurrWeap = WEAPON_SAW then FSawSoundSelect.PlayAt(FObj.X, FObj.Y);
3932 FModel.SetWeapon(FCurrWeap);
3933 if g_Game_IsNet then MH_SEND_PlayerStats(FUID);
3934 end;
3935 end;
3937 procedure TPlayer.NextWeapon();
3938 begin
3939 if g_Game_IsClient then Exit;
3940 FNextWeap := $8000;
3941 end;
3943 procedure TPlayer.PrevWeapon();
3944 begin
3945 if g_Game_IsClient then Exit;
3946 FNextWeap := $4000;
3947 end;
3949 procedure TPlayer.SetWeapon(W: Byte);
3950 begin
3951 if FCurrWeap <> W then
3952 if W = WEAPON_SAW then
3953 FSawSoundSelect.PlayAt(FObj.X, FObj.Y);
3955 FCurrWeap := W;
3956 FModel.SetWeapon(CurrWeap);
3957 resetWeaponQueue();
3958 end;
3960 function TPlayer.PickItem(ItemType: Byte; arespawn: Boolean; var remove: Boolean): Boolean;
3962 function allowBerserkSwitching (): Boolean;
3963 begin
3964 if (FBFGFireCounter <> -1) then begin result := false; exit; end;
3965 result := true;
3966 if gBerserkAutoswitch then exit;
3967 if not conIsCheatsEnabled then exit;
3968 result := false;
3969 end;
3971 var
3972 a: Boolean;
3973 switchWeapon: Byte = -1;
3974 hadWeapon: Boolean = False;
3975 begin
3976 Result := False;
3977 if g_Game_IsClient then Exit;
3979 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3980 a := LongBool(gGameSettings.Options and GAME_OPTION_WEAPONSTAY) and arespawn;
3981 remove := not a;
3982 case ItemType of
3983 ITEM_MEDKIT_SMALL:
3984 if (FHealth < PLAYER_HP_SOFT) or (FFireTime > 0) then
3985 begin
3986 if FHealth < PLAYER_HP_SOFT then IncMax(FHealth, 10, PLAYER_HP_SOFT);
3987 Result := True;
3988 remove := True;
3989 FFireTime := 0;
3990 if gFlash = 2 then Inc(FPickup, 5);
3991 end;
3993 ITEM_MEDKIT_LARGE:
3994 if (FHealth < PLAYER_HP_SOFT) or (FFireTime > 0) then
3995 begin
3996 if FHealth < PLAYER_HP_SOFT then IncMax(FHealth, 25, PLAYER_HP_SOFT);
3997 Result := True;
3998 remove := True;
3999 FFireTime := 0;
4000 if gFlash = 2 then Inc(FPickup, 5);
4001 end;
4003 ITEM_ARMOR_GREEN:
4004 if FArmor < PLAYER_AP_SOFT then
4005 begin
4006 FArmor := PLAYER_AP_SOFT;
4007 Result := True;
4008 remove := True;
4009 if gFlash = 2 then Inc(FPickup, 5);
4010 end;
4012 ITEM_ARMOR_BLUE:
4013 if FArmor < PLAYER_AP_LIMIT then
4014 begin
4015 FArmor := PLAYER_AP_LIMIT;
4016 Result := True;
4017 remove := True;
4018 if gFlash = 2 then Inc(FPickup, 5);
4019 end;
4021 ITEM_SPHERE_BLUE:
4022 if (FHealth < PLAYER_HP_LIMIT) or (FFireTime > 0) then
4023 begin
4024 if FHealth < PLAYER_HP_LIMIT then IncMax(FHealth, 100, PLAYER_HP_LIMIT);
4025 Result := True;
4026 remove := True;
4027 FFireTime := 0;
4028 if gFlash = 2 then Inc(FPickup, 5);
4029 end;
4031 ITEM_SPHERE_WHITE:
4032 if (FHealth < PLAYER_HP_LIMIT) or (FArmor < PLAYER_AP_LIMIT) or (FFireTime > 0) then
4033 begin
4034 if FHealth < PLAYER_HP_LIMIT then
4035 FHealth := PLAYER_HP_LIMIT;
4036 if FArmor < PLAYER_AP_LIMIT then
4037 FArmor := PLAYER_AP_LIMIT;
4038 Result := True;
4039 remove := True;
4040 FFireTime := 0;
4041 if gFlash = 2 then Inc(FPickup, 5);
4042 end;
4044 ITEM_WEAPON_SAW:
4045 if (not FWeapon[WEAPON_SAW]) or ((not arespawn) and (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF])) then
4046 begin
4047 hadWeapon := FWeapon[WEAPON_SAW];
4048 switchWeapon := WEAPON_SAW;
4049 FWeapon[WEAPON_SAW] := True;
4050 Result := True;
4051 if gFlash = 2 then Inc(FPickup, 5);
4052 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
4053 end;
4055 ITEM_WEAPON_SHOTGUN1:
4056 if (FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS]) or not FWeapon[WEAPON_SHOTGUN1] then
4057 begin
4058 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
4059 if a and FWeapon[WEAPON_SHOTGUN1] then Exit;
4060 hadWeapon := FWeapon[WEAPON_SHOTGUN1];
4061 switchWeapon := WEAPON_SHOTGUN1;
4062 IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
4063 FWeapon[WEAPON_SHOTGUN1] := True;
4064 Result := True;
4065 if gFlash = 2 then Inc(FPickup, 5);
4066 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
4067 end;
4069 ITEM_WEAPON_SHOTGUN2:
4070 if (FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS]) or not FWeapon[WEAPON_SHOTGUN2] then
4071 begin
4072 if a and FWeapon[WEAPON_SHOTGUN2] then Exit;
4073 hadWeapon := FWeapon[WEAPON_SHOTGUN2];
4074 switchWeapon := WEAPON_SHOTGUN2;
4075 IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
4076 FWeapon[WEAPON_SHOTGUN2] := True;
4077 Result := True;
4078 if gFlash = 2 then Inc(FPickup, 5);
4079 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
4080 end;
4082 ITEM_WEAPON_CHAINGUN:
4083 if (FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS]) or not FWeapon[WEAPON_CHAINGUN] then
4084 begin
4085 if a and FWeapon[WEAPON_CHAINGUN] then Exit;
4086 hadWeapon := FWeapon[WEAPON_CHAINGUN];
4087 switchWeapon := WEAPON_CHAINGUN;
4088 IncMax(FAmmo[A_BULLETS], 50, FMaxAmmo[A_BULLETS]);
4089 FWeapon[WEAPON_CHAINGUN] := True;
4090 Result := True;
4091 if gFlash = 2 then Inc(FPickup, 5);
4092 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
4093 end;
4095 ITEM_WEAPON_ROCKETLAUNCHER:
4096 if (FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS]) or not FWeapon[WEAPON_ROCKETLAUNCHER] then
4097 begin
4098 if a and FWeapon[WEAPON_ROCKETLAUNCHER] then Exit;
4099 switchWeapon := WEAPON_ROCKETLAUNCHER;
4100 hadWeapon := FWeapon[WEAPON_ROCKETLAUNCHER];
4101 IncMax(FAmmo[A_ROCKETS], 2, FMaxAmmo[A_ROCKETS]);
4102 FWeapon[WEAPON_ROCKETLAUNCHER] := True;
4103 Result := True;
4104 if gFlash = 2 then Inc(FPickup, 5);
4105 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
4106 end;
4108 ITEM_WEAPON_PLASMA:
4109 if (FAmmo[A_CELLS] < FMaxAmmo[A_CELLS]) or not FWeapon[WEAPON_PLASMA] then
4110 begin
4111 if a and FWeapon[WEAPON_PLASMA] then Exit;
4112 switchWeapon := WEAPON_PLASMA;
4113 hadWeapon := FWeapon[WEAPON_PLASMA];
4114 IncMax(FAmmo[A_CELLS], 40, FMaxAmmo[A_CELLS]);
4115 FWeapon[WEAPON_PLASMA] := True;
4116 Result := True;
4117 if gFlash = 2 then Inc(FPickup, 5);
4118 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
4119 end;
4121 ITEM_WEAPON_BFG:
4122 if (FAmmo[A_CELLS] < FMaxAmmo[A_CELLS]) or not FWeapon[WEAPON_BFG] then
4123 begin
4124 if a and FWeapon[WEAPON_BFG] then Exit;
4125 switchWeapon := WEAPON_BFG;
4126 hadWeapon := FWeapon[WEAPON_BFG];
4127 IncMax(FAmmo[A_CELLS], 40, FMaxAmmo[A_CELLS]);
4128 FWeapon[WEAPON_BFG] := True;
4129 Result := True;
4130 if gFlash = 2 then Inc(FPickup, 5);
4131 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
4132 end;
4134 ITEM_WEAPON_SUPERPULEMET:
4135 if (FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS]) or not FWeapon[WEAPON_SUPERPULEMET] then
4136 begin
4137 if a and FWeapon[WEAPON_SUPERPULEMET] then Exit;
4138 switchWeapon := WEAPON_SUPERPULEMET;
4139 hadWeapon := FWeapon[WEAPON_SUPERPULEMET];
4140 IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
4141 FWeapon[WEAPON_SUPERPULEMET] := True;
4142 Result := True;
4143 if gFlash = 2 then Inc(FPickup, 5);
4144 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
4145 end;
4147 ITEM_WEAPON_FLAMETHROWER:
4148 if (FAmmo[A_FUEL] < FMaxAmmo[A_FUEL]) or not FWeapon[WEAPON_FLAMETHROWER] then
4149 begin
4150 if a and FWeapon[WEAPON_FLAMETHROWER] then Exit;
4151 switchWeapon := WEAPON_FLAMETHROWER;
4152 hadWeapon := FWeapon[WEAPON_FLAMETHROWER];
4153 IncMax(FAmmo[A_FUEL], 100, FMaxAmmo[A_FUEL]);
4154 FWeapon[WEAPON_FLAMETHROWER] := True;
4155 Result := True;
4156 if gFlash = 2 then Inc(FPickup, 5);
4157 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
4158 end;
4160 ITEM_AMMO_BULLETS:
4161 if FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS] then
4162 begin
4163 IncMax(FAmmo[A_BULLETS], 10, FMaxAmmo[A_BULLETS]);
4164 Result := True;
4165 remove := True;
4166 if gFlash = 2 then Inc(FPickup, 5);
4167 end;
4169 ITEM_AMMO_BULLETS_BOX:
4170 if FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS] then
4171 begin
4172 IncMax(FAmmo[A_BULLETS], 50, FMaxAmmo[A_BULLETS]);
4173 Result := True;
4174 remove := True;
4175 if gFlash = 2 then Inc(FPickup, 5);
4176 end;
4178 ITEM_AMMO_SHELLS:
4179 if FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS] then
4180 begin
4181 IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
4182 Result := True;
4183 remove := True;
4184 if gFlash = 2 then Inc(FPickup, 5);
4185 end;
4187 ITEM_AMMO_SHELLS_BOX:
4188 if FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS] then
4189 begin
4190 IncMax(FAmmo[A_SHELLS], 25, FMaxAmmo[A_SHELLS]);
4191 Result := True;
4192 remove := True;
4193 if gFlash = 2 then Inc(FPickup, 5);
4194 end;
4196 ITEM_AMMO_ROCKET:
4197 if FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS] then
4198 begin
4199 IncMax(FAmmo[A_ROCKETS], 1, FMaxAmmo[A_ROCKETS]);
4200 Result := True;
4201 remove := True;
4202 if gFlash = 2 then Inc(FPickup, 5);
4203 end;
4205 ITEM_AMMO_ROCKET_BOX:
4206 if FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS] then
4207 begin
4208 IncMax(FAmmo[A_ROCKETS], 5, FMaxAmmo[A_ROCKETS]);
4209 Result := True;
4210 remove := True;
4211 if gFlash = 2 then Inc(FPickup, 5);
4212 end;
4214 ITEM_AMMO_CELL:
4215 if FAmmo[A_CELLS] < FMaxAmmo[A_CELLS] then
4216 begin
4217 IncMax(FAmmo[A_CELLS], 40, FMaxAmmo[A_CELLS]);
4218 Result := True;
4219 remove := True;
4220 if gFlash = 2 then Inc(FPickup, 5);
4221 end;
4223 ITEM_AMMO_CELL_BIG:
4224 if FAmmo[A_CELLS] < FMaxAmmo[A_CELLS] then
4225 begin
4226 IncMax(FAmmo[A_CELLS], 100, FMaxAmmo[A_CELLS]);
4227 Result := True;
4228 remove := True;
4229 if gFlash = 2 then Inc(FPickup, 5);
4230 end;
4232 ITEM_AMMO_FUELCAN:
4233 if FAmmo[A_FUEL] < FMaxAmmo[A_FUEL] then
4234 begin
4235 IncMax(FAmmo[A_FUEL], 100, FMaxAmmo[A_FUEL]);
4236 Result := True;
4237 remove := True;
4238 if gFlash = 2 then Inc(FPickup, 5);
4239 end;
4241 ITEM_AMMO_BACKPACK:
4242 if not(R_ITEM_BACKPACK in FRulez) or
4243 (FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS]) or
4244 (FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS]) or
4245 (FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS]) or
4246 (FAmmo[A_CELLS] < FMaxAmmo[A_CELLS]) or
4247 (FAmmo[A_FUEL] < FMaxAmmo[A_FUEL]) then
4248 begin
4249 FMaxAmmo[A_BULLETS] := AmmoLimits[1, A_BULLETS];
4250 FMaxAmmo[A_SHELLS] := AmmoLimits[1, A_SHELLS];
4251 FMaxAmmo[A_ROCKETS] := AmmoLimits[1, A_ROCKETS];
4252 FMaxAmmo[A_CELLS] := AmmoLimits[1, A_CELLS];
4253 FMaxAmmo[A_FUEL] := AmmoLimits[1, A_FUEL];
4255 if FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS] then
4256 IncMax(FAmmo[A_BULLETS], 10, FMaxAmmo[A_BULLETS]);
4257 if FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS] then
4258 IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
4259 if FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS] then
4260 IncMax(FAmmo[A_ROCKETS], 1, FMaxAmmo[A_ROCKETS]);
4261 if FAmmo[A_CELLS] < FMaxAmmo[A_CELLS] then
4262 IncMax(FAmmo[A_CELLS], 40, FMaxAmmo[A_CELLS]);
4263 if FAmmo[A_FUEL] < FMaxAmmo[A_FUEL] then
4264 IncMax(FAmmo[A_FUEL], 50, FMaxAmmo[A_FUEL]);
4266 FRulez := FRulez + [R_ITEM_BACKPACK];
4267 Result := True;
4268 remove := True;
4269 if gFlash = 2 then Inc(FPickup, 5);
4270 end;
4272 ITEM_KEY_RED:
4273 if not(R_KEY_RED in FRulez) then
4274 begin
4275 Include(FRulez, R_KEY_RED);
4276 Result := True;
4277 remove := (gGameSettings.GameMode <> GM_COOP) and (g_Player_GetCount() < 2);
4278 if gFlash = 2 then Inc(FPickup, 5);
4279 if (not remove) and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETITEM');
4280 end;
4282 ITEM_KEY_GREEN:
4283 if not(R_KEY_GREEN in FRulez) then
4284 begin
4285 Include(FRulez, R_KEY_GREEN);
4286 Result := True;
4287 remove := (gGameSettings.GameMode <> GM_COOP) and (g_Player_GetCount() < 2);
4288 if gFlash = 2 then Inc(FPickup, 5);
4289 if (not remove) and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETITEM');
4290 end;
4292 ITEM_KEY_BLUE:
4293 if not(R_KEY_BLUE in FRulez) then
4294 begin
4295 Include(FRulez, R_KEY_BLUE);
4296 Result := True;
4297 remove := (gGameSettings.GameMode <> GM_COOP) and (g_Player_GetCount() < 2);
4298 if gFlash = 2 then Inc(FPickup, 5);
4299 if (not remove) and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETITEM');
4300 end;
4302 ITEM_SUIT:
4303 if FMegaRulez[MR_SUIT] < gTime+PLAYER_SUIT_TIME then
4304 begin
4305 FMegaRulez[MR_SUIT] := gTime+PLAYER_SUIT_TIME;
4306 Result := True;
4307 remove := True;
4308 FFireTime := 0;
4309 if gFlash = 2 then Inc(FPickup, 5);
4310 end;
4312 ITEM_OXYGEN:
4313 if FAir < AIR_MAX then
4314 begin
4315 FAir := AIR_MAX;
4316 Result := True;
4317 remove := True;
4318 if gFlash = 2 then Inc(FPickup, 5);
4319 end;
4321 ITEM_MEDKIT_BLACK:
4322 begin
4323 if not (R_BERSERK in FRulez) then
4324 begin
4325 Include(FRulez, R_BERSERK);
4326 if (shouldSwitch(WP_LAST + 1, false)) then
4327 QueueWeaponSwitch(WEAPON_KASTET);
4328 if gFlash <> 0 then
4329 begin
4330 Inc(FPain, 100);
4331 if gFlash = 2 then Inc(FPickup, 5);
4332 end;
4333 FBerserk := gTime+30000;
4334 Result := True;
4335 remove := True;
4336 FFireTime := 0;
4337 end;
4338 if (FHealth < PLAYER_HP_SOFT) or (FFireTime > 0) then
4339 begin
4340 if FHealth < PLAYER_HP_SOFT then FHealth := PLAYER_HP_SOFT;
4341 FBerserk := gTime+30000;
4342 Result := True;
4343 remove := True;
4344 FFireTime := 0;
4345 end;
4346 end;
4348 ITEM_INVUL:
4349 if FMegaRulez[MR_INVUL] < gTime+PLAYER_INVUL_TIME then
4350 begin
4351 FMegaRulez[MR_INVUL] := gTime+PLAYER_INVUL_TIME;
4352 FSpawnInvul := 0;
4353 Result := True;
4354 remove := True;
4355 if gFlash = 2 then Inc(FPickup, 5);
4356 end;
4358 ITEM_BOTTLE:
4359 if (FHealth < PLAYER_HP_LIMIT) or (FFireTime > 0) then
4360 begin
4361 if FHealth < PLAYER_HP_LIMIT then IncMax(FHealth, 4, PLAYER_HP_LIMIT);
4362 Result := True;
4363 remove := True;
4364 FFireTime := 0;
4365 if gFlash = 2 then Inc(FPickup, 5);
4366 end;
4368 ITEM_HELMET:
4369 if FArmor < PLAYER_AP_LIMIT then
4370 begin
4371 IncMax(FArmor, 5, PLAYER_AP_LIMIT);
4372 Result := True;
4373 remove := True;
4374 if gFlash = 2 then Inc(FPickup, 5);
4375 end;
4377 ITEM_JETPACK:
4378 if FJetFuel < JET_MAX then
4379 begin
4380 FJetFuel := JET_MAX;
4381 Result := True;
4382 remove := True;
4383 if gFlash = 2 then Inc(FPickup, 5);
4384 end;
4386 ITEM_INVIS:
4387 if FMegaRulez[MR_INVIS] < gTime+PLAYER_INVIS_TIME then
4388 begin
4389 FMegaRulez[MR_INVIS] := gTime+PLAYER_INVIS_TIME;
4390 Result := True;
4391 remove := True;
4392 if gFlash = 2 then Inc(FPickup, 5);
4393 end;
4394 end;
4396 if (shouldSwitch(switchWeapon, hadWeapon)) then
4397 QueueWeaponSwitch(switchWeapon);
4398 end;
4400 procedure TPlayer.Touch();
4401 begin
4402 if not FAlive then
4403 Exit;
4404 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4405 if FIamBot then
4406 begin
4407 // Áðîñèòü ôëàã òîâàðèùó:
4408 if gGameSettings.GameMode = GM_CTF then
4409 DropFlag();
4410 end;
4411 end;
4413 procedure TPlayer.Push(vx, vy: Integer);
4414 begin
4415 if (not FPhysics) and FGhost then
4416 Exit;
4417 FObj.Accel.X := FObj.Accel.X + vx;
4418 FObj.Accel.Y := FObj.Accel.Y + vy;
4419 if g_Game_IsNet and g_Game_IsServer then
4420 MH_SEND_PlayerPos(True, FUID, NET_EVERYONE);
4421 end;
4423 procedure TPlayer.Reset(Force: Boolean);
4424 begin
4425 if Force then
4426 FAlive := False;
4428 FSpawned := False;
4429 FTime[T_RESPAWN] := 0;
4430 FTime[T_FLAGCAP] := 0;
4431 FGodMode := False;
4432 FNoTarget := False;
4433 FNoReload := False;
4434 FFrags := 0;
4435 FLastFrag := 0;
4436 FComboEvnt := -1;
4437 FKills := 0;
4438 FMonsterKills := 0;
4439 FDeath := 0;
4440 FSecrets := 0;
4441 FSpawnInvul := 0;
4442 FCorpse := -1;
4443 FReady := False;
4444 if FNoRespawn then
4445 begin
4446 FSpectator := False;
4447 FGhost := False;
4448 FPhysics := True;
4449 FSpectatePlayer := -1;
4450 FNoRespawn := False;
4451 end;
4452 FLives := gGameSettings.MaxLives;
4454 SetFlag(FLAG_NONE);
4455 end;
4457 procedure TPlayer.SoftReset();
4458 begin
4459 ReleaseKeys();
4461 FDamageBuffer := 0;
4462 FSlopeOld := 0;
4463 FIncCamOld := 0;
4464 FIncCam := 0;
4465 FBFGFireCounter := -1;
4466 FShellTimer := -1;
4467 FPain := 0;
4468 FLastHit := 0;
4469 FLastFrag := 0;
4470 FComboEvnt := -1;
4472 SetFlag(FLAG_NONE);
4473 SetAction(A_STAND, True);
4474 end;
4476 function TPlayer.GetRespawnPoint(): Byte;
4477 var
4478 c: Byte;
4479 begin
4480 Result := 255;
4481 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4483 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4484 if gGameSettings.GameMode in [GM_COOP, GM_SINGLE] then
4485 begin
4486 if Self = gPlayer1 then
4487 begin
4488 // player 1 should try to spawn on the player 1 point
4489 if g_Map_GetPointCount(RESPAWNPOINT_PLAYER1) > 0 then
4490 Exit(RESPAWNPOINT_PLAYER1)
4491 else if g_Map_GetPointCount(RESPAWNPOINT_PLAYER2) > 0 then
4492 Exit(RESPAWNPOINT_PLAYER2);
4493 end
4494 else if Self = gPlayer2 then
4495 begin
4496 // player 2 should try to spawn on the player 2 point
4497 if g_Map_GetPointCount(RESPAWNPOINT_PLAYER2) > 0 then
4498 Exit(RESPAWNPOINT_PLAYER2)
4499 else if g_Map_GetPointCount(RESPAWNPOINT_PLAYER1) > 0 then
4500 Exit(RESPAWNPOINT_PLAYER1);
4501 end
4502 else
4503 begin
4504 // other players randomly pick either the first or the second point
4505 c := IfThen((Random(2) = 0), RESPAWNPOINT_PLAYER1, RESPAWNPOINT_PLAYER2);
4506 if g_Map_GetPointCount(c) > 0 then
4507 Exit(c);
4508 // try the other one
4509 c := IfThen((c = RESPAWNPOINT_PLAYER1), RESPAWNPOINT_PLAYER2, RESPAWNPOINT_PLAYER1);
4510 if g_Map_GetPointCount(c) > 0 then
4511 Exit(c);
4512 end;
4513 end;
4515 // Ìÿñîïîâàë
4516 if gGameSettings.GameMode = GM_DM then
4517 begin
4518 // try DM points first
4519 if g_Map_GetPointCount(RESPAWNPOINT_DM) > 0 then
4520 Exit(RESPAWNPOINT_DM);
4521 end;
4523 // Êîìàíäíûå
4524 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
4525 begin
4526 // try team points first
4527 c := RESPAWNPOINT_DM;
4528 if FTeam = TEAM_RED then
4529 c := RESPAWNPOINT_RED
4530 else if FTeam = TEAM_BLUE then
4531 c := RESPAWNPOINT_BLUE;
4532 if g_Map_GetPointCount(c) > 0 then
4533 Exit(c);
4534 end;
4536 // still haven't found a spawnpoint, try random shit
4537 Result := g_Map_GetRandomPointType();
4538 end;
4540 procedure TPlayer.Respawn(Silent: Boolean; Force: Boolean = False);
4541 var
4542 RespawnPoint: TRespawnPoint;
4543 a, b, c: Byte;
4544 Anim: TAnimation;
4545 ID: DWORD;
4546 begin
4547 FSlopeOld := 0;
4548 FIncCamOld := 0;
4549 FIncCam := 0;
4550 FBFGFireCounter := -1;
4551 FShellTimer := -1;
4552 FPain := 0;
4553 FLastHit := 0;
4554 FSpawnInvul := 0;
4555 FCorpse := -1;
4557 if not g_Game_IsServer then
4558 Exit;
4559 if FDummy then
4560 Exit;
4561 FWantsInGame := True;
4562 FJustTeleported := True;
4563 if Force then
4564 begin
4565 FTime[T_RESPAWN] := 0;
4566 FAlive := False;
4567 end;
4568 FNetTime := 0;
4569 // if server changes MaxLives we gotta be ready
4570 if gGameSettings.MaxLives = 0 then FNoRespawn := False;
4572 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4573 if FTime[T_RESPAWN] > gTime then
4574 Exit;
4576 // Ïðîñðàë âñå æèçíè:
4577 if FNoRespawn then
4578 begin
4579 if not FSpectator then Spectate(True);
4580 FWantsInGame := True;
4581 Exit;
4582 end;
4584 if (gGameSettings.GameType <> GT_SINGLE) and (gGameSettings.GameMode <> GM_COOP) then
4585 begin // "Ñâîÿ èãðà"
4586 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4587 FRulez := FRulez-[R_BERSERK];
4588 end
4589 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4590 begin
4591 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4592 FRulez := FRulez-[R_KEY_RED, R_KEY_GREEN, R_KEY_BLUE, R_BERSERK];
4593 end;
4595 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4596 c := GetRespawnPoint();
4598 ReleaseKeys();
4599 SetFlag(FLAG_NONE);
4601 // Âîñêðåøåíèå áåç îðóæèÿ:
4602 if not FAlive then
4603 begin
4604 FHealth := Round(PLAYER_HP_SOFT * (FHandicap / 100));
4605 FArmor := 0;
4606 FAlive := True;
4607 FAir := AIR_DEF;
4608 FJetFuel := 0;
4610 for a := WP_FIRST to WP_LAST do
4611 begin
4612 FWeapon[a] := False;
4613 FReloading[a] := 0;
4614 end;
4616 FWeapon[WEAPON_PISTOL] := True;
4617 FWeapon[WEAPON_KASTET] := True;
4618 FCurrWeap := WEAPON_PISTOL;
4619 resetWeaponQueue();
4621 FModel.SetWeapon(FCurrWeap);
4623 for b := A_BULLETS to A_HIGH do
4624 FAmmo[b] := 0;
4626 FAmmo[A_BULLETS] := 50;
4628 FMaxAmmo[A_BULLETS] := AmmoLimits[0, A_BULLETS];
4629 FMaxAmmo[A_SHELLS] := AmmoLimits[0, A_SHELLS];
4630 FMaxAmmo[A_ROCKETS] := AmmoLimits[0, A_SHELLS];
4631 FMaxAmmo[A_CELLS] := AmmoLimits[0, A_CELLS];
4632 FMaxAmmo[A_FUEL] := AmmoLimits[0, A_FUEL];
4634 if (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF]) and
4635 LongBool(gGameSettings.Options and GAME_OPTION_DMKEYS) then
4636 FRulez := [R_KEY_RED, R_KEY_GREEN, R_KEY_BLUE]
4637 else
4638 FRulez := [];
4639 end;
4641 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4642 if not g_Map_GetPoint(c, RespawnPoint) then
4643 begin
4644 g_FatalError(_lc[I_GAME_ERROR_GET_SPAWN]);
4645 Exit;
4646 end;
4648 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4649 FObj.X := RespawnPoint.X-PLAYER_RECT.X;
4650 FObj.Y := RespawnPoint.Y-PLAYER_RECT.Y;
4651 FObj.oldX := FObj.X; // don't interpolate after respawn
4652 FObj.oldY := FObj.Y;
4653 FObj.Vel.X := 0;
4654 FObj.Vel.Y := 0;
4655 FObj.Accel.X := 0;
4656 FObj.Accel.Y := 0;
4658 FDirection := RespawnPoint.Direction;
4659 if FDirection = TDirection.D_LEFT then
4660 FAngle := 180
4661 else
4662 FAngle := 0;
4664 SetAction(A_STAND, True);
4665 FModel.Direction := FDirection;
4667 for a := Low(FTime) to High(FTime) do
4668 FTime[a] := 0;
4670 for a := Low(FMegaRulez) to High(FMegaRulez) do
4671 FMegaRulez[a] := 0;
4673 // Respawn invulnerability
4674 if (gGameSettings.GameType <> GT_SINGLE) and (gGameSettings.SpawnInvul > 0) then
4675 begin
4676 FMegaRulez[MR_INVUL] := gTime + gGameSettings.SpawnInvul * 1000;
4677 FSpawnInvul := FMegaRulez[MR_INVUL];
4678 end;
4680 FDamageBuffer := 0;
4681 FJetpack := False;
4682 FCanJetpack := False;
4683 FFlaming := False;
4684 FFireTime := 0;
4685 FFirePainTime := 0;
4686 FFireAttacker := 0;
4688 // Àíèìàöèÿ âîçðîæäåíèÿ:
4689 if (not gLoadGameMode) and (not Silent) then
4690 if g_Frames_Get(ID, 'FRAMES_TELEPORT') then
4691 begin
4692 Anim := TAnimation.Create(ID, False, 3);
4693 g_GFX_OnceAnim(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
4694 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32, Anim);
4695 Anim.Free();
4696 end;
4698 FSpectator := False;
4699 FGhost := False;
4700 FPhysics := True;
4701 FSpectatePlayer := -1;
4702 FSpawned := True;
4704 if (gPlayer1 = nil) and (gSpectLatchPID1 = FUID) then
4705 gPlayer1 := self;
4706 if (gPlayer2 = nil) and (gSpectLatchPID2 = FUID) then
4707 gPlayer2 := self;
4709 if g_Game_IsNet then
4710 begin
4711 MH_SEND_PlayerPos(True, FUID, NET_EVERYONE);
4712 MH_SEND_PlayerStats(FUID, NET_EVERYONE);
4713 if not Silent then
4714 MH_SEND_Effect(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
4715 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32,
4716 0, NET_GFX_TELE);
4717 end;
4718 end;
4720 procedure TPlayer.Spectate(NoMove: Boolean = False);
4721 begin
4722 if FAlive then
4723 Kill(K_EXTRAHARDKILL, FUID, HIT_SOME)
4724 else if (not NoMove) then
4725 begin
4726 GameX := gMapInfo.Width div 2;
4727 GameY := gMapInfo.Height div 2;
4728 end;
4729 FXTo := GameX;
4730 FYTo := GameY;
4732 FAlive := False;
4733 FSpectator := True;
4734 FGhost := True;
4735 FPhysics := False;
4736 FWantsInGame := False;
4737 FSpawned := False;
4738 FCorpse := -1;
4740 if FNoRespawn then
4741 begin
4742 if Self = gPlayer1 then
4743 begin
4744 gSpectLatchPID1 := FUID;
4745 gPlayer1 := nil;
4746 end
4747 else if Self = gPlayer2 then
4748 begin
4749 gSpectLatchPID2 := FUID;
4750 gPlayer2 := nil;
4751 end;
4752 end;
4754 if g_Game_IsNet then
4755 MH_SEND_PlayerStats(FUID);
4756 end;
4758 procedure TPlayer.SwitchNoClip;
4759 begin
4760 if not FAlive then
4761 Exit;
4762 FGhost := not FGhost;
4763 FPhysics := not FGhost;
4764 if FGhost then
4765 begin
4766 FXTo := FObj.X;
4767 FYTo := FObj.Y;
4768 end else
4769 begin
4770 FObj.Accel.X := 0;
4771 FObj.Accel.Y := 0;
4772 end;
4773 end;
4775 procedure TPlayer.Run(Direction: TDirection);
4776 var
4777 a, b: Integer;
4778 begin
4779 if MAX_RUNVEL > 8 then
4780 FlySmoke();
4782 // Áåæèì:
4783 if Direction = TDirection.D_LEFT then
4784 begin
4785 if FObj.Vel.X > -MAX_RUNVEL then
4786 FObj.Vel.X := FObj.Vel.X - (MAX_RUNVEL shr 3);
4787 end
4788 else
4789 if FObj.Vel.X < MAX_RUNVEL then
4790 FObj.Vel.X := FObj.Vel.X + (MAX_RUNVEL shr 3);
4792 // Âîçìîæíî, ïèíàåì êóñêè:
4793 if (FObj.Vel.X <> 0) and (gGibs <> nil) then
4794 begin
4795 b := Abs(FObj.Vel.X);
4796 if b > 1 then b := b * (Random(8 div b) + 1);
4797 for a := 0 to High(gGibs) do
4798 begin
4799 if gGibs[a].alive and
4800 g_Obj_Collide(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y+FObj.Rect.Height-4,
4801 FObj.Rect.Width, 8, @gGibs[a].Obj) and (Random(3) = 0) then
4802 begin
4803 // Ïèíàåì êóñêè
4804 if FObj.Vel.X < 0 then
4805 begin
4806 g_Obj_PushA(@gGibs[a].Obj, b, Random(61)+120) // íàëåâî
4807 end
4808 else
4809 begin
4810 g_Obj_PushA(@gGibs[a].Obj, b, Random(61)); // íàïðàâî
4811 end;
4812 gGibs[a].positionChanged(); // this updates spatial accelerators
4813 end;
4814 end;
4815 end;
4817 SetAction(A_WALK);
4818 end;
4820 procedure TPlayer.SeeDown();
4821 begin
4822 SetAction(A_SEEDOWN);
4824 if FDirection = TDirection.D_LEFT then FAngle := ANGLE_LEFTDOWN else FAngle := ANGLE_RIGHTDOWN;
4826 if FIncCam > -120 then DecMin(FIncCam, 5, -120);
4827 end;
4829 procedure TPlayer.SeeUp();
4830 begin
4831 SetAction(A_SEEUP);
4833 if FDirection = TDirection.D_LEFT then FAngle := ANGLE_LEFTUP else FAngle := ANGLE_RIGHTUP;
4835 if FIncCam < 120 then IncMax(FIncCam, 5, 120);
4836 end;
4838 procedure TPlayer.SetAction(Action: Byte; Force: Boolean = False);
4839 var
4840 Prior: Byte;
4841 begin
4842 case Action of
4843 A_WALK: Prior := 3;
4844 A_DIE1: Prior := 5;
4845 A_DIE2: Prior := 5;
4846 A_ATTACK: Prior := 2;
4847 A_SEEUP: Prior := 1;
4848 A_SEEDOWN: Prior := 1;
4849 A_ATTACKUP: Prior := 2;
4850 A_ATTACKDOWN: Prior := 2;
4851 A_PAIN: Prior := 4;
4852 else Prior := 0;
4853 end;
4855 if (Prior > FActionPrior) or Force then
4856 if not ((Prior = 2) and (FCurrWeap = WEAPON_SAW)) then
4857 begin
4858 FActionPrior := Prior;
4859 FActionAnim := Action;
4860 FActionForce := Force;
4861 FActionChanged := True;
4862 end;
4864 if Action in [A_ATTACK, A_ATTACKUP, A_ATTACKDOWN] then FModel.SetFire(True);
4865 end;
4867 function TPlayer.StayOnStep(XInc, YInc: Integer): Boolean;
4868 begin
4869 Result := not g_Map_CollidePanel(FObj.X+PLAYER_RECT.X, FObj.Y+YInc+PLAYER_RECT.Y+PLAYER_RECT.Height-1,
4870 PLAYER_RECT.Width, 1, PANEL_STEP, False)
4871 and g_Map_CollidePanel(FObj.X+PLAYER_RECT.X, FObj.Y+YInc+PLAYER_RECT.Y+PLAYER_RECT.Height,
4872 PLAYER_RECT.Width, 1, PANEL_STEP, False);
4873 end;
4875 function TPlayer.TeleportTo(X, Y: Integer; silent: Boolean; dir: Byte): Boolean;
4876 var
4877 Anim: TAnimation;
4878 ID: DWORD;
4879 begin
4880 Result := False;
4882 if g_CollideLevel(X, Y, PLAYER_RECT.Width, PLAYER_RECT.Height) then
4883 begin
4884 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj.X, FObj.Y);
4885 if g_Game_IsServer and g_Game_IsNet then
4886 MH_SEND_Sound(FObj.X, FObj.Y, 'SOUND_GAME_NOTELEPORT');
4887 Exit;
4888 end;
4890 FJustTeleported := True;
4892 Anim := nil;
4893 if not silent then
4894 begin
4895 if g_Frames_Get(ID, 'FRAMES_TELEPORT') then
4896 begin
4897 Anim := TAnimation.Create(ID, False, 3);
4898 end;
4900 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj.X, FObj.Y);
4901 g_GFX_OnceAnim(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
4902 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32, Anim);
4903 if g_Game_IsServer and g_Game_IsNet then
4904 MH_SEND_Effect(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
4905 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32, 1,
4906 NET_GFX_TELE);
4907 end;
4909 FObj.X := X-PLAYER_RECT.X;
4910 FObj.Y := Y-PLAYER_RECT.Y;
4911 FObj.oldX := FObj.X; // don't interpolate after respawn
4912 FObj.oldY := FObj.Y;
4913 if FAlive and FGhost then
4914 begin
4915 FXTo := FObj.X;
4916 FYTo := FObj.Y;
4917 end;
4919 if not g_Game_IsNet then
4920 begin
4921 if dir = 1 then
4922 begin
4923 SetDirection(TDirection.D_LEFT);
4924 FAngle := 180;
4925 end
4926 else
4927 if dir = 2 then
4928 begin
4929 SetDirection(TDirection.D_RIGHT);
4930 FAngle := 0;
4931 end
4932 else
4933 if dir = 3 then
4934 begin // îáðàòíîå
4935 if FDirection = TDirection.D_RIGHT then
4936 begin
4937 SetDirection(TDirection.D_LEFT);
4938 FAngle := 180;
4939 end
4940 else
4941 begin
4942 SetDirection(TDirection.D_RIGHT);
4943 FAngle := 0;
4944 end;
4945 end;
4946 end;
4948 if not silent and (Anim <> nil) then
4949 begin
4950 g_GFX_OnceAnim(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
4951 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32, Anim);
4952 Anim.Free();
4954 if g_Game_IsServer and g_Game_IsNet then
4955 MH_SEND_Effect(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
4956 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32, 0,
4957 NET_GFX_TELE);
4958 end;
4960 Result := True;
4961 end;
4963 function nonz(a: Single): Single;
4964 begin
4965 if a <> 0 then
4966 Result := a
4967 else
4968 Result := 1;
4969 end;
4971 function TPlayer.refreshCorpse(): Boolean;
4972 var
4973 i: Integer;
4974 begin
4975 Result := False;
4976 FCorpse := -1;
4977 if FAlive or FSpectator then
4978 Exit;
4979 if (gCorpses = nil) or (Length(gCorpses) = 0) then
4980 Exit;
4981 for i := 0 to High(gCorpses) do
4982 if gCorpses[i] <> nil then
4983 if gCorpses[i].FPlayerUID = FUID then
4984 begin
4985 Result := True;
4986 FCorpse := i;
4987 break;
4988 end;
4989 end;
4991 function TPlayer.getCameraObj(): TObj;
4992 begin
4993 if (not FAlive) and (not FSpectator) and
4994 (FCorpse >= 0) and (FCorpse < Length(gCorpses)) and
4995 (gCorpses[FCorpse] <> nil) and (gCorpses[FCorpse].FPlayerUID = FUID) then
4996 begin
4997 gCorpses[FCorpse].FObj.slopeUpLeft := FObj.slopeUpLeft;
4998 Result := gCorpses[FCorpse].FObj;
4999 end
5000 else
5001 begin
5002 Result := FObj;
5003 end;
5004 end;
5006 procedure TPlayer.PreUpdate();
5007 begin
5008 FSlopeOld := FObj.slopeUpLeft;
5009 FIncCamOld := FIncCam;
5010 FObj.oldX := FObj.X;
5011 FObj.oldY := FObj.Y;
5012 end;
5014 procedure TPlayer.Update();
5015 var
5016 b: Byte;
5017 i, ii, wx, wy, xd, yd, k: Integer;
5018 blockmon, headwater, dospawn: Boolean;
5019 NetServer: Boolean;
5020 AnyServer: Boolean;
5021 SetSpect: Boolean;
5022 begin
5023 NetServer := g_Game_IsNet and g_Game_IsServer;
5024 AnyServer := g_Game_IsServer;
5026 if g_Game_IsClient and (NetInterpLevel > 0) then
5027 DoLerp(NetInterpLevel + 1)
5028 else
5029 if FGhost then
5030 DoLerp(4);
5032 if NetServer then
5033 if (FClientID >= 0) and (NetClients[FClientID].Peer <> nil) then
5034 begin
5035 FPing := NetClients[FClientID].Peer^.lastRoundTripTime;
5036 if NetClients[FClientID].Peer^.packetsSent > 0 then
5037 FLoss := Round(100*NetClients[FClientID].Peer^.packetsLost/NetClients[FClientID].Peer^.packetsSent)
5038 else
5039 FLoss := 0;
5040 end else
5041 begin
5042 FPing := 0;
5043 FLoss := 0;
5044 end;
5046 if FAlive and (FPunchAnim <> nil) then
5047 FPunchAnim.Update();
5049 if FAlive and (gFly or FJetpack) then
5050 FlySmoke();
5052 if FDirection = TDirection.D_LEFT then
5053 FAngle := 180
5054 else
5055 FAngle := 0;
5057 if FAlive and (not FGhost) then
5058 begin
5059 if FKeys[KEY_UP].Pressed then
5060 SeeUp();
5061 if FKeys[KEY_DOWN].Pressed then
5062 SeeDown();
5063 end;
5065 if (not (FKeys[KEY_UP].Pressed or FKeys[KEY_DOWN].Pressed)) and
5066 (FIncCam <> 0) then
5067 begin
5068 i := g_basic.Sign(FIncCam);
5069 FIncCam := Abs(FIncCam);
5070 DecMin(FIncCam, 5, 0);
5071 FIncCam := FIncCam*i;
5072 end;
5074 if gTime mod (GAME_TICK*2) <> 0 then
5075 begin
5076 if (FObj.Vel.X = 0) and FAlive then
5077 begin
5078 if FKeys[KEY_LEFT].Pressed then
5079 Run(TDirection.D_LEFT);
5080 if FKeys[KEY_RIGHT].Pressed then
5081 Run(TDirection.D_RIGHT);
5082 end;
5084 if FPhysics then
5085 begin
5086 g_Obj_Move(@FObj, True, True, True);
5087 positionChanged(); // this updates spatial accelerators
5088 end;
5090 Exit;
5091 end;
5093 FActionChanged := False;
5095 if FAlive then
5096 begin
5097 // Let alive player do some actions
5098 if FKeys[KEY_LEFT].Pressed then Run(TDirection.D_LEFT);
5099 if FKeys[KEY_RIGHT].Pressed then Run(TDirection.D_RIGHT);
5100 if FKeys[KEY_FIRE].Pressed and AnyServer then Fire()
5101 else
5102 begin
5103 if AnyServer then
5104 begin
5105 FlamerOff;
5106 if NetServer then MH_SEND_PlayerStats(FUID);
5107 end;
5108 end;
5109 if FKeys[KEY_OPEN].Pressed and AnyServer then Use();
5110 if FKeys[KEY_JUMP].Pressed then Jump()
5111 else
5112 begin
5113 if AnyServer and FJetpack then
5114 begin
5115 FJetpack := False;
5116 JetpackOff;
5117 if NetServer then MH_SEND_PlayerStats(FUID);
5118 end;
5119 FCanJetpack := True;
5120 end;
5121 end
5122 else // Dead
5123 begin
5124 dospawn := False;
5125 if not FGhost then
5126 for k := Low(FKeys) to KEY_CHAT-1 do
5127 begin
5128 if FKeys[k].Pressed then
5129 begin
5130 dospawn := True;
5131 break;
5132 end;
5133 end;
5134 if dospawn then
5135 begin
5136 if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
5137 Respawn(False)
5138 else // Single
5139 if (FTime[T_RESPAWN] <= gTime) and
5140 gGameOn and (not FAlive) then
5141 begin
5142 if (g_Player_GetCount() > 1) then
5143 Respawn(False)
5144 else
5145 begin
5146 gExit := EXIT_RESTART;
5147 Exit;
5148 end;
5149 end;
5150 end;
5151 // Dead spectator actions
5152 if FGhost then
5153 begin
5154 if FKeys[KEY_OPEN].Pressed and AnyServer then Fire();
5155 if FKeys[KEY_FIRE].Pressed and AnyServer then
5156 begin
5157 if FSpectator then
5158 begin
5159 if (FSpectatePlayer >= High(gPlayers)) then
5160 FSpectatePlayer := -1
5161 else
5162 begin
5163 SetSpect := False;
5164 for I := FSpectatePlayer + 1 to High(gPlayers) do
5165 if gPlayers[I] <> nil then
5166 if gPlayers[I].alive then
5167 if gPlayers[I].UID <> FUID then
5168 begin
5169 FSpectatePlayer := I;
5170 SetSpect := True;
5171 break;
5172 end;
5174 if not SetSpect then FSpectatePlayer := -1;
5175 end;
5177 ReleaseKeys;
5178 end;
5179 end;
5180 end;
5181 end;
5182 // No clipping
5183 if FGhost then
5184 begin
5185 if FKeys[KEY_UP].Pressed or FKeys[KEY_JUMP].Pressed then
5186 begin
5187 FYTo := FObj.Y - 32;
5188 FSpectatePlayer := -1;
5189 end;
5190 if FKeys[KEY_DOWN].Pressed then
5191 begin
5192 FYTo := FObj.Y + 32;
5193 FSpectatePlayer := -1;
5194 end;
5195 if FKeys[KEY_LEFT].Pressed then
5196 begin
5197 FXTo := FObj.X - 32;
5198 FSpectatePlayer := -1;
5199 end;
5200 if FKeys[KEY_RIGHT].Pressed then
5201 begin
5202 FXTo := FObj.X + 32;
5203 FSpectatePlayer := -1;
5204 end;
5206 if (FXTo < -64) then
5207 FXTo := -64
5208 else if (FXTo > gMapInfo.Width + 32) then
5209 FXTo := gMapInfo.Width + 32;
5210 if (FYTo < -72) then
5211 FYTo := -72
5212 else if (FYTo > gMapInfo.Height + 32) then
5213 FYTo := gMapInfo.Height + 32;
5214 end;
5216 if FPhysics then
5217 begin
5218 g_Obj_Move(@FObj, True, True, True);
5219 positionChanged(); // this updates spatial accelerators
5220 end
5221 else
5222 begin
5223 FObj.Vel.X := 0;
5224 FObj.Vel.Y := 0;
5225 if FSpectator then
5226 if (FSpectatePlayer <= High(gPlayers)) and (FSpectatePlayer >= 0) then
5227 if gPlayers[FSpectatePlayer] <> nil then
5228 if gPlayers[FSpectatePlayer].alive then
5229 begin
5230 FXTo := gPlayers[FSpectatePlayer].GameX;
5231 FYTo := gPlayers[FSpectatePlayer].GameY;
5232 end;
5233 end;
5235 blockmon := g_Map_CollidePanel(FObj.X+PLAYER_HEADRECT.X, FObj.Y+PLAYER_HEADRECT.Y,
5236 PLAYER_HEADRECT.Width, PLAYER_HEADRECT.Height,
5237 PANEL_BLOCKMON, True);
5238 headwater := HeadInLiquid(0, 0);
5240 // Ñîïðîòèâëåíèå âîçäóõà:
5241 if (not FAlive) or not (FKeys[KEY_LEFT].Pressed or FKeys[KEY_RIGHT].Pressed) then
5242 if FObj.Vel.X <> 0 then
5243 FObj.Vel.X := z_dec(FObj.Vel.X, 1);
5245 if (FLastHit = HIT_TRAP) and (FPain > 90) then FPain := 90;
5246 DecMin(FPain, 5, 0);
5247 DecMin(FPickup, 1, 0);
5249 if FAlive and (FObj.Y > Integer(gMapInfo.Height)+128) and AnyServer then
5250 begin
5251 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
5252 FMegaRulez[MR_SUIT] := 0;
5253 FMegaRulez[MR_INVUL] := 0;
5254 FMegaRulez[MR_INVIS] := 0;
5255 Kill(K_FALLKILL, 0, HIT_FALL);
5256 end;
5258 i := 9;
5260 if FAlive then
5261 begin
5262 if FCurrWeap = WEAPON_SAW then
5263 if not (FSawSound.IsPlaying() or FSawSoundHit.IsPlaying() or
5264 FSawSoundSelect.IsPlaying()) then
5265 FSawSoundIdle.PlayAt(FObj.X, FObj.Y);
5267 if FJetpack then
5268 if (not FJetSoundFly.IsPlaying()) and (not FJetSoundOn.IsPlaying()) and
5269 (not FJetSoundOff.IsPlaying()) then
5270 begin
5271 FJetSoundFly.SetPosition(0);
5272 FJetSoundFly.PlayAt(FObj.X, FObj.Y);
5273 end;
5275 for b := WP_FIRST to WP_LAST do
5276 if FReloading[b] > 0 then
5277 if FNoReload then
5278 FReloading[b] := 0
5279 else
5280 Dec(FReloading[b]);
5282 if FShellTimer > -1 then
5283 if FShellTimer = 0 then
5284 begin
5285 if FShellType = SHELL_SHELL then
5286 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
5287 GameVelX, GameVelY-2, SHELL_SHELL)
5288 else if FShellType = SHELL_DBLSHELL then
5289 begin
5290 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
5291 GameVelX+1, GameVelY-2, SHELL_SHELL);
5292 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
5293 GameVelX-1, GameVelY-2, SHELL_SHELL);
5294 end;
5295 FShellTimer := -1;
5296 end else Dec(FShellTimer);
5298 if (FBFGFireCounter > -1) then
5299 if FBFGFireCounter = 0 then
5300 begin
5301 if AnyServer then
5302 begin
5303 wx := FObj.X+WEAPONPOINT[FDirection].X;
5304 wy := FObj.Y+WEAPONPOINT[FDirection].Y;
5305 xd := wx+IfThen(FDirection = TDirection.D_LEFT, -30, 30);
5306 yd := wy+firediry();
5307 g_Weapon_bfgshot(wx, wy, xd, yd, FUID);
5308 if NetServer then MH_SEND_PlayerFire(FUID, WEAPON_BFG, wx, wy, xd, yd);
5309 if (FAngle = 0) or (FAngle = 180) then SetAction(A_ATTACK)
5310 else if (FAngle = ANGLE_LEFTDOWN) or (FAngle = ANGLE_RIGHTDOWN) then SetAction(A_ATTACKDOWN)
5311 else if (FAngle = ANGLE_LEFTUP) or (FAngle = ANGLE_RIGHTUP) then SetAction(A_ATTACKUP);
5312 end;
5314 FReloading[WEAPON_BFG] := WEAPON_RELOAD[WEAPON_BFG];
5315 FBFGFireCounter := -1;
5316 end else
5317 if FNoReload then
5318 FBFGFireCounter := 0
5319 else
5320 Dec(FBFGFireCounter);
5322 if (FMegaRulez[MR_SUIT] < gTime) and AnyServer then
5323 begin
5324 b := g_GetAcidHit(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width, PLAYER_RECT.Height);
5326 if (b > 0) and (gTime mod (15*GAME_TICK) = 0) then Damage(b, 0, 0, 0, HIT_ACID);
5327 end;
5329 if (headwater or blockmon) then
5330 begin
5331 Dec(FAir);
5333 if FAir < -9 then
5334 begin
5335 if AnyServer then Damage(10, 0, 0, 0, HIT_WATER);
5336 FAir := 0;
5337 end
5338 else if (FAir mod 31 = 0) and not blockmon then
5339 begin
5340 g_GFX_Bubbles(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2), FObj.Y+PLAYER_RECT.Y-4, 5+Random(6), 8, 4);
5341 if Random(2) = 0 then
5342 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj.X, FObj.Y)
5343 else
5344 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj.X, FObj.Y);
5345 end;
5346 end else if FAir < AIR_DEF then
5347 FAir := AIR_DEF;
5349 if FFireTime > 0 then
5350 begin
5351 if BodyInLiquid(0, 0) then
5352 begin
5353 FFireTime := 0;
5354 FFirePainTime := 0;
5355 end
5356 else if FMegaRulez[MR_SUIT] >= gTime then
5357 begin
5358 if FMegaRulez[MR_SUIT] = gTime then
5359 FFireTime := 1;
5360 FFirePainTime := 0;
5361 end
5362 else
5363 begin
5364 OnFireFlame(1);
5365 if FFirePainTime <= 0 then
5366 begin
5367 if g_Game_IsServer then
5368 Damage(2, FFireAttacker, 0, 0, HIT_FLAME);
5369 FFirePainTime := 12 - FFireTime div 12;
5370 end;
5371 FFirePainTime := FFirePainTime - 1;
5372 FFireTime := FFireTime - 1;
5373 if ((FFireTime mod 33) = 0) and (FMegaRulez[MR_INVUL] < gTime) then
5374 FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
5375 if (FFireTime = 0) and g_Game_IsNet and g_Game_IsServer then
5376 MH_SEND_PlayerStats(FUID);
5377 end;
5378 end;
5380 if FDamageBuffer > 0 then
5381 begin
5382 if FDamageBuffer >= 9 then
5383 begin
5384 SetAction(A_PAIN);
5386 if FDamageBuffer < 30 then i := 9
5387 else if FDamageBuffer < 100 then i := 18
5388 else i := 27;
5389 end;
5391 ii := Round(FDamageBuffer*FHealth / nonz(FArmor*(3/4)+FHealth));
5392 FArmor := FArmor-(FDamageBuffer-ii);
5393 FHealth := FHealth-ii;
5394 if FArmor < 0 then
5395 begin
5396 FHealth := FHealth+FArmor;
5397 FArmor := 0;
5398 end;
5400 if AnyServer then
5401 if FHealth <= 0 then
5402 if FHealth > -30 then Kill(K_SIMPLEKILL, FLastSpawnerUID, FLastHit)
5403 else if FHealth > -50 then Kill(K_HARDKILL, FLastSpawnerUID, FLastHit)
5404 else Kill(K_EXTRAHARDKILL, FLastSpawnerUID, FLastHit);
5406 if FAlive and ((FLastHit <> HIT_FLAME) or (FFireTime <= 0)) then
5407 begin
5408 if FDamageBuffer <= 20 then FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y)
5409 else if FDamageBuffer <= 55 then FModel.PlaySound(MODELSOUND_PAIN, 2, FObj.X, FObj.Y)
5410 else if FDamageBuffer <= 120 then FModel.PlaySound(MODELSOUND_PAIN, 3, FObj.X, FObj.Y)
5411 else FModel.PlaySound(MODELSOUND_PAIN, 4, FObj.X, FObj.Y);
5412 end;
5414 FDamageBuffer := 0;
5415 end;
5417 {CollideItem();}
5418 end; // if FAlive then ...
5420 if (FActionAnim = A_PAIN) and (FModel.Animation <> A_PAIN) then
5421 begin
5422 FModel.ChangeAnimation(FActionAnim, FActionForce);
5423 FModel.GetCurrentAnimation.MinLength := i;
5424 FModel.GetCurrentAnimationMask.MinLength := i;
5425 end else FModel.ChangeAnimation(FActionAnim, FActionForce and (FModel.Animation <> A_STAND));
5427 if (FModel.GetCurrentAnimation.Played or ((not FActionChanged) and (FModel.Animation = A_WALK)))
5428 then SetAction(A_STAND, True);
5430 if not ((FModel.Animation = A_WALK) and (Abs(FObj.Vel.X) < 4) and not FModel.Fire) then FModel.Update;
5432 for b := Low(FKeys) to High(FKeys) do
5433 if FKeys[b].Time = 0 then FKeys[b].Pressed := False else Dec(FKeys[b].Time);
5434 end;
5437 procedure TPlayer.getMapBox (out x, y, w, h: Integer); inline;
5438 begin
5439 x := FObj.X+PLAYER_RECT.X;
5440 y := FObj.Y+PLAYER_RECT.Y;
5441 w := PLAYER_RECT.Width;
5442 h := PLAYER_RECT.Height;
5443 end;
5446 procedure TPlayer.moveBy (dx, dy: Integer); inline;
5447 begin
5448 if (dx <> 0) or (dy <> 0) then
5449 begin
5450 FObj.X += dx;
5451 FObj.Y += dy;
5452 positionChanged();
5453 end;
5454 end;
5457 function TPlayer.Collide(X, Y: Integer; Width, Height: Word): Boolean;
5458 begin
5459 Result := g_Collide(FObj.X+PLAYER_RECT.X,
5460 FObj.Y+PLAYER_RECT.Y,
5461 PLAYER_RECT.Width,
5462 PLAYER_RECT.Height,
5463 X, Y,
5464 Width, Height);
5465 end;
5467 function TPlayer.Collide(Panel: TPanel): Boolean;
5468 begin
5469 Result := g_Collide(FObj.X+PLAYER_RECT.X,
5470 FObj.Y+PLAYER_RECT.Y,
5471 PLAYER_RECT.Width,
5472 PLAYER_RECT.Height,
5473 Panel.X, Panel.Y,
5474 Panel.Width, Panel.Height);
5475 end;
5477 function TPlayer.Collide(X, Y: Integer): Boolean;
5478 begin
5479 X := X-FObj.X-PLAYER_RECT.X;
5480 Y := Y-FObj.Y-PLAYER_RECT.Y;
5481 Result := (x >= 0) and (x <= PLAYER_RECT.Width) and
5482 (y >= 0) and (y <= PLAYER_RECT.Height);
5483 end;
5485 function g_Player_ValidName(Name: string): Boolean;
5486 var
5487 a: Integer;
5488 begin
5489 Result := True;
5491 if gPlayers = nil then Exit;
5493 for a := 0 to High(gPlayers) do
5494 if gPlayers[a] <> nil then
5495 if LowerCase(Name) = LowerCase(gPlayers[a].FName) then
5496 begin
5497 Result := False;
5498 Exit;
5499 end;
5500 end;
5502 procedure TPlayer.SetDirection(Direction: TDirection);
5503 var
5504 d: TDirection;
5505 begin
5506 d := FModel.Direction;
5508 FModel.Direction := Direction;
5509 if d <> Direction then FModel.ChangeAnimation(FModel.Animation, True);
5511 FDirection := Direction;
5512 end;
5514 function TPlayer.GetKeys(): Byte;
5515 begin
5516 Result := 0;
5518 if R_KEY_RED in FRulez then Result := KEY_RED;
5519 if R_KEY_GREEN in FRulez then Result := Result or KEY_GREEN;
5520 if R_KEY_BLUE in FRulez then Result := Result or KEY_BLUE;
5522 if FTeam = TEAM_RED then Result := Result or KEY_REDTEAM;
5523 if FTeam = TEAM_BLUE then Result := Result or KEY_BLUETEAM;
5524 end;
5526 procedure TPlayer.Use();
5527 var
5528 a: Integer;
5529 begin
5530 if FTime[T_USE] > gTime then Exit;
5532 g_Triggers_PressR(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
5533 PLAYER_RECT.Height, FUID, ACTIVATE_PLAYERPRESS);
5535 for a := 0 to High(gPlayers) do
5536 if (gPlayers[a] <> nil) and (gPlayers[a] <> Self) and
5537 gPlayers[a].alive and SameTeam(FUID, gPlayers[a].FUID) and
5538 g_Obj_Collide(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y,
5539 FObj.Rect.Width, FObj.Rect.Height, @gPlayers[a].FObj) then
5540 begin
5541 gPlayers[a].Touch();
5542 if g_Game_IsNet and g_Game_IsServer then
5543 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH, gPlayers[a].FUID);
5544 end;
5546 FTime[T_USE] := gTime+120;
5547 end;
5549 procedure TPlayer.NetFire(Wpn: Byte; X, Y, AX, AY: Integer; WID: Integer = -1);
5550 var
5551 locObj: TObj;
5552 F: Boolean;
5553 WX, WY, XD, YD: Integer;
5554 begin
5555 F := False;
5556 WX := X;
5557 WY := Y;
5558 XD := AX;
5559 YD := AY;
5561 case FCurrWeap of
5562 WEAPON_KASTET:
5563 begin
5564 DoPunch();
5565 if R_BERSERK in FRulez then
5566 begin
5567 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5568 locobj.X := FObj.X+FObj.Rect.X;
5569 locobj.Y := FObj.Y+FObj.Rect.Y;
5570 locobj.rect.X := 0;
5571 locobj.rect.Y := 0;
5572 locobj.rect.Width := 39;
5573 locobj.rect.Height := 52;
5574 locobj.Vel.X := (xd-wx) div 2;
5575 locobj.Vel.Y := (yd-wy) div 2;
5576 locobj.Accel.X := xd-wx;
5577 locobj.Accel.y := yd-wy;
5579 if g_Weapon_Hit(@locobj, 50, FUID, HIT_SOME) <> 0 then
5580 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj.X, FObj.Y)
5581 else
5582 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj.X, FObj.Y);
5584 if gFlash = 1 then
5585 if FPain < 50 then
5586 FPain := min(FPain + 25, 50);
5587 end else
5588 g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 3, FUID);
5589 end;
5591 WEAPON_SAW:
5592 begin
5593 if g_Weapon_chainsaw(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y,
5594 IfThen(gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF], 9, 3), FUID) <> 0 then
5595 begin
5596 FSawSoundSelect.Stop();
5597 FSawSound.Stop();
5598 FSawSoundHit.PlayAt(FObj.X, FObj.Y);
5599 end
5600 else if not FSawSoundHit.IsPlaying() then
5601 begin
5602 FSawSoundSelect.Stop();
5603 FSawSound.PlayAt(FObj.X, FObj.Y);
5604 end;
5605 f := True;
5606 end;
5608 WEAPON_PISTOL:
5609 begin
5610 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX, Gamey);
5611 FFireAngle := FAngle;
5612 f := True;
5613 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
5614 GameVelX, GameVelY-2, SHELL_BULLET);
5615 end;
5617 WEAPON_SHOTGUN1:
5618 begin
5619 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex, Gamey);
5620 FFireAngle := FAngle;
5621 f := True;
5622 FShellTimer := 10;
5623 FShellType := SHELL_SHELL;
5624 end;
5626 WEAPON_SHOTGUN2:
5627 begin
5628 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex, Gamey);
5629 FFireAngle := FAngle;
5630 f := True;
5631 FShellTimer := 13;
5632 FShellType := SHELL_DBLSHELL;
5633 end;
5635 WEAPON_CHAINGUN:
5636 begin
5637 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex, Gamey);
5638 FFireAngle := FAngle;
5639 f := True;
5640 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
5641 GameVelX, GameVelY-2, SHELL_BULLET);
5642 end;
5644 WEAPON_ROCKETLAUNCHER:
5645 begin
5646 g_Weapon_Rocket(wx, wy, xd, yd, FUID, WID);
5647 FFireAngle := FAngle;
5648 f := True;
5649 end;
5651 WEAPON_PLASMA:
5652 begin
5653 g_Weapon_Plasma(wx, wy, xd, yd, FUID, WID);
5654 FFireAngle := FAngle;
5655 f := True;
5656 end;
5658 WEAPON_BFG:
5659 begin
5660 g_Weapon_BFGShot(wx, wy, xd, yd, FUID, WID);
5661 FFireAngle := FAngle;
5662 f := True;
5663 end;
5665 WEAPON_SUPERPULEMET:
5666 begin
5667 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex, Gamey);
5668 FFireAngle := FAngle;
5669 f := True;
5670 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
5671 GameVelX, GameVelY-2, SHELL_SHELL);
5672 end;
5674 WEAPON_FLAMETHROWER:
5675 begin
5676 g_Weapon_flame(wx, wy, xd, yd, FUID, WID);
5677 FlamerOn;
5678 FFireAngle := FAngle;
5679 f := True;
5680 end;
5681 end;
5683 if not f then Exit;
5685 if (FAngle = 0) or (FAngle = 180) then SetAction(A_ATTACK)
5686 else if (FAngle = ANGLE_LEFTDOWN) or (FAngle = ANGLE_RIGHTDOWN) then SetAction(A_ATTACKDOWN)
5687 else if (FAngle = ANGLE_LEFTUP) or (FAngle = ANGLE_RIGHTUP) then SetAction(A_ATTACKUP);
5688 end;
5690 procedure TPlayer.DoLerp(Level: Integer = 2);
5691 begin
5692 if FObj.X <> FXTo then FObj.X := Lerp(FObj.X, FXTo, Level);
5693 if FObj.Y <> FYTo then FObj.Y := Lerp(FObj.Y, FYTo, Level);
5694 end;
5696 procedure TPlayer.SetLerp(XTo, YTo: Integer);
5697 var
5698 AX, AY: Integer;
5699 begin
5700 FXTo := XTo;
5701 FYTo := YTo;
5702 if FJustTeleported or (NetInterpLevel < 1) then
5703 begin
5704 FObj.X := XTo;
5705 FObj.Y := YTo;
5706 if FJustTeleported then
5707 begin
5708 FObj.oldX := FObj.X;
5709 FObj.oldY := FObj.Y;
5710 end;
5711 end
5712 else
5713 begin
5714 AX := Abs(FXTo - FObj.X);
5715 AY := Abs(FYTo - FObj.Y);
5716 if (AX > 32) or (AX <= NetInterpLevel) then
5717 FObj.X := FXTo;
5718 if (AY > 32) or (AY <= NetInterpLevel) then
5719 FObj.Y := FYTo;
5720 end;
5721 end;
5723 function TPlayer.FullInLift(XInc, YInc: Integer): Integer;
5724 begin
5725 if g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc,
5726 PLAYER_RECT.Width, PLAYER_RECT.Height-8,
5727 PANEL_LIFTUP, False) then Result := -1
5728 else
5729 if g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc,
5730 PLAYER_RECT.Width, PLAYER_RECT.Height-8,
5731 PANEL_LIFTDOWN, False) then Result := 1
5732 else Result := 0;
5733 end;
5735 function TPlayer.GetFlag(Flag: Byte): Boolean;
5736 var
5737 s, ts: String;
5738 evtype, a: Byte;
5739 begin
5740 Result := False;
5742 if Flag = FLAG_NONE then
5743 Exit;
5745 if not g_Game_IsServer then Exit;
5747 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5748 if (Flag = FTeam) and
5749 (gFlags[Flag].State = FLAG_STATE_NORMAL) and
5750 (FFlag <> FLAG_NONE) then
5751 begin
5752 if FFlag = FLAG_RED then
5753 s := _lc[I_PLAYER_FLAG_RED]
5754 else
5755 s := _lc[I_PLAYER_FLAG_BLUE];
5757 evtype := FLAG_STATE_SCORED;
5759 ts := Format('%.4d', [gFlags[FFlag].CaptureTime]);
5760 Insert('.', ts, Length(ts) + 1 - 3);
5761 g_Console_Add(Format(_lc[I_PLAYER_FLAG_CAPTURE], [FName, s, ts]), True);
5763 g_Map_ResetFlag(FFlag);
5764 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_CAPTURE], [AnsiUpperCase(s)]), 144);
5766 if ((Self = gPlayer1) or (Self = gPlayer2)
5767 or ((gPlayer1 <> nil) and (gPlayer1.Team = FTeam))
5768 or ((gPlayer2 <> nil) and (gPlayer2.Team = FTeam))) then
5769 a := 0
5770 else
5771 a := 1;
5773 if not sound_cap_flag[a].IsPlaying() then
5774 sound_cap_flag[a].Play();
5776 gTeamStat[FTeam].Goals := gTeamStat[FTeam].Goals + 1;
5778 Result := True;
5779 if g_Game_IsNet then
5780 begin
5781 MH_SEND_FlagEvent(evtype, FFlag, FUID, False);
5782 MH_SEND_GameStats;
5783 end;
5785 gFlags[FFlag].CaptureTime := 0;
5786 SetFlag(FLAG_NONE);
5787 Exit;
5788 end;
5790 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5791 if (Flag = FTeam) and
5792 (gFlags[Flag].State = FLAG_STATE_DROPPED) then
5793 begin
5794 if Flag = FLAG_RED then
5795 s := _lc[I_PLAYER_FLAG_RED]
5796 else
5797 s := _lc[I_PLAYER_FLAG_BLUE];
5799 evtype := FLAG_STATE_RETURNED;
5800 gFlags[Flag].CaptureTime := 0;
5802 g_Console_Add(Format(_lc[I_PLAYER_FLAG_RETURN], [FName, s]), True);
5804 g_Map_ResetFlag(Flag);
5805 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_RETURN], [AnsiUpperCase(s)]), 144);
5807 if ((Self = gPlayer1) or (Self = gPlayer2)
5808 or ((gPlayer1 <> nil) and (gPlayer1.Team = FTeam))
5809 or ((gPlayer2 <> nil) and (gPlayer2.Team = FTeam))) then
5810 a := 0
5811 else
5812 a := 1;
5814 if not sound_ret_flag[a].IsPlaying() then
5815 sound_ret_flag[a].Play();
5817 Result := True;
5818 if g_Game_IsNet then
5819 begin
5820 MH_SEND_FlagEvent(evtype, Flag, FUID, False);
5821 MH_SEND_GameStats;
5822 end;
5823 Exit;
5824 end;
5826 // Ïîäîáðàë ÷óæîé ôëàã:
5827 if (Flag <> FTeam) and (FTime[T_FLAGCAP] <= gTime) then
5828 begin
5829 SetFlag(Flag);
5831 if Flag = FLAG_RED then
5832 s := _lc[I_PLAYER_FLAG_RED]
5833 else
5834 s := _lc[I_PLAYER_FLAG_BLUE];
5836 evtype := FLAG_STATE_CAPTURED;
5838 g_Console_Add(Format(_lc[I_PLAYER_FLAG_GET], [FName, s]), True);
5840 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_GET], [AnsiUpperCase(s)]), 144);
5842 gFlags[Flag].State := FLAG_STATE_CAPTURED;
5844 if ((Self = gPlayer1) or (Self = gPlayer2)
5845 or ((gPlayer1 <> nil) and (gPlayer1.Team = FTeam))
5846 or ((gPlayer2 <> nil) and (gPlayer2.Team = FTeam))) then
5847 a := 0
5848 else
5849 a := 1;
5851 if not sound_get_flag[a].IsPlaying() then
5852 sound_get_flag[a].Play();
5854 Result := True;
5855 if g_Game_IsNet then
5856 begin
5857 MH_SEND_FlagEvent(evtype, Flag, FUID, False);
5858 MH_SEND_GameStats;
5859 end;
5860 end;
5861 end;
5863 procedure TPlayer.SetFlag(Flag: Byte);
5864 begin
5865 FFlag := Flag;
5866 if FModel <> nil then
5867 FModel.SetFlag(FFlag);
5868 end;
5870 function TPlayer.TryDropFlag(): Boolean;
5871 begin
5872 if LongBool(gGameSettings.Options and GAME_OPTION_ALLOWDROPFLAG) then
5873 Result := DropFlag(False, LongBool(gGameSettings.Options and GAME_OPTION_THROWFLAG))
5874 else
5875 Result := False;
5876 end;
5878 function TPlayer.DropFlag(Silent: Boolean = True; DoThrow: Boolean = False): Boolean;
5879 var
5880 s: String;
5881 a: Byte;
5882 xv, yv: Integer;
5883 begin
5884 Result := False;
5885 if (not g_Game_IsServer) or (FFlag = FLAG_NONE) then
5886 Exit;
5887 FTime[T_FLAGCAP] := gTime + 2000;
5888 with gFlags[FFlag] do
5889 begin
5890 Obj.X := FObj.X;
5891 Obj.Y := FObj.Y;
5892 Direction := FDirection;
5893 State := FLAG_STATE_DROPPED;
5894 Count := FLAG_TIME;
5895 if DoThrow then
5896 begin
5897 xv := FObj.Vel.X + IfThen(Direction = TDirection.D_RIGHT, 10, -10);
5898 yv := FObj.Vel.Y - 2;
5899 end
5900 else
5901 begin
5902 xv := (FObj.Vel.X div 2);
5903 yv := (FObj.Vel.Y div 2) - 2;
5904 end;
5905 g_Obj_Push(@Obj, xv, yv);
5907 positionChanged(); // this updates spatial accelerators
5909 if FFlag = FLAG_RED then
5910 s := _lc[I_PLAYER_FLAG_RED]
5911 else
5912 s := _lc[I_PLAYER_FLAG_BLUE];
5914 g_Console_Add(Format(_lc[I_PLAYER_FLAG_DROP], [FName, s]), True);
5915 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_DROP], [AnsiUpperCase(s)]), 144);
5917 if ((Self = gPlayer1) or (Self = gPlayer2)
5918 or ((gPlayer1 <> nil) and (gPlayer1.Team = FTeam))
5919 or ((gPlayer2 <> nil) and (gPlayer2.Team = FTeam))) then
5920 a := 0
5921 else
5922 a := 1;
5924 if (not Silent) and (not sound_lost_flag[a].IsPlaying()) then
5925 sound_lost_flag[a].Play();
5927 if g_Game_IsNet then
5928 MH_SEND_FlagEvent(FLAG_STATE_DROPPED, Flag, FUID, False);
5929 end;
5930 SetFlag(FLAG_NONE);
5931 Result := True;
5932 end;
5934 procedure TPlayer.GetSecret();
5935 begin
5936 if (self = gPlayer1) or (self = gPlayer2) then
5937 begin
5938 g_Console_Add(Format(_lc[I_PLAYER_SECRET], [FName]), True);
5939 g_Sound_PlayEx('SOUND_GAME_SECRET');
5940 end;
5941 Inc(FSecrets);
5942 end;
5944 procedure TPlayer.PressKey(Key: Byte; Time: Word = 1);
5945 begin
5946 Assert(Key <= High(FKeys));
5948 FKeys[Key].Pressed := True;
5949 FKeys[Key].Time := Time;
5950 end;
5952 function TPlayer.IsKeyPressed(K: Byte): Boolean;
5953 begin
5954 Result := FKeys[K].Pressed;
5955 end;
5957 procedure TPlayer.ReleaseKeys();
5958 var
5959 a: Integer;
5960 begin
5961 for a := Low(FKeys) to High(FKeys) do
5962 begin
5963 FKeys[a].Pressed := False;
5964 FKeys[a].Time := 0;
5965 end;
5966 end;
5968 procedure TPlayer.OnDamage(Angle: SmallInt);
5969 begin
5970 end;
5972 function TPlayer.firediry(): Integer;
5973 begin
5974 if FKeys[KEY_UP].Pressed then Result := -42
5975 else if FKeys[KEY_DOWN].Pressed then Result := 19
5976 else Result := 0;
5977 end;
5979 procedure TPlayer.RememberState();
5980 var
5981 i: Integer;
5982 SavedState: TPlayerSavedState;
5983 begin
5984 SavedState.Health := FHealth;
5985 SavedState.Armor := FArmor;
5986 SavedState.Air := FAir;
5987 SavedState.JetFuel := FJetFuel;
5988 SavedState.CurrWeap := FCurrWeap;
5989 SavedState.NextWeap := FNextWeap;
5990 SavedState.NextWeapDelay := FNextWeapDelay;
5991 for i := Low(FWeapon) to High(FWeapon) do
5992 SavedState.Weapon[i] := FWeapon[i];
5993 for i := Low(FAmmo) to High(FAmmo) do
5994 SavedState.Ammo[i] := FAmmo[i];
5995 for i := Low(FMaxAmmo) to High(FMaxAmmo) do
5996 SavedState.MaxAmmo[i] := FMaxAmmo[i];
5997 SavedState.Rulez := FRulez - [R_KEY_RED, R_KEY_GREEN, R_KEY_BLUE];
5999 FSavedStateNum := -1;
6000 for i := Low(SavedStates) to High(SavedStates) do
6001 if not SavedStates[i].Used then
6002 begin
6003 FSavedStateNum := i;
6004 break;
6005 end;
6006 if FSavedStateNum < 0 then
6007 begin
6008 SetLength(SavedStates, Length(SavedStates) + 1);
6009 FSavedStateNum := High(SavedStates);
6010 end;
6012 SavedState.Used := True;
6013 SavedStates[FSavedStateNum] := SavedState;
6014 end;
6016 procedure TPlayer.RecallState();
6017 var
6018 i: Integer;
6019 SavedState: TPlayerSavedState;
6020 begin
6021 if(FSavedStateNum < 0) or (FSavedStateNum > High(SavedStates)) then
6022 Exit;
6024 SavedState := SavedStates[FSavedStateNum];
6025 SavedStates[FSavedStateNum].Used := False;
6026 FSavedStateNum := -1;
6028 FHealth := SavedState.Health;
6029 FArmor := SavedState.Armor;
6030 FAir := SavedState.Air;
6031 FJetFuel := SavedState.JetFuel;
6032 FCurrWeap := SavedState.CurrWeap;
6033 FNextWeap := SavedState.NextWeap;
6034 FNextWeapDelay := SavedState.NextWeapDelay;
6035 for i := Low(FWeapon) to High(FWeapon) do
6036 FWeapon[i] := SavedState.Weapon[i];
6037 for i := Low(FAmmo) to High(FAmmo) do
6038 FAmmo[i] := SavedState.Ammo[i];
6039 for i := Low(FMaxAmmo) to High(FMaxAmmo) do
6040 FMaxAmmo[i] := SavedState.MaxAmmo[i];
6041 FRulez := SavedState.Rulez;
6043 if gGameSettings.GameType = GT_SERVER then
6044 MH_SEND_PlayerStats(FUID);
6045 end;
6047 procedure TPlayer.SaveState (st: TStream);
6048 var
6049 i: Integer;
6050 b: Byte;
6051 begin
6052 // Ñèãíàòóðà èãðîêà
6053 utils.writeSign(st, 'PLYR');
6054 utils.writeInt(st, Byte(PLR_SAVE_VERSION)); // version
6055 // Áîò èëè ÷åëîâåê
6056 utils.writeBool(st, FIamBot);
6057 // UID èãðîêà
6058 utils.writeInt(st, Word(FUID));
6059 // Èìÿ èãðîêà
6060 utils.writeStr(st, FName);
6061 // Êîìàíäà
6062 utils.writeInt(st, Byte(FTeam));
6063 // Æèâ ëè
6064 utils.writeBool(st, FAlive);
6065 // Èçðàñõîäîâàë ëè âñå æèçíè
6066 utils.writeBool(st, FNoRespawn);
6067 // Íàïðàâëåíèå
6068 if FDirection = TDirection.D_LEFT then b := 1 else b := 2; // D_RIGHT
6069 utils.writeInt(st, Byte(b));
6070 // Çäîðîâüå
6071 utils.writeInt(st, LongInt(FHealth));
6072 // Êîýôôèöèåíò èíâàëèäíîñòè
6073 utils.writeInt(st, LongInt(FHandicap));
6074 // Æèçíè
6075 utils.writeInt(st, Byte(FLives));
6076 // Áðîíÿ
6077 utils.writeInt(st, LongInt(FArmor));
6078 // Çàïàñ âîçäóõà
6079 utils.writeInt(st, LongInt(FAir));
6080 // Çàïàñ ãîðþ÷åãî
6081 utils.writeInt(st, LongInt(FJetFuel));
6082 // Áîëü
6083 utils.writeInt(st, LongInt(FPain));
6084 // Óáèë
6085 utils.writeInt(st, LongInt(FKills));
6086 // Óáèë ìîíñòðîâ
6087 utils.writeInt(st, LongInt(FMonsterKills));
6088 // Ôðàãîâ
6089 utils.writeInt(st, LongInt(FFrags));
6090 // Ôðàãîâ ïîäðÿä
6091 utils.writeInt(st, Byte(FFragCombo));
6092 // Âðåìÿ ïîñëåäíåãî ôðàãà
6093 utils.writeInt(st, LongWord(FLastFrag));
6094 // Ñìåðòåé
6095 utils.writeInt(st, LongInt(FDeath));
6096 // Êàêîé ôëàã íåñåò
6097 utils.writeInt(st, Byte(FFlag));
6098 // Íàøåë ñåêðåòîâ
6099 utils.writeInt(st, LongInt(FSecrets));
6100 // Òåêóùåå îðóæèå
6101 utils.writeInt(st, Byte(FCurrWeap));
6102 // Æåëàåìîå îðóæèå
6103 utils.writeInt(st, Word(FNextWeap));
6104 // ...è ïàóçà
6105 utils.writeInt(st, Byte(FNextWeapDelay));
6106 // Âðåìÿ çàðÿäêè BFG
6107 utils.writeInt(st, SmallInt(FBFGFireCounter));
6108 // Áóôåð óðîíà
6109 utils.writeInt(st, LongInt(FDamageBuffer));
6110 // Ïîñëåäíèé óäàðèâøèé
6111 utils.writeInt(st, Word(FLastSpawnerUID));
6112 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6113 utils.writeInt(st, Byte(FLastHit));
6114 // Îáúåêò èãðîêà
6115 Obj_SaveState(st, @FObj);
6116 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6117 for i := A_BULLETS to A_HIGH do utils.writeInt(st, Word(FAmmo[i]));
6118 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6119 for i := A_BULLETS to A_HIGH do utils.writeInt(st, Word(FMaxAmmo[i]));
6120 // Íàëè÷èå îðóæèÿ
6121 for i := WP_FIRST to WP_LAST do utils.writeBool(st, FWeapon[i]);
6122 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6123 for i := WP_FIRST to WP_LAST do utils.writeInt(st, Word(FReloading[i]));
6124 // Íàëè÷èå ðþêçàêà
6125 utils.writeBool(st, (R_ITEM_BACKPACK in FRulez));
6126 // Íàëè÷èå êðàñíîãî êëþ÷à
6127 utils.writeBool(st, (R_KEY_RED in FRulez));
6128 // Íàëè÷èå çåëåíîãî êëþ÷à
6129 utils.writeBool(st, (R_KEY_GREEN in FRulez));
6130 // Íàëè÷èå ñèíåãî êëþ÷à
6131 utils.writeBool(st, (R_KEY_BLUE in FRulez));
6132 // Íàëè÷èå áåðñåðêà
6133 utils.writeBool(st, (R_BERSERK in FRulez));
6134 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6135 for i := MR_SUIT to MR_MAX do utils.writeInt(st, LongWord(FMegaRulez[i]));
6136 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6137 for i := T_RESPAWN to T_FLAGCAP do utils.writeInt(st, LongWord(FTime[i]));
6138 // Íàçâàíèå ìîäåëè
6139 utils.writeStr(st, FModel.Name);
6140 // Öâåò ìîäåëè
6141 utils.writeInt(st, Byte(FColor.R));
6142 utils.writeInt(st, Byte(FColor.G));
6143 utils.writeInt(st, Byte(FColor.B));
6144 end;
6147 procedure TPlayer.LoadState (st: TStream);
6148 var
6149 i: Integer;
6150 str: String;
6151 b: Byte;
6152 begin
6153 assert(st <> nil);
6155 // Ñèãíàòóðà èãðîêà
6156 if not utils.checkSign(st, 'PLYR') then raise XStreamError.Create('invalid player signature');
6157 if (utils.readByte(st) <> PLR_SAVE_VERSION) then raise XStreamError.Create('invalid player version');
6158 // Áîò èëè ÷åëîâåê:
6159 FIamBot := utils.readBool(st);
6160 // UID èãðîêà
6161 FUID := utils.readWord(st);
6162 // Èìÿ èãðîêà
6163 str := utils.readStr(st);
6164 if (self <> gPlayer1) and (self <> gPlayer2) then FName := str;
6165 // Êîìàíäà
6166 FTeam := utils.readByte(st);
6167 // Æèâ ëè
6168 FAlive := utils.readBool(st);
6169 // Èçðàñõîäîâàë ëè âñå æèçíè
6170 FNoRespawn := utils.readBool(st);
6171 // Íàïðàâëåíèå
6172 b := utils.readByte(st);
6173 if b = 1 then FDirection := TDirection.D_LEFT else FDirection := TDirection.D_RIGHT; // b = 2
6174 // Çäîðîâüå
6175 FHealth := utils.readLongInt(st);
6176 // Êîýôôèöèåíò èíâàëèäíîñòè
6177 FHandicap := utils.readLongInt(st);
6178 // Æèçíè
6179 FLives := utils.readByte(st);
6180 // Áðîíÿ
6181 FArmor := utils.readLongInt(st);
6182 // Çàïàñ âîçäóõà
6183 FAir := utils.readLongInt(st);
6184 // Çàïàñ ãîðþ÷åãî
6185 FJetFuel := utils.readLongInt(st);
6186 // Áîëü
6187 FPain := utils.readLongInt(st);
6188 // Óáèë
6189 FKills := utils.readLongInt(st);
6190 // Óáèë ìîíñòðîâ
6191 FMonsterKills := utils.readLongInt(st);
6192 // Ôðàãîâ
6193 FFrags := utils.readLongInt(st);
6194 // Ôðàãîâ ïîäðÿä
6195 FFragCombo := utils.readByte(st);
6196 // Âðåìÿ ïîñëåäíåãî ôðàãà
6197 FLastFrag := utils.readLongWord(st);
6198 // Ñìåðòåé
6199 FDeath := utils.readLongInt(st);
6200 // Êàêîé ôëàã íåñåò
6201 FFlag := utils.readByte(st);
6202 // Íàøåë ñåêðåòîâ
6203 FSecrets := utils.readLongInt(st);
6204 // Òåêóùåå îðóæèå
6205 FCurrWeap := utils.readByte(st);
6206 // Æåëàåìîå îðóæèå
6207 FNextWeap := utils.readWord(st);
6208 // ...è ïàóçà
6209 FNextWeapDelay := utils.readByte(st);
6210 // Âðåìÿ çàðÿäêè BFG
6211 FBFGFireCounter := utils.readSmallInt(st);
6212 // Áóôåð óðîíà
6213 FDamageBuffer := utils.readLongInt(st);
6214 // Ïîñëåäíèé óäàðèâøèé
6215 FLastSpawnerUID := utils.readWord(st);
6216 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6217 FLastHit := utils.readByte(st);
6218 // Îáúåêò èãðîêà
6219 Obj_LoadState(@FObj, st);
6220 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6221 for i := A_BULLETS to A_HIGH do FAmmo[i] := utils.readWord(st);
6222 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6223 for i := A_BULLETS to A_HIGH do FMaxAmmo[i] := utils.readWord(st);
6224 // Íàëè÷èå îðóæèÿ
6225 for i := WP_FIRST to WP_LAST do FWeapon[i] := utils.readBool(st);
6226 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6227 for i := WP_FIRST to WP_LAST do FReloading[i] := utils.readWord(st);
6228 // Íàëè÷èå ðþêçàêà
6229 if utils.readBool(st) then Include(FRulez, R_ITEM_BACKPACK);
6230 // Íàëè÷èå êðàñíîãî êëþ÷à
6231 if utils.readBool(st) then Include(FRulez, R_KEY_RED);
6232 // Íàëè÷èå çåëåíîãî êëþ÷à
6233 if utils.readBool(st) then Include(FRulez, R_KEY_GREEN);
6234 // Íàëè÷èå ñèíåãî êëþ÷à
6235 if utils.readBool(st) then Include(FRulez, R_KEY_BLUE);
6236 // Íàëè÷èå áåðñåðêà
6237 if utils.readBool(st) then Include(FRulez, R_BERSERK);
6238 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6239 for i := MR_SUIT to MR_MAX do FMegaRulez[i] := utils.readLongWord(st);
6240 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6241 for i := T_RESPAWN to T_FLAGCAP do FTime[i] := utils.readLongWord(st);
6242 // Íàçâàíèå ìîäåëè
6243 str := utils.readStr(st);
6244 // Öâåò ìîäåëè
6245 FColor.R := utils.readByte(st);
6246 FColor.G := utils.readByte(st);
6247 FColor.B := utils.readByte(st);
6248 if (self = gPlayer1) then
6249 begin
6250 str := gPlayer1Settings.Model;
6251 FColor := gPlayer1Settings.Color;
6252 end
6253 else if (self = gPlayer2) then
6254 begin
6255 str := gPlayer2Settings.Model;
6256 FColor := gPlayer2Settings.Color;
6257 end;
6258 // Îáíîâëÿåì ìîäåëü èãðîêà
6259 SetModel(str);
6260 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
6261 FModel.Color := TEAMCOLOR[FTeam]
6262 else
6263 FModel.Color := FColor;
6264 end;
6267 procedure TPlayer.AllRulez(Health: Boolean);
6268 var
6269 a: Integer;
6270 begin
6271 if Health then
6272 begin
6273 FHealth := PLAYER_HP_LIMIT;
6274 FArmor := PLAYER_AP_LIMIT;
6275 Exit;
6276 end;
6278 for a := WP_FIRST to WP_LAST do FWeapon[a] := True;
6279 for a := A_BULLETS to A_HIGH do FAmmo[a] := 30000;
6280 FRulez := FRulez+[R_KEY_RED, R_KEY_GREEN, R_KEY_BLUE];
6281 end;
6283 procedure TPlayer.RestoreHealthArmor();
6284 begin
6285 FHealth := PLAYER_HP_LIMIT;
6286 FArmor := PLAYER_AP_LIMIT;
6287 end;
6289 procedure TPlayer.FragCombo();
6290 var
6291 Param: Integer;
6292 begin
6293 if (gGameSettings.GameMode in [GM_COOP, GM_SINGLE]) or g_Game_IsClient then
6294 Exit;
6295 if gTime - FLastFrag < FRAG_COMBO_TIME then
6296 begin
6297 if FFragCombo < 5 then
6298 Inc(FFragCombo);
6299 Param := FUID or (FFragCombo shl 16);
6300 if (FComboEvnt >= Low(gDelayedEvents)) and
6301 (FComboEvnt <= High(gDelayedEvents)) and
6302 gDelayedEvents[FComboEvnt].Pending and
6303 (gDelayedEvents[FComboEvnt].DEType = DE_KILLCOMBO) and
6304 (gDelayedEvents[FComboEvnt].DENum and $FFFF = FUID) then
6305 begin
6306 gDelayedEvents[FComboEvnt].Time := gTime + 500;
6307 gDelayedEvents[FComboEvnt].DENum := Param;
6308 end
6309 else
6310 FComboEvnt := g_Game_DelayEvent(DE_KILLCOMBO, 500, Param);
6311 end
6312 else
6313 FFragCombo := 1;
6315 FLastFrag := gTime;
6316 end;
6318 procedure TPlayer.GiveItem(ItemType: Byte);
6319 begin
6320 case ItemType of
6321 ITEM_SUIT:
6322 if FMegaRulez[MR_SUIT] < gTime+PLAYER_SUIT_TIME then
6323 begin
6324 FMegaRulez[MR_SUIT] := gTime+PLAYER_SUIT_TIME;
6325 end;
6327 ITEM_OXYGEN:
6328 if FAir < AIR_MAX then
6329 begin
6330 FAir := AIR_MAX;
6331 end;
6333 ITEM_MEDKIT_BLACK:
6334 begin
6335 if not (R_BERSERK in FRulez) then
6336 begin
6337 Include(FRulez, R_BERSERK);
6338 if FBFGFireCounter < 1 then
6339 begin
6340 FCurrWeap := WEAPON_KASTET;
6341 resetWeaponQueue();
6342 FModel.SetWeapon(WEAPON_KASTET);
6343 end;
6344 if gFlash <> 0 then
6345 Inc(FPain, 100);
6346 FBerserk := gTime+30000;
6347 end;
6348 if FHealth < PLAYER_HP_SOFT then
6349 begin
6350 FHealth := PLAYER_HP_SOFT;
6351 FBerserk := gTime+30000;
6352 end;
6353 end;
6355 ITEM_INVUL:
6356 if FMegaRulez[MR_INVUL] < gTime+PLAYER_INVUL_TIME then
6357 begin
6358 FMegaRulez[MR_INVUL] := gTime+PLAYER_INVUL_TIME;
6359 FSpawnInvul := 0;
6360 end;
6362 ITEM_INVIS:
6363 if FMegaRulez[MR_INVIS] < gTime+PLAYER_INVIS_TIME then
6364 begin
6365 FMegaRulez[MR_INVIS] := gTime+PLAYER_INVIS_TIME;
6366 end;
6368 ITEM_JETPACK:
6369 if FJetFuel < JET_MAX then
6370 begin
6371 FJetFuel := JET_MAX;
6372 end;
6374 ITEM_MEDKIT_SMALL: if FHealth < PLAYER_HP_SOFT then IncMax(FHealth, 10, PLAYER_HP_SOFT);
6375 ITEM_MEDKIT_LARGE: if FHealth < PLAYER_HP_SOFT then IncMax(FHealth, 25, PLAYER_HP_SOFT);
6377 ITEM_ARMOR_GREEN: if FArmor < PLAYER_AP_SOFT then FArmor := PLAYER_AP_SOFT;
6378 ITEM_ARMOR_BLUE: if FArmor < PLAYER_AP_LIMIT then FArmor := PLAYER_AP_LIMIT;
6380 ITEM_SPHERE_BLUE: if FHealth < PLAYER_HP_LIMIT then IncMax(FHealth, 100, PLAYER_HP_LIMIT);
6381 ITEM_SPHERE_WHITE:
6382 if (FHealth < PLAYER_HP_LIMIT) or (FArmor < PLAYER_AP_LIMIT) then
6383 begin
6384 if FHealth < PLAYER_HP_LIMIT then FHealth := PLAYER_HP_LIMIT;
6385 if FArmor < PLAYER_AP_LIMIT then FArmor := PLAYER_AP_LIMIT;
6386 end;
6388 ITEM_WEAPON_SAW: FWeapon[WEAPON_SAW] := True;
6389 ITEM_WEAPON_SHOTGUN1: FWeapon[WEAPON_SHOTGUN1] := True;
6390 ITEM_WEAPON_SHOTGUN2: FWeapon[WEAPON_SHOTGUN2] := True;
6391 ITEM_WEAPON_CHAINGUN: FWeapon[WEAPON_CHAINGUN] := True;
6392 ITEM_WEAPON_ROCKETLAUNCHER: FWeapon[WEAPON_ROCKETLAUNCHER] := True;
6393 ITEM_WEAPON_PLASMA: FWeapon[WEAPON_PLASMA] := True;
6394 ITEM_WEAPON_BFG: FWeapon[WEAPON_BFG] := True;
6395 ITEM_WEAPON_SUPERPULEMET: FWeapon[WEAPON_SUPERPULEMET] := True;
6396 ITEM_WEAPON_FLAMETHROWER: FWeapon[WEAPON_FLAMETHROWER] := True;
6398 ITEM_AMMO_BULLETS: if FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS] then IncMax(FAmmo[A_BULLETS], 10, FMaxAmmo[A_BULLETS]);
6399 ITEM_AMMO_BULLETS_BOX: if FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS] then IncMax(FAmmo[A_BULLETS], 50, FMaxAmmo[A_BULLETS]);
6400 ITEM_AMMO_SHELLS: if FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS] then IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
6401 ITEM_AMMO_SHELLS_BOX: if FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS] then IncMax(FAmmo[A_SHELLS], 25, FMaxAmmo[A_SHELLS]);
6402 ITEM_AMMO_ROCKET: if FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS] then IncMax(FAmmo[A_ROCKETS], 1, FMaxAmmo[A_ROCKETS]);
6403 ITEM_AMMO_ROCKET_BOX: if FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS] then IncMax(FAmmo[A_ROCKETS], 5, FMaxAmmo[A_ROCKETS]);
6404 ITEM_AMMO_CELL: if FAmmo[A_CELLS] < FMaxAmmo[A_CELLS] then IncMax(FAmmo[A_CELLS], 40, FMaxAmmo[A_CELLS]);
6405 ITEM_AMMO_CELL_BIG: if FAmmo[A_CELLS] < FMaxAmmo[A_CELLS] then IncMax(FAmmo[A_CELLS], 100, FMaxAmmo[A_CELLS]);
6406 ITEM_AMMO_FUELCAN: if FAmmo[A_FUEL] < FMaxAmmo[A_FUEL] then IncMax(FAmmo[A_FUEL], 100, FMaxAmmo[A_FUEL]);
6408 ITEM_AMMO_BACKPACK:
6409 if (FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS]) or
6410 (FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS]) or
6411 (FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS]) or
6412 (FAmmo[A_CELLS] < FMaxAmmo[A_CELLS]) or
6413 (FMaxAmmo[A_FUEL] < AmmoLimits[1, A_FUEL]) then
6414 begin
6415 FMaxAmmo[A_BULLETS] := AmmoLimits[1, A_BULLETS];
6416 FMaxAmmo[A_SHELLS] := AmmoLimits[1, A_SHELLS];
6417 FMaxAmmo[A_ROCKETS] := AmmoLimits[1, A_ROCKETS];
6418 FMaxAmmo[A_CELLS] := AmmoLimits[1, A_CELLS];
6419 FMaxAmmo[A_FUEL] := AmmoLimits[1, A_FUEL];
6421 if FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS] then IncMax(FAmmo[A_BULLETS], 10, FMaxAmmo[A_BULLETS]);
6422 if FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS] then IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
6423 if FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS] then IncMax(FAmmo[A_ROCKETS], 1, FMaxAmmo[A_ROCKETS]);
6424 if FAmmo[A_CELLS] < FMaxAmmo[A_CELLS] then IncMax(FAmmo[A_CELLS], 40, FMaxAmmo[A_CELLS]);
6426 FRulez := FRulez + [R_ITEM_BACKPACK];
6427 end;
6429 ITEM_KEY_RED: if not (R_KEY_RED in FRulez) then Include(FRulez, R_KEY_RED);
6430 ITEM_KEY_GREEN: if not (R_KEY_GREEN in FRulez) then Include(FRulez, R_KEY_GREEN);
6431 ITEM_KEY_BLUE: if not (R_KEY_BLUE in FRulez) then Include(FRulez, R_KEY_BLUE);
6433 ITEM_BOTTLE: if FHealth < PLAYER_HP_LIMIT then IncMax(FHealth, 4, PLAYER_HP_LIMIT);
6434 ITEM_HELMET: if FArmor < PLAYER_AP_LIMIT then IncMax(FArmor, 5, PLAYER_AP_LIMIT);
6436 else
6437 Exit;
6438 end;
6439 if g_Game_IsNet and g_Game_IsServer then
6440 MH_SEND_PlayerStats(FUID);
6441 end;
6443 procedure TPlayer.FlySmoke(Times: DWORD = 1);
6444 var
6445 id, i: DWORD;
6446 Anim: TAnimation;
6447 begin
6448 if (Random(5) = 1) and (Times = 1) then
6449 Exit;
6451 if BodyInLiquid(0, 0) then
6452 begin
6453 g_GFX_Bubbles(Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2)+Random(3)-1,
6454 Obj.Y+Obj.Rect.Height+8, 1, 8, 4);
6455 if Random(2) = 0 then
6456 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj.X, FObj.Y)
6457 else
6458 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj.X, FObj.Y);
6459 Exit;
6460 end;
6462 if g_Frames_Get(id, 'FRAMES_SMOKE') then
6463 begin
6464 for i := 1 to Times do
6465 begin
6466 Anim := TAnimation.Create(id, False, 3);
6467 Anim.Alpha := 150;
6468 g_GFX_OnceAnim(Obj.X+Obj.Rect.X+Random(Obj.Rect.Width+Times*2)-(Anim.Width div 2),
6469 Obj.Y+Obj.Rect.Height-4+Random(8+Times*2), Anim, ONCEANIM_SMOKE);
6470 Anim.Free();
6471 end;
6472 end;
6473 end;
6475 procedure TPlayer.OnFireFlame(Times: DWORD = 1);
6476 var
6477 id, i: DWORD;
6478 Anim: TAnimation;
6479 begin
6480 if (Random(10) = 1) and (Times = 1) then
6481 Exit;
6483 if g_Frames_Get(id, 'FRAMES_FLAME') then
6484 begin
6485 for i := 1 to Times do
6486 begin
6487 Anim := TAnimation.Create(id, False, 3);
6488 Anim.Alpha := 0;
6489 g_GFX_OnceAnim(Obj.X+Obj.Rect.X+Random(Obj.Rect.Width+Times*2)-(Anim.Width div 2),
6490 Obj.Y+8+Random(8+Times*2), Anim, ONCEANIM_SMOKE);
6491 Anim.Free();
6492 end;
6493 end;
6494 end;
6496 procedure TPlayer.PauseSounds(Enable: Boolean);
6497 begin
6498 FSawSound.Pause(Enable);
6499 FSawSoundIdle.Pause(Enable);
6500 FSawSoundHit.Pause(Enable);
6501 FSawSoundSelect.Pause(Enable);
6502 FFlameSoundOn.Pause(Enable);
6503 FFlameSoundOff.Pause(Enable);
6504 FFlameSoundWork.Pause(Enable);
6505 FJetSoundFly.Pause(Enable);
6506 FJetSoundOn.Pause(Enable);
6507 FJetSoundOff.Pause(Enable);
6508 end;
6510 { T C o r p s e : }
6512 constructor TCorpse.Create(X, Y: Integer; ModelName: String; aMess: Boolean);
6513 begin
6514 g_Obj_Init(@FObj);
6515 FObj.X := X;
6516 FObj.Y := Y;
6517 FObj.Rect := PLAYER_CORPSERECT;
6518 FModelName := ModelName;
6519 FMess := aMess;
6521 if FMess then
6522 begin
6523 FState := CORPSE_STATE_MESS;
6524 g_PlayerModel_GetAnim(ModelName, A_DIE2, FAnimation, FAnimationMask);
6525 end
6526 else
6527 begin
6528 FState := CORPSE_STATE_NORMAL;
6529 g_PlayerModel_GetAnim(ModelName, A_DIE1, FAnimation, FAnimationMask);
6530 end;
6531 end;
6533 destructor TCorpse.Destroy();
6534 begin
6535 FAnimation.Free();
6537 inherited;
6538 end;
6540 function TCorpse.ObjPtr (): PObj; inline; begin result := @FObj; end;
6542 procedure TCorpse.positionChanged (); inline; begin end;
6544 procedure TCorpse.moveBy (dx, dy: Integer); inline;
6545 begin
6546 if (dx <> 0) or (dy <> 0) then
6547 begin
6548 FObj.X += dx;
6549 FObj.Y += dy;
6550 positionChanged();
6551 end;
6552 end;
6555 procedure TCorpse.getMapBox (out x, y, w, h: Integer); inline;
6556 begin
6557 x := FObj.X+PLAYER_CORPSERECT.X;
6558 y := FObj.Y+PLAYER_CORPSERECT.Y;
6559 w := PLAYER_CORPSERECT.Width;
6560 h := PLAYER_CORPSERECT.Height;
6561 end;
6564 procedure TCorpse.Damage(Value: Word; SpawnerUID: Word; vx, vy: Integer);
6565 var
6566 pm: TPlayerModel;
6567 Blood: TModelBlood;
6568 begin
6569 if FState = CORPSE_STATE_REMOVEME then
6570 Exit;
6572 FDamage := FDamage + Value;
6574 if FDamage > 150 then
6575 begin
6576 if FAnimation <> nil then
6577 begin
6578 FAnimation.Free();
6579 FAnimation := nil;
6581 FState := CORPSE_STATE_REMOVEME;
6583 g_Player_CreateGibs(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
6584 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
6585 FModelName, FColor);
6586 // Çâóê ìÿñà îò òðóïà:
6587 pm := g_PlayerModel_Get(FModelName);
6588 pm.PlaySound(MODELSOUND_DIE, 5, FObj.X, FObj.Y);
6589 pm.Free;
6591 // Çëîâåùèé ñìåõ:
6592 if (gBodyKillEvent <> -1)
6593 and gDelayedEvents[gBodyKillEvent].Pending then
6594 gDelayedEvents[gBodyKillEvent].Pending := False;
6595 gBodyKillEvent := g_Game_DelayEvent(DE_BODYKILL, 1050, SpawnerUID);
6596 end;
6597 end
6598 else
6599 begin
6600 Blood := g_PlayerModel_GetBlood(FModelName);
6601 FObj.Vel.X := FObj.Vel.X + vx;
6602 FObj.Vel.Y := FObj.Vel.Y + vy;
6603 g_GFX_Blood(FObj.X+PLAYER_CORPSERECT.X+(PLAYER_CORPSERECT.Width div 2),
6604 FObj.Y+PLAYER_CORPSERECT.Y+(PLAYER_CORPSERECT.Height div 2),
6605 Value, vx, vy, 16, (PLAYER_CORPSERECT.Height*2) div 3,
6606 Blood.R, Blood.G, Blood.B, Blood.Kind);
6607 end;
6608 end;
6610 procedure TCorpse.Draw();
6611 var
6612 fX, fY: Integer;
6613 begin
6614 if FState = CORPSE_STATE_REMOVEME then
6615 Exit;
6617 FObj.lerp(gLerpFactor, fX, fY);
6619 if FAnimation <> nil then
6620 FAnimation.Draw(fX, fY, TMirrorType.None);
6622 if FAnimationMask <> nil then
6623 begin
6624 e_Colors := FColor;
6625 FAnimationMask.Draw(fX, fY, TMirrorType.None);
6626 e_Colors.R := 255;
6627 e_Colors.G := 255;
6628 e_Colors.B := 255;
6629 end;
6630 end;
6632 procedure TCorpse.Update();
6633 var
6634 st: Word;
6635 begin
6636 if FState = CORPSE_STATE_REMOVEME then
6637 Exit;
6639 FObj.oldX := FObj.X;
6640 FObj.oldY := FObj.Y;
6642 if gTime mod (GAME_TICK*2) <> 0 then
6643 begin
6644 g_Obj_Move(@FObj, True, True, True);
6645 positionChanged(); // this updates spatial accelerators
6646 Exit;
6647 end;
6649 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6650 FObj.Vel.X := z_dec(FObj.Vel.X, 1);
6652 st := g_Obj_Move(@FObj, True, True, True);
6653 positionChanged(); // this updates spatial accelerators
6655 if WordBool(st and MOVE_FALLOUT) then
6656 begin
6657 FState := CORPSE_STATE_REMOVEME;
6658 Exit;
6659 end;
6661 if FAnimation <> nil then
6662 FAnimation.Update();
6663 if FAnimationMask <> nil then
6664 FAnimationMask.Update();
6665 end;
6668 procedure TCorpse.SaveState (st: TStream);
6669 var
6670 anim: Boolean;
6671 begin
6672 assert(st <> nil);
6674 // Ñèãíàòóðà òðóïà
6675 utils.writeSign(st, 'CORP');
6676 utils.writeInt(st, Byte(0));
6677 // Ñîñòîÿíèå
6678 utils.writeInt(st, Byte(FState));
6679 // Íàêîïëåííûé óðîí
6680 utils.writeInt(st, Byte(FDamage));
6681 // Öâåò
6682 utils.writeInt(st, Byte(FColor.R));
6683 utils.writeInt(st, Byte(FColor.G));
6684 utils.writeInt(st, Byte(FColor.B));
6685 // Îáúåêò òðóïà
6686 Obj_SaveState(st, @FObj);
6687 utils.writeInt(st, Word(FPlayerUID));
6688 // Åñòü ëè àíèìàöèÿ
6689 anim := (FAnimation <> nil);
6690 utils.writeBool(st, anim);
6691 // Åñëè åñòü - ñîõðàíÿåì
6692 if anim then FAnimation.SaveState(st);
6693 // Åñòü ëè ìàñêà àíèìàöèè
6694 anim := (FAnimationMask <> nil);
6695 utils.writeBool(st, anim);
6696 // Åñëè åñòü - ñîõðàíÿåì
6697 if anim then FAnimationMask.SaveState(st);
6698 end;
6701 procedure TCorpse.LoadState (st: TStream);
6702 var
6703 anim: Boolean;
6704 begin
6705 assert(st <> nil);
6707 // Ñèãíàòóðà òðóïà
6708 if not utils.checkSign(st, 'CORP') then raise XStreamError.Create('invalid corpse signature');
6709 if (utils.readByte(st) <> 0) then raise XStreamError.Create('invalid corpse version');
6710 // Ñîñòîÿíèå
6711 FState := utils.readByte(st);
6712 // Íàêîïëåííûé óðîí
6713 FDamage := utils.readByte(st);
6714 // Öâåò
6715 FColor.R := utils.readByte(st);
6716 FColor.G := utils.readByte(st);
6717 FColor.B := utils.readByte(st);
6718 // Îáúåêò òðóïà
6719 Obj_LoadState(@FObj, st);
6720 FPlayerUID := utils.readWord(st);
6721 // Åñòü ëè àíèìàöèÿ
6722 anim := utils.readBool(st);
6723 // Åñëè åñòü - çàãðóæàåì
6724 if anim then
6725 begin
6726 Assert(FAnimation <> nil, 'TCorpse.LoadState: no FAnimation');
6727 FAnimation.LoadState(st);
6728 end;
6729 // Åñòü ëè ìàñêà àíèìàöèè
6730 anim := utils.readBool(st);
6731 // Åñëè åñòü - çàãðóæàåì
6732 if anim then
6733 begin
6734 Assert(FAnimationMask <> nil, 'TCorpse.LoadState: no FAnimationMask');
6735 FAnimationMask.LoadState(st);
6736 end;
6737 end;
6739 { T B o t : }
6741 constructor TBot.Create();
6742 var
6743 a: Integer;
6744 begin
6745 inherited Create();
6747 FPhysics := True;
6748 FSpectator := False;
6749 FGhost := False;
6751 FIamBot := True;
6753 Inc(gNumBots);
6755 for a := WP_FIRST to WP_LAST do
6756 begin
6757 FDifficult.WeaponPrior[a] := WEAPON_PRIOR1[a];
6758 FDifficult.CloseWeaponPrior[a] := WEAPON_PRIOR2[a];
6759 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6760 end;
6761 end;
6763 destructor TBot.Destroy();
6764 begin
6765 Dec(gNumBots);
6766 inherited Destroy();
6767 end;
6769 procedure TBot.Draw();
6770 begin
6771 inherited Draw();
6773 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6774 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6775 end;
6777 procedure TBot.Respawn(Silent: Boolean; Force: Boolean = False);
6778 begin
6779 inherited Respawn(Silent, Force);
6781 FAIFlags := nil;
6782 FSelectedWeapon := FCurrWeap;
6783 resetWeaponQueue();
6784 FTargetUID := 0;
6785 end;
6787 procedure TBot.UpdateCombat();
6788 type
6789 TTarget = record
6790 UID: Word;
6791 X, Y: Integer;
6792 Rect: TRectWH;
6793 cX, cY: Integer;
6794 Dist: Word;
6795 Line: Boolean;
6796 Visible: Boolean;
6797 IsPlayer: Boolean;
6798 end;
6800 TTargetRecord = array of TTarget;
6802 function Compare(a, b: TTarget): Integer;
6803 begin
6804 if a.Line and not b.Line then // A íà ëèíèè îãíÿ
6805 Result := -1
6806 else
6807 if not a.Line and b.Line then // B íà ëèíèè îãíÿ
6808 Result := 1
6809 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6810 if (a.Line and b.Line) or ((not a.Line) and (not b.Line)) then
6811 begin
6812 if a.Dist > b.Dist then // B áëèæå
6813 Result := 1
6814 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6815 Result := -1;
6816 end
6817 else // Ñòðàííî -> A
6818 Result := -1;
6819 end;
6821 var
6822 a, x1, y1, x2, y2: Integer;
6823 targets: TTargetRecord;
6824 ammo: Word;
6825 Target, BestTarget: TTarget;
6826 firew, fireh: Integer;
6827 angle: SmallInt;
6828 mon: TMonster;
6829 pla, tpla: TPlayer;
6830 vsPlayer, vsMonster, ok: Boolean;
6833 function monsUpdate (mon: TMonster): Boolean;
6834 begin
6835 result := false; // don't stop
6836 if mon.alive and (mon.MonsterType <> MONSTER_BARREL) then
6837 begin
6838 if not TargetOnScreen(mon.Obj.X+mon.Obj.Rect.X, mon.Obj.Y+mon.Obj.Rect.Y) then exit;
6840 x2 := mon.Obj.X+mon.Obj.Rect.X+(mon.Obj.Rect.Width div 2);
6841 y2 := mon.Obj.Y+mon.Obj.Rect.Y+(mon.Obj.Rect.Height div 2);
6843 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6844 if g_TraceVector(x1, y1, x2, y2) then
6845 begin
6846 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6847 SetLength(targets, Length(targets)+1);
6848 with targets[High(targets)] do
6849 begin
6850 UID := mon.UID;
6851 X := mon.Obj.X;
6852 Y := mon.Obj.Y;
6853 cX := x2;
6854 cY := y2;
6855 Rect := mon.Obj.Rect;
6856 Dist := g_PatchLength(x1, y1, x2, y2);
6857 Line := (y1+4 < Target.Y + mon.Obj.Rect.Y + mon.Obj.Rect.Height) and
6858 (y1-4 > Target.Y + mon.Obj.Rect.Y);
6859 Visible := True;
6860 IsPlayer := False;
6861 end;
6862 end;
6863 end;
6864 end;
6866 begin
6867 vsPlayer := LongBool(gGameSettings.Options and GAME_OPTION_BOTVSPLAYER);
6868 vsMonster := LongBool(gGameSettings.Options and GAME_OPTION_BOTVSMONSTER);
6870 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6871 if FCurrWeap <> FSelectedWeapon then
6872 NextWeapon();
6874 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6875 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap = FSelectedWeapon) then
6876 begin
6877 RemoveAIFlag('NEEDFIRE');
6879 case FCurrWeap of
6880 WEAPON_PLASMA, WEAPON_SUPERPULEMET, WEAPON_CHAINGUN: PressKey(KEY_FIRE, 20);
6881 WEAPON_SAW, WEAPON_KASTET, WEAPON_FLAMETHROWER: PressKey(KEY_FIRE, 40);
6882 else PressKey(KEY_FIRE);
6883 end;
6884 end;
6886 // Êîîðäèíàòû ñòâîëà:
6887 x1 := FObj.X + WEAPONPOINT[FDirection].X;
6888 y1 := FObj.Y + WEAPONPOINT[FDirection].Y;
6890 Target.UID := FTargetUID;
6892 ok := False;
6893 if Target.UID <> 0 then
6894 begin // Öåëü åñòü - íàñòðàèâàåì
6895 if (g_GetUIDType(Target.UID) = UID_PLAYER) and
6896 vsPlayer then
6897 begin // Èãðîê
6898 tpla := g_Player_Get(Target.UID);
6899 if tpla <> nil then
6900 with tpla do
6901 begin
6902 if (@FObj) <> nil then
6903 begin
6904 Target.X := FObj.X;
6905 Target.Y := FObj.Y;
6906 end;
6907 end;
6909 Target.cX := Target.X + PLAYER_RECT_CX;
6910 Target.cY := Target.Y + PLAYER_RECT_CY;
6911 Target.Rect := PLAYER_RECT;
6912 Target.Visible := g_TraceVector(x1, y1, Target.cX, Target.cY);
6913 Target.Line := (y1+4 < Target.Y+PLAYER_RECT.Y+PLAYER_RECT.Height) and
6914 (y1-4 > Target.Y+PLAYER_RECT.Y);
6915 Target.IsPlayer := True;
6916 ok := True;
6917 end
6918 else
6919 if (g_GetUIDType(Target.UID) = UID_MONSTER) and
6920 vsMonster then
6921 begin // Ìîíñòð
6922 mon := g_Monsters_ByUID(Target.UID);
6923 if mon <> nil then
6924 begin
6925 Target.X := mon.Obj.X;
6926 Target.Y := mon.Obj.Y;
6928 Target.cX := Target.X + mon.Obj.Rect.X + (mon.Obj.Rect.Width div 2);
6929 Target.cY := Target.Y + mon.Obj.Rect.Y + (mon.Obj.Rect.Height div 2);
6930 Target.Rect := mon.Obj.Rect;
6931 Target.Visible := g_TraceVector(x1, y1, Target.cX, Target.cY);
6932 Target.Line := (y1+4 < Target.Y + mon.Obj.Rect.Y + mon.Obj.Rect.Height) and
6933 (y1-4 > Target.Y + mon.Obj.Rect.Y);
6934 Target.IsPlayer := False;
6935 ok := True;
6936 end;
6937 end;
6938 end;
6940 if not ok then
6941 begin // Öåëè íåò - îáíóëÿåì
6942 Target.X := 0;
6943 Target.Y := 0;
6944 Target.cX := 0;
6945 Target.cY := 0;
6946 Target.Visible := False;
6947 Target.Line := False;
6948 Target.IsPlayer := False;
6949 end;
6951 targets := nil;
6953 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6954 if (not Target.Line) or (not Target.Visible) then
6955 begin
6956 // Èãðîêè:
6957 if vsPlayer then
6958 for a := 0 to High(gPlayers) do
6959 if (gPlayers[a] <> nil) and (gPlayers[a].alive) and
6960 (gPlayers[a].FUID <> FUID) and
6961 (not SameTeam(FUID, gPlayers[a].FUID)) and
6962 (not gPlayers[a].NoTarget) and
6963 (gPlayers[a].FMegaRulez[MR_INVIS] < gTime) then
6964 begin
6965 if not TargetOnScreen(gPlayers[a].FObj.X + PLAYER_RECT.X,
6966 gPlayers[a].FObj.Y + PLAYER_RECT.Y) then
6967 Continue;
6969 x2 := gPlayers[a].FObj.X + PLAYER_RECT_CX;
6970 y2 := gPlayers[a].FObj.Y + PLAYER_RECT_CY;
6972 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6973 if g_TraceVector(x1, y1, x2, y2) then
6974 begin
6975 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6976 SetLength(targets, Length(targets)+1);
6977 with targets[High(targets)] do
6978 begin
6979 UID := gPlayers[a].FUID;
6980 X := gPlayers[a].FObj.X;
6981 Y := gPlayers[a].FObj.Y;
6982 cX := x2;
6983 cY := y2;
6984 Rect := PLAYER_RECT;
6985 Dist := g_PatchLength(x1, y1, x2, y2);
6986 Line := (y1+4 < Target.Y+PLAYER_RECT.Y+PLAYER_RECT.Height) and
6987 (y1-4 > Target.Y+PLAYER_RECT.Y);
6988 Visible := True;
6989 IsPlayer := True;
6990 end;
6991 end;
6992 end;
6994 // Ìîíñòðû:
6995 if vsMonster then g_Mons_ForEach(monsUpdate);
6996 end;
6998 // Åñëè åñòü âîçìîæíûå öåëè:
6999 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
7000 if targets <> nil then
7001 begin
7002 // Âûáèðàåì íàèëó÷øóþ öåëü:
7003 BestTarget := targets[0];
7004 if Length(targets) > 1 then
7005 for a := 1 to High(targets) do
7006 if Compare(BestTarget, targets[a]) = 1 then
7007 BestTarget := targets[a];
7009 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
7010 if ((not Target.Visible) and BestTarget.Visible and (Target.UID <> BestTarget.UID)) or
7011 ((not Target.Line) and BestTarget.Line and BestTarget.Visible) then
7012 begin
7013 Target := BestTarget;
7015 if (Healthy() = 3) or ((Healthy() = 2)) then
7016 begin // Åñëè çäîðîâû - äîãîíÿåì
7017 if ((RunDirection() = TDirection.D_LEFT) and (Target.X > FObj.X)) then
7018 SetAIFlag('GORIGHT', '1');
7019 if ((RunDirection() = TDirection.D_RIGHT) and (Target.X < FObj.X)) then
7020 SetAIFlag('GOLEFT', '1');
7021 end
7022 else
7023 begin // Åñëè ïîáèòû - óáåãàåì
7024 if ((RunDirection() = TDirection.D_LEFT) and (Target.X < FObj.X)) then
7025 SetAIFlag('GORIGHT', '1');
7026 if ((RunDirection() = TDirection.D_RIGHT) and (Target.X > FObj.X)) then
7027 SetAIFlag('GOLEFT', '1');
7028 end;
7030 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
7031 SelectWeapon(Abs(x1-Target.cX));
7032 end;
7033 end;
7035 // Åñëè åñòü öåëü:
7036 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
7037 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
7038 if Target.UID <> 0 then
7039 begin
7040 if not TargetOnScreen(Target.X + Target.Rect.X,
7041 Target.Y + Target.Rect.Y) then
7042 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
7043 if (Healthy() = 3) or ((Healthy() = 2)) then
7044 begin // Åñëè çäîðîâû - äîãîíÿåì
7045 if ((RunDirection() = TDirection.D_LEFT) and (Target.X > FObj.X)) then
7046 SetAIFlag('GORIGHT', '1');
7047 if ((RunDirection() = TDirection.D_RIGHT) and (Target.X < FObj.X)) then
7048 SetAIFlag('GOLEFT', '1');
7049 end
7050 else
7051 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
7052 Target.UID := 0;
7053 if ((RunDirection() = TDirection.D_LEFT) and (Target.X < FObj.X)) then
7054 SetAIFlag('GORIGHT', '1');
7055 if ((RunDirection() = TDirection.D_RIGHT) and (Target.X > FObj.X)) then
7056 SetAIFlag('GOLEFT', '1');
7057 end;
7058 end
7059 else
7060 begin // Öåëü ïîêà íà "ýêðàíå"
7061 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
7062 if g_TraceVector(x1, y1, Target.cX, Target.cY) then
7063 FLastVisible := gTime;
7064 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
7065 if (Abs(FObj.Y-Target.Y) <= 128) then
7066 begin
7067 if ((RunDirection() = TDirection.D_LEFT) and (Target.X > FObj.X)) then
7068 SetAIFlag('GORIGHT', '1');
7069 if ((RunDirection() = TDirection.D_RIGHT) and (Target.X < FObj.X)) then
7070 SetAIFlag('GOLEFT', '1');
7071 end;
7072 end;
7074 // Âûáèðàåì óãîë ââåðõ:
7075 if FDirection = TDirection.D_LEFT then
7076 angle := ANGLE_LEFTUP
7077 else
7078 angle := ANGLE_RIGHTUP;
7080 firew := Trunc(Cos(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
7081 fireh := Trunc(Sin(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
7083 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
7084 if g_CollideLine(x1, y1, x1+firew, y1+fireh,
7085 Target.X+Target.Rect.X+GetInterval(FDifficult.DiagPrecision, 128), //96
7086 Target.Y+Target.Rect.Y+GetInterval(FDifficult.DiagPrecision, 128),
7087 Target.Rect.Width, Target.Rect.Height) and
7088 g_TraceVector(x1, y1, Target.cX, Target.cY) then
7089 begin // òî íóæíî ñòðåëÿòü ââåðõ
7090 SetAIFlag('NEEDFIRE', '1');
7091 SetAIFlag('NEEDSEEUP', '1');
7092 end;
7094 // Âûáèðàåì óãîë âíèç:
7095 if FDirection = TDirection.D_LEFT then
7096 angle := ANGLE_LEFTDOWN
7097 else
7098 angle := ANGLE_RIGHTDOWN;
7100 firew := Trunc(Cos(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
7101 fireh := Trunc(Sin(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
7103 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
7104 if g_CollideLine(x1, y1, x1+firew, y1+fireh,
7105 Target.X+Target.Rect.X+GetInterval(FDifficult.DiagPrecision, 128),
7106 Target.Y+Target.Rect.Y+GetInterval(FDifficult.DiagPrecision, 128),
7107 Target.Rect.Width, Target.Rect.Height) and
7108 g_TraceVector(x1, y1, Target.cX, Target.cY) then
7109 begin // òî íóæíî ñòðåëÿòü âíèç
7110 SetAIFlag('NEEDFIRE', '1');
7111 SetAIFlag('NEEDSEEDOWN', '1');
7112 end;
7114 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
7115 if Target.Visible and
7116 (y1+4 < Target.Y+Target.Rect.Y+Target.Rect.Height) and
7117 (y1-4 > Target.Y+Target.Rect.Y) then
7118 begin
7119 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
7120 if ((FDirection = TDirection.D_LEFT) and (Target.X < FObj.X)) or
7121 ((FDirection = TDirection.D_RIGHT) and (Target.X > FObj.X)) then
7122 begin // òî íóæíî ñòðåëÿòü âïåðåä
7123 SetAIFlag('NEEDFIRE', '1');
7124 SetAIFlag('NEEDSEEDOWN', '');
7125 SetAIFlag('NEEDSEEUP', '');
7126 end;
7127 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
7128 if Abs(FObj.X-Target.X) < Trunc(gPlayerScreenSize.X*0.75) then
7129 if GetRnd(FDifficult.CloseJump) then
7130 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
7131 if Abs(FObj.X-Target.X) < 128 then
7132 a := 4
7133 else
7134 a := 30;
7135 if Random(a) = 0 then
7136 SetAIFlag('NEEDJUMP', '1');
7137 end;
7138 end;
7140 // Åñëè öåëü âñå åùå åñòü:
7141 if Target.UID <> 0 then
7142 if gTime-FLastVisible > 2000 then // Åñëè âèäåëè äàâíî
7143 Target.UID := 0 // òî çàáûòü öåëü
7144 else // Åñëè âèäåëè íåäàâíî
7145 begin // íî öåëü óáèëè
7146 if Target.IsPlayer then
7147 begin // Öåëü - èãðîê
7148 pla := g_Player_Get(Target.UID);
7149 if (pla = nil) or (not pla.alive) or pla.NoTarget or
7150 (pla.FMegaRulez[MR_INVIS] >= gTime) then
7151 Target.UID := 0; // òî çàáûòü öåëü
7152 end
7153 else
7154 begin // Öåëü - ìîíñòð
7155 mon := g_Monsters_ByUID(Target.UID);
7156 if (mon = nil) or (not mon.alive) then
7157 Target.UID := 0; // òî çàáûòü öåëü
7158 end;
7159 end;
7160 end; // if Target.UID <> 0
7162 FTargetUID := Target.UID;
7164 // Åñëè âîçìîæíûõ öåëåé íåò:
7165 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
7166 if targets = nil then
7167 if GetAIFlag('ATTACKLEFT') <> '' then
7168 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
7169 RemoveAIFlag('ATTACKLEFT');
7171 SetAIFlag('NEEDJUMP', '1');
7173 if RunDirection() = TDirection.D_RIGHT then
7174 begin // Èäåì íå â òó ñòîðîíó
7175 if (Healthy() > 1) and GetRnd(FDifficult.InvisFire) then
7176 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
7177 SetAIFlag('NEEDFIRE', '1');
7178 SetAIFlag('GOLEFT', '1');
7179 end;
7180 end
7181 else
7182 begin // Èäåì â íóæíóþ ñòîðîíó
7183 if GetRnd(FDifficult.InvisFire) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7184 SetAIFlag('NEEDFIRE', '1');
7185 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7186 SetAIFlag('GORIGHT', '1');
7187 end;
7188 end
7189 else
7190 if GetAIFlag('ATTACKRIGHT') <> '' then
7191 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
7192 RemoveAIFlag('ATTACKRIGHT');
7194 SetAIFlag('NEEDJUMP', '1');
7196 if RunDirection() = TDirection.D_LEFT then
7197 begin // Èäåì íå â òó ñòîðîíó
7198 if (Healthy() > 1) and GetRnd(FDifficult.InvisFire) then
7199 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
7200 SetAIFlag('NEEDFIRE', '1');
7201 SetAIFlag('GORIGHT', '1');
7202 end;
7203 end
7204 else
7205 begin
7206 if GetRnd(FDifficult.InvisFire) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7207 SetAIFlag('NEEDFIRE', '1');
7208 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7209 SetAIFlag('GOLEFT', '1');
7210 end;
7211 end;
7213 //HACK! (does it belongs there?)
7214 RealizeCurrentWeapon();
7216 // Åñëè åñòü âîçìîæíûå öåëè:
7217 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
7218 if (targets <> nil) and (GetAIFlag('NEEDFIRE') <> '') then
7219 for a := 0 to High(targets) do
7220 begin
7221 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
7222 if GetRnd(FDifficult.DiagFire) then
7223 begin
7224 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
7225 if FDirection = TDirection.D_LEFT then
7226 angle := ANGLE_LEFTUP
7227 else
7228 angle := ANGLE_RIGHTUP;
7230 firew := Trunc(Cos(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
7231 fireh := Trunc(Sin(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
7233 if g_CollideLine(x1, y1, x1+firew, y1+fireh,
7234 targets[a].X+targets[a].Rect.X+GetInterval(FDifficult.DiagPrecision, 128),
7235 targets[a].Y+targets[a].Rect.Y+GetInterval(FDifficult.DiagPrecision, 128),
7236 targets[a].Rect.Width, targets[a].Rect.Height) and
7237 g_TraceVector(x1, y1, targets[a].cX, targets[a].cY) then
7238 begin
7239 SetAIFlag('NEEDFIRE', '1');
7240 SetAIFlag('NEEDSEEUP', '1');
7241 end;
7243 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
7244 if FDirection = TDirection.D_LEFT then
7245 angle := ANGLE_LEFTDOWN
7246 else
7247 angle := ANGLE_RIGHTDOWN;
7249 firew := Trunc(Cos(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
7250 fireh := Trunc(Sin(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
7252 if g_CollideLine(x1, y1, x1+firew, y1+fireh,
7253 targets[a].X+targets[a].Rect.X+GetInterval(FDifficult.DiagPrecision, 128),
7254 targets[a].Y+targets[a].Rect.Y+GetInterval(FDifficult.DiagPrecision, 128),
7255 targets[a].Rect.Width, targets[a].Rect.Height) and
7256 g_TraceVector(x1, y1, targets[a].cX, targets[a].cY) then
7257 begin
7258 SetAIFlag('NEEDFIRE', '1');
7259 SetAIFlag('NEEDSEEDOWN', '1');
7260 end;
7261 end;
7263 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
7264 if targets[a].Line and targets[a].Visible and
7265 (((FDirection = TDirection.D_LEFT) and (targets[a].X < FObj.X)) or
7266 ((FDirection = TDirection.D_RIGHT) and (targets[a].X > FObj.X))) then
7267 begin
7268 SetAIFlag('NEEDFIRE', '1');
7269 Break;
7270 end;
7271 end;
7273 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
7274 if g_Weapon_Danger(FUID, FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y,
7275 PLAYER_RECT.Width, PLAYER_RECT.Height,
7276 40+GetInterval(FDifficult.Cover, 40)) then
7277 SetAIFlag('NEEDJUMP', '1');
7279 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
7280 ammo := GetAmmoByWeapon(FCurrWeap);
7281 if ((FCurrWeap = WEAPON_SHOTGUN2) and (ammo < 2)) or
7282 ((FCurrWeap = WEAPON_BFG) and (ammo < 40)) or
7283 (ammo = 0) then
7284 SetAIFlag('SELECTWEAPON', '1');
7286 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
7287 if GetAIFlag('SELECTWEAPON') = '1' then
7288 begin
7289 SelectWeapon(-1);
7290 RemoveAIFlag('SELECTWEAPON');
7291 end;
7292 end;
7294 procedure TBot.Update();
7295 var
7296 EnableAI: Boolean;
7297 begin
7298 if not FAlive then
7299 begin // Respawn
7300 ReleaseKeys();
7301 PressKey(KEY_UP);
7302 end
7303 else
7304 begin
7305 EnableAI := True;
7307 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
7308 if (g_debug_BotAIOff = 1) and (Team = TEAM_RED) then
7309 EnableAI := False;
7310 if (g_debug_BotAIOff = 2) and (Team = TEAM_BLUE) then
7311 EnableAI := False;
7312 if g_debug_BotAIOff = 3 then
7313 EnableAI := False;
7315 if EnableAI then
7316 begin
7317 UpdateMove();
7318 UpdateCombat();
7319 end
7320 else
7321 begin
7322 RealizeCurrentWeapon();
7323 end;
7324 end;
7326 inherited Update();
7327 end;
7329 procedure TBot.ReleaseKey(Key: Byte);
7330 begin
7331 with FKeys[Key] do
7332 begin
7333 Pressed := False;
7334 Time := 0;
7335 end;
7336 end;
7338 function TBot.KeyPressed(Key: Word): Boolean;
7339 begin
7340 Result := FKeys[Key].Pressed;
7341 end;
7343 function TBot.GetAIFlag(aName: String20): String20;
7344 var
7345 a: Integer;
7346 begin
7347 Result := '';
7349 aName := LowerCase(aName);
7351 if FAIFlags <> nil then
7352 for a := 0 to High(FAIFlags) do
7353 if LowerCase(FAIFlags[a].Name) = aName then
7354 begin
7355 Result := FAIFlags[a].Value;
7356 Break;
7357 end;
7358 end;
7360 procedure TBot.RemoveAIFlag(aName: String20);
7361 var
7362 a, b: Integer;
7363 begin
7364 if FAIFlags = nil then Exit;
7366 aName := LowerCase(aName);
7368 for a := 0 to High(FAIFlags) do
7369 if LowerCase(FAIFlags[a].Name) = aName then
7370 begin
7371 if a <> High(FAIFlags) then
7372 for b := a to High(FAIFlags)-1 do
7373 FAIFlags[b] := FAIFlags[b+1];
7375 SetLength(FAIFlags, Length(FAIFlags)-1);
7376 Break;
7377 end;
7378 end;
7380 procedure TBot.SetAIFlag(aName, fValue: String20);
7381 var
7382 a: Integer;
7383 ok: Boolean;
7384 begin
7385 a := 0;
7386 ok := False;
7388 aName := LowerCase(aName);
7390 if FAIFlags <> nil then
7391 for a := 0 to High(FAIFlags) do
7392 if LowerCase(FAIFlags[a].Name) = aName then
7393 begin
7394 ok := True;
7395 Break;
7396 end;
7398 if ok then FAIFlags[a].Value := fValue
7399 else
7400 begin
7401 SetLength(FAIFlags, Length(FAIFlags)+1);
7402 with FAIFlags[High(FAIFlags)] do
7403 begin
7404 Name := aName;
7405 Value := fValue;
7406 end;
7407 end;
7408 end;
7410 procedure TBot.UpdateMove;
7412 procedure GoLeft(Time: Word = 1);
7413 begin
7414 ReleaseKey(KEY_LEFT);
7415 ReleaseKey(KEY_RIGHT);
7416 PressKey(KEY_LEFT, Time);
7417 SetDirection(TDirection.D_LEFT);
7418 end;
7420 procedure GoRight(Time: Word = 1);
7421 begin
7422 ReleaseKey(KEY_LEFT);
7423 ReleaseKey(KEY_RIGHT);
7424 PressKey(KEY_RIGHT, Time);
7425 SetDirection(TDirection.D_RIGHT);
7426 end;
7428 function Rnd(a: Word): Boolean;
7429 begin
7430 Result := Random(a) = 0;
7431 end;
7433 procedure Turn(Time: Word = 1200);
7434 begin
7435 if RunDirection() = TDirection.D_LEFT then GoRight(Time) else GoLeft(Time);
7436 end;
7438 procedure Stop();
7439 begin
7440 ReleaseKey(KEY_LEFT);
7441 ReleaseKey(KEY_RIGHT);
7442 end;
7444 function CanRunLeft(): Boolean;
7445 begin
7446 Result := not CollideLevel(-1, 0);
7447 end;
7449 function CanRunRight(): Boolean;
7450 begin
7451 Result := not CollideLevel(1, 0);
7452 end;
7454 function CanRun(): Boolean;
7455 begin
7456 if RunDirection() = TDirection.D_LEFT then Result := CanRunLeft() else Result := CanRunRight();
7457 end;
7459 procedure Jump(Time: Word = 30);
7460 begin
7461 PressKey(KEY_JUMP, Time);
7462 end;
7464 function NearHole(): Boolean;
7465 var
7466 x, sx: Integer;
7467 begin
7468 { TODO 5 : Ëåñòíèöû }
7469 sx := IfThen(RunDirection() = TDirection.D_LEFT, -1, 1);
7470 for x := 1 to PLAYER_RECT.Width do
7471 if (not StayOnStep(x*sx, 0)) and
7472 (not CollideLevel(x*sx, PLAYER_RECT.Height)) and
7473 (not CollideLevel(x*sx, PLAYER_RECT.Height*2)) then
7474 begin
7475 Result := True;
7476 Exit;
7477 end;
7479 Result := False;
7480 end;
7482 function BorderHole(): Boolean;
7483 var
7484 x, sx, xx: Integer;
7485 begin
7486 { TODO 5 : Ëåñòíèöû }
7487 sx := IfThen(RunDirection() = TDirection.D_LEFT, -1, 1);
7488 for x := 1 to PLAYER_RECT.Width do
7489 if (not StayOnStep(x*sx, 0)) and
7490 (not CollideLevel(x*sx, PLAYER_RECT.Height)) and
7491 (not CollideLevel(x*sx, PLAYER_RECT.Height*2)) then
7492 begin
7493 for xx := x to x+32 do
7494 if CollideLevel(xx*sx, PLAYER_RECT.Height) then
7495 begin
7496 Result := True;
7497 Exit;
7498 end;
7499 end;
7501 Result := False;
7502 end;
7504 function NearDeepHole(): Boolean;
7505 var
7506 x, sx, y: Integer;
7507 begin
7508 Result := False;
7510 sx := IfThen(RunDirection() = TDirection.D_LEFT, -1, 1);
7511 y := 3;
7513 for x := 1 to PLAYER_RECT.Width do
7514 if (not StayOnStep(x*sx, 0)) and
7515 (not CollideLevel(x*sx, PLAYER_RECT.Height)) and
7516 (not CollideLevel(x*sx, PLAYER_RECT.Height*2)) then
7517 begin
7518 while FObj.Y+y*PLAYER_RECT.Height < gMapInfo.Height do
7519 begin
7520 if CollideLevel(x*sx, PLAYER_RECT.Height*y) then Exit;
7521 y := y+1;
7522 end;
7524 Result := True;
7525 end else Result := False;
7526 end;
7528 function OverDeepHole(): Boolean;
7529 var
7530 y: Integer;
7531 begin
7532 Result := False;
7534 y := 1;
7535 while FObj.Y+y*PLAYER_RECT.Height < gMapInfo.Height do
7536 begin
7537 if CollideLevel(0, PLAYER_RECT.Height*y) then Exit;
7538 y := y+1;
7539 end;
7541 Result := True;
7542 end;
7544 function OnGround(): Boolean;
7545 begin
7546 Result := StayOnStep(0, 0) or CollideLevel(0, 1);
7547 end;
7549 function OnLadder(): Boolean;
7550 begin
7551 Result := FullInStep(0, 0);
7552 end;
7554 function BelowLadder(): Boolean;
7555 begin
7556 Result := (FullInStep(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -PLAYER_RECT.Height) and
7557 not CollideLevel(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -PLAYER_RECT.Height)) or
7558 (FullInStep(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -BOT_MAXJUMP) and
7559 not CollideLevel(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -BOT_MAXJUMP));
7560 end;
7562 function BelowLiftUp(): Boolean;
7563 begin
7564 Result := ((FullInLift(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -PLAYER_RECT.Height) = -1) and
7565 not CollideLevel(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -PLAYER_RECT.Height)) or
7566 ((FullInLift(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -BOT_MAXJUMP) = -1) and
7567 not CollideLevel(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -BOT_MAXJUMP));
7568 end;
7570 function OnTopLift(): Boolean;
7571 begin
7572 Result := (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7573 end;
7575 function CanJumpOver(): Boolean;
7576 var
7577 sx, y: Integer;
7578 begin
7579 sx := IfThen(RunDirection() = TDirection.D_LEFT, -1, 1);
7581 Result := False;
7583 if not CollideLevel(sx, 0) then Exit;
7585 for y := 1 to BOT_MAXJUMP do
7586 if CollideLevel(0, -y) then Exit else
7587 if not CollideLevel(sx, -y) then
7588 begin
7589 Result := True;
7590 Exit;
7591 end;
7592 end;
7594 function CanJumpUp(Dist: ShortInt): Boolean;
7595 var
7596 y, yy: Integer;
7597 c: Boolean;
7598 begin
7599 Result := False;
7601 if CollideLevel(Dist, 0) then Exit;
7603 c := False;
7604 for y := 0 to BOT_MAXJUMP do
7605 if CollideLevel(Dist, -y) then
7606 begin
7607 c := True;
7608 Break;
7609 end;
7611 if not c then Exit;
7613 c := False;
7614 for yy := y+1 to BOT_MAXJUMP do
7615 if not CollideLevel(Dist, -yy) then
7616 begin
7617 c := True;
7618 Break;
7619 end;
7621 if not c then Exit;
7623 c := False;
7624 for y := 0 to BOT_MAXJUMP do
7625 if CollideLevel(0, -y) then
7626 begin
7627 c := True;
7628 Break;
7629 end;
7631 if c then Exit;
7633 if y < yy then Exit;
7635 Result := True;
7636 end;
7638 function IsSafeTrigger(): Boolean;
7639 var
7640 a: Integer;
7641 begin
7642 Result := True;
7643 if gTriggers = nil then
7644 Exit;
7645 for a := 0 to High(gTriggers) do
7646 if Collide(gTriggers[a].X,
7647 gTriggers[a].Y,
7648 gTriggers[a].Width,
7649 gTriggers[a].Height) and
7650 (gTriggers[a].TriggerType in [TRIGGER_EXIT, TRIGGER_CLOSEDOOR,
7651 TRIGGER_CLOSETRAP, TRIGGER_TRAP,
7652 TRIGGER_PRESS, TRIGGER_ON, TRIGGER_OFF,
7653 TRIGGER_ONOFF, TRIGGER_SPAWNMONSTER,
7654 TRIGGER_DAMAGE, TRIGGER_SHOT]) then
7655 Result := False;
7656 end;
7658 begin
7659 // Âîçìîæíî, íàæèìàåì êíîïêó:
7660 if Rnd(16) and IsSafeTrigger() then
7661 PressKey(KEY_OPEN);
7663 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7664 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7665 begin
7666 ReleaseKey(KEY_LEFT);
7667 ReleaseKey(KEY_RIGHT);
7668 Jump();
7669 end;
7671 // Èäåì âëåâî, åñëè íàäî áûëî:
7672 if GetAIFlag('GOLEFT') <> '' then
7673 begin
7674 RemoveAIFlag('GOLEFT');
7675 if CanRunLeft() then
7676 GoLeft(360);
7677 end;
7679 // Èäåì âïðàâî, åñëè íàäî áûëî:
7680 if GetAIFlag('GORIGHT') <> '' then
7681 begin
7682 RemoveAIFlag('GORIGHT');
7683 if CanRunRight() then
7684 GoRight(360);
7685 end;
7687 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7688 if FObj.X < -32 then
7689 GoRight(360)
7690 else
7691 if FObj.X+32 > gMapInfo.Width then
7692 GoLeft(360);
7694 // Ïðûãàåì, åñëè íàäî áûëî:
7695 if GetAIFlag('NEEDJUMP') <> '' then
7696 begin
7697 Jump(0);
7698 RemoveAIFlag('NEEDJUMP');
7699 end;
7701 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7702 if GetAIFlag('NEEDSEEUP') <> '' then
7703 begin
7704 ReleaseKey(KEY_UP);
7705 ReleaseKey(KEY_DOWN);
7706 PressKey(KEY_UP, 20);
7707 RemoveAIFlag('NEEDSEEUP');
7708 end;
7710 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7711 if GetAIFlag('NEEDSEEDOWN') <> '' then
7712 begin
7713 ReleaseKey(KEY_UP);
7714 ReleaseKey(KEY_DOWN);
7715 PressKey(KEY_DOWN, 20);
7716 RemoveAIFlag('NEEDSEEDOWN');
7717 end;
7719 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7720 if GetAIFlag('GOINHOLE') <> '' then
7721 if not OnGround() then
7722 begin
7723 ReleaseKey(KEY_LEFT);
7724 ReleaseKey(KEY_RIGHT);
7725 RemoveAIFlag('GOINHOLE');
7726 SetAIFlag('FALLINHOLE', '1');
7727 end;
7729 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7730 if GetAIFlag('FALLINHOLE') <> '' then
7731 if OnGround() then
7732 RemoveAIFlag('FALLINHOLE');
7734 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7735 if not (KeyPressed(KEY_LEFT) or KeyPressed(KEY_RIGHT)) then
7736 if GetAIFlag('FALLINHOLE') = '' then
7737 if (not OnLadder()) or (FObj.Vel.Y >= 0) or (OnTopLift()) then
7738 if Rnd(2) then
7739 GoLeft(360)
7740 else
7741 GoRight(360);
7743 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7744 if OnGround() and
7745 CanJumpUp(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*32) and
7746 Rnd(8) then
7747 Jump();
7749 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7750 if OnGround() and NearHole() then
7751 if NearDeepHole() then // Åñëè ýòî áåçäíà
7752 case Random(6) of
7753 0..3: Turn(); // Áåæèì îáðàòíî
7754 4: Jump(); // Ïðûãàåì
7755 5: begin // Ïðûãàåì îáðàòíî
7756 Turn();
7757 Jump();
7758 end;
7759 end
7760 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7761 if GetAIFlag('GOINHOLE') = '' then
7762 case Random(6) of
7763 0: Turn(); // Íå íóæíî òóäà
7764 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7765 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7766 if BorderHole() then
7767 SetAIFlag('GOINHOLE', '1');
7768 end;
7770 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7771 if (not CanRun()) and OnGround() then
7772 begin
7773 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7774 if CanJumpOver() or OnLadder() then
7775 Jump()
7776 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7777 if Random(2) = 0 then
7778 begin
7779 if IsSafeTrigger() then
7780 PressKey(KEY_OPEN);
7781 end else
7782 Turn();
7783 end;
7785 // Îñòàëîñü ìàëî âîçäóõà:
7786 if FAir < 36 * 2 then
7787 Jump(20);
7789 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7790 if (FMegaRulez[MR_SUIT] < gTime) and ((FLastHit = HIT_ACID) or (Healthy() <= 1)) then
7791 if BodyInAcid(0, 0) then
7792 Jump();
7793 end;
7795 function TBot.FullInStep(XInc, YInc: Integer): Boolean;
7796 begin
7797 Result := g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc,
7798 PLAYER_RECT.Width, PLAYER_RECT.Height, PANEL_STEP, False);
7799 end;
7801 {function TBot.NeedItem(Item: Byte): Byte;
7802 begin
7803 Result := 4;
7804 end;}
7806 procedure TBot.SelectWeapon(Dist: Integer);
7807 var
7808 a: Integer;
7810 function HaveAmmo(weapon: Byte): Boolean;
7811 begin
7812 case weapon of
7813 WEAPON_PISTOL: Result := FAmmo[A_BULLETS] >= 1;
7814 WEAPON_SHOTGUN1: Result := FAmmo[A_SHELLS] >= 1;
7815 WEAPON_SHOTGUN2: Result := FAmmo[A_SHELLS] >= 2;
7816 WEAPON_CHAINGUN: Result := FAmmo[A_BULLETS] >= 10;
7817 WEAPON_ROCKETLAUNCHER: Result := FAmmo[A_ROCKETS] >= 1;
7818 WEAPON_PLASMA: Result := FAmmo[A_CELLS] >= 10;
7819 WEAPON_BFG: Result := FAmmo[A_CELLS] >= 40;
7820 WEAPON_SUPERPULEMET: Result := FAmmo[A_SHELLS] >= 1;
7821 WEAPON_FLAMETHROWER: Result := FAmmo[A_FUEL] >= 1;
7822 else Result := True;
7823 end;
7824 end;
7826 begin
7827 if Dist = -1 then Dist := BOT_LONGDIST;
7829 if Dist > BOT_LONGDIST then
7830 begin // Äàëüíèé áîé
7831 for a := 0 to 9 do
7832 if FWeapon[FDifficult.WeaponPrior[a]] and HaveAmmo(FDifficult.WeaponPrior[a]) then
7833 begin
7834 FSelectedWeapon := FDifficult.WeaponPrior[a];
7835 Break;
7836 end;
7837 end
7838 else //if Dist > BOT_UNSAFEDIST then
7839 begin // Áëèæíèé áîé
7840 for a := 0 to 9 do
7841 if FWeapon[FDifficult.CloseWeaponPrior[a]] and HaveAmmo(FDifficult.CloseWeaponPrior[a]) then
7842 begin
7843 FSelectedWeapon := FDifficult.CloseWeaponPrior[a];
7844 Break;
7845 end;
7846 end;
7847 { else
7848 begin
7849 for a := 0 to 9 do
7850 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7851 begin
7852 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7853 Break;
7854 end;
7855 end;}
7856 end;
7858 function TBot.PickItem(ItemType: Byte; force: Boolean; var remove: Boolean): Boolean;
7859 begin
7860 Result := inherited PickItem(ItemType, force, remove);
7862 if Result then SetAIFlag('SELECTWEAPON', '1');
7863 end;
7865 function TBot.Heal(value: Word; Soft: Boolean): Boolean;
7866 begin
7867 Result := inherited Heal(value, Soft);
7868 end;
7870 function TBot.Healthy(): Byte;
7871 begin
7872 if FMegaRulez[MR_INVUL] >= gTime then Result := 3
7873 else if (FHealth > 80) or ((FHealth > 50) and (FArmor > 20)) then Result := 3
7874 else if (FHealth > 50) then Result := 2
7875 else if (FHealth > 20) then Result := 1
7876 else Result := 0;
7877 end;
7879 function TBot.TargetOnScreen(TX, TY: Integer): Boolean;
7880 begin
7881 Result := (Abs(FObj.X-TX) <= Trunc(gPlayerScreenSize.X*0.6)) and
7882 (Abs(FObj.Y-TY) <= Trunc(gPlayerScreenSize.Y*0.6));
7883 end;
7885 procedure TBot.OnDamage(Angle: SmallInt);
7886 var
7887 pla: TPlayer;
7888 mon: TMonster;
7889 ok: Boolean;
7890 begin
7891 inherited;
7893 if (Angle = 0) or (Angle = 180) then
7894 begin
7895 ok := False;
7896 if (g_GetUIDType(FLastSpawnerUID) = UID_PLAYER) and
7897 LongBool(gGameSettings.Options and GAME_OPTION_BOTVSPLAYER) then
7898 begin // Èãðîê
7899 pla := g_Player_Get(FLastSpawnerUID);
7900 ok := not TargetOnScreen(pla.FObj.X + PLAYER_RECT.X,
7901 pla.FObj.Y + PLAYER_RECT.Y);
7902 end
7903 else
7904 if (g_GetUIDType(FLastSpawnerUID) = UID_MONSTER) and
7905 LongBool(gGameSettings.Options and GAME_OPTION_BOTVSMONSTER) then
7906 begin // Ìîíñòð
7907 mon := g_Monsters_ByUID(FLastSpawnerUID);
7908 ok := not TargetOnScreen(mon.Obj.X + mon.Obj.Rect.X,
7909 mon.Obj.Y + mon.Obj.Rect.Y);
7910 end;
7912 if ok then
7913 if Angle = 0 then
7914 SetAIFlag('ATTACKLEFT', '1')
7915 else
7916 SetAIFlag('ATTACKRIGHT', '1');
7917 end;
7918 end;
7920 function TBot.RunDirection(): TDirection;
7921 begin
7922 if Abs(Vel.X) >= 1 then
7923 begin
7924 if Vel.X > 0 then Result := TDirection.D_RIGHT else Result := TDirection.D_LEFT;
7925 end else
7926 Result := FDirection;
7927 end;
7929 function TBot.GetRnd(a: Byte): Boolean;
7930 begin
7931 if a = 0 then Result := False
7932 else if a = 255 then Result := True
7933 else Result := Random(256) > 255-a;
7934 end;
7936 function TBot.GetInterval(a: Byte; radius: SmallInt): SmallInt;
7937 begin
7938 Result := Round((255-a)/255*radius*(Random(2)-1));
7939 end;
7942 procedure TDifficult.save (st: TStream);
7943 begin
7944 utils.writeInt(st, Byte(DiagFire));
7945 utils.writeInt(st, Byte(InvisFire));
7946 utils.writeInt(st, Byte(DiagPrecision));
7947 utils.writeInt(st, Byte(FlyPrecision));
7948 utils.writeInt(st, Byte(Cover));
7949 utils.writeInt(st, Byte(CloseJump));
7950 st.WriteBuffer(WeaponPrior[Low(WeaponPrior)], sizeof(WeaponPrior));
7951 st.WriteBuffer(CloseWeaponPrior[Low(CloseWeaponPrior)], sizeof(CloseWeaponPrior));
7952 end;
7954 procedure TDifficult.load (st: TStream);
7955 begin
7956 DiagFire := utils.readByte(st);
7957 InvisFire := utils.readByte(st);
7958 DiagPrecision := utils.readByte(st);
7959 FlyPrecision := utils.readByte(st);
7960 Cover := utils.readByte(st);
7961 CloseJump := utils.readByte(st);
7962 st.ReadBuffer(WeaponPrior[Low(WeaponPrior)], sizeof(WeaponPrior));
7963 st.ReadBuffer(CloseWeaponPrior[Low(CloseWeaponPrior)], sizeof(CloseWeaponPrior));
7964 end;
7967 procedure TBot.SaveState (st: TStream);
7968 var
7969 i: Integer;
7970 dw: Integer;
7971 begin
7972 inherited SaveState(st);
7973 utils.writeSign(st, 'BOT0');
7974 // Âûáðàííîå îðóæèå
7975 utils.writeInt(st, Byte(FSelectedWeapon));
7976 // UID öåëè
7977 utils.writeInt(st, Word(FTargetUID));
7978 // Âðåìÿ ïîòåðè öåëè
7979 utils.writeInt(st, LongWord(FLastVisible));
7980 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7981 dw := Length(FAIFlags);
7982 utils.writeInt(st, LongInt(dw));
7983 // Ôëàãè ÈÈ
7984 for i := 0 to dw-1 do
7985 begin
7986 utils.writeStr(st, FAIFlags[i].Name, 20);
7987 utils.writeStr(st, FAIFlags[i].Value, 20);
7988 end;
7989 // Íàñòðîéêè ñëîæíîñòè
7990 FDifficult.save(st);
7991 end;
7994 procedure TBot.LoadState (st: TStream);
7995 var
7996 i: Integer;
7997 dw: Integer;
7998 begin
7999 inherited LoadState(st);
8000 if not utils.checkSign(st, 'BOT0') then raise XStreamError.Create('invalid bot signature');
8001 // Âûáðàííîå îðóæèå
8002 FSelectedWeapon := utils.readByte(st);
8003 // UID öåëè
8004 FTargetUID := utils.readWord(st);
8005 // Âðåìÿ ïîòåðè öåëè
8006 FLastVisible := utils.readLongWord(st);
8007 // Êîëè÷åñòâî ôëàãîâ ÈÈ
8008 dw := utils.readLongInt(st);
8009 if (dw < 0) or (dw > 16384) then raise XStreamError.Create('invalid number of bot AI flags');
8010 SetLength(FAIFlags, dw);
8011 // Ôëàãè ÈÈ
8012 for i := 0 to dw-1 do
8013 begin
8014 FAIFlags[i].Name := utils.readStr(st, 20);
8015 FAIFlags[i].Value := utils.readStr(st, 20);
8016 end;
8017 // Íàñòðîéêè ñëîæíîñòè
8018 FDifficult.load(st);
8019 end;
8022 begin
8023 conRegVar('cheat_berserk_autoswitch', @gBerserkAutoswitch, 'autoswitch to fist when berserk pack taken', '', true, true);
8024 conRegVar('player_indicator', @gPlayerIndicator, 'Draw indicator only for current player, also for teammates, or not at all', 'Draw indicator only for current player, also for teammates, or not at all');
8025 conRegVar('player_indicator_style', @gPlayerIndicatorStyle, 'Visual appearance of indicator', 'Visual appearance of indicator');
8026 end.