DEADSOFTWARE

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