DEADSOFTWARE

Add option to skip fist switching
[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 if (FSkipFist = 1) and (not (R_BERSERK in FRulez)) then
2047 result := false
2048 else if (FSwitchToEmpty = 0) and not hasAmmoForWeapon(Weapon) then
2049 result := false
2050 end;
2052 procedure TPlayer.SwitchTeam;
2053 begin
2054 if g_Game_IsClient then
2055 Exit;
2056 if not (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then Exit;
2058 if gGameOn and FAlive then
2059 Kill(K_SIMPLEKILL, FUID, HIT_SELF);
2061 if FTeam = TEAM_RED then
2062 begin
2063 ChangeTeam(TEAM_BLUE);
2064 g_Console_Add(Format(_lc[I_PLAYER_CHTEAM_BLUE], [FName]), True);
2065 if g_Game_IsNet then
2066 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM, TEAM_BLUE, FName);
2067 end
2068 else
2069 begin
2070 ChangeTeam(TEAM_RED);
2071 g_Console_Add(Format(_lc[I_PLAYER_CHTEAM_RED], [FName]), True);
2072 if g_Game_IsNet then
2073 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM, TEAM_RED, FName);
2074 end;
2075 FPreferredTeam := FTeam;
2076 end;
2078 procedure TPlayer.ChangeTeam(Team: Byte);
2079 var
2080 OldTeam: Byte;
2081 begin
2082 OldTeam := FTeam;
2083 FTeam := Team;
2084 case Team of
2085 TEAM_RED, TEAM_BLUE:
2086 FModel.Color := TEAMCOLOR[Team];
2087 else
2088 FModel.Color := FColor;
2089 end;
2090 if (FTeam <> OldTeam) and g_Game_IsNet and g_Game_IsServer then
2091 MH_SEND_PlayerStats(FUID);
2092 end;
2095 procedure TPlayer.CollideItem();
2096 var
2097 i: Integer;
2098 r: Boolean;
2099 begin
2100 if gItems = nil then Exit;
2101 if not FAlive then Exit;
2103 for i := 0 to High(gItems) do
2104 with gItems[i] do
2105 begin
2106 if (ItemType <> ITEM_NONE) and alive then
2107 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
2108 PLAYER_RECT.Height, @Obj) then
2109 begin
2110 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
2112 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
2113 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
2114 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
2115 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
2116 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
2118 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
2119 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
2120 (gGameSettings.GameType = GT_SINGLE) and
2121 (g_Player_GetCount() > 1)) then
2122 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
2123 end;
2124 end;
2125 end;
2128 function TPlayer.CollideLevel(XInc, YInc: Integer): Boolean;
2129 begin
2130 Result := g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc,
2131 PLAYER_RECT.Width, PLAYER_RECT.Height, PANEL_WALL,
2132 False);
2133 end;
2135 constructor TPlayer.Create();
2136 begin
2137 viewPortX := 0;
2138 viewPortY := 0;
2139 viewPortW := 0;
2140 viewPortH := 0;
2141 mEDamageType := HIT_SOME;
2143 FIamBot := False;
2144 FDummy := False;
2145 FSpawned := False;
2147 FSawSound := TPlayableSound.Create();
2148 FSawSoundIdle := TPlayableSound.Create();
2149 FSawSoundHit := TPlayableSound.Create();
2150 FSawSoundSelect := TPlayableSound.Create();
2151 FFlameSoundOn := TPlayableSound.Create();
2152 FFlameSoundOff := TPlayableSound.Create();
2153 FFlameSoundWork := TPlayableSound.Create();
2154 FJetSoundFly := TPlayableSound.Create();
2155 FJetSoundOn := TPlayableSound.Create();
2156 FJetSoundOff := TPlayableSound.Create();
2158 FSawSound.SetByName('SOUND_WEAPON_FIRESAW');
2159 FSawSoundIdle.SetByName('SOUND_WEAPON_IDLESAW');
2160 FSawSoundHit.SetByName('SOUND_WEAPON_HITSAW');
2161 FSawSoundSelect.SetByName('SOUND_WEAPON_SELECTSAW');
2162 FFlameSoundOn.SetByName('SOUND_WEAPON_FLAMEON');
2163 FFlameSoundOff.SetByName('SOUND_WEAPON_FLAMEOFF');
2164 FFlameSoundWork.SetByName('SOUND_WEAPON_FLAMEWORK');
2165 FJetSoundFly.SetByName('SOUND_PLAYER_JETFLY');
2166 FJetSoundOn.SetByName('SOUND_PLAYER_JETON');
2167 FJetSoundOff.SetByName('SOUND_PLAYER_JETOFF');
2169 FSpectatePlayer := -1;
2170 FClientID := -1;
2171 FPing := 0;
2172 FLoss := 0;
2173 FSavedStateNum := -1;
2174 FShellTimer := -1;
2175 FFireTime := 0;
2176 FFirePainTime := 0;
2177 FFireAttacker := 0;
2178 FHandicap := 100;
2179 FCorpse := -1;
2181 FActualModelName := 'doomer';
2183 g_Obj_Init(@FObj);
2184 FObj.Rect := PLAYER_RECT;
2186 FBFGFireCounter := -1;
2187 FJustTeleported := False;
2188 FNetTime := 0;
2190 FWaitForFirstSpawn := false;
2192 resetWeaponQueue();
2193 end;
2195 procedure TPlayer.positionChanged (); inline;
2196 begin
2197 end;
2199 procedure TPlayer.doDamage (v: Integer);
2200 begin
2201 if (v <= 0) then exit;
2202 if (v > 32767) then v := 32767;
2203 Damage(v, 0, 0, 0, mEDamageType);
2204 end;
2206 procedure TPlayer.Damage(value: Word; SpawnerUID: Word; vx, vy: Integer; t: Byte);
2207 var
2208 c: Word;
2209 begin
2210 if (not g_Game_IsClient) and (not FAlive) then
2211 Exit;
2213 FLastHit := t;
2215 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2216 if ((t = HIT_TRAP) or (t = HIT_SELF)) and (not FGodMode) then
2217 begin
2218 if not g_Game_IsClient then
2219 begin
2220 FArmor := 0;
2221 if t = HIT_TRAP then
2222 begin
2223 // Ëîâóøêà óáèâàåò ñðàçó:
2224 FHealth := -100;
2225 Kill(K_EXTRAHARDKILL, SpawnerUID, t);
2226 end;
2227 if t = HIT_SELF then
2228 begin
2229 // Ñàìîóáèéñòâî:
2230 FHealth := 0;
2231 Kill(K_SIMPLEKILL, SpawnerUID, t);
2232 end;
2233 end;
2234 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2235 FMegaRulez[MR_SUIT] := 0;
2236 FMegaRulez[MR_INVUL] := 0;
2237 FMegaRulez[MR_INVIS] := 0;
2238 FSpawnInvul := 0;
2239 FBerserk := 0;
2240 end;
2242 // Íî îò îñòàëüíîãî ñïàñàåò:
2243 if FMegaRulez[MR_INVUL] >= gTime then
2244 Exit;
2246 // ×èò-êîä "ÃÎÐÅÖ":
2247 if FGodMode then
2248 Exit;
2250 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2251 if LongBool(gGameSettings.Options and GAME_OPTION_TEAMDAMAGE) or
2252 (SpawnerUID = FUID) or
2253 (not SameTeam(FUID, SpawnerUID)) then
2254 begin
2255 FLastSpawnerUID := SpawnerUID;
2257 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2258 if gBloodCount > 0 then
2259 begin
2260 c := Min(value, 200)*gBloodCount + Random(Min(value, 200) div 2);
2261 if value div 4 <= c then
2262 c := c - (value div 4)
2263 else
2264 c := 0;
2266 if (t = HIT_SOME) and (vx = 0) and (vy = 0) then
2267 MakeBloodSimple(c)
2268 else
2269 case t of
2270 HIT_TRAP, HIT_ACID, HIT_FLAME, HIT_SELF: MakeBloodSimple(c);
2271 HIT_BFG, HIT_ROCKET, HIT_SOME: MakeBloodVector(c, vx, vy);
2272 end;
2274 if t = HIT_WATER then
2275 g_GFX_Bubbles(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2),
2276 FObj.Y+PLAYER_RECT.Y-4, value div 2, 8, 4);
2277 end;
2279 // Áóôåð óðîíà:
2280 if FAlive then
2281 Inc(FDamageBuffer, value);
2283 // Âñïûøêà áîëè:
2284 if gFlash <> 0 then
2285 FPain := FPain + value;
2286 end;
2288 if g_Game_IsServer and g_Game_IsNet then
2289 begin
2290 MH_SEND_PlayerDamage(FUID, t, SpawnerUID, value, vx, vy);
2291 MH_SEND_PlayerStats(FUID);
2292 MH_SEND_PlayerPos(False, FUID);
2293 end;
2294 end;
2296 function TPlayer.Heal(value: Word; Soft: Boolean): Boolean;
2297 begin
2298 Result := False;
2299 if g_Game_IsClient then
2300 Exit;
2301 if not FAlive then
2302 Exit;
2304 if Soft and (FHealth < PLAYER_HP_SOFT) then
2305 begin
2306 IncMax(FHealth, value, PLAYER_HP_SOFT);
2307 Result := True;
2308 end;
2309 if (not Soft) and (FHealth < PLAYER_HP_LIMIT) then
2310 begin
2311 IncMax(FHealth, value, PLAYER_HP_LIMIT);
2312 Result := True;
2313 end;
2315 if Result and g_Game_IsServer and g_Game_IsNet then
2316 MH_SEND_PlayerStats(FUID);
2317 end;
2319 destructor TPlayer.Destroy();
2320 begin
2321 if (gPlayer1 <> nil) and (gPlayer1.FUID = FUID) then
2322 gPlayer1 := nil;
2323 if (gPlayer2 <> nil) and (gPlayer2.FUID = FUID) then
2324 gPlayer2 := nil;
2326 FSawSound.Free();
2327 FSawSoundIdle.Free();
2328 FSawSoundHit.Free();
2329 FSawSoundSelect.Free();
2330 FFlameSoundOn.Free();
2331 FFlameSoundOff.Free();
2332 FFlameSoundWork.Free();
2333 FJetSoundFly.Free();
2334 FJetSoundOn.Free();
2335 FJetSoundOff.Free();
2336 FModel.Free();
2337 if FPunchAnim <> nil then
2338 FPunchAnim.Free();
2340 inherited;
2341 end;
2343 procedure TPlayer.DrawIndicator(Color: TRGB);
2344 var
2345 indX, indY, fX, fY, fSlope: Integer;
2346 indW, indH: Word;
2347 indA: Single;
2348 a: TDFPoint;
2349 nW, nH: Byte;
2350 ID: DWORD;
2351 c: TRGB;
2352 begin
2353 if FAlive then
2354 begin
2355 FObj.lerp(gLerpFactor, fX, fY);
2356 fSlope := nlerp(FSlopeOld, FObj.slopeUpLeft, gLerpFactor);
2358 case gPlayerIndicatorStyle of
2359 0:
2360 begin
2361 if g_Texture_Get('TEXTURE_PLAYER_INDICATOR', ID) then
2362 begin
2363 e_GetTextureSize(ID, @indW, @indH);
2364 a.X := indW div 2;
2365 a.Y := indH div 2;
2367 if (FObj.X + FObj.Rect.X) < 0 then
2368 begin
2369 indA := 90;
2370 indX := fX + FObj.Rect.X + FObj.Rect.Width;
2371 indY := fY + FObj.Rect.Y + (FObj.Rect.Height - indW) div 2;
2372 end
2374 else if (FObj.X + FObj.Rect.X + FObj.Rect.Width) > Max(gMapInfo.Width, gPlayerScreenSize.X) then
2375 begin
2376 indA := 270;
2377 indX := fX + FObj.Rect.X - indH;
2378 indY := fY + FObj.Rect.Y + (FObj.Rect.Height - indW) div 2;
2379 end
2381 else if (FObj.Y - indH) < 0 then
2382 begin
2383 indA := 180;
2384 indX := fX + FObj.Rect.X + (FObj.Rect.Width - indW) div 2;
2385 indY := fY + FObj.Rect.Y + FObj.Rect.Height;
2386 end
2388 else
2389 begin
2390 indA := 0;
2391 indX := fX + FObj.Rect.X + (FObj.Rect.Width - indW) div 2;
2392 indY := fY - indH;
2393 end;
2395 indY := indY + fSlope;
2396 indX := EnsureRange(indX, 0, Max(gMapInfo.Width, gPlayerScreenSize.X) - indW);
2397 indY := EnsureRange(indY, 0, Max(gMapInfo.Height, gPlayerScreenSize.Y) - indH);
2399 c := e_Colors;
2400 e_Colors := Color;
2401 e_DrawAdv(ID, indX, indY, 0, True, False, indA, @a);
2402 e_Colors := c;
2403 end;
2404 end;
2406 1:
2407 begin
2408 e_TextureFontGetSize(gStdFont, nW, nH);
2409 indX := fX + FObj.Rect.X + (FObj.Rect.Width - Length(FName) * nW) div 2;
2410 indY := fY - nH + fSlope;
2411 e_TextureFontPrintEx(indX, indY, FName, gStdFont, Color.R, Color.G, Color.B, 1.0, True);
2412 end;
2413 end;
2414 end;
2415 end;
2417 procedure TPlayer.DrawBubble();
2418 var
2419 bubX, bubY, fX, fY: Integer;
2420 ID: LongWord;
2421 Rb, Gb, Bb,
2422 Rw, Gw, Bw: SmallInt;
2423 Dot: Byte;
2424 CObj: TObj;
2425 begin
2426 CObj := getCameraObj();
2427 CObj.lerp(gLerpFactor, fX, fY);
2428 // NB: _F_Obj.Rect is used to keep the bubble higher; this is not a mistake
2429 bubX := fX+FObj.Rect.X + IfThen(FDirection = TDirection.D_LEFT, -4, 18);
2430 bubY := fY+FObj.Rect.Y - 18;
2431 Rb := 64;
2432 Gb := 64;
2433 Bb := 64;
2434 Rw := 240;
2435 Gw := 240;
2436 Bw := 240;
2437 case gChatBubble of
2438 1: // simple textual non-bubble
2439 begin
2440 bubX := fX+FObj.Rect.X - 11;
2441 bubY := fY+FObj.Rect.Y - 17;
2442 e_TextureFontPrint(bubX, bubY, '[...]', gStdFont);
2443 Exit;
2444 end;
2445 2: // advanced pixel-perfect bubble
2446 begin
2447 if FTeam = TEAM_RED then
2448 Rb := 255
2449 else
2450 if FTeam = TEAM_BLUE then
2451 Bb := 255;
2452 end;
2453 3: // colored bubble
2454 begin
2455 Rb := FModel.Color.R;
2456 Gb := FModel.Color.G;
2457 Bb := FModel.Color.B;
2458 Rw := Min(Rb * 2 + 64, 255);
2459 Gw := Min(Gb * 2 + 64, 255);
2460 Bw := Min(Bb * 2 + 64, 255);
2461 if (Abs(Rw - Rb) < 32)
2462 or (Abs(Gw - Gb) < 32)
2463 or (Abs(Bw - Bb) < 32) then
2464 begin
2465 Rb := Max(Rw div 2 - 16, 0);
2466 Gb := Max(Gw div 2 - 16, 0);
2467 Bb := Max(Bw div 2 - 16, 0);
2468 end;
2469 end;
2470 4: // custom textured bubble
2471 begin
2472 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID) then
2473 if FDirection = TDirection.D_RIGHT then
2474 e_Draw(ID, bubX - 6, bubY - 7, 0, True, False)
2475 else
2476 e_Draw(ID, bubX - 6, bubY - 7, 0, True, False, TMirrorType.Horizontal);
2477 Exit;
2478 end;
2479 end;
2481 // Outer borders
2482 e_DrawQuad(bubX + 1, bubY , bubX + 18, bubY + 13, Rb, Gb, Bb);
2483 e_DrawQuad(bubX , bubY + 1, bubX + 19, bubY + 12, Rb, Gb, Bb);
2484 // Inner box
2485 e_DrawFillQuad(bubX + 1, bubY + 1, bubX + 18, bubY + 12, Rw, Gw, Bw, 0);
2487 // Tail
2488 Dot := IfThen(FDirection = TDirection.D_LEFT, 14, 5);
2489 e_DrawLine(1, bubX + Dot, bubY + 14, bubX + Dot, bubY + 16, Rb, Gb, Bb);
2490 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);
2491 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);
2492 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);
2493 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);
2495 // Dots
2496 Dot := 6;
2497 e_DrawFillQuad(bubX + Dot, bubY + 8, bubX + Dot + 1, bubY + 9, Rb, Gb, Bb, 0);
2498 e_DrawFillQuad(bubX + Dot + 3, bubY + 8, bubX + Dot + 4, bubY + 9, Rb, Gb, Bb, 0);
2499 e_DrawFillQuad(bubX + Dot + 6, bubY + 8, bubX + Dot + 7, bubY + 9, Rb, Gb, Bb, 0);
2500 end;
2502 procedure TPlayer.Draw();
2503 var
2504 ID: DWORD;
2505 w, h: Word;
2506 dr: Boolean;
2507 Mirror: TMirrorType;
2508 fX, fY, fSlope: Integer;
2509 begin
2510 FObj.lerp(gLerpFactor, fX, fY);
2511 fSlope := nlerp(FSlopeOld, FObj.slopeUpLeft, gLerpFactor);
2513 if FAlive then
2514 begin
2515 if Direction = TDirection.D_RIGHT then
2516 Mirror := TMirrorType.None
2517 else
2518 Mirror := TMirrorType.Horizontal;
2520 if FPunchAnim <> nil then
2521 begin
2522 FPunchAnim.Draw(fX+IfThen(Direction = TDirection.D_LEFT, 15-FObj.Rect.X, FObj.Rect.X-15),
2523 fY+fSlope+FObj.Rect.Y-11, Mirror);
2524 if FPunchAnim.played then
2525 begin
2526 FPunchAnim.Free;
2527 FPunchAnim := nil;
2528 end;
2529 end;
2531 if (FMegaRulez[MR_INVUL] > gTime) and ((gPlayerDrawn <> Self) or (FSpawnInvul >= gTime)) then
2532 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID) then
2533 begin
2534 e_GetTextureSize(ID, @w, @h);
2535 if FDirection = TDirection.D_LEFT then
2536 e_Draw(ID, fX+FObj.Rect.X+(FObj.Rect.Width div 2)-(w div 2)+4,
2537 fY+FObj.Rect.Y+(FObj.Rect.Height div 2)-(h div 2)-7+fSlope, 0, True, False)
2538 else
2539 e_Draw(ID, fX+FObj.Rect.X+(FObj.Rect.Width div 2)-(w div 2)-2,
2540 fY+FObj.Rect.Y+(FObj.Rect.Height div 2)-(h div 2)-7+fSlope, 0, True, False);
2541 end;
2543 if FMegaRulez[MR_INVIS] > gTime then
2544 begin
2545 if (gPlayerDrawn <> nil) and ((Self = gPlayerDrawn) or
2546 ((FTeam = gPlayerDrawn.Team) and (gGameSettings.GameMode <> GM_DM))) then
2547 begin
2548 if (FMegaRulez[MR_INVIS] - gTime) <= 2100 then
2549 dr := not Odd((FMegaRulez[MR_INVIS] - gTime) div 300)
2550 else
2551 dr := True;
2552 if dr then
2553 FModel.Draw(fX, fY+fSlope, 200)
2554 else
2555 FModel.Draw(fX, fY+fSlope);
2556 end
2557 else
2558 FModel.Draw(fX, fY+fSlope, 254);
2559 end
2560 else
2561 FModel.Draw(fX, fY+fSlope);
2562 end;
2564 if g_debug_Frames then
2565 begin
2566 e_DrawQuad(FObj.X+FObj.Rect.X,
2567 FObj.Y+FObj.Rect.Y,
2568 FObj.X+FObj.Rect.X+FObj.Rect.Width-1,
2569 FObj.Y+FObj.Rect.Y+FObj.Rect.Height-1,
2570 0, 255, 0);
2571 end;
2573 if (gChatBubble > 0) and (FKeys[KEY_CHAT].Pressed) and not FGhost then
2574 if (FMegaRulez[MR_INVIS] <= gTime) or ((gPlayerDrawn <> nil) and ((Self = gPlayerDrawn) or
2575 ((FTeam = gPlayerDrawn.Team) and (gGameSettings.GameMode <> GM_DM)))) then
2576 DrawBubble();
2577 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2578 if gAimLine and alive and
2579 ((Self = gPlayer1) or (Self = gPlayer2)) then
2580 DrawAim();
2581 end;
2584 procedure TPlayer.DrawAim();
2585 procedure drawCast (sz: Integer; ax0, ay0, ax1, ay1: Integer);
2586 var
2587 ex, ey: Integer;
2588 begin
2590 {$IFDEF ENABLE_HOLMES}
2591 if isValidViewPort and (self = gPlayer1) then
2592 begin
2593 g_Holmes_plrLaser(ax0, ay0, ax1, ay1);
2594 end;
2595 {$ENDIF}
2597 e_DrawLine(sz, ax0, ay0, ax1, ay1, 255, 0, 0, 96);
2598 if (g_Map_traceToNearestWall(ax0, ay0, ax1, ay1, @ex, @ey) <> nil) then
2599 begin
2600 e_DrawLine(sz, ax0, ay0, ex, ey, 0, 255, 0, 96);
2601 end
2602 else
2603 begin
2604 e_DrawLine(sz, ax0, ay0, ex, ey, 0, 0, 255, 96);
2605 end;
2606 end;
2608 var
2609 wx, wy, xx, yy: Integer;
2610 angle: SmallInt;
2611 sz, len: Word;
2612 begin
2613 wx := FObj.X + WEAPONPOINT[FDirection].X + IfThen(FDirection = TDirection.D_LEFT, 7, -7);
2614 wy := FObj.Y + WEAPONPOINT[FDirection].Y;
2615 angle := FAngle;
2616 len := 1024;
2617 sz := 2;
2618 case FCurrWeap of
2619 0: begin // Punch
2620 len := 12;
2621 sz := 4;
2622 end;
2623 1: begin // Chainsaw
2624 len := 24;
2625 sz := 6;
2626 end;
2627 2: begin // Pistol
2628 len := 1024;
2629 sz := 2;
2630 if angle = ANGLE_RIGHTUP then Dec(angle, 2);
2631 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2632 if angle = ANGLE_LEFTUP then Inc(angle, 2);
2633 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2634 end;
2635 3: begin // Shotgun
2636 len := 1024;
2637 sz := 3;
2638 if angle = ANGLE_RIGHTUP then Dec(angle, 2);
2639 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2640 if angle = ANGLE_LEFTUP then Inc(angle, 2);
2641 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2642 end;
2643 4: begin // Double Shotgun
2644 len := 1024;
2645 sz := 4;
2646 if angle = ANGLE_RIGHTUP then Dec(angle, 2);
2647 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2648 if angle = ANGLE_LEFTUP then Inc(angle, 2);
2649 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2650 end;
2651 5: begin // Chaingun
2652 len := 1024;
2653 sz := 3;
2654 if angle = ANGLE_RIGHTUP then Dec(angle, 2);
2655 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2656 if angle = ANGLE_LEFTUP then Inc(angle, 2);
2657 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2658 end;
2659 6: begin // Rocket Launcher
2660 len := 1024;
2661 sz := 7;
2662 if angle = ANGLE_RIGHTUP then Inc(angle, 2);
2663 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2664 if angle = ANGLE_LEFTUP then Dec(angle, 2);
2665 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2666 end;
2667 7: begin // Plasmagun
2668 len := 1024;
2669 sz := 5;
2670 if angle = ANGLE_RIGHTUP then Inc(angle);
2671 if angle = ANGLE_RIGHTDOWN then Inc(angle, 3);
2672 if angle = ANGLE_LEFTUP then Dec(angle);
2673 if angle = ANGLE_LEFTDOWN then Dec(angle, 3);
2674 end;
2675 8: begin // BFG
2676 len := 1024;
2677 sz := 12;
2678 if angle = ANGLE_RIGHTUP then Inc(angle, 1);
2679 if angle = ANGLE_RIGHTDOWN then Inc(angle, 2);
2680 if angle = ANGLE_LEFTUP then Dec(angle, 1);
2681 if angle = ANGLE_LEFTDOWN then Dec(angle, 2);
2682 end;
2683 9: begin // Super Chaingun
2684 len := 1024;
2685 sz := 4;
2686 if angle = ANGLE_RIGHTUP then Dec(angle, 2);
2687 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2688 if angle = ANGLE_LEFTUP then Inc(angle, 2);
2689 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2690 end;
2691 end;
2692 xx := Trunc(Cos(-DegToRad(angle)) * len) + wx;
2693 yy := Trunc(Sin(-DegToRad(angle)) * len) + wy;
2694 {$IF DEFINED(D2F_DEBUG)}
2695 drawCast(sz, wx, wy, xx, yy);
2696 {$ELSE}
2697 e_DrawLine(sz, wx, wy, xx, yy, 255, 0, 0, 96);
2698 {$ENDIF}
2699 end;
2701 procedure TPlayer.DrawGUI();
2702 var
2703 ID: DWORD;
2704 X, Y, SY, a, p, m: Integer;
2705 tw, th: Word;
2706 cw, ch: Byte;
2707 s: string;
2708 stat: TPlayerStatArray;
2709 begin
2710 X := gPlayerScreenSize.X;
2711 SY := gPlayerScreenSize.Y;
2712 Y := 0;
2714 if gShowGoals and (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
2715 begin
2716 if gGameSettings.GameMode = GM_CTF then
2717 a := 32 + 8
2718 else
2719 a := 0;
2720 if gGameSettings.GameMode = GM_CTF then
2721 begin
2722 s := 'TEXTURE_PLAYER_REDFLAG';
2723 if gFlags[FLAG_RED].State = FLAG_STATE_CAPTURED then
2724 s := 'TEXTURE_PLAYER_REDFLAG_S';
2725 if gFlags[FLAG_RED].State = FLAG_STATE_DROPPED then
2726 s := 'TEXTURE_PLAYER_REDFLAG_D';
2727 if g_Texture_Get(s, ID) then
2728 e_Draw(ID, X-16-32, 240-72-4, 0, True, False);
2729 end;
2731 s := IntToStr(gTeamStat[TEAM_RED].Goals);
2732 e_CharFont_GetSize(gMenuFont, s, tw, th);
2733 e_CharFont_PrintEx(gMenuFont, X-16-a-tw, 240-72-4, s, TEAMCOLOR[TEAM_RED]);
2735 if gGameSettings.GameMode = GM_CTF then
2736 begin
2737 s := 'TEXTURE_PLAYER_BLUEFLAG';
2738 if gFlags[FLAG_BLUE].State = FLAG_STATE_CAPTURED then
2739 s := 'TEXTURE_PLAYER_BLUEFLAG_S';
2740 if gFlags[FLAG_BLUE].State = FLAG_STATE_DROPPED then
2741 s := 'TEXTURE_PLAYER_BLUEFLAG_D';
2742 if g_Texture_Get(s, ID) then
2743 e_Draw(ID, X-16-32, 240-32-4, 0, True, False);
2744 end;
2746 s := IntToStr(gTeamStat[TEAM_BLUE].Goals);
2747 e_CharFont_GetSize(gMenuFont, s, tw, th);
2748 e_CharFont_PrintEx(gMenuFont, X-16-a-tw, 240-32-4, s, TEAMCOLOR[TEAM_BLUE]);
2749 end;
2751 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID) then
2752 e_DrawFill(ID, X, 0, 1, (gPlayerScreenSize.Y div 256)+IfThen(gPlayerScreenSize.Y mod 256 > 0, 1, 0),
2753 0, False, False);
2755 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID) then
2756 e_Draw(ID, X+2, Y, 0, True, False);
2758 if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
2759 begin
2760 if gShowStat then
2761 begin
2762 s := IntToStr(Frags);
2763 e_CharFont_GetSize(gMenuFont, s, tw, th);
2764 e_CharFont_PrintEx(gMenuFont, X-16-tw, Y, s, _RGB(255, 0, 0));
2766 s := '';
2767 p := 1;
2768 m := 0;
2769 stat := g_Player_GetStats();
2770 if stat <> nil then
2771 begin
2772 p := 1;
2774 for a := 0 to High(stat) do
2775 if stat[a].Name <> Name then
2776 begin
2777 if stat[a].Frags > m then m := stat[a].Frags;
2778 if stat[a].Frags > Frags then p := p+1;
2779 end;
2780 end;
2782 s := IntToStr(p)+' / '+IntToStr(Length(stat))+' ';
2783 if Frags >= m then s := s+'+' else s := s+'-';
2784 s := s+IntToStr(Abs(Frags-m));
2786 e_CharFont_GetSize(gMenuSmallFont, s, tw, th);
2787 e_CharFont_PrintEx(gMenuSmallFont, X-16-tw, Y+32, s, _RGB(255, 0, 0));
2788 end;
2790 if gLMSRespawn > LMS_RESPAWN_NONE then
2791 begin
2792 s := _lc[I_GAME_WARMUP];
2793 e_CharFont_GetSize(gMenuFont, s, tw, th);
2794 s := s + ': ' + IntToStr((gLMSRespawnTime - gTime) div 1000);
2795 e_CharFont_PrintEx(gMenuFont, X-64-tw, SY-32, s, _RGB(0, 255, 0));
2796 end
2797 else if gShowLives and (gGameSettings.MaxLives > 0) then
2798 begin
2799 s := IntToStr(Lives);
2800 e_CharFont_GetSize(gMenuFont, s, tw, th);
2801 e_CharFont_PrintEx(gMenuFont, X-16-tw, SY-32, s, _RGB(0, 255, 0));
2802 end;
2803 end;
2805 e_CharFont_GetSize(gMenuSmallFont, FName, tw, th);
2806 e_CharFont_PrintEx(gMenuSmallFont, X+98-(tw div 2), Y+8, FName, _RGB(255, 0, 0));
2808 if R_BERSERK in FRulez then
2809 e_Draw(gItemsTexturesID[ITEM_MEDKIT_BLACK], X+37, Y+45, 0, True, False)
2810 else
2811 e_Draw(gItemsTexturesID[ITEM_MEDKIT_LARGE], X+37, Y+45, 0, True, False);
2813 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID) then
2814 e_Draw(ID, X+36, Y+77, 0, True, False);
2816 s := IntToStr(IfThen(FHealth > 0, FHealth, 0));
2817 e_CharFont_GetSize(gMenuFont, s, tw, th);
2818 e_CharFont_PrintEx(gMenuFont, X+178-tw, Y+40, s, _RGB(255, 0, 0));
2820 s := IntToStr(FArmor);
2821 e_CharFont_GetSize(gMenuFont, s, tw, th);
2822 e_CharFont_PrintEx(gMenuFont, X+178-tw, Y+68, s, _RGB(255, 0, 0));
2824 s := IntToStr(GetAmmoByWeapon(FCurrWeap));
2826 case FCurrWeap of
2827 WEAPON_KASTET:
2828 begin
2829 s := '--';
2830 ID := gItemsTexturesID[ITEM_WEAPON_KASTET];
2831 end;
2832 WEAPON_SAW:
2833 begin
2834 s := '--';
2835 ID := gItemsTexturesID[ITEM_WEAPON_SAW];
2836 end;
2837 WEAPON_PISTOL: ID := gItemsTexturesID[ITEM_WEAPON_PISTOL];
2838 WEAPON_CHAINGUN: ID := gItemsTexturesID[ITEM_WEAPON_CHAINGUN];
2839 WEAPON_SHOTGUN1: ID := gItemsTexturesID[ITEM_WEAPON_SHOTGUN1];
2840 WEAPON_SHOTGUN2: ID := gItemsTexturesID[ITEM_WEAPON_SHOTGUN2];
2841 WEAPON_SUPERPULEMET: ID := gItemsTexturesID[ITEM_WEAPON_SUPERPULEMET];
2842 WEAPON_ROCKETLAUNCHER: ID := gItemsTexturesID[ITEM_WEAPON_ROCKETLAUNCHER];
2843 WEAPON_PLASMA: ID := gItemsTexturesID[ITEM_WEAPON_PLASMA];
2844 WEAPON_BFG: ID := gItemsTexturesID[ITEM_WEAPON_BFG];
2845 WEAPON_FLAMETHROWER: ID := gItemsTexturesID[ITEM_WEAPON_FLAMETHROWER];
2846 end;
2848 e_CharFont_GetSize(gMenuFont, s, tw, th);
2849 e_CharFont_PrintEx(gMenuFont, X+178-tw, Y+158, s, _RGB(255, 0, 0));
2850 e_Draw(ID, X+20, Y+160, 0, True, False);
2852 if R_KEY_RED in FRulez then
2853 e_Draw(gItemsTexturesID[ITEM_KEY_RED], X+78, Y+214, 0, True, False);
2855 if R_KEY_GREEN in FRulez then
2856 e_Draw(gItemsTexturesID[ITEM_KEY_GREEN], X+95, Y+214, 0, True, False);
2858 if R_KEY_BLUE in FRulez then
2859 e_Draw(gItemsTexturesID[ITEM_KEY_BLUE], X+112, Y+214, 0, True, False);
2861 if FJetFuel > 0 then
2862 begin
2863 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID) then
2864 e_Draw(ID, X+2, Y+116, 0, True, False);
2865 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID) then
2866 e_Draw(ID, X+2, Y+126, 0, True, False);
2867 e_DrawLine(4, X+16, Y+122, X+16+Trunc(168*IfThen(FAir > 0, FAir, 0)/AIR_MAX), Y+122, 0, 0, 196);
2868 e_DrawLine(4, X+16, Y+132, X+16+Trunc(168*FJetFuel/JET_MAX), Y+132, 208, 0, 0);
2869 end
2870 else
2871 begin
2872 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID) then
2873 e_Draw(ID, X+2, Y+124, 0, True, False);
2874 e_DrawLine(4, X+16, Y+130, X+16+Trunc(168*IfThen(FAir > 0, FAir, 0)/AIR_MAX), Y+130, 0, 0, 196);
2875 end;
2877 if gShowPing and g_Game_IsClient then
2878 begin
2879 s := _lc[I_GAME_PING_HUD] + IntToStr(NetPeer.lastRoundTripTime) + _lc[I_NET_SLIST_PING_MS];
2880 e_TextureFontPrint(X + 4, Y + 242, s, gStdFont);
2881 Y := Y + 16;
2882 end;
2884 if FSpectator then
2885 begin
2886 e_TextureFontPrint(X + 4, Y + 242, _lc[I_PLAYER_SPECT], gStdFont);
2887 e_TextureFontPrint(X + 4, Y + 258, _lc[I_PLAYER_SPECT2], gStdFont);
2888 e_TextureFontPrint(X + 4, Y + 274, _lc[I_PLAYER_SPECT1], gStdFont);
2889 if FNoRespawn then
2890 begin
2891 e_TextureFontGetSize(gStdFont, cw, ch);
2892 s := _lc[I_PLAYER_SPECT4];
2893 e_TextureFontPrintEx(gScreenWidth div 2 - cw*(Length(s) div 2),
2894 gScreenHeight-4-ch, s, gStdFont, 255, 255, 255, 1, True);
2895 e_TextureFontPrint(X + 4, Y + 290, _lc[I_PLAYER_SPECT1S], gStdFont);
2896 end;
2898 end;
2899 end;
2901 procedure TPlayer.DrawRulez();
2902 var
2903 dr: Boolean;
2904 begin
2905 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2906 if (FMegaRulez[MR_INVUL] >= gTime) and (FSpawnInvul < gTime) then
2907 begin
2908 if (FMegaRulez[MR_INVUL]-gTime) <= 2100 then
2909 dr := not Odd((FMegaRulez[MR_INVUL]-gTime) div 300)
2910 else
2911 dr := True;
2913 if dr then
2914 e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1,
2915 191, 191, 191, 0, TBlending.Invert);
2916 end;
2918 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2919 if FMegaRulez[MR_SUIT] >= gTime then
2920 begin
2921 if (FMegaRulez[MR_SUIT]-gTime) <= 2100 then
2922 dr := not Odd((FMegaRulez[MR_SUIT]-gTime) div 300)
2923 else
2924 dr := True;
2926 if dr then
2927 e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1,
2928 0, 96, 0, 200, TBlending.None);
2929 end;
2931 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2932 if (FBerserk >= 0) and (LongWord(FBerserk) >= gTime) and (gFlash = 2) then
2933 begin
2934 e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1,
2935 255, 0, 0, 200, TBlending.None);
2936 end;
2937 end;
2939 procedure TPlayer.DrawPain();
2940 var
2941 a, h: Integer;
2942 begin
2943 if FPain = 0 then Exit;
2945 a := FPain;
2947 if a < 15 then h := 0
2948 else if a < 35 then h := 1
2949 else if a < 55 then h := 2
2950 else if a < 75 then h := 3
2951 else if a < 95 then h := 4
2952 else h := 5;
2954 //if a > 255 then a := 255;
2956 e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255, 0, 0, 255-h*50);
2957 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2958 end;
2960 procedure TPlayer.DrawPickup();
2961 var
2962 a, h: Integer;
2963 begin
2964 if FPickup = 0 then Exit;
2966 a := FPickup;
2968 if a < 15 then h := 1
2969 else if a < 35 then h := 2
2970 else if a < 55 then h := 3
2971 else if a < 75 then h := 4
2972 else h := 5;
2974 e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 150, 200, 150, 255-h*50);
2975 end;
2977 procedure TPlayer.DoPunch();
2978 var
2979 id: DWORD;
2980 st: String;
2981 begin
2982 if FPunchAnim <> nil then begin
2983 FPunchAnim.reset();
2984 FPunchAnim.Free;
2985 FPunchAnim := nil;
2986 end;
2987 st := 'FRAMES_PUNCH';
2988 if R_BERSERK in FRulez then
2989 st := st + '_BERSERK';
2990 if FKeys[KEY_UP].Pressed then
2991 st := st + '_UP'
2992 else if FKeys[KEY_DOWN].Pressed then
2993 st := st + '_DN';
2994 g_Frames_Get(id, st);
2995 FPunchAnim := TAnimation.Create(id, False, 1);
2996 end;
2998 procedure TPlayer.Fire();
2999 var
3000 f, DidFire: Boolean;
3001 wx, wy, xd, yd: Integer;
3002 locobj: TObj;
3003 begin
3004 if g_Game_IsClient then Exit;
3005 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
3006 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
3008 if FSpectator then
3009 begin
3010 Respawn(False);
3011 Exit;
3012 end;
3014 if FReloading[FCurrWeap] <> 0 then Exit;
3016 DidFire := False;
3018 f := False;
3019 wx := FObj.X+WEAPONPOINT[FDirection].X;
3020 wy := FObj.Y+WEAPONPOINT[FDirection].Y;
3021 xd := wx+IfThen(FDirection = TDirection.D_LEFT, -30, 30);
3022 yd := wy+firediry();
3024 case FCurrWeap of
3025 WEAPON_KASTET:
3026 begin
3027 DoPunch();
3028 if R_BERSERK in FRulez then
3029 begin
3030 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
3031 locobj.X := FObj.X+FObj.Rect.X;
3032 locobj.Y := FObj.Y+FObj.Rect.Y;
3033 locobj.rect.X := 0;
3034 locobj.rect.Y := 0;
3035 locobj.rect.Width := 39;
3036 locobj.rect.Height := 52;
3037 locobj.Vel.X := (xd-wx) div 2;
3038 locobj.Vel.Y := (yd-wy) div 2;
3039 locobj.Accel.X := xd-wx;
3040 locobj.Accel.y := yd-wy;
3042 if g_Weapon_Hit(@locobj, 50, FUID, HIT_SOME) <> 0 then
3043 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj.X, FObj.Y)
3044 else
3045 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj.X, FObj.Y);
3047 if (gFlash = 1) and (FPain < 50) then FPain := min(FPain + 25, 50);
3048 end
3049 else
3050 begin
3051 g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 3, FUID);
3052 end;
3054 DidFire := True;
3055 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3056 end;
3058 WEAPON_SAW:
3059 begin
3060 if g_Weapon_chainsaw(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y,
3061 IfThen(gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF], 9, 3), FUID) <> 0 then
3062 begin
3063 FSawSoundSelect.Stop();
3064 FSawSound.Stop();
3065 FSawSoundHit.PlayAt(FObj.X, FObj.Y);
3066 end
3067 else if not FSawSoundHit.IsPlaying() then
3068 begin
3069 FSawSoundSelect.Stop();
3070 FSawSound.PlayAt(FObj.X, FObj.Y);
3071 end;
3073 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3074 DidFire := True;
3075 f := True;
3076 end;
3078 WEAPON_PISTOL:
3079 if FAmmo[A_BULLETS] > 0 then
3080 begin
3081 g_Weapon_pistol(wx, wy, xd, yd, FUID);
3082 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3083 Dec(FAmmo[A_BULLETS]);
3084 FFireAngle := FAngle;
3085 f := True;
3086 DidFire := True;
3087 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
3088 GameVelX, GameVelY-2, SHELL_BULLET);
3089 end;
3091 WEAPON_SHOTGUN1:
3092 if FAmmo[A_SHELLS] > 0 then
3093 begin
3094 g_Weapon_shotgun(wx, wy, xd, yd, FUID);
3095 if not gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx, wy);
3096 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3097 Dec(FAmmo[A_SHELLS]);
3098 FFireAngle := FAngle;
3099 f := True;
3100 DidFire := True;
3101 FShellTimer := 10;
3102 FShellType := SHELL_SHELL;
3103 end;
3105 WEAPON_SHOTGUN2:
3106 if FAmmo[A_SHELLS] >= 2 then
3107 begin
3108 g_Weapon_dshotgun(wx, wy, xd, yd, FUID);
3109 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3110 Dec(FAmmo[A_SHELLS], 2);
3111 FFireAngle := FAngle;
3112 f := True;
3113 DidFire := True;
3114 FShellTimer := 13;
3115 FShellType := SHELL_DBLSHELL;
3116 end;
3118 WEAPON_CHAINGUN:
3119 if FAmmo[A_BULLETS] > 0 then
3120 begin
3121 g_Weapon_mgun(wx, wy, xd, yd, FUID);
3122 if not gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx, wy);
3123 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3124 Dec(FAmmo[A_BULLETS]);
3125 FFireAngle := FAngle;
3126 f := True;
3127 DidFire := True;
3128 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
3129 GameVelX, GameVelY-2, SHELL_BULLET);
3130 end;
3132 WEAPON_ROCKETLAUNCHER:
3133 if FAmmo[A_ROCKETS] > 0 then
3134 begin
3135 g_Weapon_rocket(wx, wy, xd, yd, FUID);
3136 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3137 Dec(FAmmo[A_ROCKETS]);
3138 FFireAngle := FAngle;
3139 f := True;
3140 DidFire := True;
3141 end;
3143 WEAPON_PLASMA:
3144 if FAmmo[A_CELLS] > 0 then
3145 begin
3146 g_Weapon_plasma(wx, wy, xd, yd, FUID);
3147 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3148 Dec(FAmmo[A_CELLS]);
3149 FFireAngle := FAngle;
3150 f := True;
3151 DidFire := True;
3152 end;
3154 WEAPON_BFG:
3155 if (FAmmo[A_CELLS] >= 40) and (FBFGFireCounter = -1) then
3156 begin
3157 FBFGFireCounter := 17;
3158 if not FNoReload then
3159 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj.X, FObj.Y);
3160 Dec(FAmmo[A_CELLS], 40);
3161 DidFire := True;
3162 end;
3164 WEAPON_SUPERPULEMET:
3165 if FAmmo[A_SHELLS] > 0 then
3166 begin
3167 g_Weapon_shotgun(wx, wy, xd, yd, FUID);
3168 if not gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx, wy);
3169 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3170 Dec(FAmmo[A_SHELLS]);
3171 FFireAngle := FAngle;
3172 f := True;
3173 DidFire := True;
3174 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
3175 GameVelX, GameVelY-2, SHELL_SHELL);
3176 end;
3178 WEAPON_FLAMETHROWER:
3179 if FAmmo[A_FUEL] > 0 then
3180 begin
3181 g_Weapon_flame(wx, wy, xd, yd, FUID);
3182 FlamerOn;
3183 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3184 Dec(FAmmo[A_FUEL]);
3185 FFireAngle := FAngle;
3186 f := True;
3187 DidFire := True;
3188 end
3189 else
3190 begin
3191 FlamerOff;
3192 if g_Game_IsNet and g_Game_IsServer then MH_SEND_PlayerStats(FUID);
3193 end;
3194 end;
3196 if g_Game_IsNet then
3197 begin
3198 if DidFire then
3199 begin
3200 if FCurrWeap <> WEAPON_BFG then
3201 MH_SEND_PlayerFire(FUID, FCurrWeap, wx, wy, xd, yd, LastShotID)
3202 else
3203 if not FNoReload then
3204 MH_SEND_Sound(FObj.X, FObj.Y, 'SOUND_WEAPON_STARTFIREBFG');
3205 end;
3207 MH_SEND_PlayerStats(FUID);
3208 end;
3210 if not f then Exit;
3212 if (FAngle = 0) or (FAngle = 180) then SetAction(A_ATTACK)
3213 else if (FAngle = ANGLE_LEFTDOWN) or (FAngle = ANGLE_RIGHTDOWN) then SetAction(A_ATTACKDOWN)
3214 else if (FAngle = ANGLE_LEFTUP) or (FAngle = ANGLE_RIGHTUP) then SetAction(A_ATTACKUP);
3215 end;
3217 function TPlayer.GetAmmoByWeapon(Weapon: Byte): Word;
3218 begin
3219 case Weapon of
3220 WEAPON_PISTOL, WEAPON_CHAINGUN: Result := FAmmo[A_BULLETS];
3221 WEAPON_SHOTGUN1, WEAPON_SHOTGUN2, WEAPON_SUPERPULEMET: Result := FAmmo[A_SHELLS];
3222 WEAPON_ROCKETLAUNCHER: Result := FAmmo[A_ROCKETS];
3223 WEAPON_PLASMA, WEAPON_BFG: Result := FAmmo[A_CELLS];
3224 WEAPON_FLAMETHROWER: Result := FAmmo[A_FUEL];
3225 else Result := 0;
3226 end;
3227 end;
3229 function TPlayer.HeadInLiquid(XInc, YInc: Integer): Boolean;
3230 begin
3231 Result := g_Map_CollidePanel(FObj.X+PLAYER_HEADRECT.X+XInc, FObj.Y+PLAYER_HEADRECT.Y+YInc,
3232 PLAYER_HEADRECT.Width, PLAYER_HEADRECT.Height,
3233 PANEL_WATER or PANEL_ACID1 or PANEL_ACID2, True);
3234 end;
3236 procedure TPlayer.FlamerOn;
3237 begin
3238 FFlameSoundOff.Stop();
3239 FFlameSoundOff.SetPosition(0);
3240 if FFlaming then
3241 begin
3242 if (not FFlameSoundOn.IsPlaying()) and (not FFlameSoundWork.IsPlaying()) then
3243 FFlameSoundWork.PlayAt(FObj.X, FObj.Y);
3244 end
3245 else
3246 begin
3247 FFlameSoundOn.PlayAt(FObj.X, FObj.Y);
3248 FFlaming := True;
3249 end;
3250 end;
3252 procedure TPlayer.FlamerOff;
3253 begin
3254 if FFlaming then
3255 begin
3256 FFlameSoundOn.Stop();
3257 FFlameSoundOn.SetPosition(0);
3258 FFlameSoundWork.Stop();
3259 FFlameSoundWork.SetPosition(0);
3260 FFlameSoundOff.PlayAt(FObj.X, FObj.Y);
3261 FFlaming := False;
3262 end;
3263 end;
3265 procedure TPlayer.JetpackOn;
3266 begin
3267 FJetSoundFly.Stop;
3268 FJetSoundOff.Stop;
3269 FJetSoundOn.SetPosition(0);
3270 FJetSoundOn.PlayAt(FObj.X, FObj.Y);
3271 FlySmoke(8);
3272 end;
3274 procedure TPlayer.JetpackOff;
3275 begin
3276 FJetSoundFly.Stop;
3277 FJetSoundOn.Stop;
3278 FJetSoundOff.SetPosition(0);
3279 FJetSoundOff.PlayAt(FObj.X, FObj.Y);
3280 end;
3282 procedure TPlayer.CatchFire(Attacker: Word; Timeout: Integer = PLAYER_BURN_TIME);
3283 begin
3284 if Timeout <= 0 then
3285 exit;
3286 if (FMegaRulez[MR_SUIT] > gTime) or (FMegaRulez[MR_INVUL] > gTime) then
3287 exit; // Íå çàãîðàåìñÿ êîãäà åñòü çàùèòà
3288 if g_Obj_CollidePanel(@FObj, 0, 0, PANEL_WATER or PANEL_ACID1 or PANEL_ACID2) then
3289 exit; // Íå ïîäãîðàåì â âîäå íà âñÿêèé ñëó÷àé
3290 if FFireTime <= 0 then
3291 g_Sound_PlayExAt('SOUND_IGNITE', FObj.X, FObj.Y);
3292 FFireTime := Timeout;
3293 FFireAttacker := Attacker;
3294 if g_Game_IsNet and g_Game_IsServer then
3295 MH_SEND_PlayerStats(FUID);
3296 end;
3298 procedure TPlayer.Jump();
3299 begin
3300 if gFly or FJetpack then
3301 begin
3302 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
3303 if FObj.Vel.Y > -VEL_FLY then
3304 FObj.Vel.Y := FObj.Vel.Y - 3;
3305 if FJetpack then
3306 begin
3307 if FJetFuel > 0 then
3308 Dec(FJetFuel);
3309 if (FJetFuel < 1) and g_Game_IsServer then
3310 begin
3311 FJetpack := False;
3312 JetpackOff;
3313 if g_Game_IsNet then
3314 MH_SEND_PlayerStats(FUID);
3315 end;
3316 end;
3317 Exit;
3318 end;
3320 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
3321 if FGhost then
3322 FCanJetpack := False;
3324 // Ïðûãàåì èëè âñïëûâàåì:
3325 if (CollideLevel(0, 1) or
3326 g_Map_CollidePanel(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y+36, PLAYER_RECT.Width,
3327 PLAYER_RECT.Height-33, PANEL_STEP, False)
3328 ) and (FObj.Accel.Y = 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
3329 begin
3330 FObj.Vel.Y := -VEL_JUMP;
3331 FCanJetpack := False;
3332 end
3333 else
3334 begin
3335 if BodyInLiquid(0, 0) then
3336 FObj.Vel.Y := -VEL_SW
3337 else if (FJetFuel > 0) and FCanJetpack and
3338 g_Game_IsServer and (not g_Obj_CollideLiquid(@FObj, 0, 0)) then
3339 begin
3340 FJetpack := True;
3341 JetpackOn;
3342 if g_Game_IsNet then
3343 MH_SEND_PlayerStats(FUID);
3344 end;
3345 end;
3346 end;
3348 procedure TPlayer.Kill(KillType: Byte; SpawnerUID: Word; t: Byte);
3349 var
3350 a, i, k, ab, ar: Byte;
3351 s: String;
3352 mon: TMonster;
3353 plr: TPlayer;
3354 srv, netsrv: Boolean;
3355 DoFrags: Boolean;
3356 OldLR: Byte;
3357 KP: TPlayer;
3358 it: PItem;
3360 procedure PushItem(t: Byte);
3361 var
3362 id: DWORD;
3363 begin
3364 id := g_Items_Create(FObj.X, FObj.Y, t, True, False);
3365 it := g_Items_ByIdx(id);
3366 if KillType = K_EXTRAHARDKILL then // -7..+7; -8..0
3367 begin
3368 g_Obj_Push(@it.Obj, (FObj.Vel.X div 2)-7+Random(15),
3369 (FObj.Vel.Y div 2)-Random(9));
3370 it.positionChanged(); // this updates spatial accelerators
3371 end
3372 else
3373 begin
3374 if KillType = K_HARDKILL then // -5..+5; -5..0
3375 begin
3376 g_Obj_Push(@it.Obj, (FObj.Vel.X div 2)-5+Random(11),
3377 (FObj.Vel.Y div 2)-Random(6));
3378 end
3379 else // -3..+3; -3..0
3380 begin
3381 g_Obj_Push(@it.Obj, (FObj.Vel.X div 2)-3+Random(7),
3382 (FObj.Vel.Y div 2)-Random(4));
3383 end;
3384 it.positionChanged(); // this updates spatial accelerators
3385 end;
3387 if g_Game_IsNet and g_Game_IsServer then
3388 MH_SEND_ItemSpawn(True, id);
3389 end;
3391 begin
3392 DoFrags := (gGameSettings.MaxLives = 0) or (gGameSettings.GameMode = GM_COOP);
3393 Srv := g_Game_IsServer;
3394 Netsrv := g_Game_IsServer and g_Game_IsNet;
3395 if Srv then FDeath := FDeath + 1;
3396 if FAlive then
3397 begin
3398 if FGhost then
3399 FGhost := False;
3400 if not FPhysics then
3401 FPhysics := True;
3402 FAlive := False;
3403 end;
3404 FShellTimer := -1;
3406 if (gGameSettings.MaxLives > 0) and Srv and (gLMSRespawn = LMS_RESPAWN_NONE) then
3407 begin
3408 if FLives > 0 then FLives := FLives - 1;
3409 if FLives = 0 then FNoRespawn := True;
3410 end;
3412 // Íîìåð òèïà ñìåðòè:
3413 a := 1;
3414 case KillType of
3415 K_SIMPLEKILL: a := 1;
3416 K_HARDKILL: a := 2;
3417 K_EXTRAHARDKILL: a := 3;
3418 K_FALLKILL: a := 4;
3419 end;
3421 // Çâóê ñìåðòè:
3422 if not FModel.PlaySound(MODELSOUND_DIE, a, FObj.X, FObj.Y) then
3423 for i := 1 to 3 do
3424 if FModel.PlaySound(MODELSOUND_DIE, i, FObj.X, FObj.Y) then
3425 Break;
3427 // Âðåìÿ ðåñïàóíà:
3428 if Srv then
3429 case KillType of
3430 K_SIMPLEKILL:
3431 FTime[T_RESPAWN] := gTime + TIME_RESPAWN1;
3432 K_HARDKILL:
3433 FTime[T_RESPAWN] := gTime + TIME_RESPAWN2;
3434 K_EXTRAHARDKILL, K_FALLKILL:
3435 FTime[T_RESPAWN] := gTime + TIME_RESPAWN3;
3436 end;
3438 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3439 case KillType of
3440 K_SIMPLEKILL:
3441 SetAction(A_DIE1);
3442 K_HARDKILL, K_EXTRAHARDKILL:
3443 SetAction(A_DIE2);
3444 end;
3446 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3447 if (KillType <> K_FALLKILL) and (Srv) then
3448 g_Monsters_killedp();
3450 if SpawnerUID = FUID then
3451 begin // Ñàìîóáèëñÿ
3452 if Srv then
3453 begin
3454 if gGameSettings.GameMode = GM_TDM then
3455 Dec(gTeamStat[FTeam].Goals);
3456 if DoFrags or (gGameSettings.GameMode = GM_TDM) then
3457 begin
3458 Dec(FFrags);
3459 FLastFrag := 0;
3460 end;
3461 end;
3462 g_Console_Add(Format(_lc[I_PLAYER_KILL_SELF], [FName]), True);
3463 end
3464 else
3465 if g_GetUIDType(SpawnerUID) = UID_PLAYER then
3466 begin // Óáèò äðóãèì èãðîêîì
3467 KP := g_Player_Get(SpawnerUID);
3468 if (KP <> nil) and Srv then
3469 begin
3470 if (DoFrags or (gGameSettings.GameMode = GM_TDM)) then
3471 if SameTeam(FUID, SpawnerUID) then
3472 begin
3473 Dec(KP.FFrags);
3474 KP.FLastFrag := 0;
3475 end else
3476 begin
3477 Inc(KP.FFrags);
3478 KP.FragCombo();
3479 end;
3481 if (gGameSettings.GameMode = GM_TDM) and DoFrags then
3482 Inc(gTeamStat[KP.Team].Goals,
3483 IfThen(SameTeam(FUID, SpawnerUID), -1, 1));
3485 if netsrv then MH_SEND_PlayerStats(SpawnerUID);
3486 end;
3488 plr := g_Player_Get(SpawnerUID);
3489 if plr = nil then
3490 s := '?'
3491 else
3492 s := plr.FName;
3494 case KillType of
3495 K_HARDKILL:
3496 g_Console_Add(Format(_lc[I_PLAYER_KILL_EXTRAHARD_2],
3497 [FName, s]),
3498 gShowKillMsg);
3499 K_EXTRAHARDKILL:
3500 g_Console_Add(Format(_lc[I_PLAYER_KILL_EXTRAHARD_1],
3501 [FName, s]),
3502 gShowKillMsg);
3503 else
3504 g_Console_Add(Format(_lc[I_PLAYER_KILL],
3505 [FName, s]),
3506 gShowKillMsg);
3507 end;
3508 end
3509 else if g_GetUIDType(SpawnerUID) = UID_MONSTER then
3510 begin // Óáèò ìîíñòðîì
3511 mon := g_Monsters_ByUID(SpawnerUID);
3512 if mon = nil then
3513 s := '?'
3514 else
3515 s := g_Mons_GetKilledByTypeId(mon.MonsterType);
3517 case KillType of
3518 K_HARDKILL:
3519 g_Console_Add(Format(_lc[I_PLAYER_KILL_EXTRAHARD_2],
3520 [FName, s]),
3521 gShowKillMsg);
3522 K_EXTRAHARDKILL:
3523 g_Console_Add(Format(_lc[I_PLAYER_KILL_EXTRAHARD_1],
3524 [FName, s]),
3525 gShowKillMsg);
3526 else
3527 g_Console_Add(Format(_lc[I_PLAYER_KILL],
3528 [FName, s]),
3529 gShowKillMsg);
3530 end;
3531 end
3532 else // Îñîáûå òèïû ñìåðòè
3533 case t of
3534 HIT_DISCON: ;
3535 HIT_SELF: g_Console_Add(Format(_lc[I_PLAYER_KILL_SELF], [FName]), True);
3536 HIT_FALL: g_Console_Add(Format(_lc[I_PLAYER_KILL_FALL], [FName]), True);
3537 HIT_WATER: g_Console_Add(Format(_lc[I_PLAYER_KILL_WATER], [FName]), True);
3538 HIT_ACID: g_Console_Add(Format(_lc[I_PLAYER_KILL_ACID], [FName]), True);
3539 HIT_TRAP: g_Console_Add(Format(_lc[I_PLAYER_KILL_TRAP], [FName]), True);
3540 else g_Console_Add(Format(_lc[I_PLAYER_DIED], [FName]), True);
3541 end;
3543 if Srv then
3544 begin
3545 // Âûáðîñ îðóæèÿ:
3546 for a := WP_FIRST to WP_LAST do
3547 if FWeapon[a] then
3548 begin
3549 case a of
3550 WEAPON_SAW: i := ITEM_WEAPON_SAW;
3551 WEAPON_SHOTGUN1: i := ITEM_WEAPON_SHOTGUN1;
3552 WEAPON_SHOTGUN2: i := ITEM_WEAPON_SHOTGUN2;
3553 WEAPON_CHAINGUN: i := ITEM_WEAPON_CHAINGUN;
3554 WEAPON_ROCKETLAUNCHER: i := ITEM_WEAPON_ROCKETLAUNCHER;
3555 WEAPON_PLASMA: i := ITEM_WEAPON_PLASMA;
3556 WEAPON_BFG: i := ITEM_WEAPON_BFG;
3557 WEAPON_SUPERPULEMET: i := ITEM_WEAPON_SUPERPULEMET;
3558 WEAPON_FLAMETHROWER: i := ITEM_WEAPON_FLAMETHROWER;
3559 else i := 0;
3560 end;
3562 if i <> 0 then
3563 PushItem(i);
3564 end;
3566 // Âûáðîñ ðþêçàêà:
3567 if R_ITEM_BACKPACK in FRulez then
3568 PushItem(ITEM_AMMO_BACKPACK);
3570 // Âûáðîñ ðàêåòíîãî ðàíöà:
3571 if FJetFuel > 0 then
3572 PushItem(ITEM_JETPACK);
3574 // Âûáðîñ êëþ÷åé:
3575 if (not (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF])) or
3576 (not LongBool(gGameSettings.Options and GAME_OPTION_DMKEYS)) then
3577 begin
3578 if R_KEY_RED in FRulez then
3579 PushItem(ITEM_KEY_RED);
3581 if R_KEY_GREEN in FRulez then
3582 PushItem(ITEM_KEY_GREEN);
3584 if R_KEY_BLUE in FRulez then
3585 PushItem(ITEM_KEY_BLUE);
3586 end;
3588 // Âûáðîñ ôëàãà:
3589 DropFlag(KillType = K_FALLKILL);
3590 end;
3592 FCorpse := g_Player_CreateCorpse(Self);
3594 if Srv and (gGameSettings.MaxLives > 0) and FNoRespawn and
3595 (gLMSRespawn = LMS_RESPAWN_NONE) then
3596 begin
3597 a := 0;
3598 k := 0;
3599 ar := 0;
3600 ab := 0;
3601 for i := Low(gPlayers) to High(gPlayers) do
3602 begin
3603 if gPlayers[i] = nil then continue;
3604 if (not gPlayers[i].FNoRespawn) and (not gPlayers[i].FSpectator) then
3605 begin
3606 Inc(a);
3607 if gPlayers[i].FTeam = TEAM_RED then Inc(ar)
3608 else if gPlayers[i].FTeam = TEAM_BLUE then Inc(ab);
3609 k := i;
3610 end;
3611 end;
3613 OldLR := gLMSRespawn;
3614 if (gGameSettings.GameMode = GM_COOP) then
3615 begin
3616 if (a = 0) then
3617 begin
3618 // everyone is dead, restart the map
3619 g_Game_Message(_lc[I_MESSAGE_LMS_LOSE], 144);
3620 if Netsrv then
3621 MH_SEND_GameEvent(NET_EV_LMS_LOSE);
3622 gLMSRespawn := LMS_RESPAWN_FINAL;
3623 gLMSRespawnTime := gTime + 5000;
3624 end
3625 else if (a = 1) then
3626 begin
3627 if (gPlayers[k] <> nil) and not (gPlayers[k] is TBot) then
3628 if (gPlayers[k] = gPlayer1) or
3629 (gPlayers[k] = gPlayer2) then
3630 g_Console_Add('*** ' + _lc[I_MESSAGE_LMS_SURVIVOR] + ' ***', True)
3631 else if Netsrv and (gPlayers[k].FClientID >= 0) then
3632 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR, 0, 'N', gPlayers[k].FClientID);
3633 end;
3634 end
3635 else if (gGameSettings.GameMode = GM_TDM) then
3636 begin
3637 if (ab = 0) and (ar <> 0) then
3638 begin
3639 // blu team ded
3640 g_Game_Message(Format(_lc[I_MESSAGE_TLMS_WIN], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 144);
3641 if Netsrv then
3642 MH_SEND_GameEvent(NET_EV_TLMS_WIN, TEAM_RED);
3643 Inc(gTeamStat[TEAM_RED].Goals);
3644 gLMSRespawn := LMS_RESPAWN_FINAL;
3645 gLMSRespawnTime := gTime + 5000;
3646 end
3647 else if (ar = 0) and (ab <> 0) then
3648 begin
3649 // red team ded
3650 g_Game_Message(Format(_lc[I_MESSAGE_TLMS_WIN], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 144);
3651 if Netsrv then
3652 MH_SEND_GameEvent(NET_EV_TLMS_WIN, TEAM_BLUE);
3653 Inc(gTeamStat[TEAM_BLUE].Goals);
3654 gLMSRespawn := LMS_RESPAWN_FINAL;
3655 gLMSRespawnTime := gTime + 5000;
3656 end
3657 else if (ar = 0) and (ab = 0) then
3658 begin
3659 // everyone ded
3660 g_Game_Message(_lc[I_GAME_WIN_DRAW], 144);
3661 if Netsrv then
3662 MH_SEND_GameEvent(NET_EV_LMS_DRAW, 0, FName);
3663 gLMSRespawn := LMS_RESPAWN_FINAL;
3664 gLMSRespawnTime := gTime + 5000;
3665 end;
3666 end
3667 else if (gGameSettings.GameMode = GM_DM) then
3668 begin
3669 if (a = 1) then
3670 begin
3671 if gPlayers[k] <> nil then
3672 with gPlayers[k] do
3673 begin
3674 // survivor is the winner
3675 g_Game_Message(Format(_lc[I_MESSAGE_LMS_WIN], [AnsiUpperCase(FName)]), 144);
3676 if Netsrv then
3677 MH_SEND_GameEvent(NET_EV_LMS_WIN, 0, FName);
3678 Inc(FFrags);
3679 end;
3680 gLMSRespawn := LMS_RESPAWN_FINAL;
3681 gLMSRespawnTime := gTime + 5000;
3682 end
3683 else if (a = 0) then
3684 begin
3685 // everyone is dead, restart the map
3686 g_Game_Message(_lc[I_GAME_WIN_DRAW], 144);
3687 if Netsrv then
3688 MH_SEND_GameEvent(NET_EV_LMS_DRAW, 0, FName);
3689 gLMSRespawn := LMS_RESPAWN_FINAL;
3690 gLMSRespawnTime := gTime + 5000;
3691 end;
3692 end;
3693 if srv and (OldLR = LMS_RESPAWN_NONE) and (gLMSRespawn > LMS_RESPAWN_NONE) then
3694 begin
3695 if NetMode = NET_SERVER then
3696 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, gLMSRespawnTime - gTime)
3697 else
3698 g_Console_Add(Format(_lc[I_MSG_WARMUP_START], [(gLMSRespawnTime - gTime) div 1000]), True);
3699 end;
3700 end;
3702 if Netsrv then
3703 begin
3704 MH_SEND_PlayerStats(FUID);
3705 MH_SEND_PlayerDeath(FUID, KillType, t, SpawnerUID);
3706 if gGameSettings.GameMode = GM_TDM then MH_SEND_GameStats;
3707 end;
3709 if srv and FNoRespawn then Spectate(True);
3710 FWantsInGame := True;
3711 end;
3713 function TPlayer.BodyInLiquid(XInc, YInc: Integer): Boolean;
3714 begin
3715 Result := g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc, PLAYER_RECT.Width,
3716 PLAYER_RECT.Height-20, PANEL_WATER or PANEL_ACID1 or PANEL_ACID2, False);
3717 end;
3719 function TPlayer.BodyInAcid(XInc, YInc: Integer): Boolean;
3720 begin
3721 Result := g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc, PLAYER_RECT.Width,
3722 PLAYER_RECT.Height-20, PANEL_ACID1 or PANEL_ACID2, False);
3723 end;
3725 procedure TPlayer.MakeBloodSimple(Count: Word);
3726 begin
3727 g_GFX_Blood(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)+8,
3728 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2),
3729 Count div 2, 3, -1, 16, (PLAYER_RECT.Height*2 div 3),
3730 FModel.Blood.R, FModel.Blood.G, FModel.Blood.B, FModel.Blood.Kind);
3731 g_GFX_Blood(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-8,
3732 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2),
3733 Count div 2, -3, -1, 16, (PLAYER_RECT.Height*2) div 3,
3734 FModel.Blood.R, FModel.Blood.G, FModel.Blood.B, FModel.Blood.Kind);
3735 end;
3737 procedure TPlayer.MakeBloodVector(Count: Word; VelX, VelY: Integer);
3738 begin
3739 g_GFX_Blood(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2),
3740 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2),
3741 Count, VelX, VelY, 16, (PLAYER_RECT.Height*2) div 3,
3742 FModel.Blood.R, FModel.Blood.G, FModel.Blood.B, FModel.Blood.Kind);
3743 end;
3745 procedure TPlayer.ProcessWeaponAction(Action: Byte);
3746 begin
3747 if g_Game_IsClient then Exit;
3748 case Action of
3749 WP_PREV: PrevWeapon();
3750 WP_NEXT: NextWeapon();
3751 end;
3752 end;
3754 procedure TPlayer.QueueWeaponSwitch(Weapon: Byte);
3755 begin
3756 if g_Game_IsClient then Exit;
3757 if Weapon > High(FWeapon) then Exit;
3758 FNextWeap := FNextWeap or (1 shl Weapon);
3759 end;
3761 procedure TPlayer.resetWeaponQueue ();
3762 begin
3763 FNextWeap := 0;
3764 FNextWeapDelay := 0;
3765 end;
3767 function TPlayer.hasAmmoForWeapon (weapon: Byte): Boolean;
3768 begin
3769 result := false;
3770 case weapon of
3771 WEAPON_KASTET, WEAPON_SAW: result := true;
3772 WEAPON_SHOTGUN1, WEAPON_SHOTGUN2, WEAPON_SUPERPULEMET: result := (FAmmo[A_SHELLS] > 0);
3773 WEAPON_PISTOL, WEAPON_CHAINGUN: result := (FAmmo[A_BULLETS] > 0);
3774 WEAPON_ROCKETLAUNCHER: result := (FAmmo[A_ROCKETS] > 0);
3775 WEAPON_PLASMA, WEAPON_BFG: result := (FAmmo[A_CELLS] > 0);
3776 WEAPON_FLAMETHROWER: result := (FAmmo[A_FUEL] > 0);
3777 else result := (weapon < length(FWeapon));
3778 end;
3779 end;
3781 function TPlayer.shouldSwitch (weapon: Byte; hadWeapon: Boolean): Boolean;
3782 begin
3783 result := false;
3784 if (weapon < 0) or (weapon > WP_LAST + 1) then
3785 begin
3786 result := false;
3787 exit;
3788 end;
3789 if (FWeapSwitchMode = 1) and not hadWeapon then
3790 result := true
3791 else if (FWeapSwitchMode = 2) then
3792 result := (FWeapPreferences[weapon] > FWeapPreferences[FCurrWeap]);
3793 end;
3795 // return 255 for "no switch"
3796 function TPlayer.getNextWeaponIndex (): Byte;
3797 var
3798 i: Word;
3799 wantThisWeapon: array[0..64] of Boolean;
3800 wwc: Integer = 0; //HACK!
3801 dir, cwi: Integer;
3802 begin
3803 result := 255; // default result: "no switch"
3804 //e_LogWriteFln('FSWITCHTOEMPTY: %s', [FSwitchToEmpty], TMsgType.Notify);
3805 // had weapon cycling on previous frame? remove that flag
3806 if (FNextWeap and $2000) <> 0 then
3807 begin
3808 FNextWeap := FNextWeap and $1FFF;
3809 FNextWeapDelay := 0;
3810 end;
3811 // cycling has priority
3812 if (FNextWeap and $C000) <> 0 then
3813 begin
3814 if (FNextWeap and $8000) <> 0 then
3815 dir := 1
3816 else
3817 dir := -1;
3818 FNextWeap := FNextWeap or $2000; // we need this
3819 if FNextWeapDelay > 0 then
3820 exit; // cooldown time
3821 cwi := FCurrWeap;
3822 for i := 0 to High(FWeapon) do
3823 begin
3824 cwi := (cwi+length(FWeapon)+dir) mod length(FWeapon);
3825 if FWeapon[cwi] and maySwitch(cwi) then
3826 begin
3827 //e_LogWriteFln(' SWITCH: cur=%d; new=%d %s %s', [FCurrWeap, cwi, FSwitchToEmpty, hasAmmoForWeapon(cwi)], TMsgType.Notify);
3828 result := Byte(cwi);
3829 FNextWeapDelay := WEAPON_DELAY;
3830 exit;
3831 end;
3832 end;
3833 resetWeaponQueue();
3834 exit;
3835 end;
3836 // no cycling
3837 for i := 0 to High(wantThisWeapon) do
3838 wantThisWeapon[i] := false;
3839 for i := 0 to High(FWeapon) do
3840 if (FNextWeap and (1 shl i)) <> 0 then
3841 begin
3842 wantThisWeapon[i] := true;
3843 Inc(wwc);
3844 end;
3846 // exclude currently selected weapon from the set
3847 wantThisWeapon[FCurrWeap] := false;
3848 // slow down alterations a little
3849 if wwc > 1 then
3850 begin
3851 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3852 // more than one weapon requested, assume "alteration" and check alteration delay
3853 if FNextWeapDelay > 0 then
3854 begin
3855 FNextWeap := 0;
3856 exit;
3857 end; // yeah
3858 end;
3859 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3860 // but clear all counters if no weapon should be switched
3861 if wwc < 1 then
3862 begin
3863 resetWeaponQueue();
3864 exit;
3865 end;
3866 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3867 // try weapons in descending order
3868 for i := High(FWeapon) downto 0 do
3869 begin
3870 if wantThisWeapon[i] and FWeapon[i] and ((wwc = 1) or hasAmmoForWeapon(i)) then
3871 begin
3872 // i found her!
3873 result := Byte(i);
3874 resetWeaponQueue();
3875 FNextWeapDelay := WEAPON_DELAY * 2; // anyway, 'cause why not
3876 //e_LogWriteFln('FOUND %s %s %s', [result, FSwitchToEmpty, hasAmmoForWeapon(i)], TMsgType.Notify);
3877 exit;
3878 end;
3879 end;
3880 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3881 resetWeaponQueue();
3882 end;
3884 procedure TPlayer.RealizeCurrentWeapon();
3885 function switchAllowed (): Boolean;
3886 var
3887 i: Byte;
3888 begin
3889 result := false;
3890 if FBFGFireCounter <> -1 then
3891 exit;
3892 if FTime[T_SWITCH] > gTime then
3893 exit;
3894 for i := WP_FIRST to WP_LAST do
3895 if FReloading[i] > 0 then
3896 exit;
3897 result := true;
3898 end;
3900 var
3901 nw: Byte;
3902 begin
3903 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3904 //FNextWeap := FNextWeap and $1FFF;
3905 if FNextWeapDelay > 0 then Dec(FNextWeapDelay); // "alteration delay"
3907 if not switchAllowed then
3908 begin
3909 //HACK for weapon cycling
3910 if (FNextWeap and $E000) <> 0 then FNextWeap := 0;
3911 exit;
3912 end;
3914 nw := getNextWeaponIndex();
3915 //
3916 if nw = 255 then exit; // don't reset anything here
3917 if nw > High(FWeapon) then
3918 begin
3919 // don't forget to reset queue here!
3920 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
3921 resetWeaponQueue();
3922 exit;
3923 end;
3925 if FWeapon[nw] then
3926 begin
3927 FCurrWeap := nw;
3928 FTime[T_SWITCH] := gTime+156;
3929 if FCurrWeap = WEAPON_SAW then FSawSoundSelect.PlayAt(FObj.X, FObj.Y);
3930 FModel.SetWeapon(FCurrWeap);
3931 if g_Game_IsNet then MH_SEND_PlayerStats(FUID);
3932 end;
3933 end;
3935 procedure TPlayer.NextWeapon();
3936 begin
3937 if g_Game_IsClient then Exit;
3938 FNextWeap := $8000;
3939 end;
3941 procedure TPlayer.PrevWeapon();
3942 begin
3943 if g_Game_IsClient then Exit;
3944 FNextWeap := $4000;
3945 end;
3947 procedure TPlayer.SetWeapon(W: Byte);
3948 begin
3949 if FCurrWeap <> W then
3950 if W = WEAPON_SAW then
3951 FSawSoundSelect.PlayAt(FObj.X, FObj.Y);
3953 FCurrWeap := W;
3954 FModel.SetWeapon(CurrWeap);
3955 resetWeaponQueue();
3956 end;
3958 function TPlayer.PickItem(ItemType: Byte; arespawn: Boolean; var remove: Boolean): Boolean;
3960 function allowBerserkSwitching (): Boolean;
3961 begin
3962 if (FBFGFireCounter <> -1) then begin result := false; exit; end;
3963 result := true;
3964 if gBerserkAutoswitch then exit;
3965 if not conIsCheatsEnabled then exit;
3966 result := false;
3967 end;
3969 var
3970 a: Boolean;
3971 switchWeapon: Byte = -1;
3972 hadWeapon: Boolean = False;
3973 begin
3974 Result := False;
3975 if g_Game_IsClient then Exit;
3977 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3978 a := LongBool(gGameSettings.Options and GAME_OPTION_WEAPONSTAY) and arespawn;
3979 remove := not a;
3980 case ItemType of
3981 ITEM_MEDKIT_SMALL:
3982 if (FHealth < PLAYER_HP_SOFT) or (FFireTime > 0) then
3983 begin
3984 if FHealth < PLAYER_HP_SOFT then IncMax(FHealth, 10, PLAYER_HP_SOFT);
3985 Result := True;
3986 remove := True;
3987 FFireTime := 0;
3988 if gFlash = 2 then Inc(FPickup, 5);
3989 end;
3991 ITEM_MEDKIT_LARGE:
3992 if (FHealth < PLAYER_HP_SOFT) or (FFireTime > 0) then
3993 begin
3994 if FHealth < PLAYER_HP_SOFT then IncMax(FHealth, 25, PLAYER_HP_SOFT);
3995 Result := True;
3996 remove := True;
3997 FFireTime := 0;
3998 if gFlash = 2 then Inc(FPickup, 5);
3999 end;
4001 ITEM_ARMOR_GREEN:
4002 if FArmor < PLAYER_AP_SOFT then
4003 begin
4004 FArmor := PLAYER_AP_SOFT;
4005 Result := True;
4006 remove := True;
4007 if gFlash = 2 then Inc(FPickup, 5);
4008 end;
4010 ITEM_ARMOR_BLUE:
4011 if FArmor < PLAYER_AP_LIMIT then
4012 begin
4013 FArmor := PLAYER_AP_LIMIT;
4014 Result := True;
4015 remove := True;
4016 if gFlash = 2 then Inc(FPickup, 5);
4017 end;
4019 ITEM_SPHERE_BLUE:
4020 if (FHealth < PLAYER_HP_LIMIT) or (FFireTime > 0) then
4021 begin
4022 if FHealth < PLAYER_HP_LIMIT then IncMax(FHealth, 100, PLAYER_HP_LIMIT);
4023 Result := True;
4024 remove := True;
4025 FFireTime := 0;
4026 if gFlash = 2 then Inc(FPickup, 5);
4027 end;
4029 ITEM_SPHERE_WHITE:
4030 if (FHealth < PLAYER_HP_LIMIT) or (FArmor < PLAYER_AP_LIMIT) or (FFireTime > 0) then
4031 begin
4032 if FHealth < PLAYER_HP_LIMIT then
4033 FHealth := PLAYER_HP_LIMIT;
4034 if FArmor < PLAYER_AP_LIMIT then
4035 FArmor := PLAYER_AP_LIMIT;
4036 Result := True;
4037 remove := True;
4038 FFireTime := 0;
4039 if gFlash = 2 then Inc(FPickup, 5);
4040 end;
4042 ITEM_WEAPON_SAW:
4043 if (not FWeapon[WEAPON_SAW]) or ((not arespawn) and (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF])) then
4044 begin
4045 hadWeapon := FWeapon[WEAPON_SAW];
4046 switchWeapon := WEAPON_SAW;
4047 FWeapon[WEAPON_SAW] := True;
4048 Result := True;
4049 if gFlash = 2 then Inc(FPickup, 5);
4050 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
4051 end;
4053 ITEM_WEAPON_SHOTGUN1:
4054 if (FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS]) or not FWeapon[WEAPON_SHOTGUN1] then
4055 begin
4056 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
4057 if a and FWeapon[WEAPON_SHOTGUN1] then Exit;
4058 hadWeapon := FWeapon[WEAPON_SHOTGUN1];
4059 switchWeapon := WEAPON_SHOTGUN1;
4060 IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
4061 FWeapon[WEAPON_SHOTGUN1] := True;
4062 Result := True;
4063 if gFlash = 2 then Inc(FPickup, 5);
4064 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
4065 end;
4067 ITEM_WEAPON_SHOTGUN2:
4068 if (FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS]) or not FWeapon[WEAPON_SHOTGUN2] then
4069 begin
4070 if a and FWeapon[WEAPON_SHOTGUN2] then Exit;
4071 hadWeapon := FWeapon[WEAPON_SHOTGUN2];
4072 switchWeapon := WEAPON_SHOTGUN2;
4073 IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
4074 FWeapon[WEAPON_SHOTGUN2] := True;
4075 Result := True;
4076 if gFlash = 2 then Inc(FPickup, 5);
4077 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
4078 end;
4080 ITEM_WEAPON_CHAINGUN:
4081 if (FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS]) or not FWeapon[WEAPON_CHAINGUN] then
4082 begin
4083 if a and FWeapon[WEAPON_CHAINGUN] then Exit;
4084 hadWeapon := FWeapon[WEAPON_CHAINGUN];
4085 switchWeapon := WEAPON_CHAINGUN;
4086 IncMax(FAmmo[A_BULLETS], 50, FMaxAmmo[A_BULLETS]);
4087 FWeapon[WEAPON_CHAINGUN] := True;
4088 Result := True;
4089 if gFlash = 2 then Inc(FPickup, 5);
4090 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
4091 end;
4093 ITEM_WEAPON_ROCKETLAUNCHER:
4094 if (FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS]) or not FWeapon[WEAPON_ROCKETLAUNCHER] then
4095 begin
4096 if a and FWeapon[WEAPON_ROCKETLAUNCHER] then Exit;
4097 switchWeapon := WEAPON_ROCKETLAUNCHER;
4098 hadWeapon := FWeapon[WEAPON_ROCKETLAUNCHER];
4099 IncMax(FAmmo[A_ROCKETS], 2, FMaxAmmo[A_ROCKETS]);
4100 FWeapon[WEAPON_ROCKETLAUNCHER] := True;
4101 Result := True;
4102 if gFlash = 2 then Inc(FPickup, 5);
4103 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
4104 end;
4106 ITEM_WEAPON_PLASMA:
4107 if (FAmmo[A_CELLS] < FMaxAmmo[A_CELLS]) or not FWeapon[WEAPON_PLASMA] then
4108 begin
4109 if a and FWeapon[WEAPON_PLASMA] then Exit;
4110 switchWeapon := WEAPON_PLASMA;
4111 hadWeapon := FWeapon[WEAPON_PLASMA];
4112 IncMax(FAmmo[A_CELLS], 40, FMaxAmmo[A_CELLS]);
4113 FWeapon[WEAPON_PLASMA] := True;
4114 Result := True;
4115 if gFlash = 2 then Inc(FPickup, 5);
4116 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
4117 end;
4119 ITEM_WEAPON_BFG:
4120 if (FAmmo[A_CELLS] < FMaxAmmo[A_CELLS]) or not FWeapon[WEAPON_BFG] then
4121 begin
4122 if a and FWeapon[WEAPON_BFG] then Exit;
4123 switchWeapon := WEAPON_BFG;
4124 hadWeapon := FWeapon[WEAPON_BFG];
4125 IncMax(FAmmo[A_CELLS], 40, FMaxAmmo[A_CELLS]);
4126 FWeapon[WEAPON_BFG] := True;
4127 Result := True;
4128 if gFlash = 2 then Inc(FPickup, 5);
4129 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
4130 end;
4132 ITEM_WEAPON_SUPERPULEMET:
4133 if (FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS]) or not FWeapon[WEAPON_SUPERPULEMET] then
4134 begin
4135 if a and FWeapon[WEAPON_SUPERPULEMET] then Exit;
4136 switchWeapon := WEAPON_SUPERPULEMET;
4137 hadWeapon := FWeapon[WEAPON_SUPERPULEMET];
4138 IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
4139 FWeapon[WEAPON_SUPERPULEMET] := True;
4140 Result := True;
4141 if gFlash = 2 then Inc(FPickup, 5);
4142 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
4143 end;
4145 ITEM_WEAPON_FLAMETHROWER:
4146 if (FAmmo[A_FUEL] < FMaxAmmo[A_FUEL]) or not FWeapon[WEAPON_FLAMETHROWER] then
4147 begin
4148 if a and FWeapon[WEAPON_FLAMETHROWER] then Exit;
4149 switchWeapon := WEAPON_FLAMETHROWER;
4150 hadWeapon := FWeapon[WEAPON_FLAMETHROWER];
4151 IncMax(FAmmo[A_FUEL], 100, FMaxAmmo[A_FUEL]);
4152 FWeapon[WEAPON_FLAMETHROWER] := True;
4153 Result := True;
4154 if gFlash = 2 then Inc(FPickup, 5);
4155 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
4156 end;
4158 ITEM_AMMO_BULLETS:
4159 if FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS] then
4160 begin
4161 IncMax(FAmmo[A_BULLETS], 10, FMaxAmmo[A_BULLETS]);
4162 Result := True;
4163 remove := True;
4164 if gFlash = 2 then Inc(FPickup, 5);
4165 end;
4167 ITEM_AMMO_BULLETS_BOX:
4168 if FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS] then
4169 begin
4170 IncMax(FAmmo[A_BULLETS], 50, FMaxAmmo[A_BULLETS]);
4171 Result := True;
4172 remove := True;
4173 if gFlash = 2 then Inc(FPickup, 5);
4174 end;
4176 ITEM_AMMO_SHELLS:
4177 if FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS] then
4178 begin
4179 IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
4180 Result := True;
4181 remove := True;
4182 if gFlash = 2 then Inc(FPickup, 5);
4183 end;
4185 ITEM_AMMO_SHELLS_BOX:
4186 if FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS] then
4187 begin
4188 IncMax(FAmmo[A_SHELLS], 25, FMaxAmmo[A_SHELLS]);
4189 Result := True;
4190 remove := True;
4191 if gFlash = 2 then Inc(FPickup, 5);
4192 end;
4194 ITEM_AMMO_ROCKET:
4195 if FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS] then
4196 begin
4197 IncMax(FAmmo[A_ROCKETS], 1, FMaxAmmo[A_ROCKETS]);
4198 Result := True;
4199 remove := True;
4200 if gFlash = 2 then Inc(FPickup, 5);
4201 end;
4203 ITEM_AMMO_ROCKET_BOX:
4204 if FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS] then
4205 begin
4206 IncMax(FAmmo[A_ROCKETS], 5, FMaxAmmo[A_ROCKETS]);
4207 Result := True;
4208 remove := True;
4209 if gFlash = 2 then Inc(FPickup, 5);
4210 end;
4212 ITEM_AMMO_CELL:
4213 if FAmmo[A_CELLS] < FMaxAmmo[A_CELLS] then
4214 begin
4215 IncMax(FAmmo[A_CELLS], 40, FMaxAmmo[A_CELLS]);
4216 Result := True;
4217 remove := True;
4218 if gFlash = 2 then Inc(FPickup, 5);
4219 end;
4221 ITEM_AMMO_CELL_BIG:
4222 if FAmmo[A_CELLS] < FMaxAmmo[A_CELLS] then
4223 begin
4224 IncMax(FAmmo[A_CELLS], 100, FMaxAmmo[A_CELLS]);
4225 Result := True;
4226 remove := True;
4227 if gFlash = 2 then Inc(FPickup, 5);
4228 end;
4230 ITEM_AMMO_FUELCAN:
4231 if FAmmo[A_FUEL] < FMaxAmmo[A_FUEL] then
4232 begin
4233 IncMax(FAmmo[A_FUEL], 100, FMaxAmmo[A_FUEL]);
4234 Result := True;
4235 remove := True;
4236 if gFlash = 2 then Inc(FPickup, 5);
4237 end;
4239 ITEM_AMMO_BACKPACK:
4240 if not(R_ITEM_BACKPACK in FRulez) or
4241 (FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS]) or
4242 (FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS]) or
4243 (FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS]) or
4244 (FAmmo[A_CELLS] < FMaxAmmo[A_CELLS]) or
4245 (FAmmo[A_FUEL] < FMaxAmmo[A_FUEL]) then
4246 begin
4247 FMaxAmmo[A_BULLETS] := AmmoLimits[1, A_BULLETS];
4248 FMaxAmmo[A_SHELLS] := AmmoLimits[1, A_SHELLS];
4249 FMaxAmmo[A_ROCKETS] := AmmoLimits[1, A_ROCKETS];
4250 FMaxAmmo[A_CELLS] := AmmoLimits[1, A_CELLS];
4251 FMaxAmmo[A_FUEL] := AmmoLimits[1, A_FUEL];
4253 if FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS] then
4254 IncMax(FAmmo[A_BULLETS], 10, FMaxAmmo[A_BULLETS]);
4255 if FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS] then
4256 IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
4257 if FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS] then
4258 IncMax(FAmmo[A_ROCKETS], 1, FMaxAmmo[A_ROCKETS]);
4259 if FAmmo[A_CELLS] < FMaxAmmo[A_CELLS] then
4260 IncMax(FAmmo[A_CELLS], 40, FMaxAmmo[A_CELLS]);
4261 if FAmmo[A_FUEL] < FMaxAmmo[A_FUEL] then
4262 IncMax(FAmmo[A_FUEL], 50, FMaxAmmo[A_FUEL]);
4264 FRulez := FRulez + [R_ITEM_BACKPACK];
4265 Result := True;
4266 remove := True;
4267 if gFlash = 2 then Inc(FPickup, 5);
4268 end;
4270 ITEM_KEY_RED:
4271 if not(R_KEY_RED in FRulez) then
4272 begin
4273 Include(FRulez, R_KEY_RED);
4274 Result := True;
4275 remove := (gGameSettings.GameMode <> GM_COOP) and (g_Player_GetCount() < 2);
4276 if gFlash = 2 then Inc(FPickup, 5);
4277 if (not remove) and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETITEM');
4278 end;
4280 ITEM_KEY_GREEN:
4281 if not(R_KEY_GREEN in FRulez) then
4282 begin
4283 Include(FRulez, R_KEY_GREEN);
4284 Result := True;
4285 remove := (gGameSettings.GameMode <> GM_COOP) and (g_Player_GetCount() < 2);
4286 if gFlash = 2 then Inc(FPickup, 5);
4287 if (not remove) and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETITEM');
4288 end;
4290 ITEM_KEY_BLUE:
4291 if not(R_KEY_BLUE in FRulez) then
4292 begin
4293 Include(FRulez, R_KEY_BLUE);
4294 Result := True;
4295 remove := (gGameSettings.GameMode <> GM_COOP) and (g_Player_GetCount() < 2);
4296 if gFlash = 2 then Inc(FPickup, 5);
4297 if (not remove) and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETITEM');
4298 end;
4300 ITEM_SUIT:
4301 if FMegaRulez[MR_SUIT] < gTime+PLAYER_SUIT_TIME then
4302 begin
4303 FMegaRulez[MR_SUIT] := gTime+PLAYER_SUIT_TIME;
4304 Result := True;
4305 remove := True;
4306 FFireTime := 0;
4307 if gFlash = 2 then Inc(FPickup, 5);
4308 end;
4310 ITEM_OXYGEN:
4311 if FAir < AIR_MAX then
4312 begin
4313 FAir := AIR_MAX;
4314 Result := True;
4315 remove := True;
4316 if gFlash = 2 then Inc(FPickup, 5);
4317 end;
4319 ITEM_MEDKIT_BLACK:
4320 begin
4321 if not (R_BERSERK in FRulez) then
4322 begin
4323 Include(FRulez, R_BERSERK);
4324 if (shouldSwitch(WP_LAST + 1, false)) then
4325 QueueWeaponSwitch(WEAPON_KASTET);
4326 if gFlash <> 0 then
4327 begin
4328 Inc(FPain, 100);
4329 if gFlash = 2 then Inc(FPickup, 5);
4330 end;
4331 FBerserk := gTime+30000;
4332 Result := True;
4333 remove := True;
4334 FFireTime := 0;
4335 end;
4336 if (FHealth < PLAYER_HP_SOFT) or (FFireTime > 0) then
4337 begin
4338 if FHealth < PLAYER_HP_SOFT then FHealth := PLAYER_HP_SOFT;
4339 FBerserk := gTime+30000;
4340 Result := True;
4341 remove := True;
4342 FFireTime := 0;
4343 end;
4344 end;
4346 ITEM_INVUL:
4347 if FMegaRulez[MR_INVUL] < gTime+PLAYER_INVUL_TIME then
4348 begin
4349 FMegaRulez[MR_INVUL] := gTime+PLAYER_INVUL_TIME;
4350 FSpawnInvul := 0;
4351 Result := True;
4352 remove := True;
4353 if gFlash = 2 then Inc(FPickup, 5);
4354 end;
4356 ITEM_BOTTLE:
4357 if (FHealth < PLAYER_HP_LIMIT) or (FFireTime > 0) then
4358 begin
4359 if FHealth < PLAYER_HP_LIMIT then IncMax(FHealth, 4, PLAYER_HP_LIMIT);
4360 Result := True;
4361 remove := True;
4362 FFireTime := 0;
4363 if gFlash = 2 then Inc(FPickup, 5);
4364 end;
4366 ITEM_HELMET:
4367 if FArmor < PLAYER_AP_LIMIT then
4368 begin
4369 IncMax(FArmor, 5, PLAYER_AP_LIMIT);
4370 Result := True;
4371 remove := True;
4372 if gFlash = 2 then Inc(FPickup, 5);
4373 end;
4375 ITEM_JETPACK:
4376 if FJetFuel < JET_MAX then
4377 begin
4378 FJetFuel := JET_MAX;
4379 Result := True;
4380 remove := True;
4381 if gFlash = 2 then Inc(FPickup, 5);
4382 end;
4384 ITEM_INVIS:
4385 if FMegaRulez[MR_INVIS] < gTime+PLAYER_INVIS_TIME then
4386 begin
4387 FMegaRulez[MR_INVIS] := gTime+PLAYER_INVIS_TIME;
4388 Result := True;
4389 remove := True;
4390 if gFlash = 2 then Inc(FPickup, 5);
4391 end;
4392 end;
4394 if (shouldSwitch(switchWeapon, hadWeapon)) then
4395 QueueWeaponSwitch(switchWeapon);
4396 end;
4398 procedure TPlayer.Touch();
4399 begin
4400 if not FAlive then
4401 Exit;
4402 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4403 if FIamBot then
4404 begin
4405 // Áðîñèòü ôëàã òîâàðèùó:
4406 if gGameSettings.GameMode = GM_CTF then
4407 DropFlag();
4408 end;
4409 end;
4411 procedure TPlayer.Push(vx, vy: Integer);
4412 begin
4413 if (not FPhysics) and FGhost then
4414 Exit;
4415 FObj.Accel.X := FObj.Accel.X + vx;
4416 FObj.Accel.Y := FObj.Accel.Y + vy;
4417 if g_Game_IsNet and g_Game_IsServer then
4418 MH_SEND_PlayerPos(True, FUID, NET_EVERYONE);
4419 end;
4421 procedure TPlayer.Reset(Force: Boolean);
4422 begin
4423 if Force then
4424 FAlive := False;
4426 FSpawned := False;
4427 FTime[T_RESPAWN] := 0;
4428 FTime[T_FLAGCAP] := 0;
4429 FGodMode := False;
4430 FNoTarget := False;
4431 FNoReload := False;
4432 FFrags := 0;
4433 FLastFrag := 0;
4434 FComboEvnt := -1;
4435 FKills := 0;
4436 FMonsterKills := 0;
4437 FDeath := 0;
4438 FSecrets := 0;
4439 FSpawnInvul := 0;
4440 FCorpse := -1;
4441 FReady := False;
4442 if FNoRespawn then
4443 begin
4444 FSpectator := False;
4445 FGhost := False;
4446 FPhysics := True;
4447 FSpectatePlayer := -1;
4448 FNoRespawn := False;
4449 end;
4450 FLives := gGameSettings.MaxLives;
4452 SetFlag(FLAG_NONE);
4453 end;
4455 procedure TPlayer.SoftReset();
4456 begin
4457 ReleaseKeys();
4459 FDamageBuffer := 0;
4460 FSlopeOld := 0;
4461 FIncCamOld := 0;
4462 FIncCam := 0;
4463 FBFGFireCounter := -1;
4464 FShellTimer := -1;
4465 FPain := 0;
4466 FLastHit := 0;
4467 FLastFrag := 0;
4468 FComboEvnt := -1;
4470 SetFlag(FLAG_NONE);
4471 SetAction(A_STAND, True);
4472 end;
4474 function TPlayer.GetRespawnPoint(): Byte;
4475 var
4476 c: Byte;
4477 begin
4478 Result := 255;
4479 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4481 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4482 if gGameSettings.GameMode in [GM_COOP, GM_SINGLE] then
4483 begin
4484 if Self = gPlayer1 then
4485 begin
4486 // player 1 should try to spawn on the player 1 point
4487 if g_Map_GetPointCount(RESPAWNPOINT_PLAYER1) > 0 then
4488 Exit(RESPAWNPOINT_PLAYER1)
4489 else if g_Map_GetPointCount(RESPAWNPOINT_PLAYER2) > 0 then
4490 Exit(RESPAWNPOINT_PLAYER2);
4491 end
4492 else if Self = gPlayer2 then
4493 begin
4494 // player 2 should try to spawn on the player 2 point
4495 if g_Map_GetPointCount(RESPAWNPOINT_PLAYER2) > 0 then
4496 Exit(RESPAWNPOINT_PLAYER2)
4497 else if g_Map_GetPointCount(RESPAWNPOINT_PLAYER1) > 0 then
4498 Exit(RESPAWNPOINT_PLAYER1);
4499 end
4500 else
4501 begin
4502 // other players randomly pick either the first or the second point
4503 c := IfThen((Random(2) = 0), RESPAWNPOINT_PLAYER1, RESPAWNPOINT_PLAYER2);
4504 if g_Map_GetPointCount(c) > 0 then
4505 Exit(c);
4506 // try the other one
4507 c := IfThen((c = RESPAWNPOINT_PLAYER1), RESPAWNPOINT_PLAYER2, RESPAWNPOINT_PLAYER1);
4508 if g_Map_GetPointCount(c) > 0 then
4509 Exit(c);
4510 end;
4511 end;
4513 // Ìÿñîïîâàë
4514 if gGameSettings.GameMode = GM_DM then
4515 begin
4516 // try DM points first
4517 if g_Map_GetPointCount(RESPAWNPOINT_DM) > 0 then
4518 Exit(RESPAWNPOINT_DM);
4519 end;
4521 // Êîìàíäíûå
4522 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
4523 begin
4524 // try team points first
4525 c := RESPAWNPOINT_DM;
4526 if FTeam = TEAM_RED then
4527 c := RESPAWNPOINT_RED
4528 else if FTeam = TEAM_BLUE then
4529 c := RESPAWNPOINT_BLUE;
4530 if g_Map_GetPointCount(c) > 0 then
4531 Exit(c);
4532 end;
4534 // still haven't found a spawnpoint, try random shit
4535 Result := g_Map_GetRandomPointType();
4536 end;
4538 procedure TPlayer.Respawn(Silent: Boolean; Force: Boolean = False);
4539 var
4540 RespawnPoint: TRespawnPoint;
4541 a, b, c: Byte;
4542 Anim: TAnimation;
4543 ID: DWORD;
4544 begin
4545 FSlopeOld := 0;
4546 FIncCamOld := 0;
4547 FIncCam := 0;
4548 FBFGFireCounter := -1;
4549 FShellTimer := -1;
4550 FPain := 0;
4551 FLastHit := 0;
4552 FSpawnInvul := 0;
4553 FCorpse := -1;
4555 if not g_Game_IsServer then
4556 Exit;
4557 if FDummy then
4558 Exit;
4559 FWantsInGame := True;
4560 FJustTeleported := True;
4561 if Force then
4562 begin
4563 FTime[T_RESPAWN] := 0;
4564 FAlive := False;
4565 end;
4566 FNetTime := 0;
4567 // if server changes MaxLives we gotta be ready
4568 if gGameSettings.MaxLives = 0 then FNoRespawn := False;
4570 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4571 if FTime[T_RESPAWN] > gTime then
4572 Exit;
4574 // Ïðîñðàë âñå æèçíè:
4575 if FNoRespawn then
4576 begin
4577 if not FSpectator then Spectate(True);
4578 FWantsInGame := True;
4579 Exit;
4580 end;
4582 if (gGameSettings.GameType <> GT_SINGLE) and (gGameSettings.GameMode <> GM_COOP) then
4583 begin // "Ñâîÿ èãðà"
4584 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4585 FRulez := FRulez-[R_BERSERK];
4586 end
4587 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4588 begin
4589 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4590 FRulez := FRulez-[R_KEY_RED, R_KEY_GREEN, R_KEY_BLUE, R_BERSERK];
4591 end;
4593 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4594 c := GetRespawnPoint();
4596 ReleaseKeys();
4597 SetFlag(FLAG_NONE);
4599 // Âîñêðåøåíèå áåç îðóæèÿ:
4600 if not FAlive then
4601 begin
4602 FHealth := Round(PLAYER_HP_SOFT * (FHandicap / 100));
4603 FArmor := 0;
4604 FAlive := True;
4605 FAir := AIR_DEF;
4606 FJetFuel := 0;
4608 for a := WP_FIRST to WP_LAST do
4609 begin
4610 FWeapon[a] := False;
4611 FReloading[a] := 0;
4612 end;
4614 FWeapon[WEAPON_PISTOL] := True;
4615 FWeapon[WEAPON_KASTET] := True;
4616 FCurrWeap := WEAPON_PISTOL;
4617 resetWeaponQueue();
4619 FModel.SetWeapon(FCurrWeap);
4621 for b := A_BULLETS to A_HIGH do
4622 FAmmo[b] := 0;
4624 FAmmo[A_BULLETS] := 50;
4626 FMaxAmmo[A_BULLETS] := AmmoLimits[0, A_BULLETS];
4627 FMaxAmmo[A_SHELLS] := AmmoLimits[0, A_SHELLS];
4628 FMaxAmmo[A_ROCKETS] := AmmoLimits[0, A_SHELLS];
4629 FMaxAmmo[A_CELLS] := AmmoLimits[0, A_CELLS];
4630 FMaxAmmo[A_FUEL] := AmmoLimits[0, A_FUEL];
4632 if (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF]) and
4633 LongBool(gGameSettings.Options and GAME_OPTION_DMKEYS) then
4634 FRulez := [R_KEY_RED, R_KEY_GREEN, R_KEY_BLUE]
4635 else
4636 FRulez := [];
4637 end;
4639 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4640 if not g_Map_GetPoint(c, RespawnPoint) then
4641 begin
4642 g_FatalError(_lc[I_GAME_ERROR_GET_SPAWN]);
4643 Exit;
4644 end;
4646 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4647 FObj.X := RespawnPoint.X-PLAYER_RECT.X;
4648 FObj.Y := RespawnPoint.Y-PLAYER_RECT.Y;
4649 FObj.oldX := FObj.X; // don't interpolate after respawn
4650 FObj.oldY := FObj.Y;
4651 FObj.Vel.X := 0;
4652 FObj.Vel.Y := 0;
4653 FObj.Accel.X := 0;
4654 FObj.Accel.Y := 0;
4656 FDirection := RespawnPoint.Direction;
4657 if FDirection = TDirection.D_LEFT then
4658 FAngle := 180
4659 else
4660 FAngle := 0;
4662 SetAction(A_STAND, True);
4663 FModel.Direction := FDirection;
4665 for a := Low(FTime) to High(FTime) do
4666 FTime[a] := 0;
4668 for a := Low(FMegaRulez) to High(FMegaRulez) do
4669 FMegaRulez[a] := 0;
4671 // Respawn invulnerability
4672 if (gGameSettings.GameType <> GT_SINGLE) and (gGameSettings.SpawnInvul > 0) then
4673 begin
4674 FMegaRulez[MR_INVUL] := gTime + gGameSettings.SpawnInvul * 1000;
4675 FSpawnInvul := FMegaRulez[MR_INVUL];
4676 end;
4678 FDamageBuffer := 0;
4679 FJetpack := False;
4680 FCanJetpack := False;
4681 FFlaming := False;
4682 FFireTime := 0;
4683 FFirePainTime := 0;
4684 FFireAttacker := 0;
4686 // Àíèìàöèÿ âîçðîæäåíèÿ:
4687 if (not gLoadGameMode) and (not Silent) then
4688 if g_Frames_Get(ID, 'FRAMES_TELEPORT') then
4689 begin
4690 Anim := TAnimation.Create(ID, False, 3);
4691 g_GFX_OnceAnim(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
4692 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32, Anim);
4693 Anim.Free();
4694 end;
4696 FSpectator := False;
4697 FGhost := False;
4698 FPhysics := True;
4699 FSpectatePlayer := -1;
4700 FSpawned := True;
4702 if (gPlayer1 = nil) and (gSpectLatchPID1 = FUID) then
4703 gPlayer1 := self;
4704 if (gPlayer2 = nil) and (gSpectLatchPID2 = FUID) then
4705 gPlayer2 := self;
4707 if g_Game_IsNet then
4708 begin
4709 MH_SEND_PlayerPos(True, FUID, NET_EVERYONE);
4710 MH_SEND_PlayerStats(FUID, NET_EVERYONE);
4711 if not Silent then
4712 MH_SEND_Effect(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
4713 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32,
4714 0, NET_GFX_TELE);
4715 end;
4716 end;
4718 procedure TPlayer.Spectate(NoMove: Boolean = False);
4719 begin
4720 if FAlive then
4721 Kill(K_EXTRAHARDKILL, FUID, HIT_SOME)
4722 else if (not NoMove) then
4723 begin
4724 GameX := gMapInfo.Width div 2;
4725 GameY := gMapInfo.Height div 2;
4726 end;
4727 FXTo := GameX;
4728 FYTo := GameY;
4730 FAlive := False;
4731 FSpectator := True;
4732 FGhost := True;
4733 FPhysics := False;
4734 FWantsInGame := False;
4735 FSpawned := False;
4736 FCorpse := -1;
4738 if FNoRespawn then
4739 begin
4740 if Self = gPlayer1 then
4741 begin
4742 gSpectLatchPID1 := FUID;
4743 gPlayer1 := nil;
4744 end
4745 else if Self = gPlayer2 then
4746 begin
4747 gSpectLatchPID2 := FUID;
4748 gPlayer2 := nil;
4749 end;
4750 end;
4752 if g_Game_IsNet then
4753 MH_SEND_PlayerStats(FUID);
4754 end;
4756 procedure TPlayer.SwitchNoClip;
4757 begin
4758 if not FAlive then
4759 Exit;
4760 FGhost := not FGhost;
4761 FPhysics := not FGhost;
4762 if FGhost then
4763 begin
4764 FXTo := FObj.X;
4765 FYTo := FObj.Y;
4766 end else
4767 begin
4768 FObj.Accel.X := 0;
4769 FObj.Accel.Y := 0;
4770 end;
4771 end;
4773 procedure TPlayer.Run(Direction: TDirection);
4774 var
4775 a, b: Integer;
4776 begin
4777 if MAX_RUNVEL > 8 then
4778 FlySmoke();
4780 // Áåæèì:
4781 if Direction = TDirection.D_LEFT then
4782 begin
4783 if FObj.Vel.X > -MAX_RUNVEL then
4784 FObj.Vel.X := FObj.Vel.X - (MAX_RUNVEL shr 3);
4785 end
4786 else
4787 if FObj.Vel.X < MAX_RUNVEL then
4788 FObj.Vel.X := FObj.Vel.X + (MAX_RUNVEL shr 3);
4790 // Âîçìîæíî, ïèíàåì êóñêè:
4791 if (FObj.Vel.X <> 0) and (gGibs <> nil) then
4792 begin
4793 b := Abs(FObj.Vel.X);
4794 if b > 1 then b := b * (Random(8 div b) + 1);
4795 for a := 0 to High(gGibs) do
4796 begin
4797 if gGibs[a].alive and
4798 g_Obj_Collide(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y+FObj.Rect.Height-4,
4799 FObj.Rect.Width, 8, @gGibs[a].Obj) and (Random(3) = 0) then
4800 begin
4801 // Ïèíàåì êóñêè
4802 if FObj.Vel.X < 0 then
4803 begin
4804 g_Obj_PushA(@gGibs[a].Obj, b, Random(61)+120) // íàëåâî
4805 end
4806 else
4807 begin
4808 g_Obj_PushA(@gGibs[a].Obj, b, Random(61)); // íàïðàâî
4809 end;
4810 gGibs[a].positionChanged(); // this updates spatial accelerators
4811 end;
4812 end;
4813 end;
4815 SetAction(A_WALK);
4816 end;
4818 procedure TPlayer.SeeDown();
4819 begin
4820 SetAction(A_SEEDOWN);
4822 if FDirection = TDirection.D_LEFT then FAngle := ANGLE_LEFTDOWN else FAngle := ANGLE_RIGHTDOWN;
4824 if FIncCam > -120 then DecMin(FIncCam, 5, -120);
4825 end;
4827 procedure TPlayer.SeeUp();
4828 begin
4829 SetAction(A_SEEUP);
4831 if FDirection = TDirection.D_LEFT then FAngle := ANGLE_LEFTUP else FAngle := ANGLE_RIGHTUP;
4833 if FIncCam < 120 then IncMax(FIncCam, 5, 120);
4834 end;
4836 procedure TPlayer.SetAction(Action: Byte; Force: Boolean = False);
4837 var
4838 Prior: Byte;
4839 begin
4840 case Action of
4841 A_WALK: Prior := 3;
4842 A_DIE1: Prior := 5;
4843 A_DIE2: Prior := 5;
4844 A_ATTACK: Prior := 2;
4845 A_SEEUP: Prior := 1;
4846 A_SEEDOWN: Prior := 1;
4847 A_ATTACKUP: Prior := 2;
4848 A_ATTACKDOWN: Prior := 2;
4849 A_PAIN: Prior := 4;
4850 else Prior := 0;
4851 end;
4853 if (Prior > FActionPrior) or Force then
4854 if not ((Prior = 2) and (FCurrWeap = WEAPON_SAW)) then
4855 begin
4856 FActionPrior := Prior;
4857 FActionAnim := Action;
4858 FActionForce := Force;
4859 FActionChanged := True;
4860 end;
4862 if Action in [A_ATTACK, A_ATTACKUP, A_ATTACKDOWN] then FModel.SetFire(True);
4863 end;
4865 function TPlayer.StayOnStep(XInc, YInc: Integer): Boolean;
4866 begin
4867 Result := not g_Map_CollidePanel(FObj.X+PLAYER_RECT.X, FObj.Y+YInc+PLAYER_RECT.Y+PLAYER_RECT.Height-1,
4868 PLAYER_RECT.Width, 1, PANEL_STEP, False)
4869 and g_Map_CollidePanel(FObj.X+PLAYER_RECT.X, FObj.Y+YInc+PLAYER_RECT.Y+PLAYER_RECT.Height,
4870 PLAYER_RECT.Width, 1, PANEL_STEP, False);
4871 end;
4873 function TPlayer.TeleportTo(X, Y: Integer; silent: Boolean; dir: Byte): Boolean;
4874 var
4875 Anim: TAnimation;
4876 ID: DWORD;
4877 begin
4878 Result := False;
4880 if g_CollideLevel(X, Y, PLAYER_RECT.Width, PLAYER_RECT.Height) then
4881 begin
4882 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj.X, FObj.Y);
4883 if g_Game_IsServer and g_Game_IsNet then
4884 MH_SEND_Sound(FObj.X, FObj.Y, 'SOUND_GAME_NOTELEPORT');
4885 Exit;
4886 end;
4888 FJustTeleported := True;
4890 Anim := nil;
4891 if not silent then
4892 begin
4893 if g_Frames_Get(ID, 'FRAMES_TELEPORT') then
4894 begin
4895 Anim := TAnimation.Create(ID, False, 3);
4896 end;
4898 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj.X, FObj.Y);
4899 g_GFX_OnceAnim(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
4900 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32, Anim);
4901 if g_Game_IsServer and g_Game_IsNet then
4902 MH_SEND_Effect(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
4903 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32, 1,
4904 NET_GFX_TELE);
4905 end;
4907 FObj.X := X-PLAYER_RECT.X;
4908 FObj.Y := Y-PLAYER_RECT.Y;
4909 FObj.oldX := FObj.X; // don't interpolate after respawn
4910 FObj.oldY := FObj.Y;
4911 if FAlive and FGhost then
4912 begin
4913 FXTo := FObj.X;
4914 FYTo := FObj.Y;
4915 end;
4917 if not g_Game_IsNet then
4918 begin
4919 if dir = 1 then
4920 begin
4921 SetDirection(TDirection.D_LEFT);
4922 FAngle := 180;
4923 end
4924 else
4925 if dir = 2 then
4926 begin
4927 SetDirection(TDirection.D_RIGHT);
4928 FAngle := 0;
4929 end
4930 else
4931 if dir = 3 then
4932 begin // îáðàòíîå
4933 if FDirection = TDirection.D_RIGHT then
4934 begin
4935 SetDirection(TDirection.D_LEFT);
4936 FAngle := 180;
4937 end
4938 else
4939 begin
4940 SetDirection(TDirection.D_RIGHT);
4941 FAngle := 0;
4942 end;
4943 end;
4944 end;
4946 if not silent and (Anim <> nil) then
4947 begin
4948 g_GFX_OnceAnim(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
4949 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32, Anim);
4950 Anim.Free();
4952 if g_Game_IsServer and g_Game_IsNet then
4953 MH_SEND_Effect(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
4954 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32, 0,
4955 NET_GFX_TELE);
4956 end;
4958 Result := True;
4959 end;
4961 function nonz(a: Single): Single;
4962 begin
4963 if a <> 0 then
4964 Result := a
4965 else
4966 Result := 1;
4967 end;
4969 function TPlayer.refreshCorpse(): Boolean;
4970 var
4971 i: Integer;
4972 begin
4973 Result := False;
4974 FCorpse := -1;
4975 if FAlive or FSpectator then
4976 Exit;
4977 if (gCorpses = nil) or (Length(gCorpses) = 0) then
4978 Exit;
4979 for i := 0 to High(gCorpses) do
4980 if gCorpses[i] <> nil then
4981 if gCorpses[i].FPlayerUID = FUID then
4982 begin
4983 Result := True;
4984 FCorpse := i;
4985 break;
4986 end;
4987 end;
4989 function TPlayer.getCameraObj(): TObj;
4990 begin
4991 if (not FAlive) and (not FSpectator) and
4992 (FCorpse >= 0) and (FCorpse < Length(gCorpses)) and
4993 (gCorpses[FCorpse] <> nil) and (gCorpses[FCorpse].FPlayerUID = FUID) then
4994 begin
4995 gCorpses[FCorpse].FObj.slopeUpLeft := FObj.slopeUpLeft;
4996 Result := gCorpses[FCorpse].FObj;
4997 end
4998 else
4999 begin
5000 Result := FObj;
5001 end;
5002 end;
5004 procedure TPlayer.PreUpdate();
5005 begin
5006 FSlopeOld := FObj.slopeUpLeft;
5007 FIncCamOld := FIncCam;
5008 FObj.oldX := FObj.X;
5009 FObj.oldY := FObj.Y;
5010 end;
5012 procedure TPlayer.Update();
5013 var
5014 b: Byte;
5015 i, ii, wx, wy, xd, yd, k: Integer;
5016 blockmon, headwater, dospawn: Boolean;
5017 NetServer: Boolean;
5018 AnyServer: Boolean;
5019 SetSpect: Boolean;
5020 begin
5021 NetServer := g_Game_IsNet and g_Game_IsServer;
5022 AnyServer := g_Game_IsServer;
5024 if g_Game_IsClient and (NetInterpLevel > 0) then
5025 DoLerp(NetInterpLevel + 1)
5026 else
5027 if FGhost then
5028 DoLerp(4);
5030 if NetServer then
5031 if (FClientID >= 0) and (NetClients[FClientID].Peer <> nil) then
5032 begin
5033 FPing := NetClients[FClientID].Peer^.lastRoundTripTime;
5034 if NetClients[FClientID].Peer^.packetsSent > 0 then
5035 FLoss := Round(100*NetClients[FClientID].Peer^.packetsLost/NetClients[FClientID].Peer^.packetsSent)
5036 else
5037 FLoss := 0;
5038 end else
5039 begin
5040 FPing := 0;
5041 FLoss := 0;
5042 end;
5044 if FAlive and (FPunchAnim <> nil) then
5045 FPunchAnim.Update();
5047 if FAlive and (gFly or FJetpack) then
5048 FlySmoke();
5050 if FDirection = TDirection.D_LEFT then
5051 FAngle := 180
5052 else
5053 FAngle := 0;
5055 if FAlive and (not FGhost) then
5056 begin
5057 if FKeys[KEY_UP].Pressed then
5058 SeeUp();
5059 if FKeys[KEY_DOWN].Pressed then
5060 SeeDown();
5061 end;
5063 if (not (FKeys[KEY_UP].Pressed or FKeys[KEY_DOWN].Pressed)) and
5064 (FIncCam <> 0) then
5065 begin
5066 i := g_basic.Sign(FIncCam);
5067 FIncCam := Abs(FIncCam);
5068 DecMin(FIncCam, 5, 0);
5069 FIncCam := FIncCam*i;
5070 end;
5072 if gTime mod (GAME_TICK*2) <> 0 then
5073 begin
5074 if (FObj.Vel.X = 0) and FAlive then
5075 begin
5076 if FKeys[KEY_LEFT].Pressed then
5077 Run(TDirection.D_LEFT);
5078 if FKeys[KEY_RIGHT].Pressed then
5079 Run(TDirection.D_RIGHT);
5080 end;
5082 if FPhysics then
5083 begin
5084 g_Obj_Move(@FObj, True, True, True);
5085 positionChanged(); // this updates spatial accelerators
5086 end;
5088 Exit;
5089 end;
5091 FActionChanged := False;
5093 if FAlive then
5094 begin
5095 // Let alive player do some actions
5096 if FKeys[KEY_LEFT].Pressed then Run(TDirection.D_LEFT);
5097 if FKeys[KEY_RIGHT].Pressed then Run(TDirection.D_RIGHT);
5098 if FKeys[KEY_FIRE].Pressed and AnyServer then Fire()
5099 else
5100 begin
5101 if AnyServer then
5102 begin
5103 FlamerOff;
5104 if NetServer then MH_SEND_PlayerStats(FUID);
5105 end;
5106 end;
5107 if FKeys[KEY_OPEN].Pressed and AnyServer then Use();
5108 if FKeys[KEY_JUMP].Pressed then Jump()
5109 else
5110 begin
5111 if AnyServer and FJetpack then
5112 begin
5113 FJetpack := False;
5114 JetpackOff;
5115 if NetServer then MH_SEND_PlayerStats(FUID);
5116 end;
5117 FCanJetpack := True;
5118 end;
5119 end
5120 else // Dead
5121 begin
5122 dospawn := False;
5123 if not FGhost then
5124 for k := Low(FKeys) to KEY_CHAT-1 do
5125 begin
5126 if FKeys[k].Pressed then
5127 begin
5128 dospawn := True;
5129 break;
5130 end;
5131 end;
5132 if dospawn then
5133 begin
5134 if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
5135 Respawn(False)
5136 else // Single
5137 if (FTime[T_RESPAWN] <= gTime) and
5138 gGameOn and (not FAlive) then
5139 begin
5140 if (g_Player_GetCount() > 1) then
5141 Respawn(False)
5142 else
5143 begin
5144 gExit := EXIT_RESTART;
5145 Exit;
5146 end;
5147 end;
5148 end;
5149 // Dead spectator actions
5150 if FGhost then
5151 begin
5152 if FKeys[KEY_OPEN].Pressed and AnyServer then Fire();
5153 if FKeys[KEY_FIRE].Pressed and AnyServer then
5154 begin
5155 if FSpectator then
5156 begin
5157 if (FSpectatePlayer >= High(gPlayers)) then
5158 FSpectatePlayer := -1
5159 else
5160 begin
5161 SetSpect := False;
5162 for I := FSpectatePlayer + 1 to High(gPlayers) do
5163 if gPlayers[I] <> nil then
5164 if gPlayers[I].alive then
5165 if gPlayers[I].UID <> FUID then
5166 begin
5167 FSpectatePlayer := I;
5168 SetSpect := True;
5169 break;
5170 end;
5172 if not SetSpect then FSpectatePlayer := -1;
5173 end;
5175 ReleaseKeys;
5176 end;
5177 end;
5178 end;
5179 end;
5180 // No clipping
5181 if FGhost then
5182 begin
5183 if FKeys[KEY_UP].Pressed or FKeys[KEY_JUMP].Pressed then
5184 begin
5185 FYTo := FObj.Y - 32;
5186 FSpectatePlayer := -1;
5187 end;
5188 if FKeys[KEY_DOWN].Pressed then
5189 begin
5190 FYTo := FObj.Y + 32;
5191 FSpectatePlayer := -1;
5192 end;
5193 if FKeys[KEY_LEFT].Pressed then
5194 begin
5195 FXTo := FObj.X - 32;
5196 FSpectatePlayer := -1;
5197 end;
5198 if FKeys[KEY_RIGHT].Pressed then
5199 begin
5200 FXTo := FObj.X + 32;
5201 FSpectatePlayer := -1;
5202 end;
5204 if (FXTo < -64) then
5205 FXTo := -64
5206 else if (FXTo > gMapInfo.Width + 32) then
5207 FXTo := gMapInfo.Width + 32;
5208 if (FYTo < -72) then
5209 FYTo := -72
5210 else if (FYTo > gMapInfo.Height + 32) then
5211 FYTo := gMapInfo.Height + 32;
5212 end;
5214 if FPhysics then
5215 begin
5216 g_Obj_Move(@FObj, True, True, True);
5217 positionChanged(); // this updates spatial accelerators
5218 end
5219 else
5220 begin
5221 FObj.Vel.X := 0;
5222 FObj.Vel.Y := 0;
5223 if FSpectator then
5224 if (FSpectatePlayer <= High(gPlayers)) and (FSpectatePlayer >= 0) then
5225 if gPlayers[FSpectatePlayer] <> nil then
5226 if gPlayers[FSpectatePlayer].alive then
5227 begin
5228 FXTo := gPlayers[FSpectatePlayer].GameX;
5229 FYTo := gPlayers[FSpectatePlayer].GameY;
5230 end;
5231 end;
5233 blockmon := g_Map_CollidePanel(FObj.X+PLAYER_HEADRECT.X, FObj.Y+PLAYER_HEADRECT.Y,
5234 PLAYER_HEADRECT.Width, PLAYER_HEADRECT.Height,
5235 PANEL_BLOCKMON, True);
5236 headwater := HeadInLiquid(0, 0);
5238 // Ñîïðîòèâëåíèå âîçäóõà:
5239 if (not FAlive) or not (FKeys[KEY_LEFT].Pressed or FKeys[KEY_RIGHT].Pressed) then
5240 if FObj.Vel.X <> 0 then
5241 FObj.Vel.X := z_dec(FObj.Vel.X, 1);
5243 if (FLastHit = HIT_TRAP) and (FPain > 90) then FPain := 90;
5244 DecMin(FPain, 5, 0);
5245 DecMin(FPickup, 1, 0);
5247 if FAlive and (FObj.Y > Integer(gMapInfo.Height)+128) and AnyServer then
5248 begin
5249 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
5250 FMegaRulez[MR_SUIT] := 0;
5251 FMegaRulez[MR_INVUL] := 0;
5252 FMegaRulez[MR_INVIS] := 0;
5253 Kill(K_FALLKILL, 0, HIT_FALL);
5254 end;
5256 i := 9;
5258 if FAlive then
5259 begin
5260 if FCurrWeap = WEAPON_SAW then
5261 if not (FSawSound.IsPlaying() or FSawSoundHit.IsPlaying() or
5262 FSawSoundSelect.IsPlaying()) then
5263 FSawSoundIdle.PlayAt(FObj.X, FObj.Y);
5265 if FJetpack then
5266 if (not FJetSoundFly.IsPlaying()) and (not FJetSoundOn.IsPlaying()) and
5267 (not FJetSoundOff.IsPlaying()) then
5268 begin
5269 FJetSoundFly.SetPosition(0);
5270 FJetSoundFly.PlayAt(FObj.X, FObj.Y);
5271 end;
5273 for b := WP_FIRST to WP_LAST do
5274 if FReloading[b] > 0 then
5275 if FNoReload then
5276 FReloading[b] := 0
5277 else
5278 Dec(FReloading[b]);
5280 if FShellTimer > -1 then
5281 if FShellTimer = 0 then
5282 begin
5283 if FShellType = SHELL_SHELL then
5284 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
5285 GameVelX, GameVelY-2, SHELL_SHELL)
5286 else if FShellType = SHELL_DBLSHELL then
5287 begin
5288 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
5289 GameVelX+1, GameVelY-2, SHELL_SHELL);
5290 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
5291 GameVelX-1, GameVelY-2, SHELL_SHELL);
5292 end;
5293 FShellTimer := -1;
5294 end else Dec(FShellTimer);
5296 if (FBFGFireCounter > -1) then
5297 if FBFGFireCounter = 0 then
5298 begin
5299 if AnyServer then
5300 begin
5301 wx := FObj.X+WEAPONPOINT[FDirection].X;
5302 wy := FObj.Y+WEAPONPOINT[FDirection].Y;
5303 xd := wx+IfThen(FDirection = TDirection.D_LEFT, -30, 30);
5304 yd := wy+firediry();
5305 g_Weapon_bfgshot(wx, wy, xd, yd, FUID);
5306 if NetServer then MH_SEND_PlayerFire(FUID, WEAPON_BFG, wx, wy, xd, yd);
5307 if (FAngle = 0) or (FAngle = 180) then SetAction(A_ATTACK)
5308 else if (FAngle = ANGLE_LEFTDOWN) or (FAngle = ANGLE_RIGHTDOWN) then SetAction(A_ATTACKDOWN)
5309 else if (FAngle = ANGLE_LEFTUP) or (FAngle = ANGLE_RIGHTUP) then SetAction(A_ATTACKUP);
5310 end;
5312 FReloading[WEAPON_BFG] := WEAPON_RELOAD[WEAPON_BFG];
5313 FBFGFireCounter := -1;
5314 end else
5315 if FNoReload then
5316 FBFGFireCounter := 0
5317 else
5318 Dec(FBFGFireCounter);
5320 if (FMegaRulez[MR_SUIT] < gTime) and AnyServer then
5321 begin
5322 b := g_GetAcidHit(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width, PLAYER_RECT.Height);
5324 if (b > 0) and (gTime mod (15*GAME_TICK) = 0) then Damage(b, 0, 0, 0, HIT_ACID);
5325 end;
5327 if (headwater or blockmon) then
5328 begin
5329 Dec(FAir);
5331 if FAir < -9 then
5332 begin
5333 if AnyServer then Damage(10, 0, 0, 0, HIT_WATER);
5334 FAir := 0;
5335 end
5336 else if (FAir mod 31 = 0) and not blockmon then
5337 begin
5338 g_GFX_Bubbles(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2), FObj.Y+PLAYER_RECT.Y-4, 5+Random(6), 8, 4);
5339 if Random(2) = 0 then
5340 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj.X, FObj.Y)
5341 else
5342 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj.X, FObj.Y);
5343 end;
5344 end else if FAir < AIR_DEF then
5345 FAir := AIR_DEF;
5347 if FFireTime > 0 then
5348 begin
5349 if BodyInLiquid(0, 0) then
5350 begin
5351 FFireTime := 0;
5352 FFirePainTime := 0;
5353 end
5354 else if FMegaRulez[MR_SUIT] >= gTime then
5355 begin
5356 if FMegaRulez[MR_SUIT] = gTime then
5357 FFireTime := 1;
5358 FFirePainTime := 0;
5359 end
5360 else
5361 begin
5362 OnFireFlame(1);
5363 if FFirePainTime <= 0 then
5364 begin
5365 if g_Game_IsServer then
5366 Damage(2, FFireAttacker, 0, 0, HIT_FLAME);
5367 FFirePainTime := 12 - FFireTime div 12;
5368 end;
5369 FFirePainTime := FFirePainTime - 1;
5370 FFireTime := FFireTime - 1;
5371 if ((FFireTime mod 33) = 0) and (FMegaRulez[MR_INVUL] < gTime) then
5372 FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
5373 if (FFireTime = 0) and g_Game_IsNet and g_Game_IsServer then
5374 MH_SEND_PlayerStats(FUID);
5375 end;
5376 end;
5378 if FDamageBuffer > 0 then
5379 begin
5380 if FDamageBuffer >= 9 then
5381 begin
5382 SetAction(A_PAIN);
5384 if FDamageBuffer < 30 then i := 9
5385 else if FDamageBuffer < 100 then i := 18
5386 else i := 27;
5387 end;
5389 ii := Round(FDamageBuffer*FHealth / nonz(FArmor*(3/4)+FHealth));
5390 FArmor := FArmor-(FDamageBuffer-ii);
5391 FHealth := FHealth-ii;
5392 if FArmor < 0 then
5393 begin
5394 FHealth := FHealth+FArmor;
5395 FArmor := 0;
5396 end;
5398 if AnyServer then
5399 if FHealth <= 0 then
5400 if FHealth > -30 then Kill(K_SIMPLEKILL, FLastSpawnerUID, FLastHit)
5401 else if FHealth > -50 then Kill(K_HARDKILL, FLastSpawnerUID, FLastHit)
5402 else Kill(K_EXTRAHARDKILL, FLastSpawnerUID, FLastHit);
5404 if FAlive and ((FLastHit <> HIT_FLAME) or (FFireTime <= 0)) then
5405 begin
5406 if FDamageBuffer <= 20 then FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y)
5407 else if FDamageBuffer <= 55 then FModel.PlaySound(MODELSOUND_PAIN, 2, FObj.X, FObj.Y)
5408 else if FDamageBuffer <= 120 then FModel.PlaySound(MODELSOUND_PAIN, 3, FObj.X, FObj.Y)
5409 else FModel.PlaySound(MODELSOUND_PAIN, 4, FObj.X, FObj.Y);
5410 end;
5412 FDamageBuffer := 0;
5413 end;
5415 {CollideItem();}
5416 end; // if FAlive then ...
5418 if (FActionAnim = A_PAIN) and (FModel.Animation <> A_PAIN) then
5419 begin
5420 FModel.ChangeAnimation(FActionAnim, FActionForce);
5421 FModel.GetCurrentAnimation.MinLength := i;
5422 FModel.GetCurrentAnimationMask.MinLength := i;
5423 end else FModel.ChangeAnimation(FActionAnim, FActionForce and (FModel.Animation <> A_STAND));
5425 if (FModel.GetCurrentAnimation.Played or ((not FActionChanged) and (FModel.Animation = A_WALK)))
5426 then SetAction(A_STAND, True);
5428 if not ((FModel.Animation = A_WALK) and (Abs(FObj.Vel.X) < 4) and not FModel.Fire) then FModel.Update;
5430 for b := Low(FKeys) to High(FKeys) do
5431 if FKeys[b].Time = 0 then FKeys[b].Pressed := False else Dec(FKeys[b].Time);
5432 end;
5435 procedure TPlayer.getMapBox (out x, y, w, h: Integer); inline;
5436 begin
5437 x := FObj.X+PLAYER_RECT.X;
5438 y := FObj.Y+PLAYER_RECT.Y;
5439 w := PLAYER_RECT.Width;
5440 h := PLAYER_RECT.Height;
5441 end;
5444 procedure TPlayer.moveBy (dx, dy: Integer); inline;
5445 begin
5446 if (dx <> 0) or (dy <> 0) then
5447 begin
5448 FObj.X += dx;
5449 FObj.Y += dy;
5450 positionChanged();
5451 end;
5452 end;
5455 function TPlayer.Collide(X, Y: Integer; Width, Height: Word): Boolean;
5456 begin
5457 Result := g_Collide(FObj.X+PLAYER_RECT.X,
5458 FObj.Y+PLAYER_RECT.Y,
5459 PLAYER_RECT.Width,
5460 PLAYER_RECT.Height,
5461 X, Y,
5462 Width, Height);
5463 end;
5465 function TPlayer.Collide(Panel: TPanel): Boolean;
5466 begin
5467 Result := g_Collide(FObj.X+PLAYER_RECT.X,
5468 FObj.Y+PLAYER_RECT.Y,
5469 PLAYER_RECT.Width,
5470 PLAYER_RECT.Height,
5471 Panel.X, Panel.Y,
5472 Panel.Width, Panel.Height);
5473 end;
5475 function TPlayer.Collide(X, Y: Integer): Boolean;
5476 begin
5477 X := X-FObj.X-PLAYER_RECT.X;
5478 Y := Y-FObj.Y-PLAYER_RECT.Y;
5479 Result := (x >= 0) and (x <= PLAYER_RECT.Width) and
5480 (y >= 0) and (y <= PLAYER_RECT.Height);
5481 end;
5483 function g_Player_ValidName(Name: string): Boolean;
5484 var
5485 a: Integer;
5486 begin
5487 Result := True;
5489 if gPlayers = nil then Exit;
5491 for a := 0 to High(gPlayers) do
5492 if gPlayers[a] <> nil then
5493 if LowerCase(Name) = LowerCase(gPlayers[a].FName) then
5494 begin
5495 Result := False;
5496 Exit;
5497 end;
5498 end;
5500 procedure TPlayer.SetDirection(Direction: TDirection);
5501 var
5502 d: TDirection;
5503 begin
5504 d := FModel.Direction;
5506 FModel.Direction := Direction;
5507 if d <> Direction then FModel.ChangeAnimation(FModel.Animation, True);
5509 FDirection := Direction;
5510 end;
5512 function TPlayer.GetKeys(): Byte;
5513 begin
5514 Result := 0;
5516 if R_KEY_RED in FRulez then Result := KEY_RED;
5517 if R_KEY_GREEN in FRulez then Result := Result or KEY_GREEN;
5518 if R_KEY_BLUE in FRulez then Result := Result or KEY_BLUE;
5520 if FTeam = TEAM_RED then Result := Result or KEY_REDTEAM;
5521 if FTeam = TEAM_BLUE then Result := Result or KEY_BLUETEAM;
5522 end;
5524 procedure TPlayer.Use();
5525 var
5526 a: Integer;
5527 begin
5528 if FTime[T_USE] > gTime then Exit;
5530 g_Triggers_PressR(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
5531 PLAYER_RECT.Height, FUID, ACTIVATE_PLAYERPRESS);
5533 for a := 0 to High(gPlayers) do
5534 if (gPlayers[a] <> nil) and (gPlayers[a] <> Self) and
5535 gPlayers[a].alive and SameTeam(FUID, gPlayers[a].FUID) and
5536 g_Obj_Collide(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y,
5537 FObj.Rect.Width, FObj.Rect.Height, @gPlayers[a].FObj) then
5538 begin
5539 gPlayers[a].Touch();
5540 if g_Game_IsNet and g_Game_IsServer then
5541 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH, gPlayers[a].FUID);
5542 end;
5544 FTime[T_USE] := gTime+120;
5545 end;
5547 procedure TPlayer.NetFire(Wpn: Byte; X, Y, AX, AY: Integer; WID: Integer = -1);
5548 var
5549 locObj: TObj;
5550 F: Boolean;
5551 WX, WY, XD, YD: Integer;
5552 begin
5553 F := False;
5554 WX := X;
5555 WY := Y;
5556 XD := AX;
5557 YD := AY;
5559 case FCurrWeap of
5560 WEAPON_KASTET:
5561 begin
5562 DoPunch();
5563 if R_BERSERK in FRulez then
5564 begin
5565 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5566 locobj.X := FObj.X+FObj.Rect.X;
5567 locobj.Y := FObj.Y+FObj.Rect.Y;
5568 locobj.rect.X := 0;
5569 locobj.rect.Y := 0;
5570 locobj.rect.Width := 39;
5571 locobj.rect.Height := 52;
5572 locobj.Vel.X := (xd-wx) div 2;
5573 locobj.Vel.Y := (yd-wy) div 2;
5574 locobj.Accel.X := xd-wx;
5575 locobj.Accel.y := yd-wy;
5577 if g_Weapon_Hit(@locobj, 50, FUID, HIT_SOME) <> 0 then
5578 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj.X, FObj.Y)
5579 else
5580 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj.X, FObj.Y);
5582 if gFlash = 1 then
5583 if FPain < 50 then
5584 FPain := min(FPain + 25, 50);
5585 end else
5586 g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 3, FUID);
5587 end;
5589 WEAPON_SAW:
5590 begin
5591 if g_Weapon_chainsaw(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y,
5592 IfThen(gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF], 9, 3), FUID) <> 0 then
5593 begin
5594 FSawSoundSelect.Stop();
5595 FSawSound.Stop();
5596 FSawSoundHit.PlayAt(FObj.X, FObj.Y);
5597 end
5598 else if not FSawSoundHit.IsPlaying() then
5599 begin
5600 FSawSoundSelect.Stop();
5601 FSawSound.PlayAt(FObj.X, FObj.Y);
5602 end;
5603 f := True;
5604 end;
5606 WEAPON_PISTOL:
5607 begin
5608 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX, Gamey);
5609 FFireAngle := FAngle;
5610 f := True;
5611 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
5612 GameVelX, GameVelY-2, SHELL_BULLET);
5613 end;
5615 WEAPON_SHOTGUN1:
5616 begin
5617 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex, Gamey);
5618 FFireAngle := FAngle;
5619 f := True;
5620 FShellTimer := 10;
5621 FShellType := SHELL_SHELL;
5622 end;
5624 WEAPON_SHOTGUN2:
5625 begin
5626 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex, Gamey);
5627 FFireAngle := FAngle;
5628 f := True;
5629 FShellTimer := 13;
5630 FShellType := SHELL_DBLSHELL;
5631 end;
5633 WEAPON_CHAINGUN:
5634 begin
5635 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex, Gamey);
5636 FFireAngle := FAngle;
5637 f := True;
5638 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
5639 GameVelX, GameVelY-2, SHELL_BULLET);
5640 end;
5642 WEAPON_ROCKETLAUNCHER:
5643 begin
5644 g_Weapon_Rocket(wx, wy, xd, yd, FUID, WID);
5645 FFireAngle := FAngle;
5646 f := True;
5647 end;
5649 WEAPON_PLASMA:
5650 begin
5651 g_Weapon_Plasma(wx, wy, xd, yd, FUID, WID);
5652 FFireAngle := FAngle;
5653 f := True;
5654 end;
5656 WEAPON_BFG:
5657 begin
5658 g_Weapon_BFGShot(wx, wy, xd, yd, FUID, WID);
5659 FFireAngle := FAngle;
5660 f := True;
5661 end;
5663 WEAPON_SUPERPULEMET:
5664 begin
5665 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex, Gamey);
5666 FFireAngle := FAngle;
5667 f := True;
5668 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
5669 GameVelX, GameVelY-2, SHELL_SHELL);
5670 end;
5672 WEAPON_FLAMETHROWER:
5673 begin
5674 g_Weapon_flame(wx, wy, xd, yd, FUID, WID);
5675 FlamerOn;
5676 FFireAngle := FAngle;
5677 f := True;
5678 end;
5679 end;
5681 if not f then Exit;
5683 if (FAngle = 0) or (FAngle = 180) then SetAction(A_ATTACK)
5684 else if (FAngle = ANGLE_LEFTDOWN) or (FAngle = ANGLE_RIGHTDOWN) then SetAction(A_ATTACKDOWN)
5685 else if (FAngle = ANGLE_LEFTUP) or (FAngle = ANGLE_RIGHTUP) then SetAction(A_ATTACKUP);
5686 end;
5688 procedure TPlayer.DoLerp(Level: Integer = 2);
5689 begin
5690 if FObj.X <> FXTo then FObj.X := Lerp(FObj.X, FXTo, Level);
5691 if FObj.Y <> FYTo then FObj.Y := Lerp(FObj.Y, FYTo, Level);
5692 end;
5694 procedure TPlayer.SetLerp(XTo, YTo: Integer);
5695 var
5696 AX, AY: Integer;
5697 begin
5698 FXTo := XTo;
5699 FYTo := YTo;
5700 if FJustTeleported or (NetInterpLevel < 1) then
5701 begin
5702 FObj.X := XTo;
5703 FObj.Y := YTo;
5704 if FJustTeleported then
5705 begin
5706 FObj.oldX := FObj.X;
5707 FObj.oldY := FObj.Y;
5708 end;
5709 end
5710 else
5711 begin
5712 AX := Abs(FXTo - FObj.X);
5713 AY := Abs(FYTo - FObj.Y);
5714 if (AX > 32) or (AX <= NetInterpLevel) then
5715 FObj.X := FXTo;
5716 if (AY > 32) or (AY <= NetInterpLevel) then
5717 FObj.Y := FYTo;
5718 end;
5719 end;
5721 function TPlayer.FullInLift(XInc, YInc: Integer): Integer;
5722 begin
5723 if g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc,
5724 PLAYER_RECT.Width, PLAYER_RECT.Height-8,
5725 PANEL_LIFTUP, False) then Result := -1
5726 else
5727 if g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc,
5728 PLAYER_RECT.Width, PLAYER_RECT.Height-8,
5729 PANEL_LIFTDOWN, False) then Result := 1
5730 else Result := 0;
5731 end;
5733 function TPlayer.GetFlag(Flag: Byte): Boolean;
5734 var
5735 s, ts: String;
5736 evtype, a: Byte;
5737 begin
5738 Result := False;
5740 if Flag = FLAG_NONE then
5741 Exit;
5743 if not g_Game_IsServer then Exit;
5745 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5746 if (Flag = FTeam) and
5747 (gFlags[Flag].State = FLAG_STATE_NORMAL) and
5748 (FFlag <> FLAG_NONE) then
5749 begin
5750 if FFlag = FLAG_RED then
5751 s := _lc[I_PLAYER_FLAG_RED]
5752 else
5753 s := _lc[I_PLAYER_FLAG_BLUE];
5755 evtype := FLAG_STATE_SCORED;
5757 ts := Format('%.4d', [gFlags[FFlag].CaptureTime]);
5758 Insert('.', ts, Length(ts) + 1 - 3);
5759 g_Console_Add(Format(_lc[I_PLAYER_FLAG_CAPTURE], [FName, s, ts]), True);
5761 g_Map_ResetFlag(FFlag);
5762 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_CAPTURE], [AnsiUpperCase(s)]), 144);
5764 if ((Self = gPlayer1) or (Self = gPlayer2)
5765 or ((gPlayer1 <> nil) and (gPlayer1.Team = FTeam))
5766 or ((gPlayer2 <> nil) and (gPlayer2.Team = FTeam))) then
5767 a := 0
5768 else
5769 a := 1;
5771 if not sound_cap_flag[a].IsPlaying() then
5772 sound_cap_flag[a].Play();
5774 gTeamStat[FTeam].Goals := gTeamStat[FTeam].Goals + 1;
5776 Result := True;
5777 if g_Game_IsNet then
5778 begin
5779 MH_SEND_FlagEvent(evtype, FFlag, FUID, False);
5780 MH_SEND_GameStats;
5781 end;
5783 gFlags[FFlag].CaptureTime := 0;
5784 SetFlag(FLAG_NONE);
5785 Exit;
5786 end;
5788 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5789 if (Flag = FTeam) and
5790 (gFlags[Flag].State = FLAG_STATE_DROPPED) then
5791 begin
5792 if Flag = FLAG_RED then
5793 s := _lc[I_PLAYER_FLAG_RED]
5794 else
5795 s := _lc[I_PLAYER_FLAG_BLUE];
5797 evtype := FLAG_STATE_RETURNED;
5798 gFlags[Flag].CaptureTime := 0;
5800 g_Console_Add(Format(_lc[I_PLAYER_FLAG_RETURN], [FName, s]), True);
5802 g_Map_ResetFlag(Flag);
5803 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_RETURN], [AnsiUpperCase(s)]), 144);
5805 if ((Self = gPlayer1) or (Self = gPlayer2)
5806 or ((gPlayer1 <> nil) and (gPlayer1.Team = FTeam))
5807 or ((gPlayer2 <> nil) and (gPlayer2.Team = FTeam))) then
5808 a := 0
5809 else
5810 a := 1;
5812 if not sound_ret_flag[a].IsPlaying() then
5813 sound_ret_flag[a].Play();
5815 Result := True;
5816 if g_Game_IsNet then
5817 begin
5818 MH_SEND_FlagEvent(evtype, Flag, FUID, False);
5819 MH_SEND_GameStats;
5820 end;
5821 Exit;
5822 end;
5824 // Ïîäîáðàë ÷óæîé ôëàã:
5825 if (Flag <> FTeam) and (FTime[T_FLAGCAP] <= gTime) then
5826 begin
5827 SetFlag(Flag);
5829 if Flag = FLAG_RED then
5830 s := _lc[I_PLAYER_FLAG_RED]
5831 else
5832 s := _lc[I_PLAYER_FLAG_BLUE];
5834 evtype := FLAG_STATE_CAPTURED;
5836 g_Console_Add(Format(_lc[I_PLAYER_FLAG_GET], [FName, s]), True);
5838 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_GET], [AnsiUpperCase(s)]), 144);
5840 gFlags[Flag].State := FLAG_STATE_CAPTURED;
5842 if ((Self = gPlayer1) or (Self = gPlayer2)
5843 or ((gPlayer1 <> nil) and (gPlayer1.Team = FTeam))
5844 or ((gPlayer2 <> nil) and (gPlayer2.Team = FTeam))) then
5845 a := 0
5846 else
5847 a := 1;
5849 if not sound_get_flag[a].IsPlaying() then
5850 sound_get_flag[a].Play();
5852 Result := True;
5853 if g_Game_IsNet then
5854 begin
5855 MH_SEND_FlagEvent(evtype, Flag, FUID, False);
5856 MH_SEND_GameStats;
5857 end;
5858 end;
5859 end;
5861 procedure TPlayer.SetFlag(Flag: Byte);
5862 begin
5863 FFlag := Flag;
5864 if FModel <> nil then
5865 FModel.SetFlag(FFlag);
5866 end;
5868 function TPlayer.TryDropFlag(): Boolean;
5869 begin
5870 if LongBool(gGameSettings.Options and GAME_OPTION_ALLOWDROPFLAG) then
5871 Result := DropFlag(False, LongBool(gGameSettings.Options and GAME_OPTION_THROWFLAG))
5872 else
5873 Result := False;
5874 end;
5876 function TPlayer.DropFlag(Silent: Boolean = True; DoThrow: Boolean = False): Boolean;
5877 var
5878 s: String;
5879 a: Byte;
5880 xv, yv: Integer;
5881 begin
5882 Result := False;
5883 if (not g_Game_IsServer) or (FFlag = FLAG_NONE) then
5884 Exit;
5885 FTime[T_FLAGCAP] := gTime + 2000;
5886 with gFlags[FFlag] do
5887 begin
5888 Obj.X := FObj.X;
5889 Obj.Y := FObj.Y;
5890 Direction := FDirection;
5891 State := FLAG_STATE_DROPPED;
5892 Count := FLAG_TIME;
5893 if DoThrow then
5894 begin
5895 xv := FObj.Vel.X + IfThen(Direction = TDirection.D_RIGHT, 10, -10);
5896 yv := FObj.Vel.Y - 2;
5897 end
5898 else
5899 begin
5900 xv := (FObj.Vel.X div 2);
5901 yv := (FObj.Vel.Y div 2) - 2;
5902 end;
5903 g_Obj_Push(@Obj, xv, yv);
5905 positionChanged(); // this updates spatial accelerators
5907 if FFlag = FLAG_RED then
5908 s := _lc[I_PLAYER_FLAG_RED]
5909 else
5910 s := _lc[I_PLAYER_FLAG_BLUE];
5912 g_Console_Add(Format(_lc[I_PLAYER_FLAG_DROP], [FName, s]), True);
5913 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_DROP], [AnsiUpperCase(s)]), 144);
5915 if ((Self = gPlayer1) or (Self = gPlayer2)
5916 or ((gPlayer1 <> nil) and (gPlayer1.Team = FTeam))
5917 or ((gPlayer2 <> nil) and (gPlayer2.Team = FTeam))) then
5918 a := 0
5919 else
5920 a := 1;
5922 if (not Silent) and (not sound_lost_flag[a].IsPlaying()) then
5923 sound_lost_flag[a].Play();
5925 if g_Game_IsNet then
5926 MH_SEND_FlagEvent(FLAG_STATE_DROPPED, Flag, FUID, False);
5927 end;
5928 SetFlag(FLAG_NONE);
5929 Result := True;
5930 end;
5932 procedure TPlayer.GetSecret();
5933 begin
5934 if (self = gPlayer1) or (self = gPlayer2) then
5935 begin
5936 g_Console_Add(Format(_lc[I_PLAYER_SECRET], [FName]), True);
5937 g_Sound_PlayEx('SOUND_GAME_SECRET');
5938 end;
5939 Inc(FSecrets);
5940 end;
5942 procedure TPlayer.PressKey(Key: Byte; Time: Word = 1);
5943 begin
5944 Assert(Key <= High(FKeys));
5946 FKeys[Key].Pressed := True;
5947 FKeys[Key].Time := Time;
5948 end;
5950 function TPlayer.IsKeyPressed(K: Byte): Boolean;
5951 begin
5952 Result := FKeys[K].Pressed;
5953 end;
5955 procedure TPlayer.ReleaseKeys();
5956 var
5957 a: Integer;
5958 begin
5959 for a := Low(FKeys) to High(FKeys) do
5960 begin
5961 FKeys[a].Pressed := False;
5962 FKeys[a].Time := 0;
5963 end;
5964 end;
5966 procedure TPlayer.OnDamage(Angle: SmallInt);
5967 begin
5968 end;
5970 function TPlayer.firediry(): Integer;
5971 begin
5972 if FKeys[KEY_UP].Pressed then Result := -42
5973 else if FKeys[KEY_DOWN].Pressed then Result := 19
5974 else Result := 0;
5975 end;
5977 procedure TPlayer.RememberState();
5978 var
5979 i: Integer;
5980 SavedState: TPlayerSavedState;
5981 begin
5982 SavedState.Health := FHealth;
5983 SavedState.Armor := FArmor;
5984 SavedState.Air := FAir;
5985 SavedState.JetFuel := FJetFuel;
5986 SavedState.CurrWeap := FCurrWeap;
5987 SavedState.NextWeap := FNextWeap;
5988 SavedState.NextWeapDelay := FNextWeapDelay;
5989 for i := Low(FWeapon) to High(FWeapon) do
5990 SavedState.Weapon[i] := FWeapon[i];
5991 for i := Low(FAmmo) to High(FAmmo) do
5992 SavedState.Ammo[i] := FAmmo[i];
5993 for i := Low(FMaxAmmo) to High(FMaxAmmo) do
5994 SavedState.MaxAmmo[i] := FMaxAmmo[i];
5995 SavedState.Rulez := FRulez - [R_KEY_RED, R_KEY_GREEN, R_KEY_BLUE];
5997 FSavedStateNum := -1;
5998 for i := Low(SavedStates) to High(SavedStates) do
5999 if not SavedStates[i].Used then
6000 begin
6001 FSavedStateNum := i;
6002 break;
6003 end;
6004 if FSavedStateNum < 0 then
6005 begin
6006 SetLength(SavedStates, Length(SavedStates) + 1);
6007 FSavedStateNum := High(SavedStates);
6008 end;
6010 SavedState.Used := True;
6011 SavedStates[FSavedStateNum] := SavedState;
6012 end;
6014 procedure TPlayer.RecallState();
6015 var
6016 i: Integer;
6017 SavedState: TPlayerSavedState;
6018 begin
6019 if(FSavedStateNum < 0) or (FSavedStateNum > High(SavedStates)) then
6020 Exit;
6022 SavedState := SavedStates[FSavedStateNum];
6023 SavedStates[FSavedStateNum].Used := False;
6024 FSavedStateNum := -1;
6026 FHealth := SavedState.Health;
6027 FArmor := SavedState.Armor;
6028 FAir := SavedState.Air;
6029 FJetFuel := SavedState.JetFuel;
6030 FCurrWeap := SavedState.CurrWeap;
6031 FNextWeap := SavedState.NextWeap;
6032 FNextWeapDelay := SavedState.NextWeapDelay;
6033 for i := Low(FWeapon) to High(FWeapon) do
6034 FWeapon[i] := SavedState.Weapon[i];
6035 for i := Low(FAmmo) to High(FAmmo) do
6036 FAmmo[i] := SavedState.Ammo[i];
6037 for i := Low(FMaxAmmo) to High(FMaxAmmo) do
6038 FMaxAmmo[i] := SavedState.MaxAmmo[i];
6039 FRulez := SavedState.Rulez;
6041 if gGameSettings.GameType = GT_SERVER then
6042 MH_SEND_PlayerStats(FUID);
6043 end;
6045 procedure TPlayer.SaveState (st: TStream);
6046 var
6047 i: Integer;
6048 b: Byte;
6049 begin
6050 // Ñèãíàòóðà èãðîêà
6051 utils.writeSign(st, 'PLYR');
6052 utils.writeInt(st, Byte(PLR_SAVE_VERSION)); // version
6053 // Áîò èëè ÷åëîâåê
6054 utils.writeBool(st, FIamBot);
6055 // UID èãðîêà
6056 utils.writeInt(st, Word(FUID));
6057 // Èìÿ èãðîêà
6058 utils.writeStr(st, FName);
6059 // Êîìàíäà
6060 utils.writeInt(st, Byte(FTeam));
6061 // Æèâ ëè
6062 utils.writeBool(st, FAlive);
6063 // Èçðàñõîäîâàë ëè âñå æèçíè
6064 utils.writeBool(st, FNoRespawn);
6065 // Íàïðàâëåíèå
6066 if FDirection = TDirection.D_LEFT then b := 1 else b := 2; // D_RIGHT
6067 utils.writeInt(st, Byte(b));
6068 // Çäîðîâüå
6069 utils.writeInt(st, LongInt(FHealth));
6070 // Êîýôôèöèåíò èíâàëèäíîñòè
6071 utils.writeInt(st, LongInt(FHandicap));
6072 // Æèçíè
6073 utils.writeInt(st, Byte(FLives));
6074 // Áðîíÿ
6075 utils.writeInt(st, LongInt(FArmor));
6076 // Çàïàñ âîçäóõà
6077 utils.writeInt(st, LongInt(FAir));
6078 // Çàïàñ ãîðþ÷åãî
6079 utils.writeInt(st, LongInt(FJetFuel));
6080 // Áîëü
6081 utils.writeInt(st, LongInt(FPain));
6082 // Óáèë
6083 utils.writeInt(st, LongInt(FKills));
6084 // Óáèë ìîíñòðîâ
6085 utils.writeInt(st, LongInt(FMonsterKills));
6086 // Ôðàãîâ
6087 utils.writeInt(st, LongInt(FFrags));
6088 // Ôðàãîâ ïîäðÿä
6089 utils.writeInt(st, Byte(FFragCombo));
6090 // Âðåìÿ ïîñëåäíåãî ôðàãà
6091 utils.writeInt(st, LongWord(FLastFrag));
6092 // Ñìåðòåé
6093 utils.writeInt(st, LongInt(FDeath));
6094 // Êàêîé ôëàã íåñåò
6095 utils.writeInt(st, Byte(FFlag));
6096 // Íàøåë ñåêðåòîâ
6097 utils.writeInt(st, LongInt(FSecrets));
6098 // Òåêóùåå îðóæèå
6099 utils.writeInt(st, Byte(FCurrWeap));
6100 // Æåëàåìîå îðóæèå
6101 utils.writeInt(st, Word(FNextWeap));
6102 // ...è ïàóçà
6103 utils.writeInt(st, Byte(FNextWeapDelay));
6104 // Âðåìÿ çàðÿäêè BFG
6105 utils.writeInt(st, SmallInt(FBFGFireCounter));
6106 // Áóôåð óðîíà
6107 utils.writeInt(st, LongInt(FDamageBuffer));
6108 // Ïîñëåäíèé óäàðèâøèé
6109 utils.writeInt(st, Word(FLastSpawnerUID));
6110 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6111 utils.writeInt(st, Byte(FLastHit));
6112 // Îáúåêò èãðîêà
6113 Obj_SaveState(st, @FObj);
6114 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6115 for i := A_BULLETS to A_HIGH do utils.writeInt(st, Word(FAmmo[i]));
6116 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6117 for i := A_BULLETS to A_HIGH do utils.writeInt(st, Word(FMaxAmmo[i]));
6118 // Íàëè÷èå îðóæèÿ
6119 for i := WP_FIRST to WP_LAST do utils.writeBool(st, FWeapon[i]);
6120 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6121 for i := WP_FIRST to WP_LAST do utils.writeInt(st, Word(FReloading[i]));
6122 // Íàëè÷èå ðþêçàêà
6123 utils.writeBool(st, (R_ITEM_BACKPACK in FRulez));
6124 // Íàëè÷èå êðàñíîãî êëþ÷à
6125 utils.writeBool(st, (R_KEY_RED in FRulez));
6126 // Íàëè÷èå çåëåíîãî êëþ÷à
6127 utils.writeBool(st, (R_KEY_GREEN in FRulez));
6128 // Íàëè÷èå ñèíåãî êëþ÷à
6129 utils.writeBool(st, (R_KEY_BLUE in FRulez));
6130 // Íàëè÷èå áåðñåðêà
6131 utils.writeBool(st, (R_BERSERK in FRulez));
6132 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6133 for i := MR_SUIT to MR_MAX do utils.writeInt(st, LongWord(FMegaRulez[i]));
6134 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6135 for i := T_RESPAWN to T_FLAGCAP do utils.writeInt(st, LongWord(FTime[i]));
6136 // Íàçâàíèå ìîäåëè
6137 utils.writeStr(st, FModel.Name);
6138 // Öâåò ìîäåëè
6139 utils.writeInt(st, Byte(FColor.R));
6140 utils.writeInt(st, Byte(FColor.G));
6141 utils.writeInt(st, Byte(FColor.B));
6142 end;
6145 procedure TPlayer.LoadState (st: TStream);
6146 var
6147 i: Integer;
6148 str: String;
6149 b: Byte;
6150 begin
6151 assert(st <> nil);
6153 // Ñèãíàòóðà èãðîêà
6154 if not utils.checkSign(st, 'PLYR') then raise XStreamError.Create('invalid player signature');
6155 if (utils.readByte(st) <> PLR_SAVE_VERSION) then raise XStreamError.Create('invalid player version');
6156 // Áîò èëè ÷åëîâåê:
6157 FIamBot := utils.readBool(st);
6158 // UID èãðîêà
6159 FUID := utils.readWord(st);
6160 // Èìÿ èãðîêà
6161 str := utils.readStr(st);
6162 if (self <> gPlayer1) and (self <> gPlayer2) then FName := str;
6163 // Êîìàíäà
6164 FTeam := utils.readByte(st);
6165 // Æèâ ëè
6166 FAlive := utils.readBool(st);
6167 // Èçðàñõîäîâàë ëè âñå æèçíè
6168 FNoRespawn := utils.readBool(st);
6169 // Íàïðàâëåíèå
6170 b := utils.readByte(st);
6171 if b = 1 then FDirection := TDirection.D_LEFT else FDirection := TDirection.D_RIGHT; // b = 2
6172 // Çäîðîâüå
6173 FHealth := utils.readLongInt(st);
6174 // Êîýôôèöèåíò èíâàëèäíîñòè
6175 FHandicap := utils.readLongInt(st);
6176 // Æèçíè
6177 FLives := utils.readByte(st);
6178 // Áðîíÿ
6179 FArmor := utils.readLongInt(st);
6180 // Çàïàñ âîçäóõà
6181 FAir := utils.readLongInt(st);
6182 // Çàïàñ ãîðþ÷åãî
6183 FJetFuel := utils.readLongInt(st);
6184 // Áîëü
6185 FPain := utils.readLongInt(st);
6186 // Óáèë
6187 FKills := utils.readLongInt(st);
6188 // Óáèë ìîíñòðîâ
6189 FMonsterKills := utils.readLongInt(st);
6190 // Ôðàãîâ
6191 FFrags := utils.readLongInt(st);
6192 // Ôðàãîâ ïîäðÿä
6193 FFragCombo := utils.readByte(st);
6194 // Âðåìÿ ïîñëåäíåãî ôðàãà
6195 FLastFrag := utils.readLongWord(st);
6196 // Ñìåðòåé
6197 FDeath := utils.readLongInt(st);
6198 // Êàêîé ôëàã íåñåò
6199 FFlag := utils.readByte(st);
6200 // Íàøåë ñåêðåòîâ
6201 FSecrets := utils.readLongInt(st);
6202 // Òåêóùåå îðóæèå
6203 FCurrWeap := utils.readByte(st);
6204 // Æåëàåìîå îðóæèå
6205 FNextWeap := utils.readWord(st);
6206 // ...è ïàóçà
6207 FNextWeapDelay := utils.readByte(st);
6208 // Âðåìÿ çàðÿäêè BFG
6209 FBFGFireCounter := utils.readSmallInt(st);
6210 // Áóôåð óðîíà
6211 FDamageBuffer := utils.readLongInt(st);
6212 // Ïîñëåäíèé óäàðèâøèé
6213 FLastSpawnerUID := utils.readWord(st);
6214 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6215 FLastHit := utils.readByte(st);
6216 // Îáúåêò èãðîêà
6217 Obj_LoadState(@FObj, st);
6218 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6219 for i := A_BULLETS to A_HIGH do FAmmo[i] := utils.readWord(st);
6220 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6221 for i := A_BULLETS to A_HIGH do FMaxAmmo[i] := utils.readWord(st);
6222 // Íàëè÷èå îðóæèÿ
6223 for i := WP_FIRST to WP_LAST do FWeapon[i] := utils.readBool(st);
6224 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6225 for i := WP_FIRST to WP_LAST do FReloading[i] := utils.readWord(st);
6226 // Íàëè÷èå ðþêçàêà
6227 if utils.readBool(st) then Include(FRulez, R_ITEM_BACKPACK);
6228 // Íàëè÷èå êðàñíîãî êëþ÷à
6229 if utils.readBool(st) then Include(FRulez, R_KEY_RED);
6230 // Íàëè÷èå çåëåíîãî êëþ÷à
6231 if utils.readBool(st) then Include(FRulez, R_KEY_GREEN);
6232 // Íàëè÷èå ñèíåãî êëþ÷à
6233 if utils.readBool(st) then Include(FRulez, R_KEY_BLUE);
6234 // Íàëè÷èå áåðñåðêà
6235 if utils.readBool(st) then Include(FRulez, R_BERSERK);
6236 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6237 for i := MR_SUIT to MR_MAX do FMegaRulez[i] := utils.readLongWord(st);
6238 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6239 for i := T_RESPAWN to T_FLAGCAP do FTime[i] := utils.readLongWord(st);
6240 // Íàçâàíèå ìîäåëè
6241 str := utils.readStr(st);
6242 // Öâåò ìîäåëè
6243 FColor.R := utils.readByte(st);
6244 FColor.G := utils.readByte(st);
6245 FColor.B := utils.readByte(st);
6246 if (self = gPlayer1) then
6247 begin
6248 str := gPlayer1Settings.Model;
6249 FColor := gPlayer1Settings.Color;
6250 end
6251 else if (self = gPlayer2) then
6252 begin
6253 str := gPlayer2Settings.Model;
6254 FColor := gPlayer2Settings.Color;
6255 end;
6256 // Îáíîâëÿåì ìîäåëü èãðîêà
6257 SetModel(str);
6258 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
6259 FModel.Color := TEAMCOLOR[FTeam]
6260 else
6261 FModel.Color := FColor;
6262 end;
6265 procedure TPlayer.AllRulez(Health: Boolean);
6266 var
6267 a: Integer;
6268 begin
6269 if Health then
6270 begin
6271 FHealth := PLAYER_HP_LIMIT;
6272 FArmor := PLAYER_AP_LIMIT;
6273 Exit;
6274 end;
6276 for a := WP_FIRST to WP_LAST do FWeapon[a] := True;
6277 for a := A_BULLETS to A_HIGH do FAmmo[a] := 30000;
6278 FRulez := FRulez+[R_KEY_RED, R_KEY_GREEN, R_KEY_BLUE];
6279 end;
6281 procedure TPlayer.RestoreHealthArmor();
6282 begin
6283 FHealth := PLAYER_HP_LIMIT;
6284 FArmor := PLAYER_AP_LIMIT;
6285 end;
6287 procedure TPlayer.FragCombo();
6288 var
6289 Param: Integer;
6290 begin
6291 if (gGameSettings.GameMode in [GM_COOP, GM_SINGLE]) or g_Game_IsClient then
6292 Exit;
6293 if gTime - FLastFrag < FRAG_COMBO_TIME then
6294 begin
6295 if FFragCombo < 5 then
6296 Inc(FFragCombo);
6297 Param := FUID or (FFragCombo shl 16);
6298 if (FComboEvnt >= Low(gDelayedEvents)) and
6299 (FComboEvnt <= High(gDelayedEvents)) and
6300 gDelayedEvents[FComboEvnt].Pending and
6301 (gDelayedEvents[FComboEvnt].DEType = DE_KILLCOMBO) and
6302 (gDelayedEvents[FComboEvnt].DENum and $FFFF = FUID) then
6303 begin
6304 gDelayedEvents[FComboEvnt].Time := gTime + 500;
6305 gDelayedEvents[FComboEvnt].DENum := Param;
6306 end
6307 else
6308 FComboEvnt := g_Game_DelayEvent(DE_KILLCOMBO, 500, Param);
6309 end
6310 else
6311 FFragCombo := 1;
6313 FLastFrag := gTime;
6314 end;
6316 procedure TPlayer.GiveItem(ItemType: Byte);
6317 begin
6318 case ItemType of
6319 ITEM_SUIT:
6320 if FMegaRulez[MR_SUIT] < gTime+PLAYER_SUIT_TIME then
6321 begin
6322 FMegaRulez[MR_SUIT] := gTime+PLAYER_SUIT_TIME;
6323 end;
6325 ITEM_OXYGEN:
6326 if FAir < AIR_MAX then
6327 begin
6328 FAir := AIR_MAX;
6329 end;
6331 ITEM_MEDKIT_BLACK:
6332 begin
6333 if not (R_BERSERK in FRulez) then
6334 begin
6335 Include(FRulez, R_BERSERK);
6336 if FBFGFireCounter < 1 then
6337 begin
6338 FCurrWeap := WEAPON_KASTET;
6339 resetWeaponQueue();
6340 FModel.SetWeapon(WEAPON_KASTET);
6341 end;
6342 if gFlash <> 0 then
6343 Inc(FPain, 100);
6344 FBerserk := gTime+30000;
6345 end;
6346 if FHealth < PLAYER_HP_SOFT then
6347 begin
6348 FHealth := PLAYER_HP_SOFT;
6349 FBerserk := gTime+30000;
6350 end;
6351 end;
6353 ITEM_INVUL:
6354 if FMegaRulez[MR_INVUL] < gTime+PLAYER_INVUL_TIME then
6355 begin
6356 FMegaRulez[MR_INVUL] := gTime+PLAYER_INVUL_TIME;
6357 FSpawnInvul := 0;
6358 end;
6360 ITEM_INVIS:
6361 if FMegaRulez[MR_INVIS] < gTime+PLAYER_INVIS_TIME then
6362 begin
6363 FMegaRulez[MR_INVIS] := gTime+PLAYER_INVIS_TIME;
6364 end;
6366 ITEM_JETPACK:
6367 if FJetFuel < JET_MAX then
6368 begin
6369 FJetFuel := JET_MAX;
6370 end;
6372 ITEM_MEDKIT_SMALL: if FHealth < PLAYER_HP_SOFT then IncMax(FHealth, 10, PLAYER_HP_SOFT);
6373 ITEM_MEDKIT_LARGE: if FHealth < PLAYER_HP_SOFT then IncMax(FHealth, 25, PLAYER_HP_SOFT);
6375 ITEM_ARMOR_GREEN: if FArmor < PLAYER_AP_SOFT then FArmor := PLAYER_AP_SOFT;
6376 ITEM_ARMOR_BLUE: if FArmor < PLAYER_AP_LIMIT then FArmor := PLAYER_AP_LIMIT;
6378 ITEM_SPHERE_BLUE: if FHealth < PLAYER_HP_LIMIT then IncMax(FHealth, 100, PLAYER_HP_LIMIT);
6379 ITEM_SPHERE_WHITE:
6380 if (FHealth < PLAYER_HP_LIMIT) or (FArmor < PLAYER_AP_LIMIT) then
6381 begin
6382 if FHealth < PLAYER_HP_LIMIT then FHealth := PLAYER_HP_LIMIT;
6383 if FArmor < PLAYER_AP_LIMIT then FArmor := PLAYER_AP_LIMIT;
6384 end;
6386 ITEM_WEAPON_SAW: FWeapon[WEAPON_SAW] := True;
6387 ITEM_WEAPON_SHOTGUN1: FWeapon[WEAPON_SHOTGUN1] := True;
6388 ITEM_WEAPON_SHOTGUN2: FWeapon[WEAPON_SHOTGUN2] := True;
6389 ITEM_WEAPON_CHAINGUN: FWeapon[WEAPON_CHAINGUN] := True;
6390 ITEM_WEAPON_ROCKETLAUNCHER: FWeapon[WEAPON_ROCKETLAUNCHER] := True;
6391 ITEM_WEAPON_PLASMA: FWeapon[WEAPON_PLASMA] := True;
6392 ITEM_WEAPON_BFG: FWeapon[WEAPON_BFG] := True;
6393 ITEM_WEAPON_SUPERPULEMET: FWeapon[WEAPON_SUPERPULEMET] := True;
6394 ITEM_WEAPON_FLAMETHROWER: FWeapon[WEAPON_FLAMETHROWER] := True;
6396 ITEM_AMMO_BULLETS: if FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS] then IncMax(FAmmo[A_BULLETS], 10, FMaxAmmo[A_BULLETS]);
6397 ITEM_AMMO_BULLETS_BOX: if FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS] then IncMax(FAmmo[A_BULLETS], 50, FMaxAmmo[A_BULLETS]);
6398 ITEM_AMMO_SHELLS: if FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS] then IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
6399 ITEM_AMMO_SHELLS_BOX: if FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS] then IncMax(FAmmo[A_SHELLS], 25, FMaxAmmo[A_SHELLS]);
6400 ITEM_AMMO_ROCKET: if FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS] then IncMax(FAmmo[A_ROCKETS], 1, FMaxAmmo[A_ROCKETS]);
6401 ITEM_AMMO_ROCKET_BOX: if FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS] then IncMax(FAmmo[A_ROCKETS], 5, FMaxAmmo[A_ROCKETS]);
6402 ITEM_AMMO_CELL: if FAmmo[A_CELLS] < FMaxAmmo[A_CELLS] then IncMax(FAmmo[A_CELLS], 40, FMaxAmmo[A_CELLS]);
6403 ITEM_AMMO_CELL_BIG: if FAmmo[A_CELLS] < FMaxAmmo[A_CELLS] then IncMax(FAmmo[A_CELLS], 100, FMaxAmmo[A_CELLS]);
6404 ITEM_AMMO_FUELCAN: if FAmmo[A_FUEL] < FMaxAmmo[A_FUEL] then IncMax(FAmmo[A_FUEL], 100, FMaxAmmo[A_FUEL]);
6406 ITEM_AMMO_BACKPACK:
6407 if (FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS]) or
6408 (FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS]) or
6409 (FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS]) or
6410 (FAmmo[A_CELLS] < FMaxAmmo[A_CELLS]) or
6411 (FMaxAmmo[A_FUEL] < AmmoLimits[1, A_FUEL]) then
6412 begin
6413 FMaxAmmo[A_BULLETS] := AmmoLimits[1, A_BULLETS];
6414 FMaxAmmo[A_SHELLS] := AmmoLimits[1, A_SHELLS];
6415 FMaxAmmo[A_ROCKETS] := AmmoLimits[1, A_ROCKETS];
6416 FMaxAmmo[A_CELLS] := AmmoLimits[1, A_CELLS];
6417 FMaxAmmo[A_FUEL] := AmmoLimits[1, A_FUEL];
6419 if FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS] then IncMax(FAmmo[A_BULLETS], 10, FMaxAmmo[A_BULLETS]);
6420 if FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS] then IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
6421 if FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS] then IncMax(FAmmo[A_ROCKETS], 1, FMaxAmmo[A_ROCKETS]);
6422 if FAmmo[A_CELLS] < FMaxAmmo[A_CELLS] then IncMax(FAmmo[A_CELLS], 40, FMaxAmmo[A_CELLS]);
6424 FRulez := FRulez + [R_ITEM_BACKPACK];
6425 end;
6427 ITEM_KEY_RED: if not (R_KEY_RED in FRulez) then Include(FRulez, R_KEY_RED);
6428 ITEM_KEY_GREEN: if not (R_KEY_GREEN in FRulez) then Include(FRulez, R_KEY_GREEN);
6429 ITEM_KEY_BLUE: if not (R_KEY_BLUE in FRulez) then Include(FRulez, R_KEY_BLUE);
6431 ITEM_BOTTLE: if FHealth < PLAYER_HP_LIMIT then IncMax(FHealth, 4, PLAYER_HP_LIMIT);
6432 ITEM_HELMET: if FArmor < PLAYER_AP_LIMIT then IncMax(FArmor, 5, PLAYER_AP_LIMIT);
6434 else
6435 Exit;
6436 end;
6437 if g_Game_IsNet and g_Game_IsServer then
6438 MH_SEND_PlayerStats(FUID);
6439 end;
6441 procedure TPlayer.FlySmoke(Times: DWORD = 1);
6442 var
6443 id, i: DWORD;
6444 Anim: TAnimation;
6445 begin
6446 if (Random(5) = 1) and (Times = 1) then
6447 Exit;
6449 if BodyInLiquid(0, 0) then
6450 begin
6451 g_GFX_Bubbles(Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2)+Random(3)-1,
6452 Obj.Y+Obj.Rect.Height+8, 1, 8, 4);
6453 if Random(2) = 0 then
6454 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj.X, FObj.Y)
6455 else
6456 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj.X, FObj.Y);
6457 Exit;
6458 end;
6460 if g_Frames_Get(id, 'FRAMES_SMOKE') then
6461 begin
6462 for i := 1 to Times do
6463 begin
6464 Anim := TAnimation.Create(id, False, 3);
6465 Anim.Alpha := 150;
6466 g_GFX_OnceAnim(Obj.X+Obj.Rect.X+Random(Obj.Rect.Width+Times*2)-(Anim.Width div 2),
6467 Obj.Y+Obj.Rect.Height-4+Random(8+Times*2), Anim, ONCEANIM_SMOKE);
6468 Anim.Free();
6469 end;
6470 end;
6471 end;
6473 procedure TPlayer.OnFireFlame(Times: DWORD = 1);
6474 var
6475 id, i: DWORD;
6476 Anim: TAnimation;
6477 begin
6478 if (Random(10) = 1) and (Times = 1) then
6479 Exit;
6481 if g_Frames_Get(id, 'FRAMES_FLAME') then
6482 begin
6483 for i := 1 to Times do
6484 begin
6485 Anim := TAnimation.Create(id, False, 3);
6486 Anim.Alpha := 0;
6487 g_GFX_OnceAnim(Obj.X+Obj.Rect.X+Random(Obj.Rect.Width+Times*2)-(Anim.Width div 2),
6488 Obj.Y+8+Random(8+Times*2), Anim, ONCEANIM_SMOKE);
6489 Anim.Free();
6490 end;
6491 end;
6492 end;
6494 procedure TPlayer.PauseSounds(Enable: Boolean);
6495 begin
6496 FSawSound.Pause(Enable);
6497 FSawSoundIdle.Pause(Enable);
6498 FSawSoundHit.Pause(Enable);
6499 FSawSoundSelect.Pause(Enable);
6500 FFlameSoundOn.Pause(Enable);
6501 FFlameSoundOff.Pause(Enable);
6502 FFlameSoundWork.Pause(Enable);
6503 FJetSoundFly.Pause(Enable);
6504 FJetSoundOn.Pause(Enable);
6505 FJetSoundOff.Pause(Enable);
6506 end;
6508 { T C o r p s e : }
6510 constructor TCorpse.Create(X, Y: Integer; ModelName: String; aMess: Boolean);
6511 begin
6512 g_Obj_Init(@FObj);
6513 FObj.X := X;
6514 FObj.Y := Y;
6515 FObj.Rect := PLAYER_CORPSERECT;
6516 FModelName := ModelName;
6517 FMess := aMess;
6519 if FMess then
6520 begin
6521 FState := CORPSE_STATE_MESS;
6522 g_PlayerModel_GetAnim(ModelName, A_DIE2, FAnimation, FAnimationMask);
6523 end
6524 else
6525 begin
6526 FState := CORPSE_STATE_NORMAL;
6527 g_PlayerModel_GetAnim(ModelName, A_DIE1, FAnimation, FAnimationMask);
6528 end;
6529 end;
6531 destructor TCorpse.Destroy();
6532 begin
6533 FAnimation.Free();
6535 inherited;
6536 end;
6538 function TCorpse.ObjPtr (): PObj; inline; begin result := @FObj; end;
6540 procedure TCorpse.positionChanged (); inline; begin end;
6542 procedure TCorpse.moveBy (dx, dy: Integer); inline;
6543 begin
6544 if (dx <> 0) or (dy <> 0) then
6545 begin
6546 FObj.X += dx;
6547 FObj.Y += dy;
6548 positionChanged();
6549 end;
6550 end;
6553 procedure TCorpse.getMapBox (out x, y, w, h: Integer); inline;
6554 begin
6555 x := FObj.X+PLAYER_CORPSERECT.X;
6556 y := FObj.Y+PLAYER_CORPSERECT.Y;
6557 w := PLAYER_CORPSERECT.Width;
6558 h := PLAYER_CORPSERECT.Height;
6559 end;
6562 procedure TCorpse.Damage(Value: Word; SpawnerUID: Word; vx, vy: Integer);
6563 var
6564 pm: TPlayerModel;
6565 Blood: TModelBlood;
6566 begin
6567 if FState = CORPSE_STATE_REMOVEME then
6568 Exit;
6570 FDamage := FDamage + Value;
6572 if FDamage > 150 then
6573 begin
6574 if FAnimation <> nil then
6575 begin
6576 FAnimation.Free();
6577 FAnimation := nil;
6579 FState := CORPSE_STATE_REMOVEME;
6581 g_Player_CreateGibs(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
6582 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
6583 FModelName, FColor);
6584 // Çâóê ìÿñà îò òðóïà:
6585 pm := g_PlayerModel_Get(FModelName);
6586 pm.PlaySound(MODELSOUND_DIE, 5, FObj.X, FObj.Y);
6587 pm.Free;
6589 // Çëîâåùèé ñìåõ:
6590 if (gBodyKillEvent <> -1)
6591 and gDelayedEvents[gBodyKillEvent].Pending then
6592 gDelayedEvents[gBodyKillEvent].Pending := False;
6593 gBodyKillEvent := g_Game_DelayEvent(DE_BODYKILL, 1050, SpawnerUID);
6594 end;
6595 end
6596 else
6597 begin
6598 Blood := g_PlayerModel_GetBlood(FModelName);
6599 FObj.Vel.X := FObj.Vel.X + vx;
6600 FObj.Vel.Y := FObj.Vel.Y + vy;
6601 g_GFX_Blood(FObj.X+PLAYER_CORPSERECT.X+(PLAYER_CORPSERECT.Width div 2),
6602 FObj.Y+PLAYER_CORPSERECT.Y+(PLAYER_CORPSERECT.Height div 2),
6603 Value, vx, vy, 16, (PLAYER_CORPSERECT.Height*2) div 3,
6604 Blood.R, Blood.G, Blood.B, Blood.Kind);
6605 end;
6606 end;
6608 procedure TCorpse.Draw();
6609 var
6610 fX, fY: Integer;
6611 begin
6612 if FState = CORPSE_STATE_REMOVEME then
6613 Exit;
6615 FObj.lerp(gLerpFactor, fX, fY);
6617 if FAnimation <> nil then
6618 FAnimation.Draw(fX, fY, TMirrorType.None);
6620 if FAnimationMask <> nil then
6621 begin
6622 e_Colors := FColor;
6623 FAnimationMask.Draw(fX, fY, TMirrorType.None);
6624 e_Colors.R := 255;
6625 e_Colors.G := 255;
6626 e_Colors.B := 255;
6627 end;
6628 end;
6630 procedure TCorpse.Update();
6631 var
6632 st: Word;
6633 begin
6634 if FState = CORPSE_STATE_REMOVEME then
6635 Exit;
6637 FObj.oldX := FObj.X;
6638 FObj.oldY := FObj.Y;
6640 if gTime mod (GAME_TICK*2) <> 0 then
6641 begin
6642 g_Obj_Move(@FObj, True, True, True);
6643 positionChanged(); // this updates spatial accelerators
6644 Exit;
6645 end;
6647 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6648 FObj.Vel.X := z_dec(FObj.Vel.X, 1);
6650 st := g_Obj_Move(@FObj, True, True, True);
6651 positionChanged(); // this updates spatial accelerators
6653 if WordBool(st and MOVE_FALLOUT) then
6654 begin
6655 FState := CORPSE_STATE_REMOVEME;
6656 Exit;
6657 end;
6659 if FAnimation <> nil then
6660 FAnimation.Update();
6661 if FAnimationMask <> nil then
6662 FAnimationMask.Update();
6663 end;
6666 procedure TCorpse.SaveState (st: TStream);
6667 var
6668 anim: Boolean;
6669 begin
6670 assert(st <> nil);
6672 // Ñèãíàòóðà òðóïà
6673 utils.writeSign(st, 'CORP');
6674 utils.writeInt(st, Byte(0));
6675 // Ñîñòîÿíèå
6676 utils.writeInt(st, Byte(FState));
6677 // Íàêîïëåííûé óðîí
6678 utils.writeInt(st, Byte(FDamage));
6679 // Öâåò
6680 utils.writeInt(st, Byte(FColor.R));
6681 utils.writeInt(st, Byte(FColor.G));
6682 utils.writeInt(st, Byte(FColor.B));
6683 // Îáúåêò òðóïà
6684 Obj_SaveState(st, @FObj);
6685 utils.writeInt(st, Word(FPlayerUID));
6686 // Åñòü ëè àíèìàöèÿ
6687 anim := (FAnimation <> nil);
6688 utils.writeBool(st, anim);
6689 // Åñëè åñòü - ñîõðàíÿåì
6690 if anim then FAnimation.SaveState(st);
6691 // Åñòü ëè ìàñêà àíèìàöèè
6692 anim := (FAnimationMask <> nil);
6693 utils.writeBool(st, anim);
6694 // Åñëè åñòü - ñîõðàíÿåì
6695 if anim then FAnimationMask.SaveState(st);
6696 end;
6699 procedure TCorpse.LoadState (st: TStream);
6700 var
6701 anim: Boolean;
6702 begin
6703 assert(st <> nil);
6705 // Ñèãíàòóðà òðóïà
6706 if not utils.checkSign(st, 'CORP') then raise XStreamError.Create('invalid corpse signature');
6707 if (utils.readByte(st) <> 0) then raise XStreamError.Create('invalid corpse version');
6708 // Ñîñòîÿíèå
6709 FState := utils.readByte(st);
6710 // Íàêîïëåííûé óðîí
6711 FDamage := utils.readByte(st);
6712 // Öâåò
6713 FColor.R := utils.readByte(st);
6714 FColor.G := utils.readByte(st);
6715 FColor.B := utils.readByte(st);
6716 // Îáúåêò òðóïà
6717 Obj_LoadState(@FObj, st);
6718 FPlayerUID := utils.readWord(st);
6719 // Åñòü ëè àíèìàöèÿ
6720 anim := utils.readBool(st);
6721 // Åñëè åñòü - çàãðóæàåì
6722 if anim then
6723 begin
6724 Assert(FAnimation <> nil, 'TCorpse.LoadState: no FAnimation');
6725 FAnimation.LoadState(st);
6726 end;
6727 // Åñòü ëè ìàñêà àíèìàöèè
6728 anim := utils.readBool(st);
6729 // Åñëè åñòü - çàãðóæàåì
6730 if anim then
6731 begin
6732 Assert(FAnimationMask <> nil, 'TCorpse.LoadState: no FAnimationMask');
6733 FAnimationMask.LoadState(st);
6734 end;
6735 end;
6737 { T B o t : }
6739 constructor TBot.Create();
6740 var
6741 a: Integer;
6742 begin
6743 inherited Create();
6745 FPhysics := True;
6746 FSpectator := False;
6747 FGhost := False;
6749 FIamBot := True;
6751 Inc(gNumBots);
6753 for a := WP_FIRST to WP_LAST do
6754 begin
6755 FDifficult.WeaponPrior[a] := WEAPON_PRIOR1[a];
6756 FDifficult.CloseWeaponPrior[a] := WEAPON_PRIOR2[a];
6757 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6758 end;
6759 end;
6761 destructor TBot.Destroy();
6762 begin
6763 Dec(gNumBots);
6764 inherited Destroy();
6765 end;
6767 procedure TBot.Draw();
6768 begin
6769 inherited Draw();
6771 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6772 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6773 end;
6775 procedure TBot.Respawn(Silent: Boolean; Force: Boolean = False);
6776 begin
6777 inherited Respawn(Silent, Force);
6779 FAIFlags := nil;
6780 FSelectedWeapon := FCurrWeap;
6781 resetWeaponQueue();
6782 FTargetUID := 0;
6783 end;
6785 procedure TBot.UpdateCombat();
6786 type
6787 TTarget = record
6788 UID: Word;
6789 X, Y: Integer;
6790 Rect: TRectWH;
6791 cX, cY: Integer;
6792 Dist: Word;
6793 Line: Boolean;
6794 Visible: Boolean;
6795 IsPlayer: Boolean;
6796 end;
6798 TTargetRecord = array of TTarget;
6800 function Compare(a, b: TTarget): Integer;
6801 begin
6802 if a.Line and not b.Line then // A íà ëèíèè îãíÿ
6803 Result := -1
6804 else
6805 if not a.Line and b.Line then // B íà ëèíèè îãíÿ
6806 Result := 1
6807 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6808 if (a.Line and b.Line) or ((not a.Line) and (not b.Line)) then
6809 begin
6810 if a.Dist > b.Dist then // B áëèæå
6811 Result := 1
6812 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6813 Result := -1;
6814 end
6815 else // Ñòðàííî -> A
6816 Result := -1;
6817 end;
6819 var
6820 a, x1, y1, x2, y2: Integer;
6821 targets: TTargetRecord;
6822 ammo: Word;
6823 Target, BestTarget: TTarget;
6824 firew, fireh: Integer;
6825 angle: SmallInt;
6826 mon: TMonster;
6827 pla, tpla: TPlayer;
6828 vsPlayer, vsMonster, ok: Boolean;
6831 function monsUpdate (mon: TMonster): Boolean;
6832 begin
6833 result := false; // don't stop
6834 if mon.alive and (mon.MonsterType <> MONSTER_BARREL) then
6835 begin
6836 if not TargetOnScreen(mon.Obj.X+mon.Obj.Rect.X, mon.Obj.Y+mon.Obj.Rect.Y) then exit;
6838 x2 := mon.Obj.X+mon.Obj.Rect.X+(mon.Obj.Rect.Width div 2);
6839 y2 := mon.Obj.Y+mon.Obj.Rect.Y+(mon.Obj.Rect.Height div 2);
6841 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6842 if g_TraceVector(x1, y1, x2, y2) then
6843 begin
6844 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6845 SetLength(targets, Length(targets)+1);
6846 with targets[High(targets)] do
6847 begin
6848 UID := mon.UID;
6849 X := mon.Obj.X;
6850 Y := mon.Obj.Y;
6851 cX := x2;
6852 cY := y2;
6853 Rect := mon.Obj.Rect;
6854 Dist := g_PatchLength(x1, y1, x2, y2);
6855 Line := (y1+4 < Target.Y + mon.Obj.Rect.Y + mon.Obj.Rect.Height) and
6856 (y1-4 > Target.Y + mon.Obj.Rect.Y);
6857 Visible := True;
6858 IsPlayer := False;
6859 end;
6860 end;
6861 end;
6862 end;
6864 begin
6865 vsPlayer := LongBool(gGameSettings.Options and GAME_OPTION_BOTVSPLAYER);
6866 vsMonster := LongBool(gGameSettings.Options and GAME_OPTION_BOTVSMONSTER);
6868 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6869 if FCurrWeap <> FSelectedWeapon then
6870 NextWeapon();
6872 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6873 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap = FSelectedWeapon) then
6874 begin
6875 RemoveAIFlag('NEEDFIRE');
6877 case FCurrWeap of
6878 WEAPON_PLASMA, WEAPON_SUPERPULEMET, WEAPON_CHAINGUN: PressKey(KEY_FIRE, 20);
6879 WEAPON_SAW, WEAPON_KASTET, WEAPON_FLAMETHROWER: PressKey(KEY_FIRE, 40);
6880 else PressKey(KEY_FIRE);
6881 end;
6882 end;
6884 // Êîîðäèíàòû ñòâîëà:
6885 x1 := FObj.X + WEAPONPOINT[FDirection].X;
6886 y1 := FObj.Y + WEAPONPOINT[FDirection].Y;
6888 Target.UID := FTargetUID;
6890 ok := False;
6891 if Target.UID <> 0 then
6892 begin // Öåëü åñòü - íàñòðàèâàåì
6893 if (g_GetUIDType(Target.UID) = UID_PLAYER) and
6894 vsPlayer then
6895 begin // Èãðîê
6896 tpla := g_Player_Get(Target.UID);
6897 if tpla <> nil then
6898 with tpla do
6899 begin
6900 if (@FObj) <> nil then
6901 begin
6902 Target.X := FObj.X;
6903 Target.Y := FObj.Y;
6904 end;
6905 end;
6907 Target.cX := Target.X + PLAYER_RECT_CX;
6908 Target.cY := Target.Y + PLAYER_RECT_CY;
6909 Target.Rect := PLAYER_RECT;
6910 Target.Visible := g_TraceVector(x1, y1, Target.cX, Target.cY);
6911 Target.Line := (y1+4 < Target.Y+PLAYER_RECT.Y+PLAYER_RECT.Height) and
6912 (y1-4 > Target.Y+PLAYER_RECT.Y);
6913 Target.IsPlayer := True;
6914 ok := True;
6915 end
6916 else
6917 if (g_GetUIDType(Target.UID) = UID_MONSTER) and
6918 vsMonster then
6919 begin // Ìîíñòð
6920 mon := g_Monsters_ByUID(Target.UID);
6921 if mon <> nil then
6922 begin
6923 Target.X := mon.Obj.X;
6924 Target.Y := mon.Obj.Y;
6926 Target.cX := Target.X + mon.Obj.Rect.X + (mon.Obj.Rect.Width div 2);
6927 Target.cY := Target.Y + mon.Obj.Rect.Y + (mon.Obj.Rect.Height div 2);
6928 Target.Rect := mon.Obj.Rect;
6929 Target.Visible := g_TraceVector(x1, y1, Target.cX, Target.cY);
6930 Target.Line := (y1+4 < Target.Y + mon.Obj.Rect.Y + mon.Obj.Rect.Height) and
6931 (y1-4 > Target.Y + mon.Obj.Rect.Y);
6932 Target.IsPlayer := False;
6933 ok := True;
6934 end;
6935 end;
6936 end;
6938 if not ok then
6939 begin // Öåëè íåò - îáíóëÿåì
6940 Target.X := 0;
6941 Target.Y := 0;
6942 Target.cX := 0;
6943 Target.cY := 0;
6944 Target.Visible := False;
6945 Target.Line := False;
6946 Target.IsPlayer := False;
6947 end;
6949 targets := nil;
6951 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6952 if (not Target.Line) or (not Target.Visible) then
6953 begin
6954 // Èãðîêè:
6955 if vsPlayer then
6956 for a := 0 to High(gPlayers) do
6957 if (gPlayers[a] <> nil) and (gPlayers[a].alive) and
6958 (gPlayers[a].FUID <> FUID) and
6959 (not SameTeam(FUID, gPlayers[a].FUID)) and
6960 (not gPlayers[a].NoTarget) and
6961 (gPlayers[a].FMegaRulez[MR_INVIS] < gTime) then
6962 begin
6963 if not TargetOnScreen(gPlayers[a].FObj.X + PLAYER_RECT.X,
6964 gPlayers[a].FObj.Y + PLAYER_RECT.Y) then
6965 Continue;
6967 x2 := gPlayers[a].FObj.X + PLAYER_RECT_CX;
6968 y2 := gPlayers[a].FObj.Y + PLAYER_RECT_CY;
6970 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6971 if g_TraceVector(x1, y1, x2, y2) then
6972 begin
6973 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6974 SetLength(targets, Length(targets)+1);
6975 with targets[High(targets)] do
6976 begin
6977 UID := gPlayers[a].FUID;
6978 X := gPlayers[a].FObj.X;
6979 Y := gPlayers[a].FObj.Y;
6980 cX := x2;
6981 cY := y2;
6982 Rect := PLAYER_RECT;
6983 Dist := g_PatchLength(x1, y1, x2, y2);
6984 Line := (y1+4 < Target.Y+PLAYER_RECT.Y+PLAYER_RECT.Height) and
6985 (y1-4 > Target.Y+PLAYER_RECT.Y);
6986 Visible := True;
6987 IsPlayer := True;
6988 end;
6989 end;
6990 end;
6992 // Ìîíñòðû:
6993 if vsMonster then g_Mons_ForEach(monsUpdate);
6994 end;
6996 // Åñëè åñòü âîçìîæíûå öåëè:
6997 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6998 if targets <> nil then
6999 begin
7000 // Âûáèðàåì íàèëó÷øóþ öåëü:
7001 BestTarget := targets[0];
7002 if Length(targets) > 1 then
7003 for a := 1 to High(targets) do
7004 if Compare(BestTarget, targets[a]) = 1 then
7005 BestTarget := targets[a];
7007 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
7008 if ((not Target.Visible) and BestTarget.Visible and (Target.UID <> BestTarget.UID)) or
7009 ((not Target.Line) and BestTarget.Line and BestTarget.Visible) then
7010 begin
7011 Target := BestTarget;
7013 if (Healthy() = 3) or ((Healthy() = 2)) then
7014 begin // Åñëè çäîðîâû - äîãîíÿåì
7015 if ((RunDirection() = TDirection.D_LEFT) and (Target.X > FObj.X)) then
7016 SetAIFlag('GORIGHT', '1');
7017 if ((RunDirection() = TDirection.D_RIGHT) and (Target.X < FObj.X)) then
7018 SetAIFlag('GOLEFT', '1');
7019 end
7020 else
7021 begin // Åñëè ïîáèòû - óáåãàåì
7022 if ((RunDirection() = TDirection.D_LEFT) and (Target.X < FObj.X)) then
7023 SetAIFlag('GORIGHT', '1');
7024 if ((RunDirection() = TDirection.D_RIGHT) and (Target.X > FObj.X)) then
7025 SetAIFlag('GOLEFT', '1');
7026 end;
7028 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
7029 SelectWeapon(Abs(x1-Target.cX));
7030 end;
7031 end;
7033 // Åñëè åñòü öåëü:
7034 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
7035 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
7036 if Target.UID <> 0 then
7037 begin
7038 if not TargetOnScreen(Target.X + Target.Rect.X,
7039 Target.Y + Target.Rect.Y) then
7040 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
7041 if (Healthy() = 3) or ((Healthy() = 2)) then
7042 begin // Åñëè çäîðîâû - äîãîíÿåì
7043 if ((RunDirection() = TDirection.D_LEFT) and (Target.X > FObj.X)) then
7044 SetAIFlag('GORIGHT', '1');
7045 if ((RunDirection() = TDirection.D_RIGHT) and (Target.X < FObj.X)) then
7046 SetAIFlag('GOLEFT', '1');
7047 end
7048 else
7049 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
7050 Target.UID := 0;
7051 if ((RunDirection() = TDirection.D_LEFT) and (Target.X < FObj.X)) then
7052 SetAIFlag('GORIGHT', '1');
7053 if ((RunDirection() = TDirection.D_RIGHT) and (Target.X > FObj.X)) then
7054 SetAIFlag('GOLEFT', '1');
7055 end;
7056 end
7057 else
7058 begin // Öåëü ïîêà íà "ýêðàíå"
7059 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
7060 if g_TraceVector(x1, y1, Target.cX, Target.cY) then
7061 FLastVisible := gTime;
7062 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
7063 if (Abs(FObj.Y-Target.Y) <= 128) then
7064 begin
7065 if ((RunDirection() = TDirection.D_LEFT) and (Target.X > FObj.X)) then
7066 SetAIFlag('GORIGHT', '1');
7067 if ((RunDirection() = TDirection.D_RIGHT) and (Target.X < FObj.X)) then
7068 SetAIFlag('GOLEFT', '1');
7069 end;
7070 end;
7072 // Âûáèðàåì óãîë ââåðõ:
7073 if FDirection = TDirection.D_LEFT then
7074 angle := ANGLE_LEFTUP
7075 else
7076 angle := ANGLE_RIGHTUP;
7078 firew := Trunc(Cos(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
7079 fireh := Trunc(Sin(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
7081 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
7082 if g_CollideLine(x1, y1, x1+firew, y1+fireh,
7083 Target.X+Target.Rect.X+GetInterval(FDifficult.DiagPrecision, 128), //96
7084 Target.Y+Target.Rect.Y+GetInterval(FDifficult.DiagPrecision, 128),
7085 Target.Rect.Width, Target.Rect.Height) and
7086 g_TraceVector(x1, y1, Target.cX, Target.cY) then
7087 begin // òî íóæíî ñòðåëÿòü ââåðõ
7088 SetAIFlag('NEEDFIRE', '1');
7089 SetAIFlag('NEEDSEEUP', '1');
7090 end;
7092 // Âûáèðàåì óãîë âíèç:
7093 if FDirection = TDirection.D_LEFT then
7094 angle := ANGLE_LEFTDOWN
7095 else
7096 angle := ANGLE_RIGHTDOWN;
7098 firew := Trunc(Cos(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
7099 fireh := Trunc(Sin(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
7101 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
7102 if g_CollideLine(x1, y1, x1+firew, y1+fireh,
7103 Target.X+Target.Rect.X+GetInterval(FDifficult.DiagPrecision, 128),
7104 Target.Y+Target.Rect.Y+GetInterval(FDifficult.DiagPrecision, 128),
7105 Target.Rect.Width, Target.Rect.Height) and
7106 g_TraceVector(x1, y1, Target.cX, Target.cY) then
7107 begin // òî íóæíî ñòðåëÿòü âíèç
7108 SetAIFlag('NEEDFIRE', '1');
7109 SetAIFlag('NEEDSEEDOWN', '1');
7110 end;
7112 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
7113 if Target.Visible and
7114 (y1+4 < Target.Y+Target.Rect.Y+Target.Rect.Height) and
7115 (y1-4 > Target.Y+Target.Rect.Y) then
7116 begin
7117 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
7118 if ((FDirection = TDirection.D_LEFT) and (Target.X < FObj.X)) or
7119 ((FDirection = TDirection.D_RIGHT) and (Target.X > FObj.X)) then
7120 begin // òî íóæíî ñòðåëÿòü âïåðåä
7121 SetAIFlag('NEEDFIRE', '1');
7122 SetAIFlag('NEEDSEEDOWN', '');
7123 SetAIFlag('NEEDSEEUP', '');
7124 end;
7125 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
7126 if Abs(FObj.X-Target.X) < Trunc(gPlayerScreenSize.X*0.75) then
7127 if GetRnd(FDifficult.CloseJump) then
7128 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
7129 if Abs(FObj.X-Target.X) < 128 then
7130 a := 4
7131 else
7132 a := 30;
7133 if Random(a) = 0 then
7134 SetAIFlag('NEEDJUMP', '1');
7135 end;
7136 end;
7138 // Åñëè öåëü âñå åùå åñòü:
7139 if Target.UID <> 0 then
7140 if gTime-FLastVisible > 2000 then // Åñëè âèäåëè äàâíî
7141 Target.UID := 0 // òî çàáûòü öåëü
7142 else // Åñëè âèäåëè íåäàâíî
7143 begin // íî öåëü óáèëè
7144 if Target.IsPlayer then
7145 begin // Öåëü - èãðîê
7146 pla := g_Player_Get(Target.UID);
7147 if (pla = nil) or (not pla.alive) or pla.NoTarget or
7148 (pla.FMegaRulez[MR_INVIS] >= gTime) then
7149 Target.UID := 0; // òî çàáûòü öåëü
7150 end
7151 else
7152 begin // Öåëü - ìîíñòð
7153 mon := g_Monsters_ByUID(Target.UID);
7154 if (mon = nil) or (not mon.alive) then
7155 Target.UID := 0; // òî çàáûòü öåëü
7156 end;
7157 end;
7158 end; // if Target.UID <> 0
7160 FTargetUID := Target.UID;
7162 // Åñëè âîçìîæíûõ öåëåé íåò:
7163 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
7164 if targets = nil then
7165 if GetAIFlag('ATTACKLEFT') <> '' then
7166 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
7167 RemoveAIFlag('ATTACKLEFT');
7169 SetAIFlag('NEEDJUMP', '1');
7171 if RunDirection() = TDirection.D_RIGHT then
7172 begin // Èäåì íå â òó ñòîðîíó
7173 if (Healthy() > 1) and GetRnd(FDifficult.InvisFire) then
7174 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
7175 SetAIFlag('NEEDFIRE', '1');
7176 SetAIFlag('GOLEFT', '1');
7177 end;
7178 end
7179 else
7180 begin // Èäåì â íóæíóþ ñòîðîíó
7181 if GetRnd(FDifficult.InvisFire) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7182 SetAIFlag('NEEDFIRE', '1');
7183 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7184 SetAIFlag('GORIGHT', '1');
7185 end;
7186 end
7187 else
7188 if GetAIFlag('ATTACKRIGHT') <> '' then
7189 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
7190 RemoveAIFlag('ATTACKRIGHT');
7192 SetAIFlag('NEEDJUMP', '1');
7194 if RunDirection() = TDirection.D_LEFT then
7195 begin // Èäåì íå â òó ñòîðîíó
7196 if (Healthy() > 1) and GetRnd(FDifficult.InvisFire) then
7197 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
7198 SetAIFlag('NEEDFIRE', '1');
7199 SetAIFlag('GORIGHT', '1');
7200 end;
7201 end
7202 else
7203 begin
7204 if GetRnd(FDifficult.InvisFire) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7205 SetAIFlag('NEEDFIRE', '1');
7206 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7207 SetAIFlag('GOLEFT', '1');
7208 end;
7209 end;
7211 //HACK! (does it belongs there?)
7212 RealizeCurrentWeapon();
7214 // Åñëè åñòü âîçìîæíûå öåëè:
7215 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
7216 if (targets <> nil) and (GetAIFlag('NEEDFIRE') <> '') then
7217 for a := 0 to High(targets) do
7218 begin
7219 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
7220 if GetRnd(FDifficult.DiagFire) then
7221 begin
7222 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
7223 if FDirection = TDirection.D_LEFT then
7224 angle := ANGLE_LEFTUP
7225 else
7226 angle := ANGLE_RIGHTUP;
7228 firew := Trunc(Cos(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
7229 fireh := Trunc(Sin(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
7231 if g_CollideLine(x1, y1, x1+firew, y1+fireh,
7232 targets[a].X+targets[a].Rect.X+GetInterval(FDifficult.DiagPrecision, 128),
7233 targets[a].Y+targets[a].Rect.Y+GetInterval(FDifficult.DiagPrecision, 128),
7234 targets[a].Rect.Width, targets[a].Rect.Height) and
7235 g_TraceVector(x1, y1, targets[a].cX, targets[a].cY) then
7236 begin
7237 SetAIFlag('NEEDFIRE', '1');
7238 SetAIFlag('NEEDSEEUP', '1');
7239 end;
7241 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
7242 if FDirection = TDirection.D_LEFT then
7243 angle := ANGLE_LEFTDOWN
7244 else
7245 angle := ANGLE_RIGHTDOWN;
7247 firew := Trunc(Cos(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
7248 fireh := Trunc(Sin(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
7250 if g_CollideLine(x1, y1, x1+firew, y1+fireh,
7251 targets[a].X+targets[a].Rect.X+GetInterval(FDifficult.DiagPrecision, 128),
7252 targets[a].Y+targets[a].Rect.Y+GetInterval(FDifficult.DiagPrecision, 128),
7253 targets[a].Rect.Width, targets[a].Rect.Height) and
7254 g_TraceVector(x1, y1, targets[a].cX, targets[a].cY) then
7255 begin
7256 SetAIFlag('NEEDFIRE', '1');
7257 SetAIFlag('NEEDSEEDOWN', '1');
7258 end;
7259 end;
7261 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
7262 if targets[a].Line and targets[a].Visible and
7263 (((FDirection = TDirection.D_LEFT) and (targets[a].X < FObj.X)) or
7264 ((FDirection = TDirection.D_RIGHT) and (targets[a].X > FObj.X))) then
7265 begin
7266 SetAIFlag('NEEDFIRE', '1');
7267 Break;
7268 end;
7269 end;
7271 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
7272 if g_Weapon_Danger(FUID, FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y,
7273 PLAYER_RECT.Width, PLAYER_RECT.Height,
7274 40+GetInterval(FDifficult.Cover, 40)) then
7275 SetAIFlag('NEEDJUMP', '1');
7277 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
7278 ammo := GetAmmoByWeapon(FCurrWeap);
7279 if ((FCurrWeap = WEAPON_SHOTGUN2) and (ammo < 2)) or
7280 ((FCurrWeap = WEAPON_BFG) and (ammo < 40)) or
7281 (ammo = 0) then
7282 SetAIFlag('SELECTWEAPON', '1');
7284 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
7285 if GetAIFlag('SELECTWEAPON') = '1' then
7286 begin
7287 SelectWeapon(-1);
7288 RemoveAIFlag('SELECTWEAPON');
7289 end;
7290 end;
7292 procedure TBot.Update();
7293 var
7294 EnableAI: Boolean;
7295 begin
7296 if not FAlive then
7297 begin // Respawn
7298 ReleaseKeys();
7299 PressKey(KEY_UP);
7300 end
7301 else
7302 begin
7303 EnableAI := True;
7305 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
7306 if (g_debug_BotAIOff = 1) and (Team = TEAM_RED) then
7307 EnableAI := False;
7308 if (g_debug_BotAIOff = 2) and (Team = TEAM_BLUE) then
7309 EnableAI := False;
7310 if g_debug_BotAIOff = 3 then
7311 EnableAI := False;
7313 if EnableAI then
7314 begin
7315 UpdateMove();
7316 UpdateCombat();
7317 end
7318 else
7319 begin
7320 RealizeCurrentWeapon();
7321 end;
7322 end;
7324 inherited Update();
7325 end;
7327 procedure TBot.ReleaseKey(Key: Byte);
7328 begin
7329 with FKeys[Key] do
7330 begin
7331 Pressed := False;
7332 Time := 0;
7333 end;
7334 end;
7336 function TBot.KeyPressed(Key: Word): Boolean;
7337 begin
7338 Result := FKeys[Key].Pressed;
7339 end;
7341 function TBot.GetAIFlag(aName: String20): String20;
7342 var
7343 a: Integer;
7344 begin
7345 Result := '';
7347 aName := LowerCase(aName);
7349 if FAIFlags <> nil then
7350 for a := 0 to High(FAIFlags) do
7351 if LowerCase(FAIFlags[a].Name) = aName then
7352 begin
7353 Result := FAIFlags[a].Value;
7354 Break;
7355 end;
7356 end;
7358 procedure TBot.RemoveAIFlag(aName: String20);
7359 var
7360 a, b: Integer;
7361 begin
7362 if FAIFlags = nil then Exit;
7364 aName := LowerCase(aName);
7366 for a := 0 to High(FAIFlags) do
7367 if LowerCase(FAIFlags[a].Name) = aName then
7368 begin
7369 if a <> High(FAIFlags) then
7370 for b := a to High(FAIFlags)-1 do
7371 FAIFlags[b] := FAIFlags[b+1];
7373 SetLength(FAIFlags, Length(FAIFlags)-1);
7374 Break;
7375 end;
7376 end;
7378 procedure TBot.SetAIFlag(aName, fValue: String20);
7379 var
7380 a: Integer;
7381 ok: Boolean;
7382 begin
7383 a := 0;
7384 ok := False;
7386 aName := LowerCase(aName);
7388 if FAIFlags <> nil then
7389 for a := 0 to High(FAIFlags) do
7390 if LowerCase(FAIFlags[a].Name) = aName then
7391 begin
7392 ok := True;
7393 Break;
7394 end;
7396 if ok then FAIFlags[a].Value := fValue
7397 else
7398 begin
7399 SetLength(FAIFlags, Length(FAIFlags)+1);
7400 with FAIFlags[High(FAIFlags)] do
7401 begin
7402 Name := aName;
7403 Value := fValue;
7404 end;
7405 end;
7406 end;
7408 procedure TBot.UpdateMove;
7410 procedure GoLeft(Time: Word = 1);
7411 begin
7412 ReleaseKey(KEY_LEFT);
7413 ReleaseKey(KEY_RIGHT);
7414 PressKey(KEY_LEFT, Time);
7415 SetDirection(TDirection.D_LEFT);
7416 end;
7418 procedure GoRight(Time: Word = 1);
7419 begin
7420 ReleaseKey(KEY_LEFT);
7421 ReleaseKey(KEY_RIGHT);
7422 PressKey(KEY_RIGHT, Time);
7423 SetDirection(TDirection.D_RIGHT);
7424 end;
7426 function Rnd(a: Word): Boolean;
7427 begin
7428 Result := Random(a) = 0;
7429 end;
7431 procedure Turn(Time: Word = 1200);
7432 begin
7433 if RunDirection() = TDirection.D_LEFT then GoRight(Time) else GoLeft(Time);
7434 end;
7436 procedure Stop();
7437 begin
7438 ReleaseKey(KEY_LEFT);
7439 ReleaseKey(KEY_RIGHT);
7440 end;
7442 function CanRunLeft(): Boolean;
7443 begin
7444 Result := not CollideLevel(-1, 0);
7445 end;
7447 function CanRunRight(): Boolean;
7448 begin
7449 Result := not CollideLevel(1, 0);
7450 end;
7452 function CanRun(): Boolean;
7453 begin
7454 if RunDirection() = TDirection.D_LEFT then Result := CanRunLeft() else Result := CanRunRight();
7455 end;
7457 procedure Jump(Time: Word = 30);
7458 begin
7459 PressKey(KEY_JUMP, Time);
7460 end;
7462 function NearHole(): Boolean;
7463 var
7464 x, sx: Integer;
7465 begin
7466 { TODO 5 : Ëåñòíèöû }
7467 sx := IfThen(RunDirection() = TDirection.D_LEFT, -1, 1);
7468 for x := 1 to PLAYER_RECT.Width do
7469 if (not StayOnStep(x*sx, 0)) and
7470 (not CollideLevel(x*sx, PLAYER_RECT.Height)) and
7471 (not CollideLevel(x*sx, PLAYER_RECT.Height*2)) then
7472 begin
7473 Result := True;
7474 Exit;
7475 end;
7477 Result := False;
7478 end;
7480 function BorderHole(): Boolean;
7481 var
7482 x, sx, xx: Integer;
7483 begin
7484 { TODO 5 : Ëåñòíèöû }
7485 sx := IfThen(RunDirection() = TDirection.D_LEFT, -1, 1);
7486 for x := 1 to PLAYER_RECT.Width do
7487 if (not StayOnStep(x*sx, 0)) and
7488 (not CollideLevel(x*sx, PLAYER_RECT.Height)) and
7489 (not CollideLevel(x*sx, PLAYER_RECT.Height*2)) then
7490 begin
7491 for xx := x to x+32 do
7492 if CollideLevel(xx*sx, PLAYER_RECT.Height) then
7493 begin
7494 Result := True;
7495 Exit;
7496 end;
7497 end;
7499 Result := False;
7500 end;
7502 function NearDeepHole(): Boolean;
7503 var
7504 x, sx, y: Integer;
7505 begin
7506 Result := False;
7508 sx := IfThen(RunDirection() = TDirection.D_LEFT, -1, 1);
7509 y := 3;
7511 for x := 1 to PLAYER_RECT.Width do
7512 if (not StayOnStep(x*sx, 0)) and
7513 (not CollideLevel(x*sx, PLAYER_RECT.Height)) and
7514 (not CollideLevel(x*sx, PLAYER_RECT.Height*2)) then
7515 begin
7516 while FObj.Y+y*PLAYER_RECT.Height < gMapInfo.Height do
7517 begin
7518 if CollideLevel(x*sx, PLAYER_RECT.Height*y) then Exit;
7519 y := y+1;
7520 end;
7522 Result := True;
7523 end else Result := False;
7524 end;
7526 function OverDeepHole(): Boolean;
7527 var
7528 y: Integer;
7529 begin
7530 Result := False;
7532 y := 1;
7533 while FObj.Y+y*PLAYER_RECT.Height < gMapInfo.Height do
7534 begin
7535 if CollideLevel(0, PLAYER_RECT.Height*y) then Exit;
7536 y := y+1;
7537 end;
7539 Result := True;
7540 end;
7542 function OnGround(): Boolean;
7543 begin
7544 Result := StayOnStep(0, 0) or CollideLevel(0, 1);
7545 end;
7547 function OnLadder(): Boolean;
7548 begin
7549 Result := FullInStep(0, 0);
7550 end;
7552 function BelowLadder(): Boolean;
7553 begin
7554 Result := (FullInStep(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -PLAYER_RECT.Height) and
7555 not CollideLevel(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -PLAYER_RECT.Height)) or
7556 (FullInStep(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -BOT_MAXJUMP) and
7557 not CollideLevel(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -BOT_MAXJUMP));
7558 end;
7560 function BelowLiftUp(): Boolean;
7561 begin
7562 Result := ((FullInLift(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -PLAYER_RECT.Height) = -1) and
7563 not CollideLevel(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -PLAYER_RECT.Height)) or
7564 ((FullInLift(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -BOT_MAXJUMP) = -1) and
7565 not CollideLevel(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -BOT_MAXJUMP));
7566 end;
7568 function OnTopLift(): Boolean;
7569 begin
7570 Result := (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7571 end;
7573 function CanJumpOver(): Boolean;
7574 var
7575 sx, y: Integer;
7576 begin
7577 sx := IfThen(RunDirection() = TDirection.D_LEFT, -1, 1);
7579 Result := False;
7581 if not CollideLevel(sx, 0) then Exit;
7583 for y := 1 to BOT_MAXJUMP do
7584 if CollideLevel(0, -y) then Exit else
7585 if not CollideLevel(sx, -y) then
7586 begin
7587 Result := True;
7588 Exit;
7589 end;
7590 end;
7592 function CanJumpUp(Dist: ShortInt): Boolean;
7593 var
7594 y, yy: Integer;
7595 c: Boolean;
7596 begin
7597 Result := False;
7599 if CollideLevel(Dist, 0) then Exit;
7601 c := False;
7602 for y := 0 to BOT_MAXJUMP do
7603 if CollideLevel(Dist, -y) then
7604 begin
7605 c := True;
7606 Break;
7607 end;
7609 if not c then Exit;
7611 c := False;
7612 for yy := y+1 to BOT_MAXJUMP do
7613 if not CollideLevel(Dist, -yy) then
7614 begin
7615 c := True;
7616 Break;
7617 end;
7619 if not c then Exit;
7621 c := False;
7622 for y := 0 to BOT_MAXJUMP do
7623 if CollideLevel(0, -y) then
7624 begin
7625 c := True;
7626 Break;
7627 end;
7629 if c then Exit;
7631 if y < yy then Exit;
7633 Result := True;
7634 end;
7636 function IsSafeTrigger(): Boolean;
7637 var
7638 a: Integer;
7639 begin
7640 Result := True;
7641 if gTriggers = nil then
7642 Exit;
7643 for a := 0 to High(gTriggers) do
7644 if Collide(gTriggers[a].X,
7645 gTriggers[a].Y,
7646 gTriggers[a].Width,
7647 gTriggers[a].Height) and
7648 (gTriggers[a].TriggerType in [TRIGGER_EXIT, TRIGGER_CLOSEDOOR,
7649 TRIGGER_CLOSETRAP, TRIGGER_TRAP,
7650 TRIGGER_PRESS, TRIGGER_ON, TRIGGER_OFF,
7651 TRIGGER_ONOFF, TRIGGER_SPAWNMONSTER,
7652 TRIGGER_DAMAGE, TRIGGER_SHOT]) then
7653 Result := False;
7654 end;
7656 begin
7657 // Âîçìîæíî, íàæèìàåì êíîïêó:
7658 if Rnd(16) and IsSafeTrigger() then
7659 PressKey(KEY_OPEN);
7661 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7662 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7663 begin
7664 ReleaseKey(KEY_LEFT);
7665 ReleaseKey(KEY_RIGHT);
7666 Jump();
7667 end;
7669 // Èäåì âëåâî, åñëè íàäî áûëî:
7670 if GetAIFlag('GOLEFT') <> '' then
7671 begin
7672 RemoveAIFlag('GOLEFT');
7673 if CanRunLeft() then
7674 GoLeft(360);
7675 end;
7677 // Èäåì âïðàâî, åñëè íàäî áûëî:
7678 if GetAIFlag('GORIGHT') <> '' then
7679 begin
7680 RemoveAIFlag('GORIGHT');
7681 if CanRunRight() then
7682 GoRight(360);
7683 end;
7685 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7686 if FObj.X < -32 then
7687 GoRight(360)
7688 else
7689 if FObj.X+32 > gMapInfo.Width then
7690 GoLeft(360);
7692 // Ïðûãàåì, åñëè íàäî áûëî:
7693 if GetAIFlag('NEEDJUMP') <> '' then
7694 begin
7695 Jump(0);
7696 RemoveAIFlag('NEEDJUMP');
7697 end;
7699 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7700 if GetAIFlag('NEEDSEEUP') <> '' then
7701 begin
7702 ReleaseKey(KEY_UP);
7703 ReleaseKey(KEY_DOWN);
7704 PressKey(KEY_UP, 20);
7705 RemoveAIFlag('NEEDSEEUP');
7706 end;
7708 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7709 if GetAIFlag('NEEDSEEDOWN') <> '' then
7710 begin
7711 ReleaseKey(KEY_UP);
7712 ReleaseKey(KEY_DOWN);
7713 PressKey(KEY_DOWN, 20);
7714 RemoveAIFlag('NEEDSEEDOWN');
7715 end;
7717 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7718 if GetAIFlag('GOINHOLE') <> '' then
7719 if not OnGround() then
7720 begin
7721 ReleaseKey(KEY_LEFT);
7722 ReleaseKey(KEY_RIGHT);
7723 RemoveAIFlag('GOINHOLE');
7724 SetAIFlag('FALLINHOLE', '1');
7725 end;
7727 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7728 if GetAIFlag('FALLINHOLE') <> '' then
7729 if OnGround() then
7730 RemoveAIFlag('FALLINHOLE');
7732 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7733 if not (KeyPressed(KEY_LEFT) or KeyPressed(KEY_RIGHT)) then
7734 if GetAIFlag('FALLINHOLE') = '' then
7735 if (not OnLadder()) or (FObj.Vel.Y >= 0) or (OnTopLift()) then
7736 if Rnd(2) then
7737 GoLeft(360)
7738 else
7739 GoRight(360);
7741 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7742 if OnGround() and
7743 CanJumpUp(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*32) and
7744 Rnd(8) then
7745 Jump();
7747 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7748 if OnGround() and NearHole() then
7749 if NearDeepHole() then // Åñëè ýòî áåçäíà
7750 case Random(6) of
7751 0..3: Turn(); // Áåæèì îáðàòíî
7752 4: Jump(); // Ïðûãàåì
7753 5: begin // Ïðûãàåì îáðàòíî
7754 Turn();
7755 Jump();
7756 end;
7757 end
7758 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7759 if GetAIFlag('GOINHOLE') = '' then
7760 case Random(6) of
7761 0: Turn(); // Íå íóæíî òóäà
7762 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7763 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7764 if BorderHole() then
7765 SetAIFlag('GOINHOLE', '1');
7766 end;
7768 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7769 if (not CanRun()) and OnGround() then
7770 begin
7771 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7772 if CanJumpOver() or OnLadder() then
7773 Jump()
7774 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7775 if Random(2) = 0 then
7776 begin
7777 if IsSafeTrigger() then
7778 PressKey(KEY_OPEN);
7779 end else
7780 Turn();
7781 end;
7783 // Îñòàëîñü ìàëî âîçäóõà:
7784 if FAir < 36 * 2 then
7785 Jump(20);
7787 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7788 if (FMegaRulez[MR_SUIT] < gTime) and ((FLastHit = HIT_ACID) or (Healthy() <= 1)) then
7789 if BodyInAcid(0, 0) then
7790 Jump();
7791 end;
7793 function TBot.FullInStep(XInc, YInc: Integer): Boolean;
7794 begin
7795 Result := g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc,
7796 PLAYER_RECT.Width, PLAYER_RECT.Height, PANEL_STEP, False);
7797 end;
7799 {function TBot.NeedItem(Item: Byte): Byte;
7800 begin
7801 Result := 4;
7802 end;}
7804 procedure TBot.SelectWeapon(Dist: Integer);
7805 var
7806 a: Integer;
7808 function HaveAmmo(weapon: Byte): Boolean;
7809 begin
7810 case weapon of
7811 WEAPON_PISTOL: Result := FAmmo[A_BULLETS] >= 1;
7812 WEAPON_SHOTGUN1: Result := FAmmo[A_SHELLS] >= 1;
7813 WEAPON_SHOTGUN2: Result := FAmmo[A_SHELLS] >= 2;
7814 WEAPON_CHAINGUN: Result := FAmmo[A_BULLETS] >= 10;
7815 WEAPON_ROCKETLAUNCHER: Result := FAmmo[A_ROCKETS] >= 1;
7816 WEAPON_PLASMA: Result := FAmmo[A_CELLS] >= 10;
7817 WEAPON_BFG: Result := FAmmo[A_CELLS] >= 40;
7818 WEAPON_SUPERPULEMET: Result := FAmmo[A_SHELLS] >= 1;
7819 WEAPON_FLAMETHROWER: Result := FAmmo[A_FUEL] >= 1;
7820 else Result := True;
7821 end;
7822 end;
7824 begin
7825 if Dist = -1 then Dist := BOT_LONGDIST;
7827 if Dist > BOT_LONGDIST then
7828 begin // Äàëüíèé áîé
7829 for a := 0 to 9 do
7830 if FWeapon[FDifficult.WeaponPrior[a]] and HaveAmmo(FDifficult.WeaponPrior[a]) then
7831 begin
7832 FSelectedWeapon := FDifficult.WeaponPrior[a];
7833 Break;
7834 end;
7835 end
7836 else //if Dist > BOT_UNSAFEDIST then
7837 begin // Áëèæíèé áîé
7838 for a := 0 to 9 do
7839 if FWeapon[FDifficult.CloseWeaponPrior[a]] and HaveAmmo(FDifficult.CloseWeaponPrior[a]) then
7840 begin
7841 FSelectedWeapon := FDifficult.CloseWeaponPrior[a];
7842 Break;
7843 end;
7844 end;
7845 { else
7846 begin
7847 for a := 0 to 9 do
7848 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7849 begin
7850 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7851 Break;
7852 end;
7853 end;}
7854 end;
7856 function TBot.PickItem(ItemType: Byte; force: Boolean; var remove: Boolean): Boolean;
7857 begin
7858 Result := inherited PickItem(ItemType, force, remove);
7860 if Result then SetAIFlag('SELECTWEAPON', '1');
7861 end;
7863 function TBot.Heal(value: Word; Soft: Boolean): Boolean;
7864 begin
7865 Result := inherited Heal(value, Soft);
7866 end;
7868 function TBot.Healthy(): Byte;
7869 begin
7870 if FMegaRulez[MR_INVUL] >= gTime then Result := 3
7871 else if (FHealth > 80) or ((FHealth > 50) and (FArmor > 20)) then Result := 3
7872 else if (FHealth > 50) then Result := 2
7873 else if (FHealth > 20) then Result := 1
7874 else Result := 0;
7875 end;
7877 function TBot.TargetOnScreen(TX, TY: Integer): Boolean;
7878 begin
7879 Result := (Abs(FObj.X-TX) <= Trunc(gPlayerScreenSize.X*0.6)) and
7880 (Abs(FObj.Y-TY) <= Trunc(gPlayerScreenSize.Y*0.6));
7881 end;
7883 procedure TBot.OnDamage(Angle: SmallInt);
7884 var
7885 pla: TPlayer;
7886 mon: TMonster;
7887 ok: Boolean;
7888 begin
7889 inherited;
7891 if (Angle = 0) or (Angle = 180) then
7892 begin
7893 ok := False;
7894 if (g_GetUIDType(FLastSpawnerUID) = UID_PLAYER) and
7895 LongBool(gGameSettings.Options and GAME_OPTION_BOTVSPLAYER) then
7896 begin // Èãðîê
7897 pla := g_Player_Get(FLastSpawnerUID);
7898 ok := not TargetOnScreen(pla.FObj.X + PLAYER_RECT.X,
7899 pla.FObj.Y + PLAYER_RECT.Y);
7900 end
7901 else
7902 if (g_GetUIDType(FLastSpawnerUID) = UID_MONSTER) and
7903 LongBool(gGameSettings.Options and GAME_OPTION_BOTVSMONSTER) then
7904 begin // Ìîíñòð
7905 mon := g_Monsters_ByUID(FLastSpawnerUID);
7906 ok := not TargetOnScreen(mon.Obj.X + mon.Obj.Rect.X,
7907 mon.Obj.Y + mon.Obj.Rect.Y);
7908 end;
7910 if ok then
7911 if Angle = 0 then
7912 SetAIFlag('ATTACKLEFT', '1')
7913 else
7914 SetAIFlag('ATTACKRIGHT', '1');
7915 end;
7916 end;
7918 function TBot.RunDirection(): TDirection;
7919 begin
7920 if Abs(Vel.X) >= 1 then
7921 begin
7922 if Vel.X > 0 then Result := TDirection.D_RIGHT else Result := TDirection.D_LEFT;
7923 end else
7924 Result := FDirection;
7925 end;
7927 function TBot.GetRnd(a: Byte): Boolean;
7928 begin
7929 if a = 0 then Result := False
7930 else if a = 255 then Result := True
7931 else Result := Random(256) > 255-a;
7932 end;
7934 function TBot.GetInterval(a: Byte; radius: SmallInt): SmallInt;
7935 begin
7936 Result := Round((255-a)/255*radius*(Random(2)-1));
7937 end;
7940 procedure TDifficult.save (st: TStream);
7941 begin
7942 utils.writeInt(st, Byte(DiagFire));
7943 utils.writeInt(st, Byte(InvisFire));
7944 utils.writeInt(st, Byte(DiagPrecision));
7945 utils.writeInt(st, Byte(FlyPrecision));
7946 utils.writeInt(st, Byte(Cover));
7947 utils.writeInt(st, Byte(CloseJump));
7948 st.WriteBuffer(WeaponPrior[Low(WeaponPrior)], sizeof(WeaponPrior));
7949 st.WriteBuffer(CloseWeaponPrior[Low(CloseWeaponPrior)], sizeof(CloseWeaponPrior));
7950 end;
7952 procedure TDifficult.load (st: TStream);
7953 begin
7954 DiagFire := utils.readByte(st);
7955 InvisFire := utils.readByte(st);
7956 DiagPrecision := utils.readByte(st);
7957 FlyPrecision := utils.readByte(st);
7958 Cover := utils.readByte(st);
7959 CloseJump := utils.readByte(st);
7960 st.ReadBuffer(WeaponPrior[Low(WeaponPrior)], sizeof(WeaponPrior));
7961 st.ReadBuffer(CloseWeaponPrior[Low(CloseWeaponPrior)], sizeof(CloseWeaponPrior));
7962 end;
7965 procedure TBot.SaveState (st: TStream);
7966 var
7967 i: Integer;
7968 dw: Integer;
7969 begin
7970 inherited SaveState(st);
7971 utils.writeSign(st, 'BOT0');
7972 // Âûáðàííîå îðóæèå
7973 utils.writeInt(st, Byte(FSelectedWeapon));
7974 // UID öåëè
7975 utils.writeInt(st, Word(FTargetUID));
7976 // Âðåìÿ ïîòåðè öåëè
7977 utils.writeInt(st, LongWord(FLastVisible));
7978 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7979 dw := Length(FAIFlags);
7980 utils.writeInt(st, LongInt(dw));
7981 // Ôëàãè ÈÈ
7982 for i := 0 to dw-1 do
7983 begin
7984 utils.writeStr(st, FAIFlags[i].Name, 20);
7985 utils.writeStr(st, FAIFlags[i].Value, 20);
7986 end;
7987 // Íàñòðîéêè ñëîæíîñòè
7988 FDifficult.save(st);
7989 end;
7992 procedure TBot.LoadState (st: TStream);
7993 var
7994 i: Integer;
7995 dw: Integer;
7996 begin
7997 inherited LoadState(st);
7998 if not utils.checkSign(st, 'BOT0') then raise XStreamError.Create('invalid bot signature');
7999 // Âûáðàííîå îðóæèå
8000 FSelectedWeapon := utils.readByte(st);
8001 // UID öåëè
8002 FTargetUID := utils.readWord(st);
8003 // Âðåìÿ ïîòåðè öåëè
8004 FLastVisible := utils.readLongWord(st);
8005 // Êîëè÷åñòâî ôëàãîâ ÈÈ
8006 dw := utils.readLongInt(st);
8007 if (dw < 0) or (dw > 16384) then raise XStreamError.Create('invalid number of bot AI flags');
8008 SetLength(FAIFlags, dw);
8009 // Ôëàãè ÈÈ
8010 for i := 0 to dw-1 do
8011 begin
8012 FAIFlags[i].Name := utils.readStr(st, 20);
8013 FAIFlags[i].Value := utils.readStr(st, 20);
8014 end;
8015 // Íàñòðîéêè ñëîæíîñòè
8016 FDifficult.load(st);
8017 end;
8020 begin
8021 conRegVar('cheat_berserk_autoswitch', @gBerserkAutoswitch, 'autoswitch to fist when berserk pack taken', '', true, true);
8022 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');
8023 conRegVar('player_indicator_style', @gPlayerIndicatorStyle, 'Visual appearance of indicator', 'Visual appearance of indicator');
8024 end.