DEADSOFTWARE

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