DEADSOFTWARE

Player: Add missing sounds to pause
[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, either version 3 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *)
16 {$INCLUDE ../shared/a_modes.inc}
17 {$M+}
18 unit g_player;
20 interface
22 uses
23 SysUtils, Classes,
24 {$IFDEF USE_MEMPOOL}mempool,{$ENDIF}
25 e_graphics, g_playermodel, g_basic, g_textures,
26 g_weapons, g_phys, g_sound, g_saveload, MAPDEF,
27 g_panel;
29 const
30 KEY_LEFT = 1;
31 KEY_RIGHT = 2;
32 KEY_UP = 3;
33 KEY_DOWN = 4;
34 KEY_FIRE = 5;
35 KEY_NEXTWEAPON = 6;
36 KEY_PREVWEAPON = 7;
37 KEY_OPEN = 8;
38 KEY_JUMP = 9;
39 KEY_CHAT = 10;
41 R_ITEM_BACKPACK = 0;
42 R_KEY_RED = 1;
43 R_KEY_GREEN = 2;
44 R_KEY_BLUE = 3;
45 R_BERSERK = 4;
47 MR_SUIT = 0;
48 MR_INVUL = 1;
49 MR_INVIS = 2;
50 MR_MAX = 2;
52 A_BULLETS = 0;
53 A_SHELLS = 1;
54 A_ROCKETS = 2;
55 A_CELLS = 3;
56 A_FUEL = 4;
57 A_HIGH = 4;
59 AmmoLimits: Array [0..1] of Array [A_BULLETS..A_HIGH] of Word =
60 ((200, 50, 50, 300, 100),
61 (400, 100, 100, 600, 200));
63 K_SIMPLEKILL = 0;
64 K_HARDKILL = 1;
65 K_EXTRAHARDKILL = 2;
66 K_FALLKILL = 3;
68 T_RESPAWN = 0;
69 T_SWITCH = 1;
70 T_USE = 2;
71 T_FLAGCAP = 3;
73 TEAM_NONE = 0;
74 TEAM_RED = 1;
75 TEAM_BLUE = 2;
76 TEAM_COOP = 3;
78 SHELL_BULLET = 0;
79 SHELL_SHELL = 1;
80 SHELL_DBLSHELL = 2;
82 ANGLE_NONE = Low(SmallInt);
84 CORPSE_STATE_REMOVEME = 0;
85 CORPSE_STATE_NORMAL = 1;
86 CORPSE_STATE_MESS = 2;
88 PLAYER_RECT: TRectWH = (X:15; Y:12; Width:34; Height:52);
89 PLAYER_RECT_CX = 15+(34 div 2);
90 PLAYER_RECT_CY = 12+(52 div 2);
91 PLAYER_CORPSERECT: TRectWH = (X:15; Y:48; Width:34; Height:16);
93 PLAYER_HP_SOFT = 100;
94 PLAYER_HP_LIMIT = 200;
95 PLAYER_AP_SOFT = 100;
96 PLAYER_AP_LIMIT = 200;
97 SUICIDE_DAMAGE = 112;
98 WEAPON_DELAY = 5;
100 PLAYER1_DEF_COLOR: TRGB = (R:64; G:175; B:48);
101 PLAYER2_DEF_COLOR: TRGB = (R:96; G:96; B:96);
103 type
104 TPlayerStat = record
105 Ping: Word;
106 Loss: Byte;
107 Name: String;
108 Team: Byte;
109 Frags: SmallInt;
110 Deaths: SmallInt;
111 Lives: Byte;
112 Kills: Word;
113 Color: TRGB;
114 Spectator: Boolean;
115 end;
117 TPlayerStatArray = Array of TPlayerStat;
119 TPlayerSavedState = record
120 Health: Integer;
121 Armor: Integer;
122 Air: Integer;
123 JetFuel: Integer;
124 CurrWeap: Byte;
125 NextWeap: WORD;
126 NextWeapDelay: Byte;
127 Ammo: Array [A_BULLETS..A_HIGH] of Word;
128 MaxAmmo: Array [A_BULLETS..A_HIGH] of Word;
129 Weapon: Array [WP_FIRST..WP_LAST] of Boolean;
130 Rulez: Set of R_ITEM_BACKPACK..R_BERSERK;
131 WaitRecall: Boolean;
132 end;
134 TKeyState = record
135 Pressed: Boolean;
136 Time: Word;
137 end;
139 TPlayer = class{$IFDEF USE_MEMPOOL}(TPoolObject){$ENDIF}
140 private
141 FIamBot: Boolean;
142 FUID: Word;
143 FName: String;
144 FTeam: Byte;
145 FAlive: Boolean;
146 FSpawned: Boolean;
147 FDirection: TDirection;
148 FHealth: Integer;
149 FLives: Byte;
150 FArmor: Integer;
151 FAir: Integer;
152 FPain: Integer;
153 FPickup: Integer;
154 FKills: Integer;
155 FMonsterKills: Integer;
156 FFrags: Integer;
157 FFragCombo: Byte;
158 FLastFrag: LongWord;
159 FComboEvnt: Integer;
160 FDeath: Integer;
161 FCanJetpack: Boolean;
162 FJetFuel: Integer;
163 FFlag: Byte;
164 FSecrets: Integer;
165 FCurrWeap: Byte;
166 FNextWeap: WORD;
167 FNextWeapDelay: Byte; // frames
168 FBFGFireCounter: SmallInt;
169 FLastSpawnerUID: Word;
170 FLastHit: Byte;
171 FObj: TObj;
172 FXTo, FYTo: Integer;
173 FSpectatePlayer: Integer;
174 FFirePainTime: Integer;
175 FFireAttacker: Word;
177 FSavedState: TPlayerSavedState;
179 FModel: TPlayerModel;
180 FPunchAnim: TAnimation;
181 FActionPrior: Byte;
182 FActionAnim: Byte;
183 FActionForce: Boolean;
184 FActionChanged: Boolean;
185 FAngle: SmallInt;
186 FFireAngle: SmallInt;
187 FIncCam: Integer;
188 FShellTimer: Integer;
189 FShellType: Byte;
190 FSawSound: TPlayableSound;
191 FSawSoundIdle: TPlayableSound;
192 FSawSoundHit: TPlayableSound;
193 FSawSoundSelect: TPlayableSound;
194 FJetSoundOn: TPlayableSound;
195 FJetSoundOff: TPlayableSound;
196 FJetSoundFly: TPlayableSound;
197 FGodMode: Boolean;
198 FNoTarget: Boolean;
199 FNoReload: Boolean;
200 FJustTeleported: Boolean;
201 FNetTime: LongWord;
202 mEDamageType: Integer;
205 function CollideLevel(XInc, YInc: Integer): Boolean;
206 function StayOnStep(XInc, YInc: Integer): Boolean;
207 function HeadInLiquid(XInc, YInc: Integer): Boolean;
208 function BodyInLiquid(XInc, YInc: Integer): Boolean;
209 function BodyInAcid(XInc, YInc: Integer): Boolean;
210 function FullInLift(XInc, YInc: Integer): Integer;
211 {procedure CollideItem();}
212 procedure FlySmoke(Times: DWORD = 1);
213 procedure OnFireFlame(Times: DWORD = 1);
214 function GetAmmoByWeapon(Weapon: Byte): Word;
215 procedure SetAction(Action: Byte; Force: Boolean = False);
216 procedure OnDamage(Angle: SmallInt); virtual;
217 function firediry(): Integer;
218 procedure DoPunch();
220 procedure Run(Direction: TDirection);
221 procedure NextWeapon();
222 procedure PrevWeapon();
223 procedure SeeUp();
224 procedure SeeDown();
225 procedure Fire();
226 procedure Jump();
227 procedure Use();
229 function getNextWeaponIndex (): Byte; // return 255 for "no switch"
230 procedure resetWeaponQueue ();
231 function hasAmmoForWeapon (weapon: Byte): Boolean;
233 procedure doDamage (v: Integer);
235 function followCorpse(): Boolean;
237 public
238 FDamageBuffer: Integer;
240 FAmmo: Array [A_BULLETS..A_HIGH] of Word;
241 FMaxAmmo: Array [A_BULLETS..A_HIGH] of Word;
242 FWeapon: Array [WP_FIRST..WP_LAST] of Boolean;
243 FRulez: Set of R_ITEM_BACKPACK..R_BERSERK;
244 FBerserk: Integer;
245 FMegaRulez: Array [MR_SUIT..MR_MAX] of DWORD;
246 FReloading: Array [WP_FIRST..WP_LAST] of Word;
247 FTime: Array [T_RESPAWN..T_FLAGCAP] of DWORD;
248 FKeys: Array [KEY_LEFT..KEY_CHAT] of TKeyState;
249 FColor: TRGB;
250 FPreferredTeam: Byte;
251 FSpectator: Boolean;
252 FNoRespawn: Boolean;
253 FWantsInGame: Boolean;
254 FGhost: Boolean;
255 FPhysics: Boolean;
256 FJetpack: Boolean;
257 FActualModelName: string;
258 FClientID: SmallInt;
259 FPing: Word;
260 FLoss: Byte;
261 FDummy: Boolean;
262 FFireTime: Integer;
264 // debug: viewport offset
265 viewPortX, viewPortY, viewPortW, viewPortH: Integer;
267 function isValidViewPort (): Boolean; inline;
269 constructor Create(); virtual;
270 destructor Destroy(); override;
271 procedure Respawn(Silent: Boolean; Force: Boolean = False); virtual;
272 function GetRespawnPoint(): Byte;
273 procedure PressKey(Key: Byte; Time: Word = 1);
274 procedure ReleaseKeys();
275 procedure SetModel(ModelName: String);
276 procedure SetColor(Color: TRGB);
277 procedure SetWeapon(W: Byte);
278 function IsKeyPressed(K: Byte): Boolean;
279 function GetKeys(): Byte;
280 function PickItem(ItemType: Byte; arespawn: Boolean; var remove: Boolean): Boolean; virtual;
281 function Collide(X, Y: Integer; Width, Height: Word): Boolean; overload;
282 function Collide(Panel: TPanel): Boolean; overload;
283 function Collide(X, Y: Integer): Boolean; overload;
284 procedure SetDirection(Direction: TDirection);
285 procedure GetSecret();
286 function TeleportTo(X, Y: Integer; silent: Boolean; dir: Byte): Boolean;
287 procedure Touch();
288 procedure Push(vx, vy: Integer);
289 procedure ChangeModel(ModelName: String);
290 procedure SwitchTeam;
291 procedure ChangeTeam(Team: Byte);
292 procedure BFGHit();
293 function GetFlag(Flag: Byte): Boolean;
294 procedure SetFlag(Flag: Byte);
295 function DropFlag(Silent: Boolean = True): Boolean;
296 procedure AllRulez(Health: Boolean);
297 procedure RestoreHealthArmor();
298 procedure FragCombo();
299 procedure GiveItem(ItemType: Byte);
300 procedure Damage(value: Word; SpawnerUID: Word; vx, vy: Integer; t: Byte); virtual;
301 function Heal(value: Word; Soft: Boolean): Boolean; virtual;
302 procedure MakeBloodVector(Count: Word; VelX, VelY: Integer);
303 procedure MakeBloodSimple(Count: Word);
304 procedure Kill(KillType: Byte; SpawnerUID: Word; t: Byte);
305 procedure Reset(Force: Boolean);
306 procedure Spectate(NoMove: Boolean = False);
307 procedure SwitchNoClip;
308 procedure SoftReset();
309 procedure Draw(); virtual;
310 procedure DrawPain();
311 procedure DrawPickup();
312 procedure DrawRulez();
313 procedure DrawAim();
314 procedure DrawIndicator();
315 procedure DrawBubble();
316 procedure DrawGUI();
317 procedure Update(); virtual;
318 procedure RememberState();
319 procedure RecallState();
320 procedure SaveState (st: TStream); virtual;
321 procedure LoadState (st: TStream); virtual;
322 procedure PauseSounds(Enable: Boolean);
323 procedure NetFire(Wpn: Byte; X, Y, AX, AY: Integer; WID: Integer = -1);
324 procedure DoLerp(Level: Integer = 2);
325 procedure SetLerp(XTo, YTo: Integer);
326 procedure QueueWeaponSwitch(Weapon: Byte);
327 procedure RealizeCurrentWeapon();
328 procedure JetpackOn;
329 procedure JetpackOff;
330 procedure CatchFire(Attacker: Word);
332 //WARNING! this does nothing for now, but still call it!
333 procedure positionChanged (); //WARNING! call this after entity position was changed, or coldet will not work right!
335 procedure getMapBox (out x, y, w, h: Integer); inline;
336 procedure moveBy (dx, dy: Integer); inline;
338 public
339 property Vel: TPoint2i read FObj.Vel;
340 property Obj: TObj read FObj;
342 property Name: String read FName write FName;
343 property Model: TPlayerModel read FModel;
344 property Health: Integer read FHealth write FHealth;
345 property Lives: Byte read FLives write FLives;
346 property Armor: Integer read FArmor write FArmor;
347 property Air: Integer read FAir write FAir;
348 property JetFuel: Integer read FJetFuel write FJetFuel;
349 property Frags: Integer read FFrags write FFrags;
350 property Death: Integer read FDeath write FDeath;
351 property Kills: Integer read FKills write FKills;
352 property CurrWeap: Byte read FCurrWeap write FCurrWeap;
353 property MonsterKills: Integer read FMonsterKills write FMonsterKills;
354 property Secrets: Integer read FSecrets;
355 property GodMode: Boolean read FGodMode write FGodMode;
356 property NoTarget: Boolean read FNoTarget write FNoTarget;
357 property NoReload: Boolean read FNoReload write FNoReload;
358 property alive: Boolean read FAlive write FAlive;
359 property Flag: Byte read FFlag;
360 property Team: Byte read FTeam write FTeam;
361 property Direction: TDirection read FDirection;
362 property GameX: Integer read FObj.X write FObj.X;
363 property GameY: Integer read FObj.Y write FObj.Y;
364 property GameVelX: Integer read FObj.Vel.X write FObj.Vel.X;
365 property GameVelY: Integer read FObj.Vel.Y write FObj.Vel.Y;
366 property GameAccelX: Integer read FObj.Accel.X write FObj.Accel.X;
367 property GameAccelY: Integer read FObj.Accel.Y write FObj.Accel.Y;
368 property IncCam: Integer read FIncCam write FIncCam;
369 property UID: Word read FUID write FUID;
370 property JustTeleported: Boolean read FJustTeleported write FJustTeleported;
371 property NetTime: LongWord read FNetTime write FNetTime;
373 published
374 property eName: String read FName write FName;
375 property eHealth: Integer read FHealth write FHealth;
376 property eLives: Byte read FLives write FLives;
377 property eArmor: Integer read FArmor write FArmor;
378 property eAir: Integer read FAir write FAir;
379 property eJetFuel: Integer read FJetFuel write FJetFuel;
380 property eFrags: Integer read FFrags write FFrags;
381 property eDeath: Integer read FDeath write FDeath;
382 property eKills: Integer read FKills write FKills;
383 property eCurrWeap: Byte read FCurrWeap write FCurrWeap;
384 property eMonsterKills: Integer read FMonsterKills write FMonsterKills;
385 property eSecrets: Integer read FSecrets write FSecrets;
386 property eGodMode: Boolean read FGodMode write FGodMode;
387 property eNoTarget: Boolean read FNoTarget write FNoTarget;
388 property eNoReload: Boolean read FNoReload write FNoReload;
389 property eAlive: Boolean read FAlive write FAlive;
390 property eFlag: Byte read FFlag;
391 property eTeam: Byte read FTeam write FTeam;
392 property eDirection: TDirection read FDirection;
393 property eGameX: Integer read FObj.X write FObj.X;
394 property eGameY: Integer read FObj.Y write FObj.Y;
395 property eGameVelX: Integer read FObj.Vel.X write FObj.Vel.X;
396 property eGameVelY: Integer read FObj.Vel.Y write FObj.Vel.Y;
397 property eGameAccelX: Integer read FObj.Accel.X write FObj.Accel.X;
398 property eGameAccelY: Integer read FObj.Accel.Y write FObj.Accel.Y;
399 property eIncCam: Integer read FIncCam write FIncCam;
400 property eUID: Word read FUID;
401 property eJustTeleported: Boolean read FJustTeleported;
402 property eNetTime: LongWord read FNetTime;
404 // set this before assigning something to `eDamage`
405 property eDamageType: Integer read mEDamageType write mEDamageType;
406 property eDamage: Integer write doDamage;
407 end;
409 TDifficult = record
410 public
411 DiagFire: Byte;
412 InvisFire: Byte;
413 DiagPrecision: Byte;
414 FlyPrecision: Byte;
415 Cover: Byte;
416 CloseJump: Byte;
417 WeaponPrior: packed array [WP_FIRST..WP_LAST] of Byte;
418 CloseWeaponPrior: packed array [WP_FIRST..WP_LAST] of Byte;
419 //SafeWeaponPrior: Array [WP_FIRST..WP_LAST] of Byte;
421 public
422 procedure save (st: TStream);
423 procedure load (st: TStream);
424 end;
426 TAIFlag = record
427 Name: String;
428 Value: String;
429 end;
431 TBot = class(TPlayer)
432 private
433 FSelectedWeapon: Byte;
434 FTargetUID: Word;
435 FLastVisible: DWORD;
436 FAIFlags: Array of TAIFlag;
437 FDifficult: TDifficult;
439 function GetRnd(a: Byte): Boolean;
440 function GetInterval(a: Byte; radius: SmallInt): SmallInt;
441 function RunDirection(): TDirection;
442 function FullInStep(XInc, YInc: Integer): Boolean;
443 //function NeedItem(Item: Byte): Byte;
444 procedure SelectWeapon(Dist: Integer);
445 procedure SetAIFlag(aName, fValue: String20);
446 function GetAIFlag(aName: String20): String20;
447 procedure RemoveAIFlag(aName: String20);
448 function Healthy(): Byte;
449 procedure UpdateMove();
450 procedure UpdateCombat();
451 function KeyPressed(Key: Word): Boolean;
452 procedure ReleaseKey(Key: Byte);
453 function TargetOnScreen(TX, TY: Integer): Boolean;
454 procedure OnDamage(Angle: SmallInt); override;
456 public
457 procedure Respawn(Silent: Boolean; Force: Boolean = False); override;
458 constructor Create(); override;
459 destructor Destroy(); override;
460 procedure Draw(); override;
461 function PickItem(ItemType: Byte; force: Boolean; var remove: Boolean): Boolean; override;
462 function Heal(value: Word; Soft: Boolean): Boolean; override;
463 procedure Update(); override;
464 procedure SaveState (st: TStream); override;
465 procedure LoadState (st: TStream); override;
466 end;
468 PGib = ^TGib;
469 TGib = record
470 alive: Boolean;
471 ID: DWORD;
472 MaskID: DWORD;
473 RAngle: Integer;
474 Color: TRGB;
475 Obj: TObj;
477 procedure getMapBox (out x, y, w, h: Integer); inline;
478 procedure moveBy (dx, dy: Integer); inline;
480 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
481 end;
484 PShell = ^TShell;
485 TShell = record
486 SpriteID: DWORD;
487 alive: Boolean;
488 SType: Byte;
489 RAngle: Integer;
490 Timeout: Cardinal;
491 CX, CY: Integer;
492 Obj: TObj;
494 procedure getMapBox (out x, y, w, h: Integer); inline;
495 procedure moveBy (dx, dy: Integer); inline;
497 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
498 end;
500 TCorpse = class{$IFDEF USE_MEMPOOL}(TPoolObject){$ENDIF}
501 private
502 FModelName: String;
503 FMess: Boolean;
504 FState: Byte;
505 FDamage: Byte;
506 FColor: TRGB;
507 FObj: TObj;
508 FPlayerUID: Word;
509 FAnimation: TAnimation;
510 FAnimationMask: TAnimation;
512 public
513 constructor Create(X, Y: Integer; ModelName: String; aMess: Boolean);
514 destructor Destroy(); override;
515 procedure Damage(Value: Word; vx, vy: Integer);
516 procedure Update();
517 procedure Draw();
518 procedure SaveState (st: TStream);
519 procedure LoadState (st: TStream);
521 procedure getMapBox (out x, y, w, h: Integer); inline;
522 procedure moveBy (dx, dy: Integer); inline;
524 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
526 function ObjPtr (): PObj; inline;
528 property Obj: TObj read FObj; // copies object
529 property State: Byte read FState;
530 property Mess: Boolean read FMess;
531 end;
533 TTeamStat = Array [TEAM_RED..TEAM_BLUE] of
534 record
535 Goals: SmallInt;
536 end;
538 var
539 gPlayers: Array of TPlayer;
540 gCorpses: Array of TCorpse;
541 gGibs: Array of TGib;
542 gShells: Array of TShell;
543 gTeamStat: TTeamStat;
544 gFly: Boolean = False;
545 gAimLine: Boolean = False;
546 gChatBubble: Byte = 0;
547 gPlayerIndicator: Boolean = True;
548 gNumBots: Word = 0;
549 gLMSPID1: Word = 0;
550 gLMSPID2: Word = 0;
551 MAX_RUNVEL: Integer = 8;
552 VEL_JUMP: Integer = 10;
553 SHELL_TIMEOUT: Cardinal = 60000;
555 function Lerp(X, Y, Factor: Integer): Integer;
557 procedure g_Gibs_SetMax(Count: Word);
558 function g_Gibs_GetMax(): Word;
559 procedure g_Corpses_SetMax(Count: Word);
560 function g_Corpses_GetMax(): Word;
561 procedure g_Shells_SetMax(Count: Word);
562 function g_Shells_GetMax(): Word;
564 procedure g_Player_Init();
565 procedure g_Player_Free();
566 function g_Player_Create(ModelName: String; Color: TRGB; Team: Byte; Bot: Boolean): Word;
567 function g_Player_CreateFromState (st: TStream): Word;
568 procedure g_Player_Remove(UID: Word);
569 procedure g_Player_ResetTeams();
570 procedure g_Player_UpdateAll();
571 procedure g_Player_DrawAll();
572 procedure g_Player_DrawDebug(p: TPlayer);
573 procedure g_Player_DrawHealth();
574 procedure g_Player_RememberAll();
575 procedure g_Player_ResetAll(Force, Silent: Boolean);
576 function g_Player_Get(UID: Word): TPlayer;
577 function g_Player_GetCount(): Byte;
578 function g_Player_GetStats(): TPlayerStatArray;
579 function g_Player_ValidName(Name: String): Boolean;
580 procedure g_Player_CreateCorpse(Player: TPlayer);
581 procedure g_Player_CreateGibs(fX, fY: Integer; ModelName: String; fColor: TRGB);
582 procedure g_Player_CreateShell(fX, fY, dX, dY: Integer; T: Byte);
583 procedure g_Player_UpdatePhysicalObjects();
584 procedure g_Player_DrawCorpses();
585 procedure g_Player_DrawShells();
586 procedure g_Player_RemoveAllCorpses();
587 procedure g_Player_Corpses_SaveState (st: TStream);
588 procedure g_Player_Corpses_LoadState (st: TStream);
589 procedure g_Bot_Add(Team, Difficult: Byte);
590 procedure g_Bot_AddList(Team: Byte; lname: ShortString; num: Integer = -1);
591 procedure g_Bot_MixNames();
592 procedure g_Bot_RemoveAll();
594 implementation
596 uses
597 {$INCLUDE ../nogl/noGLuses.inc}
598 {$IFDEF ENABLE_HOLMES}
599 g_holmes,
600 {$ENDIF}
601 e_log, g_map, g_items, g_console, g_gfx, Math,
602 g_options, g_triggers, g_menu, g_game, g_grid,
603 wadreader, g_main, g_monsters, CONFIG, g_language,
604 g_net, g_netmsg, g_window,
605 utils, xstreams;
607 const PLR_SAVE_VERSION = 0;
609 type
610 TBotProfile = record
611 name: ShortString;
612 model: ShortString;
613 team: Byte;
614 color: TRGB;
615 diag_fire: Byte;
616 invis_fire: Byte;
617 diag_precision: Byte;
618 fly_precision: Byte;
619 cover: Byte;
620 close_jump: Byte;
621 w_prior1: Array [WP_FIRST..WP_LAST] of Byte;
622 w_prior2: Array [WP_FIRST..WP_LAST] of Byte;
623 w_prior3: Array [WP_FIRST..WP_LAST] of Byte;
624 end;
626 const
627 TIME_RESPAWN1 = 1500;
628 TIME_RESPAWN2 = 2000;
629 TIME_RESPAWN3 = 3000;
630 AIR_DEF = 360;
631 AIR_MAX = 1091;
632 JET_MAX = 540; // ~30 sec
633 PLAYER_SUIT_TIME = 30000;
634 PLAYER_INVUL_TIME = 30000;
635 PLAYER_INVIS_TIME = 35000;
636 FRAG_COMBO_TIME = 3000;
637 VEL_SW = 4;
638 VEL_FLY = 6;
639 ANGLE_RIGHTUP = 55;
640 ANGLE_RIGHTDOWN = -35;
641 ANGLE_LEFTUP = 125;
642 ANGLE_LEFTDOWN = -145;
643 PLAYER_HEADRECT: TRectWH = (X:24; Y:12; Width:20; Height:12);
644 WEAPONPOINT: Array [TDirection] of TDFPoint = ((X:16; Y:32), (X:47; Y:32));
645 BOT_MAXJUMP = 84;
646 BOT_LONGDIST = 300;
647 BOT_UNSAFEDIST = 128;
648 TEAMCOLOR: Array [TEAM_RED..TEAM_BLUE] of TRGB = ((R:255; G:0; B:0),
649 (R:0; G:0; B:255));
650 DIFFICULT_EASY: TDifficult = (DiagFire: 32; InvisFire: 32; DiagPrecision: 32;
651 FlyPrecision: 32; Cover: 32; CloseJump: 32;
652 WeaponPrior:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior:(0,0,0,0,0,0,0,0,0,0,0));
653 DIFFICULT_MEDIUM: TDifficult = (DiagFire: 127; InvisFire: 127; DiagPrecision: 127;
654 FlyPrecision: 127; Cover: 127; CloseJump: 127;
655 WeaponPrior:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior:(0,0,0,0,0,0,0,0,0,0,0));
656 DIFFICULT_HARD: TDifficult = (DiagFire: 255; InvisFire: 255; DiagPrecision: 255;
657 FlyPrecision: 255; Cover: 255; CloseJump: 255;
658 WeaponPrior:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior:(0,0,0,0,0,0,0,0,0,0,0));
659 WEAPON_PRIOR1: Array [WP_FIRST..WP_LAST] of Byte =
660 (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
661 WEAPON_SHOTGUN2, WEAPON_SHOTGUN1,
662 WEAPON_CHAINGUN, WEAPON_PLASMA, WEAPON_ROCKETLAUNCHER,
663 WEAPON_BFG, WEAPON_PISTOL, WEAPON_SAW, WEAPON_KASTET);
664 WEAPON_PRIOR2: Array [WP_FIRST..WP_LAST] of Byte =
665 (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
666 WEAPON_BFG, WEAPON_ROCKETLAUNCHER,
667 WEAPON_SHOTGUN2, WEAPON_PLASMA, WEAPON_SHOTGUN1,
668 WEAPON_CHAINGUN, WEAPON_PISTOL, WEAPON_SAW, WEAPON_KASTET);
669 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
670 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
671 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
672 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
673 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
674 WEAPON_RELOAD: Array [WP_FIRST..WP_LAST] of Byte =
675 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
677 PLAYER_SIGNATURE = $52594C50; // 'PLYR'
678 CORPSE_SIGNATURE = $50524F43; // 'CORP'
680 BOTNAMES_FILENAME = 'botnames.txt';
681 BOTLIST_FILENAME = 'botlist.txt';
683 var
684 MaxGibs: Word = 150;
685 MaxCorpses: Word = 20;
686 MaxShells: Word = 300;
687 CurrentGib: Integer = 0;
688 CurrentShell: Integer = 0;
689 BotNames: Array of String;
690 BotList: Array of TBotProfile;
693 function Lerp(X, Y, Factor: Integer): Integer;
694 begin
695 Result := X + ((Y - X) div Factor);
696 end;
698 function SameTeam(UID1, UID2: Word): Boolean;
699 begin
700 Result := False;
702 if (UID1 > UID_MAX_PLAYER) or (UID1 <= UID_MAX_GAME) or
703 (UID2 > UID_MAX_PLAYER) or (UID2 <= UID_MAX_GAME) then Exit;
705 if (g_Player_Get(UID1) = nil) or (g_Player_Get(UID2) = nil) then Exit;
707 if ((g_Player_Get(UID1).Team = TEAM_NONE) or
708 (g_Player_Get(UID2).Team = TEAM_NONE)) then Exit;
710 Result := g_Player_Get(UID1).FTeam = g_Player_Get(UID2).FTeam;
711 end;
713 procedure g_Gibs_SetMax(Count: Word);
714 begin
715 MaxGibs := Count;
716 SetLength(gGibs, Count);
718 if CurrentGib >= Count then
719 CurrentGib := 0;
720 end;
722 function g_Gibs_GetMax(): Word;
723 begin
724 Result := MaxGibs;
725 end;
727 procedure g_Shells_SetMax(Count: Word);
728 begin
729 MaxShells := Count;
730 SetLength(gShells, Count);
732 if CurrentShell >= Count then
733 CurrentShell := 0;
734 end;
736 function g_Shells_GetMax(): Word;
737 begin
738 Result := MaxShells;
739 end;
742 procedure g_Corpses_SetMax(Count: Word);
743 begin
744 MaxCorpses := Count;
745 SetLength(gCorpses, Count);
746 end;
748 function g_Corpses_GetMax(): Word;
749 begin
750 Result := MaxCorpses;
751 end;
753 function g_Player_Create(ModelName: String; Color: TRGB; Team: Byte; Bot: Boolean): Word;
754 var
755 a: Integer;
756 ok: Boolean;
757 begin
758 Result := 0;
760 ok := False;
761 a := 0;
763 // Åñòü ëè ìåñòî â gPlayers:
764 if gPlayers <> nil then
765 for a := 0 to High(gPlayers) do
766 if gPlayers[a] = nil then
767 begin
768 ok := True;
769 Break;
770 end;
772 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
773 if not ok then
774 begin
775 SetLength(gPlayers, Length(gPlayers)+1);
776 a := High(gPlayers);
777 end;
779 // Ñîçäàåì îáúåêò èãðîêà:
780 if Bot then
781 gPlayers[a] := TBot.Create()
782 else
783 gPlayers[a] := TPlayer.Create();
786 gPlayers[a].FActualModelName := ModelName;
787 gPlayers[a].SetModel(ModelName);
789 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
790 if gPlayers[a].FModel = nil then
791 begin
792 gPlayers[a].Free();
793 gPlayers[a] := nil;
794 g_FatalError(Format(_lc[I_GAME_ERROR_MODEL], [ModelName]));
795 Exit;
796 end;
798 if not (Team in [TEAM_RED, TEAM_BLUE]) then
799 if Random(2) = 0 then
800 Team := TEAM_RED
801 else
802 Team := TEAM_BLUE;
803 gPlayers[a].FPreferredTeam := Team;
805 case gGameSettings.GameMode of
806 GM_DM: gPlayers[a].FTeam := TEAM_NONE;
807 GM_TDM,
808 GM_CTF: gPlayers[a].FTeam := gPlayers[a].FPreferredTeam;
809 GM_SINGLE,
810 GM_COOP: gPlayers[a].FTeam := TEAM_COOP;
811 end;
813 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
814 gPlayers[a].FColor := Color;
815 if gPlayers[a].FTeam in [TEAM_RED, TEAM_BLUE] then
816 gPlayers[a].FModel.Color := TEAMCOLOR[gPlayers[a].FTeam]
817 else
818 gPlayers[a].FModel.Color := Color;
820 gPlayers[a].FUID := g_CreateUID(UID_PLAYER);
821 gPlayers[a].FAlive := False;
823 Result := gPlayers[a].FUID;
824 end;
826 function g_Player_CreateFromState (st: TStream): Word;
827 var
828 a, i: Integer;
829 ok, Bot: Boolean;
830 b: Byte;
831 begin
832 result := 0;
833 if (st = nil) then exit; //???
835 // Ñèãíàòóðà èãðîêà
836 if not utils.checkSign(st, 'PLYR') then raise XStreamError.Create('invalid player signature');
837 if (utils.readByte(st) <> PLR_SAVE_VERSION) then raise XStreamError.Create('invalid player version');
839 // Áîò èëè ÷åëîâåê:
840 Bot := utils.readBool(st);
842 ok := false;
843 a := 0;
845 // Åñòü ëè ìåñòî â gPlayers:
846 for a := 0 to High(gPlayers) do if (gPlayers[a] = nil) then begin ok := true; break; end;
848 // Íåò ìåñòà - ðàñøèðÿåì gPlayers
849 if not ok then
850 begin
851 SetLength(gPlayers, Length(gPlayers)+1);
852 a := High(gPlayers);
853 end;
855 // Ñîçäàåì îáúåêò èãðîêà
856 if Bot then
857 gPlayers[a] := TBot.Create()
858 else
859 gPlayers[a] := TPlayer.Create();
860 gPlayers[a].FIamBot := Bot;
861 gPlayers[a].FPhysics := True;
863 // UID èãðîêà
864 gPlayers[a].FUID := utils.readWord(st);
865 // Èìÿ èãðîêà
866 gPlayers[a].FName := utils.readStr(st);
867 // Êîìàíäà
868 gPlayers[a].FTeam := utils.readByte(st);
869 gPlayers[a].FPreferredTeam := gPlayers[a].FTeam;
870 // Æèâ ëè
871 gPlayers[a].FAlive := utils.readBool(st);
872 // Èçðàñõîäîâàë ëè âñå æèçíè
873 gPlayers[a].FNoRespawn := utils.readBool(st);
874 // Íàïðàâëåíèå
875 b := utils.readByte(st);
876 if b = 1 then gPlayers[a].FDirection := TDirection.D_LEFT else gPlayers[a].FDirection := TDirection.D_RIGHT; // b = 2
877 // Çäîðîâüå
878 gPlayers[a].FHealth := utils.readLongInt(st);
879 // Æèçíè
880 gPlayers[a].FLives := utils.readByte(st);
881 // Áðîíÿ
882 gPlayers[a].FArmor := utils.readLongInt(st);
883 // Çàïàñ âîçäóõà
884 gPlayers[a].FAir := utils.readLongInt(st);
885 // Çàïàñ ãîðþ÷åãî
886 gPlayers[a].FJetFuel := utils.readLongInt(st);
887 // Áîëü
888 gPlayers[a].FPain := utils.readLongInt(st);
889 // Óáèë
890 gPlayers[a].FKills := utils.readLongInt(st);
891 // Óáèë ìîíñòðîâ
892 gPlayers[a].FMonsterKills := utils.readLongInt(st);
893 // Ôðàãîâ
894 gPlayers[a].FFrags := utils.readLongInt(st);
895 // Ôðàãîâ ïîäðÿä
896 gPlayers[a].FFragCombo := utils.readByte(st);
897 // Âðåìÿ ïîñëåäíåãî ôðàãà
898 gPlayers[a].FLastFrag := utils.readLongWord(st);
899 // Ñìåðòåé
900 gPlayers[a].FDeath := utils.readLongInt(st);
901 // Êàêîé ôëàã íåñåò
902 gPlayers[a].FFlag := utils.readByte(st);
903 // Íàøåë ñåêðåòîâ
904 gPlayers[a].FSecrets := utils.readLongInt(st);
905 // Òåêóùåå îðóæèå
906 gPlayers[a].FCurrWeap := utils.readByte(st);
907 // Ñëåäóþùåå æåëàåìîå îðóæèå
908 gPlayers[a].FNextWeap := utils.readWord(st);
909 // ...è ïàóçà
910 gPlayers[a].FNextWeapDelay := utils.readByte(st);
911 // Âðåìÿ çàðÿäêè BFG
912 gPlayers[a].FBFGFireCounter := utils.readSmallInt(st);
913 // Áóôåð óðîíà
914 gPlayers[a].FDamageBuffer := utils.readLongInt(st);
915 // Ïîñëåäíèé óäàðèâøèé
916 gPlayers[a].FLastSpawnerUID := utils.readWord(st);
917 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
918 gPlayers[a].FLastHit := utils.readByte(st);
919 // Îáúåêò èãðîêà:
920 Obj_LoadState(@gPlayers[a].FObj, st);
921 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
922 for i := A_BULLETS to A_HIGH do gPlayers[a].FAmmo[i] := utils.readWord(st);
923 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
924 for i := A_BULLETS to A_HIGH do gPlayers[a].FMaxAmmo[i] := utils.readWord(st);
925 // Íàëè÷èå îðóæèÿ
926 for i := WP_FIRST to WP_LAST do gPlayers[a].FWeapon[i] := utils.readBool(st);
927 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
928 for i := WP_FIRST to WP_LAST do gPlayers[a].FReloading[i] := utils.readWord(st);
929 // Íàëè÷èå ðþêçàêà
930 if utils.readBool(st) then Include(gPlayers[a].FRulez, R_ITEM_BACKPACK);
931 // Íàëè÷èå êðàñíîãî êëþ÷à
932 if utils.readBool(st) then Include(gPlayers[a].FRulez, R_KEY_RED);
933 // Íàëè÷èå çåëåíîãî êëþ÷à
934 if utils.readBool(st) then Include(gPlayers[a].FRulez, R_KEY_GREEN);
935 // Íàëè÷èå ñèíåãî êëþ÷à
936 if utils.readBool(st) then Include(gPlayers[a].FRulez, R_KEY_BLUE);
937 // Íàëè÷èå áåðñåðêà
938 if utils.readBool(st) then Include(gPlayers[a].FRulez, R_BERSERK);
939 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
940 for i := MR_SUIT to MR_MAX do gPlayers[a].FMegaRulez[i] := utils.readLongWord(st);
941 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
942 for i := T_RESPAWN to T_FLAGCAP do gPlayers[a].FTime[i] := utils.readLongWord(st);
944 // Íàçâàíèå ìîäåëè:
945 gPlayers[a].FActualModelName := utils.readStr(st);
946 // Öâåò ìîäåëè
947 gPlayers[a].FColor.R := utils.readByte(st);
948 gPlayers[a].FColor.G := utils.readByte(st);
949 gPlayers[a].FColor.B := utils.readByte(st);
950 // Îáíîâëÿåì ìîäåëü èãðîêà
951 gPlayers[a].SetModel(gPlayers[a].FActualModelName);
953 // Íåò ìîäåëè - ñîçäàíèå íåâîçìîæíî
954 if (gPlayers[a].FModel = nil) then
955 begin
956 gPlayers[a].Free();
957 gPlayers[a] := nil;
958 g_FatalError(Format(_lc[I_GAME_ERROR_MODEL], [gPlayers[a].FActualModelName]));
959 exit;
960 end;
962 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû
963 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
964 gPlayers[a].FModel.Color := TEAMCOLOR[gPlayers[a].FTeam]
965 else
966 gPlayers[a].FModel.Color := gPlayers[a].FColor;
968 result := gPlayers[a].FUID;
969 end;
972 procedure g_Player_ResetTeams();
973 var
974 a: Integer;
975 begin
976 if g_Game_IsClient then
977 Exit;
978 if gPlayers = nil then
979 Exit;
980 for a := Low(gPlayers) to High(gPlayers) do
981 if gPlayers[a] <> nil then
982 case gGameSettings.GameMode of
983 GM_DM:
984 gPlayers[a].ChangeTeam(TEAM_NONE);
985 GM_TDM, GM_CTF:
986 if not (gPlayers[a].Team in [TEAM_RED, TEAM_BLUE]) then
987 if gPlayers[a].FPreferredTeam in [TEAM_RED, TEAM_BLUE] then
988 gPlayers[a].ChangeTeam(gPlayers[a].FPreferredTeam)
989 else
990 if a mod 2 = 0 then
991 gPlayers[a].ChangeTeam(TEAM_RED)
992 else
993 gPlayers[a].ChangeTeam(TEAM_BLUE);
994 GM_SINGLE,
995 GM_COOP:
996 gPlayers[a].ChangeTeam(TEAM_COOP);
997 end;
998 end;
1000 procedure g_Bot_Add(Team, Difficult: Byte);
1001 var
1002 m: SSArray;
1003 _name, _model: String;
1004 a, tr, tb: Integer;
1005 begin
1006 if not g_Game_IsServer then Exit;
1008 // Ñïèñîê íàçâàíèé ìîäåëåé:
1009 m := g_PlayerModel_GetNames();
1010 if m = nil then
1011 Exit;
1013 // Êîìàíäà:
1014 if (gGameSettings.GameType = GT_SINGLE) or (gGameSettings.GameMode = GM_COOP) then
1015 Team := TEAM_COOP // COOP
1016 else
1017 if gGameSettings.GameMode = GM_DM then
1018 Team := TEAM_NONE // DM
1019 else
1020 if Team = TEAM_NONE then // CTF / TDM
1021 begin
1022 // Àâòîáàëàíñ êîìàíä:
1023 tr := 0;
1024 tb := 0;
1026 for a := 0 to High(gPlayers) do
1027 if gPlayers[a] <> nil then
1028 begin
1029 if gPlayers[a].Team = TEAM_RED then
1030 Inc(tr)
1031 else
1032 if gPlayers[a].Team = TEAM_BLUE then
1033 Inc(tb);
1034 end;
1036 if tr > tb then
1037 Team := TEAM_BLUE
1038 else
1039 if tb > tr then
1040 Team := TEAM_RED
1041 else // tr = tb
1042 if Random(2) = 0 then
1043 Team := TEAM_RED
1044 else
1045 Team := TEAM_BLUE;
1046 end;
1048 // Âûáèðàåì áîòó èìÿ:
1049 _name := '';
1050 if BotNames <> nil then
1051 for a := 0 to High(BotNames) do
1052 if g_Player_ValidName(BotNames[a]) then
1053 begin
1054 _name := BotNames[a];
1055 Break;
1056 end;
1058 // Èìåíè íåò, çàäàåì ñëó÷àéíîå:
1059 if _name = '' then
1060 repeat
1061 _name := Format('DFBOT%.2d', [Random(100)]);
1062 until g_Player_ValidName(_name);
1064 // Âûáèðàåì ñëó÷àéíóþ ìîäåëü:
1065 _model := m[Random(Length(m))];
1067 // Ñîçäàåì áîòà:
1068 with g_Player_Get(g_Player_Create(_model,
1069 _RGB(Min(Random(9)*32, 255),
1070 Min(Random(9)*32, 255),
1071 Min(Random(9)*32, 255)),
1072 Team, True)) as TBot do
1073 begin
1074 Name := _name;
1076 case Difficult of
1077 1: FDifficult := DIFFICULT_EASY;
1078 2: FDifficult := DIFFICULT_MEDIUM;
1079 else FDifficult := DIFFICULT_HARD;
1080 end;
1082 for a := WP_FIRST to WP_LAST do
1083 begin
1084 FDifficult.WeaponPrior[a] := WEAPON_PRIOR1[a];
1085 FDifficult.CloseWeaponPrior[a] := WEAPON_PRIOR2[a];
1086 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1087 end;
1089 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [Name]), True);
1091 if g_Game_IsNet then MH_SEND_PlayerCreate(UID);
1092 if g_Game_IsServer and (gGameSettings.MaxLives > 0) then
1093 Spectate();
1094 end;
1095 end;
1097 procedure g_Bot_AddList(Team: Byte; lName: ShortString; num: Integer = -1);
1098 var
1099 m: SSArray;
1100 _name, _model: String;
1101 a: Integer;
1102 begin
1103 if not g_Game_IsServer then Exit;
1105 // Ñïèñîê íàçâàíèé ìîäåëåé:
1106 m := g_PlayerModel_GetNames();
1107 if m = nil then
1108 Exit;
1110 // Êîìàíäà:
1111 if (gGameSettings.GameType = GT_SINGLE) or (gGameSettings.GameMode = GM_COOP) then
1112 Team := TEAM_COOP // COOP
1113 else
1114 if gGameSettings.GameMode = GM_DM then
1115 Team := TEAM_NONE // DM
1116 else
1117 if Team = TEAM_NONE then
1118 Team := BotList[num].team; // CTF / TDM
1120 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1121 lName := AnsiLowerCase(lName);
1122 if (num < 0) or (num > Length(BotList)-1) then
1123 num := -1;
1124 if (num = -1) and (lName <> '') and (BotList <> nil) then
1125 for a := 0 to High(BotList) do
1126 if AnsiLowerCase(BotList[a].name) = lName then
1127 begin
1128 num := a;
1129 Break;
1130 end;
1131 if num = -1 then
1132 Exit;
1134 // Èìÿ áîòà:
1135 _name := BotList[num].name;
1136 // Çàíÿòî - âûáèðàåì ñëó÷àéíîå:
1137 if not g_Player_ValidName(_name) then
1138 repeat
1139 _name := Format('DFBOT%.2d', [Random(100)]);
1140 until g_Player_ValidName(_name);
1142 // Ìîäåëü:
1143 _model := BotList[num].model;
1144 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1145 if not InSArray(_model, m) then
1146 _model := m[Random(Length(m))];
1148 // Ñîçäàåì áîòà:
1149 with g_Player_Get(g_Player_Create(_model, BotList[num].color, Team, True)) as TBot do
1150 begin
1151 Name := _name;
1153 FDifficult.DiagFire := BotList[num].diag_fire;
1154 FDifficult.InvisFire := BotList[num].invis_fire;
1155 FDifficult.DiagPrecision := BotList[num].diag_precision;
1156 FDifficult.FlyPrecision := BotList[num].fly_precision;
1157 FDifficult.Cover := BotList[num].cover;
1158 FDifficult.CloseJump := BotList[num].close_jump;
1160 for a := WP_FIRST to WP_LAST do
1161 begin
1162 FDifficult.WeaponPrior[a] := BotList[num].w_prior1[a];
1163 FDifficult.CloseWeaponPrior[a] := BotList[num].w_prior2[a];
1164 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1165 end;
1167 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [Name]), True);
1169 if g_Game_IsNet then MH_SEND_PlayerCreate(UID);
1170 end;
1171 end;
1173 procedure g_Bot_RemoveAll();
1174 var
1175 a: Integer;
1176 begin
1177 if not g_Game_IsServer then Exit;
1178 if gPlayers = nil then Exit;
1180 for a := 0 to High(gPlayers) do
1181 if gPlayers[a] <> nil then
1182 if gPlayers[a] is TBot then
1183 begin
1184 gPlayers[a].Lives := 0;
1185 gPlayers[a].Kill(K_SIMPLEKILL, 0, HIT_DISCON);
1186 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [gPlayers[a].Name]), True);
1187 g_Player_Remove(gPlayers[a].FUID);
1188 end;
1190 g_Bot_MixNames();
1191 end;
1193 procedure g_Bot_MixNames();
1194 var
1195 s: String;
1196 a, b: Integer;
1197 begin
1198 if BotNames <> nil then
1199 for a := 0 to High(BotNames) do
1200 begin
1201 b := Random(Length(BotNames));
1202 s := BotNames[a];
1203 Botnames[a] := BotNames[b];
1204 BotNames[b] := s;
1205 end;
1206 end;
1208 procedure g_Player_Remove(UID: Word);
1209 var
1210 i: Integer;
1211 begin
1212 if gPlayers = nil then Exit;
1214 if g_Game_IsServer and g_Game_IsNet then
1215 MH_SEND_PlayerDelete(UID);
1217 for i := 0 to High(gPlayers) do
1218 if gPlayers[i] <> nil then
1219 if gPlayers[i].FUID = UID then
1220 begin
1221 if gPlayers[i] is TPlayer then
1222 TPlayer(gPlayers[i]).Free()
1223 else
1224 TBot(gPlayers[i]).Free();
1225 gPlayers[i] := nil;
1226 Exit;
1227 end;
1228 end;
1230 procedure g_Player_Init();
1231 var
1232 F: TextFile;
1233 s: String;
1234 a, b: Integer;
1235 config: TConfig;
1236 sa: SSArray;
1237 begin
1238 BotNames := nil;
1240 if not FileExists(DataDir + BOTNAMES_FILENAME) then
1241 Exit;
1243 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1244 AssignFile(F, DataDir + BOTNAMES_FILENAME);
1245 Reset(F);
1247 while not EOF(F) do
1248 begin
1249 ReadLn(F, s);
1251 s := Trim(s);
1252 if s = '' then
1253 Continue;
1255 SetLength(BotNames, Length(BotNames)+1);
1256 BotNames[High(BotNames)] := s;
1257 end;
1259 CloseFile(F);
1261 // Ïåðåìåøèâàåì èõ:
1262 g_Bot_MixNames();
1264 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1265 config := TConfig.CreateFile(DataDir + BOTLIST_FILENAME);
1266 BotList := nil;
1267 a := 0;
1269 while config.SectionExists(IntToStr(a)) do
1270 begin
1271 SetLength(BotList, Length(BotList)+1);
1273 with BotList[High(BotList)] do
1274 begin
1275 // Èìÿ áîòà:
1276 name := config.ReadStr(IntToStr(a), 'name', '');
1277 // Ìîäåëü:
1278 model := config.ReadStr(IntToStr(a), 'model', '');
1279 // Êîìàíäà:
1280 if config.ReadStr(IntToStr(a), 'team', 'red') = 'red' then
1281 team := TEAM_RED
1282 else
1283 team := TEAM_BLUE;
1284 // Öâåò ìîäåëè:
1285 sa := parse(config.ReadStr(IntToStr(a), 'color', ''));
1286 color.R := StrToIntDef(sa[0], 0);
1287 color.G := StrToIntDef(sa[1], 0);
1288 color.B := StrToIntDef(sa[2], 0);
1289 // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì:
1290 diag_fire := config.ReadInt(IntToStr(a), 'diag_fire', 0);
1291 // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó:
1292 invis_fire := config.ReadInt(IntToStr(a), 'invis_fire', 0);
1293 // Òî÷íîñòü ñòðåëüáû ïîä óãëîì:
1294 diag_precision := config.ReadInt(IntToStr(a), 'diag_precision', 0);
1295 // Òî÷íîñòü ñòðåëüáû â ïîëåòå:
1296 fly_precision := config.ReadInt(IntToStr(a), 'fly_precision', 0);
1297 // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ:
1298 cover := config.ReadInt(IntToStr(a), 'cover', 0);
1299 // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà:
1300 close_jump := config.ReadInt(IntToStr(a), 'close_jump', 0);
1301 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ:
1302 sa := parse(config.ReadStr(IntToStr(a), 'w_prior1', ''));
1303 if Length(sa) = 10 then
1304 for b := 0 to 9 do
1305 w_prior1[b] := EnsureRange(StrToInt(sa[b]), 0, 9);
1306 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ:
1307 sa := parse(config.ReadStr(IntToStr(a), 'w_prior2', ''));
1308 if Length(sa) = 10 then
1309 for b := 0 to 9 do
1310 w_prior2[b] := EnsureRange(StrToInt(sa[b]), 0, 9);
1312 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1313 if Length(sa) = 10 then
1314 for b := 0 to 9 do
1315 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1316 end;
1318 a := a + 1;
1319 end;
1321 config.Free();
1322 end;
1324 procedure g_Player_Free();
1325 var
1326 i: Integer;
1327 begin
1328 if gPlayers <> nil then
1329 begin
1330 for i := 0 to High(gPlayers) do
1331 if gPlayers[i] <> nil then
1332 begin
1333 if gPlayers[i] is TPlayer then
1334 TPlayer(gPlayers[i]).Free()
1335 else
1336 TBot(gPlayers[i]).Free();
1337 gPlayers[i] := nil;
1338 end;
1340 gPlayers := nil;
1341 end;
1343 gPlayer1 := nil;
1344 gPlayer2 := nil;
1345 end;
1347 procedure g_Player_UpdateAll();
1348 var
1349 i: Integer;
1350 begin
1351 if gPlayers = nil then Exit;
1353 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1354 for i := 0 to High(gPlayers) do
1355 begin
1356 if gPlayers[i] <> nil then
1357 begin
1358 if gPlayers[i] is TPlayer then
1359 begin
1360 gPlayers[i].Update();
1361 gPlayers[i].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1362 end
1363 else
1364 begin
1365 // bot updates weapons in `UpdateCombat()`
1366 TBot(gPlayers[i]).Update();
1367 end;
1368 end;
1369 end;
1370 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1371 end;
1373 procedure g_Player_DrawAll();
1374 var
1375 i: Integer;
1376 begin
1377 if gPlayers = nil then Exit;
1379 for i := 0 to High(gPlayers) do
1380 if gPlayers[i] <> nil then
1381 if gPlayers[i] is TPlayer then gPlayers[i].Draw()
1382 else TBot(gPlayers[i]).Draw();
1383 end;
1385 procedure g_Player_DrawDebug(p: TPlayer);
1386 var
1387 fW, fH: Byte;
1388 begin
1389 if p = nil then Exit;
1390 if (@p.FObj) = nil then Exit;
1392 e_TextureFontGetSize(gStdFont, fW, fH);
1394 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p.FObj.X), gStdFont);
1395 e_TextureFontPrint(0, fH , 'Pos Y: ' + IntToStr(p.FObj.Y), gStdFont);
1396 e_TextureFontPrint(0, fH * 2, 'Vel X: ' + IntToStr(p.FObj.Vel.X), gStdFont);
1397 e_TextureFontPrint(0, fH * 3, 'Vel Y: ' + IntToStr(p.FObj.Vel.Y), gStdFont);
1398 e_TextureFontPrint(0, fH * 4, 'Acc X: ' + IntToStr(p.FObj.Accel.X), gStdFont);
1399 e_TextureFontPrint(0, fH * 5, 'Acc Y: ' + IntToStr(p.FObj.Accel.Y), gStdFont);
1400 end;
1402 procedure g_Player_DrawHealth();
1403 var
1404 i: Integer;
1405 fW, fH: Byte;
1406 begin
1407 if gPlayers = nil then Exit;
1408 e_TextureFontGetSize(gStdFont, fW, fH);
1410 for i := 0 to High(gPlayers) do
1411 if gPlayers[i] <> nil then
1412 begin
1413 e_TextureFontPrint(gPlayers[i].FObj.X + gPlayers[i].FObj.Rect.X,
1414 gPlayers[i].FObj.Y + gPlayers[i].FObj.Rect.Y + gPlayers[i].FObj.Rect.Height - fH * 2,
1415 IntToStr(gPlayers[i].FHealth), gStdFont);
1416 e_TextureFontPrint(gPlayers[i].FObj.X + gPlayers[i].FObj.Rect.X,
1417 gPlayers[i].FObj.Y + gPlayers[i].FObj.Rect.Y + gPlayers[i].FObj.Rect.Height - fH,
1418 IntToStr(gPlayers[i].FArmor), gStdFont);
1419 end;
1420 end;
1422 function g_Player_Get(UID: Word): TPlayer;
1423 var
1424 a: Integer;
1425 begin
1426 Result := nil;
1428 if gPlayers = nil then
1429 Exit;
1431 for a := 0 to High(gPlayers) do
1432 if gPlayers[a] <> nil then
1433 if gPlayers[a].FUID = UID then
1434 begin
1435 Result := gPlayers[a];
1436 Exit;
1437 end;
1438 end;
1440 function g_Player_GetCount(): Byte;
1441 var
1442 a: Integer;
1443 begin
1444 Result := 0;
1446 if gPlayers = nil then
1447 Exit;
1449 for a := 0 to High(gPlayers) do
1450 if gPlayers[a] <> nil then
1451 Result := Result + 1;
1452 end;
1454 function g_Player_GetStats(): TPlayerStatArray;
1455 var
1456 a: Integer;
1457 begin
1458 Result := nil;
1460 if gPlayers = nil then Exit;
1462 for a := 0 to High(gPlayers) do
1463 if gPlayers[a] <> nil then
1464 begin
1465 SetLength(Result, Length(Result)+1);
1466 with Result[High(Result)] do
1467 begin
1468 Ping := gPlayers[a].FPing;
1469 Loss := gPlayers[a].FLoss;
1470 Name := gPlayers[a].FName;
1471 Team := gPlayers[a].FTeam;
1472 Frags := gPlayers[a].FFrags;
1473 Deaths := gPlayers[a].FDeath;
1474 Kills := gPlayers[a].FKills;
1475 Color := gPlayers[a].FModel.Color;
1476 Lives := gPlayers[a].FLives;
1477 Spectator := gPlayers[a].FSpectator;
1478 end;
1479 end;
1480 end;
1482 procedure g_Player_RememberAll;
1483 var
1484 i: Integer;
1485 begin
1486 for i := Low(gPlayers) to High(gPlayers) do
1487 if (gPlayers[i] <> nil) and gPlayers[i].alive then
1488 gPlayers[i].RememberState;
1489 end;
1491 procedure g_Player_ResetAll(Force, Silent: Boolean);
1492 var
1493 i: Integer;
1494 begin
1495 gTeamStat[TEAM_RED].Goals := 0;
1496 gTeamStat[TEAM_BLUE].Goals := 0;
1498 if gPlayers <> nil then
1499 for i := 0 to High(gPlayers) do
1500 if gPlayers[i] <> nil then
1501 begin
1502 gPlayers[i].Reset(Force);
1504 if gPlayers[i] is TPlayer then
1505 begin
1506 if (not gPlayers[i].FSpectator) or gPlayers[i].FWantsInGame then
1507 gPlayers[i].Respawn(Silent)
1508 else
1509 gPlayers[i].Spectate();
1510 end
1511 else
1512 TBot(gPlayers[i]).Respawn(Silent);
1513 end;
1514 end;
1516 procedure g_Player_CreateCorpse(Player: TPlayer);
1517 var
1518 i: Integer;
1519 find_id: DWORD;
1520 ok: Boolean;
1521 begin
1522 if Player.alive then
1523 Exit;
1525 // Ðàçðûâàåì ñâÿçü ñ ïðåæíèì òðóïîì:
1526 if gCorpses <> nil then
1527 for i := 0 to High(gCorpses) do
1528 if gCorpses[i] <> nil then
1529 if gCorpses[i].FPlayerUID = Player.FUID then
1530 gCorpses[i].FPlayerUID := 0;
1532 if Player.FObj.Y >= gMapInfo.Height+128 then
1533 Exit;
1535 with Player do
1536 begin
1537 if (FHealth >= -50) or (gGibsCount = 0) then
1538 begin
1539 if (gCorpses = nil) or (Length(gCorpses) = 0) then
1540 Exit;
1542 ok := False;
1543 for find_id := 0 to High(gCorpses) do
1544 if gCorpses[find_id] = nil then
1545 begin
1546 ok := True;
1547 Break;
1548 end;
1550 if not ok then
1551 find_id := Random(Length(gCorpses));
1553 gCorpses[find_id] := TCorpse.Create(FObj.X, FObj.Y, FModel.Name, FHealth < -20);
1554 gCorpses[find_id].FColor := FModel.Color;
1555 gCorpses[find_id].FObj.Vel := FObj.Vel;
1556 gCorpses[find_id].FObj.Accel := FObj.Accel;
1557 gCorpses[find_id].FPlayerUID := FUID;
1558 end
1559 else
1560 g_Player_CreateGibs(FObj.X + PLAYER_RECT_CX,
1561 FObj.Y + PLAYER_RECT_CY,
1562 FModel.Name, FModel.Color);
1563 end;
1564 end;
1566 procedure g_Player_CreateShell(fX, fY, dX, dY: Integer; T: Byte);
1567 var
1568 SID: DWORD;
1569 begin
1570 if (gShells = nil) or (Length(gShells) = 0) then
1571 Exit;
1573 with gShells[CurrentShell] do
1574 begin
1575 SpriteID := 0;
1576 g_Obj_Init(@Obj);
1577 Obj.Rect.X := 0;
1578 Obj.Rect.Y := 0;
1579 if T = SHELL_BULLET then
1580 begin
1581 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID) then
1582 SpriteID := SID;
1583 CX := 2;
1584 CY := 1;
1585 Obj.Rect.Width := 4;
1586 Obj.Rect.Height := 2;
1587 end
1588 else
1589 begin
1590 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID) then
1591 SpriteID := SID;
1592 CX := 4;
1593 CY := 2;
1594 Obj.Rect.Width := 7;
1595 Obj.Rect.Height := 3;
1596 end;
1597 SType := T;
1598 alive := True;
1599 Obj.X := fX;
1600 Obj.Y := fY;
1601 g_Obj_Push(@Obj, dX + Random(4)-Random(4), dY-Random(4));
1602 positionChanged(); // this updates spatial accelerators
1603 RAngle := Random(360);
1604 Timeout := gTime + SHELL_TIMEOUT;
1606 if CurrentShell >= High(gShells) then
1607 CurrentShell := 0
1608 else
1609 Inc(CurrentShell);
1610 end;
1611 end;
1613 procedure g_Player_CreateGibs(fX, fY: Integer; ModelName: string; fColor: TRGB);
1614 var
1615 a: Integer;
1616 GibsArray: TGibsArray;
1617 Blood: TModelBlood;
1618 begin
1619 if (gGibs = nil) or (Length(gGibs) = 0) then
1620 Exit;
1621 if not g_PlayerModel_GetGibs(ModelName, GibsArray) then
1622 Exit;
1623 Blood := g_PlayerModel_GetBlood(ModelName);
1625 for a := 0 to High(GibsArray) do
1626 with gGibs[CurrentGib] do
1627 begin
1628 Color := fColor;
1629 ID := GibsArray[a].ID;
1630 MaskID := GibsArray[a].MaskID;
1631 alive := True;
1632 g_Obj_Init(@Obj);
1633 Obj.Rect := GibsArray[a].Rect;
1634 Obj.X := fX-GibsArray[a].Rect.X-(GibsArray[a].Rect.Width div 2);
1635 Obj.Y := fY-GibsArray[a].Rect.Y-(GibsArray[a].Rect.Height div 2);
1636 g_Obj_PushA(@Obj, 25 + Random(10), Random(361));
1637 positionChanged(); // this updates spatial accelerators
1638 RAngle := Random(360);
1640 if gBloodCount > 0 then
1641 g_GFX_Blood(fX, fY, 16*gBloodCount+Random(5*gBloodCount), -16+Random(33), -16+Random(33),
1642 Random(48), Random(48), Blood.R, Blood.G, Blood.B, Blood.Kind);
1644 if CurrentGib >= High(gGibs) then
1645 CurrentGib := 0
1646 else
1647 Inc(CurrentGib);
1648 end;
1649 end;
1651 procedure g_Player_UpdatePhysicalObjects();
1652 var
1653 i: Integer;
1654 vel: TPoint2i;
1655 mr: Word;
1657 procedure ShellSound_Bounce(X, Y: Integer; T: Byte);
1658 var
1659 k: Integer;
1660 begin
1661 k := 1 + Random(2);
1662 if T = SHELL_BULLET then
1663 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k), X, Y)
1664 else
1665 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k), X, Y);
1666 end;
1668 begin
1669 // Êóñêè ìÿñà:
1670 if gGibs <> nil then
1671 for i := 0 to High(gGibs) do
1672 if gGibs[i].alive then
1673 with gGibs[i] do
1674 begin
1675 vel := Obj.Vel;
1676 mr := g_Obj_Move(@Obj, True, False, True);
1677 positionChanged(); // this updates spatial accelerators
1679 if WordBool(mr and MOVE_FALLOUT) then
1680 begin
1681 alive := False;
1682 Continue;
1683 end;
1685 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1686 if WordBool(mr and MOVE_HITWALL) then
1687 Obj.Vel.X := -(vel.X div 2);
1688 if WordBool(mr and (MOVE_HITCEIL or MOVE_HITLAND)) then
1689 Obj.Vel.Y := -(vel.Y div 2);
1691 if (Obj.Vel.X >= 0) then
1692 begin // Clockwise
1693 RAngle := RAngle + Abs(Obj.Vel.X)*6 + Abs(Obj.Vel.Y);
1694 if RAngle >= 360 then
1695 RAngle := RAngle mod 360;
1696 end else begin // Counter-clockwise
1697 RAngle := RAngle - Abs(Obj.Vel.X)*6 - Abs(Obj.Vel.Y);
1698 if RAngle < 0 then
1699 RAngle := (360 - (Abs(RAngle) mod 360)) mod 360;
1700 end;
1702 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1703 if gTime mod (GAME_TICK*3) = 0 then
1704 Obj.Vel.X := z_dec(Obj.Vel.X, 1);
1705 end;
1707 // Òðóïû:
1708 if gCorpses <> nil then
1709 for i := 0 to High(gCorpses) do
1710 if gCorpses[i] <> nil then
1711 if gCorpses[i].State = CORPSE_STATE_REMOVEME then
1712 begin
1713 gCorpses[i].Free();
1714 gCorpses[i] := nil;
1715 end
1716 else
1717 gCorpses[i].Update();
1719 // Ãèëüçû:
1720 if gShells <> nil then
1721 for i := 0 to High(gShells) do
1722 if gShells[i].alive then
1723 with gShells[i] do
1724 begin
1725 vel := Obj.Vel;
1726 mr := g_Obj_Move(@Obj, True, False, True);
1727 positionChanged(); // this updates spatial accelerators
1729 if WordBool(mr and MOVE_FALLOUT) or (gShells[i].Timeout < gTime) then
1730 begin
1731 alive := False;
1732 Continue;
1733 end;
1735 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1736 if WordBool(mr and MOVE_HITWALL) then
1737 begin
1738 Obj.Vel.X := -(vel.X div 2);
1739 if not WordBool(mr and MOVE_INWATER) then
1740 ShellSound_Bounce(Obj.X, Obj.Y, SType);
1741 end;
1742 if WordBool(mr and (MOVE_HITCEIL or MOVE_HITLAND)) then
1743 begin
1744 Obj.Vel.Y := -(vel.Y div 2);
1745 if Obj.Vel.X <> 0 then Obj.Vel.X := Obj.Vel.X div 2;
1746 if (Obj.Vel.X = 0) and (Obj.Vel.Y = 0) then
1747 begin
1748 if RAngle mod 90 <> 0 then
1749 RAngle := (RAngle div 90) * 90;
1750 end
1751 else if not WordBool(mr and MOVE_INWATER) then
1752 ShellSound_Bounce(Obj.X, Obj.Y, SType);
1753 end;
1755 if (Obj.Vel.X >= 0) then
1756 begin // Clockwise
1757 RAngle := RAngle + Abs(Obj.Vel.X)*8 + Abs(Obj.Vel.Y);
1758 if RAngle >= 360 then
1759 RAngle := RAngle mod 360;
1760 end else begin // Counter-clockwise
1761 RAngle := RAngle - Abs(Obj.Vel.X)*8 - Abs(Obj.Vel.Y);
1762 if RAngle < 0 then
1763 RAngle := (360 - (Abs(RAngle) mod 360)) mod 360;
1764 end;
1765 end;
1766 end;
1769 procedure TGib.getMapBox (out x, y, w, h: Integer); inline;
1770 begin
1771 x := Obj.X+Obj.Rect.X;
1772 y := Obj.Y+Obj.Rect.Y;
1773 w := Obj.Rect.Width;
1774 h := Obj.Rect.Height;
1775 end;
1777 procedure TGib.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 TShell.getMapBox (out x, y, w, h: Integer); inline;
1789 begin
1790 x := Obj.X;
1791 y := Obj.Y;
1792 w := Obj.Rect.Width;
1793 h := Obj.Rect.Height;
1794 end;
1796 procedure TShell.moveBy (dx, dy: Integer); inline;
1797 begin
1798 if (dx <> 0) or (dy <> 0) then
1799 begin
1800 Obj.X += dx;
1801 Obj.Y += dy;
1802 positionChanged();
1803 end;
1804 end;
1807 procedure TGib.positionChanged (); inline; begin end;
1808 procedure TShell.positionChanged (); inline; begin end;
1811 procedure g_Player_DrawCorpses();
1812 var
1813 i: Integer;
1814 a: TDFPoint;
1815 begin
1816 if gGibs <> nil then
1817 for i := 0 to High(gGibs) do
1818 if gGibs[i].alive then
1819 with gGibs[i] do
1820 begin
1821 if not g_Obj_Collide(sX, sY, sWidth, sHeight, @Obj) then
1822 Continue;
1824 a.X := Obj.Rect.X+(Obj.Rect.Width div 2);
1825 a.y := Obj.Rect.Y+(Obj.Rect.Height div 2);
1827 e_DrawAdv(ID, Obj.X, Obj.Y, 0, True, False, RAngle, @a, TMirrorType.None);
1829 e_Colors := Color;
1830 e_DrawAdv(MaskID, Obj.X, Obj.Y, 0, True, False, RAngle, @a, TMirrorType.None);
1831 e_Colors.R := 255;
1832 e_Colors.G := 255;
1833 e_Colors.B := 255;
1834 end;
1836 if gCorpses <> nil then
1837 for i := 0 to High(gCorpses) do
1838 if gCorpses[i] <> nil then
1839 gCorpses[i].Draw();
1840 end;
1842 procedure g_Player_DrawShells();
1843 var
1844 i: Integer;
1845 a: TDFPoint;
1846 begin
1847 if gShells <> nil then
1848 for i := 0 to High(gShells) do
1849 if gShells[i].alive then
1850 with gShells[i] do
1851 begin
1852 if not g_Obj_Collide(sX, sY, sWidth, sHeight, @Obj) then
1853 Continue;
1855 a.X := CX;
1856 a.Y := CY;
1858 e_DrawAdv(SpriteID, Obj.X, Obj.Y, 0, True, False, RAngle, @a, TMirrorType.None);
1859 end;
1860 end;
1862 procedure g_Player_RemoveAllCorpses();
1863 var
1864 i: Integer;
1865 begin
1866 gGibs := nil;
1867 gShells := nil;
1868 SetLength(gGibs, MaxGibs);
1869 SetLength(gShells, MaxGibs);
1870 CurrentGib := 0;
1871 CurrentShell := 0;
1873 if gCorpses <> nil then
1874 for i := 0 to High(gCorpses) do
1875 gCorpses[i].Free();
1877 gCorpses := nil;
1878 SetLength(gCorpses, MaxCorpses);
1879 end;
1881 procedure g_Player_Corpses_SaveState (st: TStream);
1882 var
1883 count, i: Integer;
1884 begin
1885 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ
1886 count := 0;
1887 for i := 0 to High(gCorpses) do if (gCorpses[i] <> nil) then Inc(count);
1889 // Êîëè÷åñòâî òðóïîâ
1890 utils.writeInt(st, LongInt(count));
1892 if (count = 0) then exit;
1894 // Ñîõðàíÿåì òðóïû
1895 for i := 0 to High(gCorpses) do
1896 begin
1897 if gCorpses[i] <> nil then
1898 begin
1899 // Íàçâàíèå ìîäåëè
1900 utils.writeStr(st, gCorpses[i].FModelName);
1901 // Òèï ñìåðòè
1902 utils.writeBool(st, gCorpses[i].Mess);
1903 // Ñîõðàíÿåì äàííûå òðóïà:
1904 gCorpses[i].SaveState(st);
1905 end;
1906 end;
1907 end;
1910 procedure g_Player_Corpses_LoadState (st: TStream);
1911 var
1912 count, i: Integer;
1913 str: String;
1914 b: Boolean;
1915 begin
1916 assert(st <> nil);
1918 g_Player_RemoveAllCorpses();
1920 // Êîëè÷åñòâî òðóïîâ:
1921 count := utils.readLongInt(st);
1922 if (count < 0) or (count > Length(gCorpses)) then raise XStreamError.Create('invalid number of corpses');
1924 if (count = 0) then exit;
1926 // Çàãðóæàåì òðóïû
1927 for i := 0 to count-1 do
1928 begin
1929 // Íàçâàíèå ìîäåëè:
1930 str := utils.readStr(st);
1931 // Òèï ñìåðòè
1932 b := utils.readBool(st);
1933 // Ñîçäàåì òðóï
1934 gCorpses[i] := TCorpse.Create(0, 0, str, b);
1935 // Çàãðóæàåì äàííûå òðóïà
1936 gCorpses[i].LoadState(st);
1937 end;
1938 end;
1941 { T P l a y e r : }
1943 function TPlayer.isValidViewPort (): Boolean; inline; begin result := (viewPortW > 0) and (viewPortH > 0); end;
1945 procedure TPlayer.BFGHit();
1946 begin
1947 g_Weapon_BFGHit(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
1948 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2));
1949 if g_Game_IsServer and g_Game_IsNet then
1950 MH_SEND_Effect(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
1951 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
1952 0, NET_GFX_BFGHIT);
1953 end;
1955 procedure TPlayer.ChangeModel(ModelName: string);
1956 var
1957 locModel: TPlayerModel;
1958 begin
1959 locModel := g_PlayerModel_Get(ModelName);
1960 if locModel = nil then Exit;
1962 FModel.Free();
1963 FModel := locModel;
1964 end;
1966 procedure TPlayer.SetModel(ModelName: string);
1967 var
1968 m: TPlayerModel;
1969 begin
1970 m := g_PlayerModel_Get(ModelName);
1971 if m = nil then
1972 begin
1973 g_SimpleError(Format(_lc[I_GAME_ERROR_MODEL_FALLBACK], [ModelName]));
1974 m := g_PlayerModel_Get('doomer');
1975 if m = nil then
1976 begin
1977 g_FatalError(Format(_lc[I_GAME_ERROR_MODEL], ['doomer']));
1978 Exit;
1979 end;
1980 end;
1982 if FModel <> nil then
1983 FModel.Free();
1985 FModel := m;
1987 if not (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
1988 FModel.Color := FColor
1989 else
1990 FModel.Color := TEAMCOLOR[FTeam];
1991 FModel.SetWeapon(FCurrWeap);
1992 FModel.SetFlag(FFlag);
1993 SetDirection(FDirection);
1994 end;
1996 procedure TPlayer.SetColor(Color: TRGB);
1997 begin
1998 FColor := Color;
1999 if not (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
2000 if FModel <> nil then FModel.Color := Color;
2001 end;
2003 procedure TPlayer.SwitchTeam;
2004 begin
2005 if g_Game_IsClient then
2006 Exit;
2007 if not (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then Exit;
2009 if gGameOn and FAlive then
2010 Kill(K_SIMPLEKILL, FUID, HIT_SELF);
2012 if FTeam = TEAM_RED then
2013 begin
2014 ChangeTeam(TEAM_BLUE);
2015 g_Console_Add(Format(_lc[I_PLAYER_CHTEAM_BLUE], [FName]), True);
2016 if g_Game_IsNet then
2017 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM, TEAM_BLUE, FName);
2018 end
2019 else
2020 begin
2021 ChangeTeam(TEAM_RED);
2022 g_Console_Add(Format(_lc[I_PLAYER_CHTEAM_RED], [FName]), True);
2023 if g_Game_IsNet then
2024 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM, TEAM_RED, FName);
2025 end;
2026 FPreferredTeam := FTeam;
2027 end;
2029 procedure TPlayer.ChangeTeam(Team: Byte);
2030 var
2031 OldTeam: Byte;
2032 begin
2033 OldTeam := FTeam;
2034 FTeam := Team;
2035 case Team of
2036 TEAM_RED, TEAM_BLUE:
2037 FModel.Color := TEAMCOLOR[Team];
2038 else
2039 FModel.Color := FColor;
2040 end;
2041 if (FTeam <> OldTeam) and g_Game_IsNet and g_Game_IsServer then
2042 MH_SEND_PlayerStats(FUID);
2043 end;
2046 procedure TPlayer.CollideItem();
2047 var
2048 i: Integer;
2049 r: Boolean;
2050 begin
2051 if gItems = nil then Exit;
2052 if not FAlive then Exit;
2054 for i := 0 to High(gItems) do
2055 with gItems[i] do
2056 begin
2057 if (ItemType <> ITEM_NONE) and alive then
2058 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
2059 PLAYER_RECT.Height, @Obj) then
2060 begin
2061 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
2063 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
2064 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
2065 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
2066 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
2067 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
2069 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
2070 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
2071 (gGameSettings.GameType = GT_SINGLE) and
2072 (g_Player_GetCount() > 1)) then
2073 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
2074 end;
2075 end;
2076 end;
2079 function TPlayer.CollideLevel(XInc, YInc: Integer): Boolean;
2080 begin
2081 Result := g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc,
2082 PLAYER_RECT.Width, PLAYER_RECT.Height, PANEL_WALL,
2083 False);
2084 end;
2086 constructor TPlayer.Create();
2087 begin
2088 viewPortX := 0;
2089 viewPortY := 0;
2090 viewPortW := 0;
2091 viewPortH := 0;
2092 mEDamageType := HIT_SOME;
2094 FIamBot := False;
2095 FDummy := False;
2096 FSpawned := False;
2098 FSawSound := TPlayableSound.Create();
2099 FSawSoundIdle := TPlayableSound.Create();
2100 FSawSoundHit := TPlayableSound.Create();
2101 FSawSoundSelect := TPlayableSound.Create();
2102 FJetSoundFly := TPlayableSound.Create();
2103 FJetSoundOn := TPlayableSound.Create();
2104 FJetSoundOff := TPlayableSound.Create();
2106 FSawSound.SetByName('SOUND_WEAPON_FIRESAW');
2107 FSawSoundIdle.SetByName('SOUND_WEAPON_IDLESAW');
2108 FSawSoundHit.SetByName('SOUND_WEAPON_HITSAW');
2109 FSawSoundSelect.SetByName('SOUND_WEAPON_SELECTSAW');
2110 FJetSoundFly.SetByName('SOUND_PLAYER_JETFLY');
2111 FJetSoundOn.SetByName('SOUND_PLAYER_JETON');
2112 FJetSoundOff.SetByName('SOUND_PLAYER_JETOFF');
2114 FSpectatePlayer := -1;
2115 FClientID := -1;
2116 FPing := 0;
2117 FLoss := 0;
2118 FSavedState.WaitRecall := False;
2119 FShellTimer := -1;
2120 FFireTime := 0;
2121 FFirePainTime := 0;
2122 FFireAttacker := 0;
2124 FActualModelName := 'doomer';
2126 g_Obj_Init(@FObj);
2127 FObj.Rect := PLAYER_RECT;
2129 FBFGFireCounter := -1;
2130 FJustTeleported := False;
2131 FNetTime := 0;
2133 resetWeaponQueue();
2134 end;
2136 procedure TPlayer.positionChanged (); inline;
2137 begin
2138 end;
2140 procedure TPlayer.doDamage (v: Integer);
2141 begin
2142 if (v <= 0) then exit;
2143 if (v > 32767) then v := 32767;
2144 Damage(v, 0, 0, 0, mEDamageType);
2145 end;
2147 procedure TPlayer.Damage(value: Word; SpawnerUID: Word; vx, vy: Integer; t: Byte);
2148 var
2149 c: Word;
2150 begin
2151 if (not g_Game_IsClient) and (not FAlive) then
2152 Exit;
2154 FLastHit := t;
2156 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2157 if ((t = HIT_TRAP) or (t = HIT_SELF)) and (not FGodMode) then
2158 begin
2159 if not g_Game_IsClient then
2160 begin
2161 FArmor := 0;
2162 if t = HIT_TRAP then
2163 begin
2164 // Ëîâóøêà óáèâàåò ñðàçó:
2165 FHealth := -100;
2166 Kill(K_EXTRAHARDKILL, SpawnerUID, t);
2167 end;
2168 if t = HIT_SELF then
2169 begin
2170 // Ñàìîóáèéñòâî:
2171 FHealth := 0;
2172 Kill(K_SIMPLEKILL, SpawnerUID, t);
2173 end;
2174 end;
2175 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2176 FMegaRulez[MR_SUIT] := 0;
2177 FMegaRulez[MR_INVUL] := 0;
2178 FMegaRulez[MR_INVIS] := 0;
2179 FBerserk := 0;
2180 end;
2182 // Íî îò îñòàëüíîãî ñïàñàåò:
2183 if FMegaRulez[MR_INVUL] >= gTime then
2184 Exit;
2186 // ×èò-êîä "ÃÎÐÅÖ":
2187 if FGodMode then
2188 Exit;
2190 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2191 if LongBool(gGameSettings.Options and GAME_OPTION_TEAMDAMAGE) or
2192 (SpawnerUID = FUID) or
2193 (not SameTeam(FUID, SpawnerUID)) then
2194 begin
2195 FLastSpawnerUID := SpawnerUID;
2197 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2198 if gBloodCount > 0 then
2199 begin
2200 c := Min(value, 200)*gBloodCount + Random(Min(value, 200) div 2);
2201 if value div 4 <= c then
2202 c := c - (value div 4)
2203 else
2204 c := 0;
2206 if (t = HIT_SOME) and (vx = 0) and (vy = 0) then
2207 MakeBloodSimple(c)
2208 else
2209 case t of
2210 HIT_TRAP, HIT_ACID, HIT_FLAME, HIT_SELF: MakeBloodSimple(c);
2211 HIT_BFG, HIT_ROCKET, HIT_SOME: MakeBloodVector(c, vx, vy);
2212 end;
2214 if t = HIT_WATER then
2215 g_GFX_Bubbles(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2),
2216 FObj.Y+PLAYER_RECT.Y-4, value div 2, 8, 4);
2217 end;
2219 // Áóôåð óðîíà:
2220 if FAlive then
2221 Inc(FDamageBuffer, value);
2223 // Âñïûøêà áîëè:
2224 if gFlash <> 0 then
2225 FPain := FPain + value;
2226 end;
2228 if g_Game_IsServer and g_Game_IsNet then
2229 begin
2230 MH_SEND_PlayerDamage(FUID, t, SpawnerUID, value, vx, vy);
2231 MH_SEND_PlayerStats(FUID);
2232 MH_SEND_PlayerPos(False, FUID);
2233 end;
2234 end;
2236 function TPlayer.Heal(value: Word; Soft: Boolean): Boolean;
2237 begin
2238 Result := False;
2239 if g_Game_IsClient then
2240 Exit;
2241 if not FAlive then
2242 Exit;
2244 if Soft and (FHealth < PLAYER_HP_SOFT) then
2245 begin
2246 IncMax(FHealth, value, PLAYER_HP_SOFT);
2247 Result := True;
2248 end;
2249 if (not Soft) and (FHealth < PLAYER_HP_LIMIT) then
2250 begin
2251 IncMax(FHealth, value, PLAYER_HP_LIMIT);
2252 Result := True;
2253 end;
2255 if Result and g_Game_IsServer and g_Game_IsNet then
2256 MH_SEND_PlayerStats(FUID);
2257 end;
2259 destructor TPlayer.Destroy();
2260 begin
2261 if (gPlayer1 <> nil) and (gPlayer1.FUID = FUID) then
2262 gPlayer1 := nil;
2263 if (gPlayer2 <> nil) and (gPlayer2.FUID = FUID) then
2264 gPlayer2 := nil;
2266 FSawSound.Free();
2267 FSawSoundIdle.Free();
2268 FSawSoundHit.Free();
2269 FSawSoundSelect.Free();
2270 FJetSoundFly.Free();
2271 FJetSoundOn.Free();
2272 FJetSoundOff.Free();
2273 FModel.Free();
2274 if FPunchAnim <> nil then
2275 FPunchAnim.Free();
2277 inherited;
2278 end;
2280 procedure TPlayer.DrawIndicator();
2281 var
2282 indX, indY: Integer;
2283 indW, indH: Word;
2284 ID: DWORD;
2285 begin
2286 if FAlive then
2287 begin
2288 indX := FObj.X+FObj.Rect.X;
2289 indY := FObj.Y;
2290 if g_Texture_Get('TEXTURE_PLAYER_INDICATOR', ID) then
2291 begin
2292 e_GetTextureSize(ID, @indW, @indH);
2293 e_Draw(ID, indX + indW div 2, indY - indH, 0, True, False);
2294 end;
2295 end;
2296 //e_TextureFontPrint(indX, indY, FName, gStdFont); // Shows player name overhead
2297 end;
2299 procedure TPlayer.DrawBubble();
2300 var
2301 bubX, bubY: Integer;
2302 ID: LongWord;
2303 Rb, Gb, Bb,
2304 Rw, Gw, Bw: SmallInt;
2305 Dot: Byte;
2306 begin
2307 bubX := FObj.X+FObj.Rect.X + IfThen(FDirection = TDirection.D_LEFT, -4, 18);
2308 bubY := FObj.Y+FObj.Rect.Y - 18;
2309 Rb := 64;
2310 Gb := 64;
2311 Bb := 64;
2312 Rw := 240;
2313 Gw := 240;
2314 Bw := 240;
2315 case gChatBubble of
2316 1: // simple textual non-bubble
2317 begin
2318 bubX := FObj.X+FObj.Rect.X - 11;
2319 bubY := FObj.Y+FObj.Rect.Y - 17;
2320 e_TextureFontPrint(bubX, bubY, '[...]', gStdFont);
2321 Exit;
2322 end;
2323 2: // advanced pixel-perfect bubble
2324 begin
2325 if FTeam = TEAM_RED then
2326 Rb := 255
2327 else
2328 if FTeam = TEAM_BLUE then
2329 Bb := 255;
2330 end;
2331 3: // colored bubble
2332 begin
2333 Rb := FModel.Color.R;
2334 Gb := FModel.Color.G;
2335 Bb := FModel.Color.B;
2336 Rw := Min(Rb * 2 + 64, 255);
2337 Gw := Min(Gb * 2 + 64, 255);
2338 Bw := Min(Bb * 2 + 64, 255);
2339 if (Abs(Rw - Rb) < 32)
2340 or (Abs(Gw - Gb) < 32)
2341 or (Abs(Bw - Bb) < 32) then
2342 begin
2343 Rb := Max(Rw div 2 - 16, 0);
2344 Gb := Max(Gw div 2 - 16, 0);
2345 Bb := Max(Bw div 2 - 16, 0);
2346 end;
2347 end;
2348 4: // custom textured bubble
2349 begin
2350 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID) then
2351 if FDirection = TDirection.D_RIGHT then
2352 e_Draw(ID, bubX - 6, bubY - 7, 0, True, False)
2353 else
2354 e_Draw(ID, bubX - 6, bubY - 7, 0, True, False, TMirrorType.Horizontal);
2355 Exit;
2356 end;
2357 end;
2359 // Outer borders
2360 e_DrawQuad(bubX + 1, bubY , bubX + 18, bubY + 13, Rb, Gb, Bb);
2361 e_DrawQuad(bubX , bubY + 1, bubX + 19, bubY + 12, Rb, Gb, Bb);
2362 // Inner box
2363 e_DrawFillQuad(bubX + 1, bubY + 1, bubX + 18, bubY + 12, Rw, Gw, Bw, 0);
2365 // Tail
2366 Dot := IfThen(FDirection = TDirection.D_LEFT, 14, 5);
2367 e_DrawLine(1, bubX + Dot, bubY + 14, bubX + Dot, bubY + 16, Rb, Gb, Bb);
2368 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);
2369 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);
2370 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);
2371 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);
2373 // Dots
2374 Dot := 6;
2375 e_DrawFillQuad(bubX + Dot, bubY + 8, bubX + Dot + 1, bubY + 9, Rb, Gb, Bb, 0);
2376 e_DrawFillQuad(bubX + Dot + 3, bubY + 8, bubX + Dot + 4, bubY + 9, Rb, Gb, Bb, 0);
2377 e_DrawFillQuad(bubX + Dot + 6, bubY + 8, bubX + Dot + 7, bubY + 9, Rb, Gb, Bb, 0);
2378 end;
2380 procedure TPlayer.Draw();
2381 var
2382 ID: DWORD;
2383 w, h: Word;
2384 dr: Boolean;
2385 Mirror: TMirrorType;
2386 begin
2387 if FAlive then
2388 begin
2389 if Direction = TDirection.D_RIGHT then
2390 Mirror := TMirrorType.None
2391 else
2392 Mirror := TMirrorType.Horizontal;
2394 if FPunchAnim <> nil then
2395 begin
2396 FPunchAnim.Draw(FObj.X+IfThen(Direction = TDirection.D_LEFT, 15-FObj.Rect.X, FObj.Rect.X-15),
2397 FObj.Y+FObj.Rect.Y-11, Mirror);
2398 if FPunchAnim.played then
2399 begin
2400 FPunchAnim.Free;
2401 FPunchAnim := nil;
2402 end;
2403 end;
2405 if (FMegaRulez[MR_INVUL] > gTime) and (gPlayerDrawn <> Self) then
2406 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID) then
2407 begin
2408 e_GetTextureSize(ID, @w, @h);
2409 if FDirection = TDirection.D_LEFT then
2410 e_Draw(ID, FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2)-(w div 2)+4,
2411 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2)-(h div 2)-7+FObj.slopeUpLeft, 0, True, False)
2412 else
2413 e_Draw(ID, FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2)-(w div 2)-2,
2414 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2)-(h div 2)-7+FObj.slopeUpLeft, 0, True, False);
2415 end;
2417 if FMegaRulez[MR_INVIS] > gTime then
2418 begin
2419 if (gPlayerDrawn <> nil) and ((Self = gPlayerDrawn) or
2420 ((FTeam = gPlayerDrawn.Team) and (gGameSettings.GameMode <> GM_DM))) then
2421 begin
2422 if (FMegaRulez[MR_INVIS] - gTime) <= 2100 then
2423 dr := not Odd((FMegaRulez[MR_INVIS] - gTime) div 300)
2424 else
2425 dr := True;
2426 if dr then
2427 FModel.Draw(FObj.X, FObj.Y+FObj.slopeUpLeft, 200)
2428 else
2429 FModel.Draw(FObj.X, FObj.Y+FObj.slopeUpLeft);
2430 end
2431 else
2432 FModel.Draw(FObj.X, FObj.Y+FObj.slopeUpLeft, 254);
2433 end
2434 else
2435 FModel.Draw(FObj.X, FObj.Y+FObj.slopeUpLeft);
2436 end;
2438 if g_debug_Frames then
2439 begin
2440 e_DrawQuad(FObj.X+FObj.Rect.X,
2441 FObj.Y+FObj.Rect.Y,
2442 FObj.X+FObj.Rect.X+FObj.Rect.Width-1,
2443 FObj.Y+FObj.Rect.Y+FObj.Rect.Height-1,
2444 0, 255, 0);
2445 end;
2447 if (gChatBubble > 0) and (FKeys[KEY_CHAT].Pressed) and not FGhost then
2448 if (FMegaRulez[MR_INVIS] <= gTime) or ((gPlayerDrawn <> nil) and ((Self = gPlayerDrawn) or
2449 ((FTeam = gPlayerDrawn.Team) and (gGameSettings.GameMode <> GM_DM)))) then
2450 DrawBubble();
2451 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2452 if gAimLine and alive and
2453 ((Self = gPlayer1) or (Self = gPlayer2)) then
2454 DrawAim();
2455 end;
2458 procedure TPlayer.DrawAim();
2459 procedure drawCast (sz: Integer; ax0, ay0, ax1, ay1: Integer);
2460 var
2461 ex, ey: Integer;
2462 begin
2464 {$IFDEF ENABLE_HOLMES}
2465 if isValidViewPort and (self = gPlayer1) then
2466 begin
2467 g_Holmes_plrLaser(ax0, ay0, ax1, ay1);
2468 end;
2469 {$ENDIF}
2471 e_DrawLine(sz, ax0, ay0, ax1, ay1, 255, 0, 0, 96);
2472 if (g_Map_traceToNearestWall(ax0, ay0, ax1, ay1, @ex, @ey) <> nil) then
2473 begin
2474 e_DrawLine(sz, ax0, ay0, ex, ey, 0, 255, 0, 96);
2475 end
2476 else
2477 begin
2478 e_DrawLine(sz, ax0, ay0, ex, ey, 0, 0, 255, 96);
2479 end;
2480 end;
2482 var
2483 wx, wy, xx, yy: Integer;
2484 angle: SmallInt;
2485 sz, len: Word;
2486 begin
2487 wx := FObj.X + WEAPONPOINT[FDirection].X + IfThen(FDirection = TDirection.D_LEFT, 7, -7);
2488 wy := FObj.Y + WEAPONPOINT[FDirection].Y;
2489 angle := FAngle;
2490 len := 1024;
2491 sz := 2;
2492 case FCurrWeap of
2493 0: begin // Punch
2494 len := 12;
2495 sz := 4;
2496 end;
2497 1: begin // Chainsaw
2498 len := 24;
2499 sz := 6;
2500 end;
2501 2: begin // Pistol
2502 len := 1024;
2503 sz := 2;
2504 if angle = ANGLE_RIGHTUP then Dec(angle, 2);
2505 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2506 if angle = ANGLE_LEFTUP then Inc(angle, 2);
2507 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2508 end;
2509 3: begin // Shotgun
2510 len := 1024;
2511 sz := 3;
2512 if angle = ANGLE_RIGHTUP then Dec(angle, 2);
2513 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2514 if angle = ANGLE_LEFTUP then Inc(angle, 2);
2515 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2516 end;
2517 4: begin // Double Shotgun
2518 len := 1024;
2519 sz := 4;
2520 if angle = ANGLE_RIGHTUP then Dec(angle, 2);
2521 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2522 if angle = ANGLE_LEFTUP then Inc(angle, 2);
2523 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2524 end;
2525 5: begin // Chaingun
2526 len := 1024;
2527 sz := 3;
2528 if angle = ANGLE_RIGHTUP then Dec(angle, 2);
2529 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2530 if angle = ANGLE_LEFTUP then Inc(angle, 2);
2531 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2532 end;
2533 6: begin // Rocket Launcher
2534 len := 1024;
2535 sz := 7;
2536 if angle = ANGLE_RIGHTUP then Inc(angle, 2);
2537 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2538 if angle = ANGLE_LEFTUP then Dec(angle, 2);
2539 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2540 end;
2541 7: begin // Plasmagun
2542 len := 1024;
2543 sz := 5;
2544 if angle = ANGLE_RIGHTUP then Inc(angle);
2545 if angle = ANGLE_RIGHTDOWN then Inc(angle, 3);
2546 if angle = ANGLE_LEFTUP then Dec(angle);
2547 if angle = ANGLE_LEFTDOWN then Dec(angle, 3);
2548 end;
2549 8: begin // BFG
2550 len := 1024;
2551 sz := 12;
2552 if angle = ANGLE_RIGHTUP then Inc(angle, 1);
2553 if angle = ANGLE_RIGHTDOWN then Inc(angle, 2);
2554 if angle = ANGLE_LEFTUP then Dec(angle, 1);
2555 if angle = ANGLE_LEFTDOWN then Dec(angle, 2);
2556 end;
2557 9: begin // Super Chaingun
2558 len := 1024;
2559 sz := 4;
2560 if angle = ANGLE_RIGHTUP then Dec(angle, 2);
2561 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2562 if angle = ANGLE_LEFTUP then Inc(angle, 2);
2563 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2564 end;
2565 end;
2566 xx := Trunc(Cos(-DegToRad(angle)) * len) + wx;
2567 yy := Trunc(Sin(-DegToRad(angle)) * len) + wy;
2568 {$IF DEFINED(D2F_DEBUG)}
2569 drawCast(sz, wx, wy, xx, yy);
2570 {$ELSE}
2571 e_DrawLine(sz, wx, wy, xx, yy, 255, 0, 0, 96);
2572 {$ENDIF}
2573 end;
2575 procedure TPlayer.DrawGUI();
2576 var
2577 ID: DWORD;
2578 X, Y, SY, a, p, m: Integer;
2579 tw, th: Word;
2580 cw, ch: Byte;
2581 s: string;
2582 stat: TPlayerStatArray;
2583 begin
2584 X := gPlayerScreenSize.X;
2585 SY := gPlayerScreenSize.Y;
2586 Y := 0;
2588 if gShowGoals and (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
2589 begin
2590 if gGameSettings.GameMode = GM_CTF then
2591 a := 32 + 8
2592 else
2593 a := 0;
2594 if gGameSettings.GameMode = GM_CTF then
2595 begin
2596 s := 'TEXTURE_PLAYER_REDFLAG';
2597 if gFlags[FLAG_RED].State = FLAG_STATE_CAPTURED then
2598 s := 'TEXTURE_PLAYER_REDFLAG_S';
2599 if gFlags[FLAG_RED].State = FLAG_STATE_DROPPED then
2600 s := 'TEXTURE_PLAYER_REDFLAG_D';
2601 if g_Texture_Get(s, ID) then
2602 e_Draw(ID, X-16-32, 240-72-4, 0, True, False);
2603 end;
2605 s := IntToStr(gTeamStat[TEAM_RED].Goals);
2606 e_CharFont_GetSize(gMenuFont, s, tw, th);
2607 e_CharFont_PrintEx(gMenuFont, X-16-a-tw, 240-72-4, s, TEAMCOLOR[TEAM_RED]);
2609 if gGameSettings.GameMode = GM_CTF then
2610 begin
2611 s := 'TEXTURE_PLAYER_BLUEFLAG';
2612 if gFlags[FLAG_BLUE].State = FLAG_STATE_CAPTURED then
2613 s := 'TEXTURE_PLAYER_BLUEFLAG_S';
2614 if gFlags[FLAG_BLUE].State = FLAG_STATE_DROPPED then
2615 s := 'TEXTURE_PLAYER_BLUEFLAG_D';
2616 if g_Texture_Get(s, ID) then
2617 e_Draw(ID, X-16-32, 240-32-4, 0, True, False);
2618 end;
2620 s := IntToStr(gTeamStat[TEAM_BLUE].Goals);
2621 e_CharFont_GetSize(gMenuFont, s, tw, th);
2622 e_CharFont_PrintEx(gMenuFont, X-16-a-tw, 240-32-4, s, TEAMCOLOR[TEAM_BLUE]);
2623 end;
2625 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID) then
2626 e_DrawFill(ID, X, 0, 1, (gPlayerScreenSize.Y div 256)+IfThen(gPlayerScreenSize.Y mod 256 > 0, 1, 0),
2627 0, False, False);
2629 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID) then
2630 e_Draw(ID, X+2, Y, 0, True, False);
2632 if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
2633 begin
2634 if gShowStat then
2635 begin
2636 s := IntToStr(Frags);
2637 e_CharFont_GetSize(gMenuFont, s, tw, th);
2638 e_CharFont_PrintEx(gMenuFont, X-16-tw, Y, s, _RGB(255, 0, 0));
2640 s := '';
2641 p := 1;
2642 m := 0;
2643 stat := g_Player_GetStats();
2644 if stat <> nil then
2645 begin
2646 p := 1;
2648 for a := 0 to High(stat) do
2649 if stat[a].Name <> Name then
2650 begin
2651 if stat[a].Frags > m then m := stat[a].Frags;
2652 if stat[a].Frags > Frags then p := p+1;
2653 end;
2654 end;
2656 s := IntToStr(p)+' / '+IntToStr(Length(stat))+' ';
2657 if Frags >= m then s := s+'+' else s := s+'-';
2658 s := s+IntToStr(Abs(Frags-m));
2660 e_CharFont_GetSize(gMenuSmallFont, s, tw, th);
2661 e_CharFont_PrintEx(gMenuSmallFont, X-16-tw, Y+32, s, _RGB(255, 0, 0));
2662 end;
2664 if gShowLives and (gGameSettings.MaxLives > 0) then
2665 begin
2666 s := IntToStr(Lives);
2667 e_CharFont_GetSize(gMenuFont, s, tw, th);
2668 e_CharFont_PrintEx(gMenuFont, X-16-tw, SY-32, s, _RGB(0, 255, 0));
2669 end;
2670 end;
2672 e_CharFont_GetSize(gMenuSmallFont, FName, tw, th);
2673 e_CharFont_PrintEx(gMenuSmallFont, X+98-(tw div 2), Y+8, FName, _RGB(255, 0, 0));
2675 if R_BERSERK in FRulez then
2676 e_Draw(gItemsTexturesID[ITEM_MEDKIT_BLACK], X+37, Y+45, 0, True, False)
2677 else
2678 e_Draw(gItemsTexturesID[ITEM_MEDKIT_LARGE], X+37, Y+45, 0, True, False);
2680 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID) then
2681 e_Draw(ID, X+36, Y+77, 0, True, False);
2683 s := IntToStr(IfThen(FHealth > 0, FHealth, 0));
2684 e_CharFont_GetSize(gMenuFont, s, tw, th);
2685 e_CharFont_PrintEx(gMenuFont, X+178-tw, Y+40, s, _RGB(255, 0, 0));
2687 s := IntToStr(FArmor);
2688 e_CharFont_GetSize(gMenuFont, s, tw, th);
2689 e_CharFont_PrintEx(gMenuFont, X+178-tw, Y+68, s, _RGB(255, 0, 0));
2691 s := IntToStr(GetAmmoByWeapon(FCurrWeap));
2693 case FCurrWeap of
2694 WEAPON_KASTET:
2695 begin
2696 s := '--';
2697 ID := gItemsTexturesID[ITEM_WEAPON_KASTET];
2698 end;
2699 WEAPON_SAW:
2700 begin
2701 s := '--';
2702 ID := gItemsTexturesID[ITEM_WEAPON_SAW];
2703 end;
2704 WEAPON_PISTOL: ID := gItemsTexturesID[ITEM_WEAPON_PISTOL];
2705 WEAPON_CHAINGUN: ID := gItemsTexturesID[ITEM_WEAPON_CHAINGUN];
2706 WEAPON_SHOTGUN1: ID := gItemsTexturesID[ITEM_WEAPON_SHOTGUN1];
2707 WEAPON_SHOTGUN2: ID := gItemsTexturesID[ITEM_WEAPON_SHOTGUN2];
2708 WEAPON_SUPERPULEMET: ID := gItemsTexturesID[ITEM_WEAPON_SUPERPULEMET];
2709 WEAPON_ROCKETLAUNCHER: ID := gItemsTexturesID[ITEM_WEAPON_ROCKETLAUNCHER];
2710 WEAPON_PLASMA: ID := gItemsTexturesID[ITEM_WEAPON_PLASMA];
2711 WEAPON_BFG: ID := gItemsTexturesID[ITEM_WEAPON_BFG];
2712 WEAPON_FLAMETHROWER: ID := gItemsTexturesID[ITEM_WEAPON_FLAMETHROWER];
2713 end;
2715 e_CharFont_GetSize(gMenuFont, s, tw, th);
2716 e_CharFont_PrintEx(gMenuFont, X+178-tw, Y+158, s, _RGB(255, 0, 0));
2717 e_Draw(ID, X+20, Y+160, 0, True, False);
2719 if R_KEY_RED in FRulez then
2720 e_Draw(gItemsTexturesID[ITEM_KEY_RED], X+78, Y+214, 0, True, False);
2722 if R_KEY_GREEN in FRulez then
2723 e_Draw(gItemsTexturesID[ITEM_KEY_GREEN], X+95, Y+214, 0, True, False);
2725 if R_KEY_BLUE in FRulez then
2726 e_Draw(gItemsTexturesID[ITEM_KEY_BLUE], X+112, Y+214, 0, True, False);
2728 if FJetFuel > 0 then
2729 begin
2730 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID) then
2731 e_Draw(ID, X+2, Y+116, 0, True, False);
2732 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID) then
2733 e_Draw(ID, X+2, Y+126, 0, True, False);
2734 e_DrawLine(4, X+16, Y+122, X+16+Trunc(168*IfThen(FAir > 0, FAir, 0)/AIR_MAX), Y+122, 0, 0, 196);
2735 e_DrawLine(4, X+16, Y+132, X+16+Trunc(168*FJetFuel/JET_MAX), Y+132, 208, 0, 0);
2736 end
2737 else
2738 begin
2739 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID) then
2740 e_Draw(ID, X+2, Y+124, 0, True, False);
2741 e_DrawLine(4, X+16, Y+130, X+16+Trunc(168*IfThen(FAir > 0, FAir, 0)/AIR_MAX), Y+130, 0, 0, 196);
2742 end;
2744 if gShowPing and g_Game_IsClient then
2745 begin
2746 s := _lc[I_GAME_PING_HUD] + IntToStr(NetPeer.lastRoundTripTime) + _lc[I_NET_SLIST_PING_MS];
2747 e_TextureFontPrint(X + 4, Y + 242, s, gStdFont);
2748 Y := Y + 16;
2749 end;
2751 if FSpectator then
2752 begin
2753 e_TextureFontPrint(X + 4, Y + 242, _lc[I_PLAYER_SPECT], gStdFont);
2754 e_TextureFontPrint(X + 4, Y + 258, _lc[I_PLAYER_SPECT2], gStdFont);
2755 e_TextureFontPrint(X + 4, Y + 274, _lc[I_PLAYER_SPECT1], gStdFont);
2756 if FNoRespawn then
2757 begin
2758 e_TextureFontGetSize(gStdFont, cw, ch);
2759 s := _lc[I_PLAYER_SPECT4];
2760 e_TextureFontPrintEx(gScreenWidth div 2 - cw*(Length(s) div 2),
2761 gScreenHeight-4-ch, s, gStdFont, 255, 255, 255, 1, True);
2762 e_TextureFontPrint(X + 4, Y + 290, _lc[I_PLAYER_SPECT1S], gStdFont);
2763 end;
2765 end;
2766 end;
2768 procedure TPlayer.DrawRulez();
2769 var
2770 dr: Boolean;
2771 begin
2772 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2773 if FMegaRulez[MR_INVUL] >= gTime then
2774 begin
2775 if (FMegaRulez[MR_INVUL]-gTime) <= 2100 then
2776 dr := not Odd((FMegaRulez[MR_INVUL]-gTime) div 300)
2777 else
2778 dr := True;
2780 if dr then
2781 e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1,
2782 191, 191, 191, 0, TBlending.Invert);
2783 end;
2785 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2786 if FMegaRulez[MR_SUIT] >= gTime then
2787 begin
2788 if (FMegaRulez[MR_SUIT]-gTime) <= 2100 then
2789 dr := not Odd((FMegaRulez[MR_SUIT]-gTime) div 300)
2790 else
2791 dr := True;
2793 if dr then
2794 e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1,
2795 0, 96, 0, 200, TBlending.None);
2796 end;
2798 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2799 if (FBerserk >= 0) and (LongWord(FBerserk) >= gTime) and (gFlash = 2) then
2800 begin
2801 e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1,
2802 255, 0, 0, 200, TBlending.None);
2803 end;
2804 end;
2806 procedure TPlayer.DrawPain();
2807 var
2808 a, h: Integer;
2809 begin
2810 if FPain = 0 then Exit;
2812 a := FPain;
2814 if a < 15 then h := 0
2815 else if a < 35 then h := 1
2816 else if a < 55 then h := 2
2817 else if a < 75 then h := 3
2818 else if a < 95 then h := 4
2819 else h := 5;
2821 //if a > 255 then a := 255;
2823 e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255, 0, 0, 255-h*50);
2824 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2825 end;
2827 procedure TPlayer.DrawPickup();
2828 var
2829 a, h: Integer;
2830 begin
2831 if FPickup = 0 then Exit;
2833 a := FPickup;
2835 if a < 15 then h := 1
2836 else if a < 35 then h := 2
2837 else if a < 55 then h := 3
2838 else if a < 75 then h := 4
2839 else h := 5;
2841 e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 150, 200, 150, 255-h*50);
2842 end;
2844 procedure TPlayer.DoPunch();
2845 var
2846 id: DWORD;
2847 st: String;
2848 begin
2849 if FPunchAnim <> nil then begin
2850 FPunchAnim.reset();
2851 FPunchAnim.Free;
2852 FPunchAnim := nil;
2853 end;
2854 st := 'FRAMES_PUNCH';
2855 if R_BERSERK in FRulez then
2856 st := st + '_BERSERK';
2857 if FKeys[KEY_UP].Pressed then
2858 st := st + '_UP'
2859 else if FKeys[KEY_DOWN].Pressed then
2860 st := st + '_DN';
2861 g_Frames_Get(id, st);
2862 FPunchAnim := TAnimation.Create(id, False, 1);
2863 end;
2865 procedure TPlayer.Fire();
2866 var
2867 f, DidFire: Boolean;
2868 wx, wy, xd, yd: Integer;
2869 locobj: TObj;
2870 begin
2871 if g_Game_IsClient then Exit;
2872 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
2873 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
2875 if FSpectator then
2876 begin
2877 Respawn(False);
2878 Exit;
2879 end;
2881 if FReloading[FCurrWeap] <> 0 then Exit;
2883 DidFire := False;
2885 f := False;
2886 wx := FObj.X+WEAPONPOINT[FDirection].X;
2887 wy := FObj.Y+WEAPONPOINT[FDirection].Y;
2888 xd := wx+IfThen(FDirection = TDirection.D_LEFT, -30, 30);
2889 yd := wy+firediry();
2891 case FCurrWeap of
2892 WEAPON_KASTET:
2893 begin
2894 DoPunch();
2895 if R_BERSERK in FRulez then
2896 begin
2897 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2898 locobj.X := FObj.X+FObj.Rect.X;
2899 locobj.Y := FObj.Y+FObj.Rect.Y;
2900 locobj.rect.X := 0;
2901 locobj.rect.Y := 0;
2902 locobj.rect.Width := 39;
2903 locobj.rect.Height := 52;
2904 locobj.Vel.X := (xd-wx) div 2;
2905 locobj.Vel.Y := (yd-wy) div 2;
2906 locobj.Accel.X := xd-wx;
2907 locobj.Accel.y := yd-wy;
2909 if g_Weapon_Hit(@locobj, 50, FUID, HIT_SOME) <> 0 then
2910 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj.X, FObj.Y)
2911 else
2912 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj.X, FObj.Y);
2914 if (gFlash = 1) and (FPain < 50) then FPain := min(FPain + 25, 50);
2915 end
2916 else
2917 begin
2918 g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 3, FUID);
2919 end;
2921 DidFire := True;
2922 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
2923 end;
2925 WEAPON_SAW:
2926 begin
2927 if g_Weapon_chainsaw(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y,
2928 IfThen(gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF], 9, 3), FUID) <> 0 then
2929 begin
2930 FSawSoundSelect.Stop();
2931 FSawSound.Stop();
2932 FSawSoundHit.PlayAt(FObj.X, FObj.Y);
2933 end
2934 else if not FSawSoundHit.IsPlaying() then
2935 begin
2936 FSawSoundSelect.Stop();
2937 FSawSound.PlayAt(FObj.X, FObj.Y);
2938 end;
2940 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
2941 DidFire := True;
2942 f := True;
2943 end;
2945 WEAPON_PISTOL:
2946 if FAmmo[A_BULLETS] > 0 then
2947 begin
2948 g_Weapon_pistol(wx, wy, xd, yd, FUID);
2949 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
2950 Dec(FAmmo[A_BULLETS]);
2951 FFireAngle := FAngle;
2952 f := True;
2953 DidFire := True;
2954 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
2955 GameVelX, GameVelY-2, SHELL_BULLET);
2956 end;
2958 WEAPON_SHOTGUN1:
2959 if FAmmo[A_SHELLS] > 0 then
2960 begin
2961 g_Weapon_shotgun(wx, wy, xd, yd, FUID);
2962 if not gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx, wy);
2963 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
2964 Dec(FAmmo[A_SHELLS]);
2965 FFireAngle := FAngle;
2966 f := True;
2967 DidFire := True;
2968 FShellTimer := 10;
2969 FShellType := SHELL_SHELL;
2970 end;
2972 WEAPON_SHOTGUN2:
2973 if FAmmo[A_SHELLS] >= 2 then
2974 begin
2975 g_Weapon_dshotgun(wx, wy, xd, yd, FUID);
2976 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
2977 Dec(FAmmo[A_SHELLS], 2);
2978 FFireAngle := FAngle;
2979 f := True;
2980 DidFire := True;
2981 FShellTimer := 13;
2982 FShellType := SHELL_DBLSHELL;
2983 end;
2985 WEAPON_CHAINGUN:
2986 if FAmmo[A_BULLETS] > 0 then
2987 begin
2988 g_Weapon_mgun(wx, wy, xd, yd, FUID);
2989 if not gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx, wy);
2990 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
2991 Dec(FAmmo[A_BULLETS]);
2992 FFireAngle := FAngle;
2993 f := True;
2994 DidFire := True;
2995 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
2996 GameVelX, GameVelY-2, SHELL_BULLET);
2997 end;
2999 WEAPON_ROCKETLAUNCHER:
3000 if FAmmo[A_ROCKETS] > 0 then
3001 begin
3002 g_Weapon_rocket(wx, wy, xd, yd, FUID);
3003 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3004 Dec(FAmmo[A_ROCKETS]);
3005 FFireAngle := FAngle;
3006 f := True;
3007 DidFire := True;
3008 end;
3010 WEAPON_PLASMA:
3011 if FAmmo[A_CELLS] > 0 then
3012 begin
3013 g_Weapon_plasma(wx, wy, xd, yd, FUID);
3014 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3015 Dec(FAmmo[A_CELLS]);
3016 FFireAngle := FAngle;
3017 f := True;
3018 DidFire := True;
3019 end;
3021 WEAPON_BFG:
3022 if (FAmmo[A_CELLS] >= 40) and (FBFGFireCounter = -1) then
3023 begin
3024 FBFGFireCounter := 17;
3025 if not FNoReload then
3026 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj.X, FObj.Y);
3027 Dec(FAmmo[A_CELLS], 40);
3028 DidFire := True;
3029 end;
3031 WEAPON_SUPERPULEMET:
3032 if FAmmo[A_SHELLS] > 0 then
3033 begin
3034 g_Weapon_shotgun(wx, wy, xd, yd, FUID);
3035 if not gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx, wy);
3036 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3037 Dec(FAmmo[A_SHELLS]);
3038 FFireAngle := FAngle;
3039 f := True;
3040 DidFire := True;
3041 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
3042 GameVelX, GameVelY-2, SHELL_SHELL);
3043 end;
3045 WEAPON_FLAMETHROWER:
3046 if FAmmo[A_FUEL] > 0 then
3047 begin
3048 g_Weapon_flame(wx, wy, xd, yd, FUID);
3049 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3050 Dec(FAmmo[A_FUEL]);
3051 FFireAngle := FAngle;
3052 f := True;
3053 DidFire := True;
3054 end;
3055 end;
3057 if g_Game_IsNet then
3058 begin
3059 if DidFire then
3060 begin
3061 if FCurrWeap <> WEAPON_BFG then
3062 MH_SEND_PlayerFire(FUID, FCurrWeap, wx, wy, xd, yd, LastShotID)
3063 else
3064 if not FNoReload then
3065 MH_SEND_Sound(FObj.X, FObj.Y, 'SOUND_WEAPON_STARTFIREBFG');
3066 end;
3068 MH_SEND_PlayerStats(FUID);
3069 end;
3071 if not f then Exit;
3073 if (FAngle = 0) or (FAngle = 180) then SetAction(A_ATTACK)
3074 else if (FAngle = ANGLE_LEFTDOWN) or (FAngle = ANGLE_RIGHTDOWN) then SetAction(A_ATTACKDOWN)
3075 else if (FAngle = ANGLE_LEFTUP) or (FAngle = ANGLE_RIGHTUP) then SetAction(A_ATTACKUP);
3076 end;
3078 function TPlayer.GetAmmoByWeapon(Weapon: Byte): Word;
3079 begin
3080 case Weapon of
3081 WEAPON_PISTOL, WEAPON_CHAINGUN: Result := FAmmo[A_BULLETS];
3082 WEAPON_SHOTGUN1, WEAPON_SHOTGUN2, WEAPON_SUPERPULEMET: Result := FAmmo[A_SHELLS];
3083 WEAPON_ROCKETLAUNCHER: Result := FAmmo[A_ROCKETS];
3084 WEAPON_PLASMA, WEAPON_BFG: Result := FAmmo[A_CELLS];
3085 WEAPON_FLAMETHROWER: Result := FAmmo[A_FUEL];
3086 else Result := 0;
3087 end;
3088 end;
3090 function TPlayer.HeadInLiquid(XInc, YInc: Integer): Boolean;
3091 begin
3092 Result := g_Map_CollidePanel(FObj.X+PLAYER_HEADRECT.X+XInc, FObj.Y+PLAYER_HEADRECT.Y+YInc,
3093 PLAYER_HEADRECT.Width, PLAYER_HEADRECT.Height,
3094 PANEL_WATER or PANEL_ACID1 or PANEL_ACID2, True);
3095 end;
3097 procedure TPlayer.JetpackOn;
3098 begin
3099 FJetSoundFly.Stop;
3100 FJetSoundOff.Stop;
3101 FJetSoundOn.SetPosition(0);
3102 FJetSoundOn.PlayAt(FObj.X, FObj.Y);
3103 FlySmoke(8);
3104 end;
3106 procedure TPlayer.JetpackOff;
3107 begin
3108 FJetSoundFly.Stop;
3109 FJetSoundOn.Stop;
3110 FJetSoundOff.SetPosition(0);
3111 FJetSoundOff.PlayAt(FObj.X, FObj.Y);
3112 end;
3114 procedure TPlayer.CatchFire(Attacker: Word);
3115 begin
3116 FFireTime := 100;
3117 FFireAttacker := Attacker;
3118 if g_Game_IsNet and g_Game_IsServer then
3119 MH_SEND_PlayerStats(FUID);
3120 end;
3122 procedure TPlayer.Jump();
3123 begin
3124 if gFly or FJetpack then
3125 begin
3126 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
3127 if FObj.Vel.Y > -VEL_FLY then
3128 FObj.Vel.Y := FObj.Vel.Y - 3;
3129 if FJetpack then
3130 begin
3131 if FJetFuel > 0 then
3132 Dec(FJetFuel);
3133 if (FJetFuel < 1) and g_Game_IsServer then
3134 begin
3135 FJetpack := False;
3136 JetpackOff;
3137 if g_Game_IsNet then
3138 MH_SEND_PlayerStats(FUID);
3139 end;
3140 end;
3141 Exit;
3142 end;
3144 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
3145 if FGhost then
3146 FCanJetpack := False;
3148 // Ïðûãàåì èëè âñïëûâàåì:
3149 if (CollideLevel(0, 1) or
3150 g_Map_CollidePanel(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y+36, PLAYER_RECT.Width,
3151 PLAYER_RECT.Height-33, PANEL_STEP, False)
3152 ) and (FObj.Accel.Y = 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
3153 begin
3154 FObj.Vel.Y := -VEL_JUMP;
3155 FCanJetpack := False;
3156 end
3157 else
3158 begin
3159 if BodyInLiquid(0, 0) then
3160 FObj.Vel.Y := -VEL_SW
3161 else if (FJetFuel > 0) and FCanJetpack and
3162 g_Game_IsServer and (not g_Obj_CollideLiquid(@FObj, 0, 0)) then
3163 begin
3164 FJetpack := True;
3165 JetpackOn;
3166 if g_Game_IsNet then
3167 MH_SEND_PlayerStats(FUID);
3168 end;
3169 end;
3170 end;
3172 procedure TPlayer.Kill(KillType: Byte; SpawnerUID: Word; t: Byte);
3173 var
3174 a, i, k, ab, ar: Byte;
3175 s: String;
3176 mon: TMonster;
3177 plr: TPlayer;
3178 srv, netsrv: Boolean;
3179 DoFrags: Boolean;
3180 OldLR: Byte;
3181 KP: TPlayer;
3182 it: PItem;
3184 procedure PushItem(t: Byte);
3185 var
3186 id: DWORD;
3187 begin
3188 id := g_Items_Create(FObj.X, FObj.Y, t, True, False);
3189 it := g_Items_ByIdx(id);
3190 if KillType = K_EXTRAHARDKILL then // -7..+7; -8..0
3191 begin
3192 g_Obj_Push(@it.Obj, (FObj.Vel.X div 2)-7+Random(15),
3193 (FObj.Vel.Y div 2)-Random(9));
3194 it.positionChanged(); // this updates spatial accelerators
3195 end
3196 else
3197 begin
3198 if KillType = K_HARDKILL then // -5..+5; -5..0
3199 begin
3200 g_Obj_Push(@it.Obj, (FObj.Vel.X div 2)-5+Random(11),
3201 (FObj.Vel.Y div 2)-Random(6));
3202 end
3203 else // -3..+3; -3..0
3204 begin
3205 g_Obj_Push(@it.Obj, (FObj.Vel.X div 2)-3+Random(7),
3206 (FObj.Vel.Y div 2)-Random(4));
3207 end;
3208 it.positionChanged(); // this updates spatial accelerators
3209 end;
3211 if g_Game_IsNet and g_Game_IsServer then
3212 MH_SEND_ItemSpawn(True, id);
3213 end;
3215 begin
3216 DoFrags := (gGameSettings.MaxLives = 0) or (gGameSettings.GameMode = GM_COOP);
3217 Srv := g_Game_IsServer;
3218 Netsrv := g_Game_IsServer and g_Game_IsNet;
3219 if Srv then FDeath := FDeath + 1;
3220 if FAlive then
3221 begin
3222 if FGhost then
3223 FGhost := False;
3224 if not FPhysics then
3225 FPhysics := True;
3226 FAlive := False;
3227 end;
3228 FShellTimer := -1;
3230 if (gGameSettings.MaxLives > 0) and Srv and (gLMSRespawn = LMS_RESPAWN_NONE) then
3231 begin
3232 if FLives > 0 then FLives := FLives - 1;
3233 if FLives = 0 then FNoRespawn := True;
3234 end;
3236 // Íîìåð òèïà ñìåðòè:
3237 a := 1;
3238 case KillType of
3239 K_SIMPLEKILL: a := 1;
3240 K_HARDKILL: a := 2;
3241 K_EXTRAHARDKILL: a := 3;
3242 K_FALLKILL: a := 4;
3243 end;
3245 // Çâóê ñìåðòè:
3246 if not FModel.PlaySound(MODELSOUND_DIE, a, FObj.X, FObj.Y) then
3247 for i := 1 to 3 do
3248 if FModel.PlaySound(MODELSOUND_DIE, i, FObj.X, FObj.Y) then
3249 Break;
3251 // Âðåìÿ ðåñïàóíà:
3252 if Srv then
3253 case KillType of
3254 K_SIMPLEKILL:
3255 FTime[T_RESPAWN] := gTime + TIME_RESPAWN1;
3256 K_HARDKILL:
3257 FTime[T_RESPAWN] := gTime + TIME_RESPAWN2;
3258 K_EXTRAHARDKILL, K_FALLKILL:
3259 FTime[T_RESPAWN] := gTime + TIME_RESPAWN3;
3260 end;
3262 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3263 case KillType of
3264 K_SIMPLEKILL:
3265 SetAction(A_DIE1);
3266 K_HARDKILL, K_EXTRAHARDKILL:
3267 SetAction(A_DIE2);
3268 end;
3270 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3271 if (KillType <> K_FALLKILL) and (Srv) then
3272 g_Monsters_killedp();
3274 if SpawnerUID = FUID then
3275 begin // Ñàìîóáèëñÿ
3276 if Srv and (DoFrags or (gGameSettings.GameMode = GM_TDM)) then
3277 begin
3278 Dec(FFrags);
3279 FLastFrag := 0;
3280 end;
3281 g_Console_Add(Format(_lc[I_PLAYER_KILL_SELF], [FName]), True);
3282 end
3283 else
3284 if g_GetUIDType(SpawnerUID) = UID_PLAYER then
3285 begin // Óáèò äðóãèì èãðîêîì
3286 KP := g_Player_Get(SpawnerUID);
3287 if (KP <> nil) and Srv then
3288 begin
3289 if (DoFrags or (gGameSettings.GameMode = GM_TDM)) then
3290 if SameTeam(FUID, SpawnerUID) then
3291 begin
3292 Dec(KP.FFrags);
3293 KP.FLastFrag := 0;
3294 end else
3295 begin
3296 Inc(KP.FFrags);
3297 KP.FragCombo();
3298 end;
3300 if (gGameSettings.GameMode = GM_TDM) and DoFrags then
3301 Inc(gTeamStat[KP.Team].Goals,
3302 IfThen(SameTeam(FUID, SpawnerUID), -1, 1));
3304 if netsrv then MH_SEND_PlayerStats(SpawnerUID);
3305 end;
3307 plr := g_Player_Get(SpawnerUID);
3308 if plr = nil then
3309 s := '?'
3310 else
3311 s := plr.FName;
3313 case KillType of
3314 K_HARDKILL:
3315 g_Console_Add(Format(_lc[I_PLAYER_KILL_EXTRAHARD_2],
3316 [FName, s]),
3317 gShowKillMsg);
3318 K_EXTRAHARDKILL:
3319 g_Console_Add(Format(_lc[I_PLAYER_KILL_EXTRAHARD_1],
3320 [FName, s]),
3321 gShowKillMsg);
3322 else
3323 g_Console_Add(Format(_lc[I_PLAYER_KILL],
3324 [FName, s]),
3325 gShowKillMsg);
3326 end;
3327 end
3328 else if g_GetUIDType(SpawnerUID) = UID_MONSTER then
3329 begin // Óáèò ìîíñòðîì
3330 mon := g_Monsters_ByUID(SpawnerUID);
3331 if mon = nil then
3332 s := '?'
3333 else
3334 s := g_Mons_GetKilledByTypeId(mon.MonsterType);
3336 case KillType of
3337 K_HARDKILL:
3338 g_Console_Add(Format(_lc[I_PLAYER_KILL_EXTRAHARD_2],
3339 [FName, s]),
3340 gShowKillMsg);
3341 K_EXTRAHARDKILL:
3342 g_Console_Add(Format(_lc[I_PLAYER_KILL_EXTRAHARD_1],
3343 [FName, s]),
3344 gShowKillMsg);
3345 else
3346 g_Console_Add(Format(_lc[I_PLAYER_KILL],
3347 [FName, s]),
3348 gShowKillMsg);
3349 end;
3350 end
3351 else // Îñîáûå òèïû ñìåðòè
3352 case t of
3353 HIT_DISCON: ;
3354 HIT_SELF: g_Console_Add(Format(_lc[I_PLAYER_KILL_SELF], [FName]), True);
3355 HIT_FALL: g_Console_Add(Format(_lc[I_PLAYER_KILL_FALL], [FName]), True);
3356 HIT_WATER: g_Console_Add(Format(_lc[I_PLAYER_KILL_WATER], [FName]), True);
3357 HIT_ACID: g_Console_Add(Format(_lc[I_PLAYER_KILL_ACID], [FName]), True);
3358 HIT_TRAP: g_Console_Add(Format(_lc[I_PLAYER_KILL_TRAP], [FName]), True);
3359 else g_Console_Add(Format(_lc[I_PLAYER_DIED], [FName]), True);
3360 end;
3362 if Srv then
3363 begin
3364 // Âûáðîñ îðóæèÿ:
3365 for a := WP_FIRST to WP_LAST do
3366 if FWeapon[a] then
3367 begin
3368 case a of
3369 WEAPON_SAW: i := ITEM_WEAPON_SAW;
3370 WEAPON_SHOTGUN1: i := ITEM_WEAPON_SHOTGUN1;
3371 WEAPON_SHOTGUN2: i := ITEM_WEAPON_SHOTGUN2;
3372 WEAPON_CHAINGUN: i := ITEM_WEAPON_CHAINGUN;
3373 WEAPON_ROCKETLAUNCHER: i := ITEM_WEAPON_ROCKETLAUNCHER;
3374 WEAPON_PLASMA: i := ITEM_WEAPON_PLASMA;
3375 WEAPON_BFG: i := ITEM_WEAPON_BFG;
3376 WEAPON_SUPERPULEMET: i := ITEM_WEAPON_SUPERPULEMET;
3377 WEAPON_FLAMETHROWER: i := ITEM_WEAPON_FLAMETHROWER;
3378 else i := 0;
3379 end;
3381 if i <> 0 then
3382 PushItem(i);
3383 end;
3385 // Âûáðîñ ðþêçàêà:
3386 if R_ITEM_BACKPACK in FRulez then
3387 PushItem(ITEM_AMMO_BACKPACK);
3389 // Âûáðîñ ðàêåòíîãî ðàíöà:
3390 if FJetFuel > 0 then
3391 PushItem(ITEM_JETPACK);
3393 // Âûáðîñ êëþ÷åé:
3394 if not (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF]) then
3395 begin
3396 if R_KEY_RED in FRulez then
3397 PushItem(ITEM_KEY_RED);
3399 if R_KEY_GREEN in FRulez then
3400 PushItem(ITEM_KEY_GREEN);
3402 if R_KEY_BLUE in FRulez then
3403 PushItem(ITEM_KEY_BLUE);
3404 end;
3406 // Âûáðîñ ôëàãà:
3407 DropFlag(KillType = K_FALLKILL);
3408 end;
3410 g_Player_CreateCorpse(Self);
3412 if Srv and (gGameSettings.MaxLives > 0) and FNoRespawn and
3413 (gLMSRespawn = LMS_RESPAWN_NONE) then
3414 begin
3415 a := 0;
3416 k := 0;
3417 ar := 0;
3418 ab := 0;
3419 for i := Low(gPlayers) to High(gPlayers) do
3420 begin
3421 if gPlayers[i] = nil then continue;
3422 if (not gPlayers[i].FNoRespawn) and (not gPlayers[i].FSpectator) then
3423 begin
3424 Inc(a);
3425 if gPlayers[i].FTeam = TEAM_RED then Inc(ar)
3426 else if gPlayers[i].FTeam = TEAM_BLUE then Inc(ab);
3427 k := i;
3428 end;
3429 end;
3431 OldLR := gLMSRespawn;
3432 if (gGameSettings.GameMode = GM_COOP) then
3433 begin
3434 if (a = 0) then
3435 begin
3436 // everyone is dead, restart the map
3437 g_Game_Message(_lc[I_MESSAGE_LMS_LOSE], 144);
3438 if Netsrv then
3439 MH_SEND_GameEvent(NET_EV_LMS_LOSE);
3440 gLMSRespawn := LMS_RESPAWN_FINAL;
3441 gLMSRespawnTime := gTime + 5000;
3442 end
3443 else if (a = 1) then
3444 begin
3445 if (gPlayers[k] <> nil) and not (gPlayers[k] is TBot) then
3446 if (gPlayers[k] = gPlayer1) or
3447 (gPlayers[k] = gPlayer2) then
3448 g_Console_Add('*** ' + _lc[I_MESSAGE_LMS_SURVIVOR] + ' ***', True)
3449 else if Netsrv and (gPlayers[k].FClientID >= 0) then
3450 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR, 0, 'N', gPlayers[k].FClientID);
3451 end;
3452 end
3453 else if (gGameSettings.GameMode = GM_TDM) then
3454 begin
3455 if (ab = 0) and (ar <> 0) then
3456 begin
3457 // blu team ded
3458 g_Game_Message(Format(_lc[I_MESSAGE_TLMS_WIN], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 144);
3459 if Netsrv then
3460 MH_SEND_GameEvent(NET_EV_TLMS_WIN, TEAM_RED);
3461 Inc(gTeamStat[TEAM_RED].Goals);
3462 gLMSRespawn := LMS_RESPAWN_FINAL;
3463 gLMSRespawnTime := gTime + 5000;
3464 end
3465 else if (ar = 0) and (ab <> 0) then
3466 begin
3467 // red team ded
3468 g_Game_Message(Format(_lc[I_MESSAGE_TLMS_WIN], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 144);
3469 if Netsrv then
3470 MH_SEND_GameEvent(NET_EV_TLMS_WIN, TEAM_BLUE);
3471 Inc(gTeamStat[TEAM_BLUE].Goals);
3472 gLMSRespawn := LMS_RESPAWN_FINAL;
3473 gLMSRespawnTime := gTime + 5000;
3474 end
3475 else if (ar = 0) and (ab = 0) then
3476 begin
3477 // everyone ded
3478 g_Game_Message(_lc[I_GAME_WIN_DRAW], 144);
3479 if Netsrv then
3480 MH_SEND_GameEvent(NET_EV_LMS_DRAW, 0, FName);
3481 gLMSRespawn := LMS_RESPAWN_FINAL;
3482 gLMSRespawnTime := gTime + 5000;
3483 end;
3484 end
3485 else if (gGameSettings.GameMode = GM_DM) then
3486 begin
3487 if (a = 1) then
3488 begin
3489 if gPlayers[k] <> nil then
3490 with gPlayers[k] do
3491 begin
3492 // survivor is the winner
3493 g_Game_Message(Format(_lc[I_MESSAGE_LMS_WIN], [AnsiUpperCase(FName)]), 144);
3494 if Netsrv then
3495 MH_SEND_GameEvent(NET_EV_LMS_WIN, 0, FName);
3496 Inc(FFrags);
3497 end;
3498 gLMSRespawn := LMS_RESPAWN_FINAL;
3499 gLMSRespawnTime := gTime + 5000;
3500 end
3501 else if (a = 0) then
3502 begin
3503 // everyone is dead, restart the map
3504 g_Game_Message(_lc[I_GAME_WIN_DRAW], 144);
3505 if Netsrv then
3506 MH_SEND_GameEvent(NET_EV_LMS_DRAW, 0, FName);
3507 gLMSRespawn := LMS_RESPAWN_FINAL;
3508 gLMSRespawnTime := gTime + 5000;
3509 end;
3510 end;
3511 if srv and (OldLR = LMS_RESPAWN_NONE) and (gLMSRespawn > LMS_RESPAWN_NONE) then
3512 begin
3513 if NetMode = NET_SERVER then
3514 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, (gLMSRespawnTime - gTime) div 1000)
3515 else
3516 g_Console_Add(Format(_lc[I_MSG_WARMUP_START], [(gLMSRespawnTime - gTime) div 1000]), True);
3517 end;
3518 end;
3520 if Netsrv then
3521 begin
3522 MH_SEND_PlayerStats(FUID);
3523 MH_SEND_PlayerDeath(FUID, KillType, t, SpawnerUID);
3524 if gGameSettings.GameMode = GM_TDM then MH_SEND_GameStats;
3525 end;
3527 if srv and FNoRespawn then Spectate(True);
3528 FWantsInGame := True;
3529 end;
3531 function TPlayer.BodyInLiquid(XInc, YInc: Integer): Boolean;
3532 begin
3533 Result := g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc, PLAYER_RECT.Width,
3534 PLAYER_RECT.Height-20, PANEL_WATER or PANEL_ACID1 or PANEL_ACID2, False);
3535 end;
3537 function TPlayer.BodyInAcid(XInc, YInc: Integer): Boolean;
3538 begin
3539 Result := g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc, PLAYER_RECT.Width,
3540 PLAYER_RECT.Height-20, PANEL_ACID1 or PANEL_ACID2, False);
3541 end;
3543 procedure TPlayer.MakeBloodSimple(Count: Word);
3544 begin
3545 g_GFX_Blood(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)+8,
3546 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2),
3547 Count div 2, 3, -1, 16, (PLAYER_RECT.Height*2 div 3),
3548 FModel.Blood.R, FModel.Blood.G, FModel.Blood.B, FModel.Blood.Kind);
3549 g_GFX_Blood(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-8,
3550 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2),
3551 Count div 2, -3, -1, 16, (PLAYER_RECT.Height*2) div 3,
3552 FModel.Blood.R, FModel.Blood.G, FModel.Blood.B, FModel.Blood.Kind);
3553 end;
3555 procedure TPlayer.MakeBloodVector(Count: Word; VelX, VelY: Integer);
3556 begin
3557 g_GFX_Blood(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2),
3558 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2),
3559 Count, VelX, VelY, 16, (PLAYER_RECT.Height*2) div 3,
3560 FModel.Blood.R, FModel.Blood.G, FModel.Blood.B, FModel.Blood.Kind);
3561 end;
3563 procedure TPlayer.QueueWeaponSwitch(Weapon: Byte);
3564 begin
3565 if g_Game_IsClient then Exit;
3566 if Weapon > High(FWeapon) then Exit;
3567 FNextWeap := FNextWeap or (1 shl Weapon);
3568 end;
3570 procedure TPlayer.resetWeaponQueue ();
3571 begin
3572 FNextWeap := 0;
3573 FNextWeapDelay := 0;
3574 end;
3576 function TPlayer.hasAmmoForWeapon (weapon: Byte): Boolean;
3577 begin
3578 result := false;
3579 case weapon of
3580 WEAPON_KASTET, WEAPON_SAW: result := true;
3581 WEAPON_SHOTGUN1, WEAPON_SHOTGUN2: result := (FAmmo[A_SHELLS] > 0);
3582 WEAPON_PISTOL, WEAPON_CHAINGUN, WEAPON_SUPERPULEMET: result := (FAmmo[A_BULLETS] > 0);
3583 WEAPON_ROCKETLAUNCHER: result := (FAmmo[A_ROCKETS] > 0);
3584 WEAPON_PLASMA, WEAPON_BFG: result := (FAmmo[A_CELLS] > 0);
3585 WEAPON_FLAMETHROWER: result := (FAmmo[A_FUEL] > 0);
3586 else result := (weapon < length(FWeapon));
3587 end;
3588 end;
3590 // return 255 for "no switch"
3591 function TPlayer.getNextWeaponIndex (): Byte;
3592 var
3593 i: Word;
3594 wantThisWeapon: array[0..64] of Boolean;
3595 wwc: Integer = 0; //HACK!
3596 dir, cwi: Integer;
3597 begin
3598 result := 255; // default result: "no switch"
3599 // had weapon cycling on previous frame? remove that flag
3600 if (FNextWeap and $2000) <> 0 then
3601 begin
3602 FNextWeap := FNextWeap and $1FFF;
3603 FNextWeapDelay := 0;
3604 end;
3605 // cycling has priority
3606 if (FNextWeap and $C000) <> 0 then
3607 begin
3608 if (FNextWeap and $8000) <> 0 then
3609 dir := 1
3610 else
3611 dir := -1;
3612 FNextWeap := FNextWeap or $2000; // we need this
3613 if FNextWeapDelay > 0 then
3614 exit; // cooldown time
3615 cwi := FCurrWeap;
3616 for i := 0 to High(FWeapon) do
3617 begin
3618 cwi := (cwi+length(FWeapon)+dir) mod length(FWeapon);
3619 if FWeapon[cwi] then
3620 begin
3621 //e_WriteLog(Format(' SWITCH: cur=%d; new=%d', [FCurrWeap, cwi]), MSG_WARNING);
3622 result := Byte(cwi);
3623 FNextWeapDelay := WEAPON_DELAY;
3624 exit;
3625 end;
3626 end;
3627 resetWeaponQueue();
3628 exit;
3629 end;
3630 // no cycling
3631 for i := 0 to High(wantThisWeapon) do
3632 wantThisWeapon[i] := false;
3633 for i := 0 to High(FWeapon) do
3634 if (FNextWeap and (1 shl i)) <> 0 then
3635 begin
3636 wantThisWeapon[i] := true;
3637 Inc(wwc);
3638 end;
3639 // exclude currently selected weapon from the set
3640 wantThisWeapon[FCurrWeap] := false;
3641 // slow down alterations a little
3642 if wwc > 1 then
3643 begin
3644 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3645 // more than one weapon requested, assume "alteration" and check alteration delay
3646 if FNextWeapDelay > 0 then
3647 begin
3648 FNextWeap := 0;
3649 exit;
3650 end; // yeah
3651 end;
3652 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3653 // but clear all counters if no weapon should be switched
3654 if wwc < 1 then
3655 begin
3656 resetWeaponQueue();
3657 exit;
3658 end;
3659 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3660 // try weapons in descending order
3661 for i := High(FWeapon) downto 0 do
3662 begin
3663 if wantThisWeapon[i] and FWeapon[i] and ((wwc = 1) or hasAmmoForWeapon(i)) then
3664 begin
3665 // i found her!
3666 result := Byte(i);
3667 resetWeaponQueue();
3668 FNextWeapDelay := WEAPON_DELAY; // anyway, 'cause why not
3669 exit;
3670 end;
3671 end;
3672 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3673 resetWeaponQueue();
3674 end;
3676 procedure TPlayer.RealizeCurrentWeapon();
3677 function switchAllowed (): Boolean;
3678 var
3679 i: Byte;
3680 begin
3681 result := false;
3682 if FBFGFireCounter <> -1 then
3683 exit;
3684 if FTime[T_SWITCH] > gTime then
3685 exit;
3686 for i := WP_FIRST to WP_LAST do
3687 if FReloading[i] > 0 then
3688 exit;
3689 result := true;
3690 end;
3692 var
3693 nw: Byte;
3694 begin
3695 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3696 //FNextWeap := FNextWeap and $1FFF;
3697 if FNextWeapDelay > 0 then Dec(FNextWeapDelay); // "alteration delay"
3699 if not switchAllowed then
3700 begin
3701 //HACK for weapon cycling
3702 if (FNextWeap and $E000) <> 0 then FNextWeap := 0;
3703 exit;
3704 end;
3706 nw := getNextWeaponIndex();
3707 if nw = 255 then exit; // don't reset anything here
3708 if nw > High(FWeapon) then
3709 begin
3710 // don't forget to reset queue here!
3711 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
3712 resetWeaponQueue();
3713 exit;
3714 end;
3716 if FWeapon[nw] then
3717 begin
3718 FCurrWeap := nw;
3719 FTime[T_SWITCH] := gTime+156;
3720 if FCurrWeap = WEAPON_SAW then FSawSoundSelect.PlayAt(FObj.X, FObj.Y);
3721 FModel.SetWeapon(FCurrWeap);
3722 if g_Game_IsNet then MH_SEND_PlayerStats(FUID);
3723 end;
3724 end;
3726 procedure TPlayer.NextWeapon();
3727 begin
3728 if g_Game_IsClient then Exit;
3729 FNextWeap := $8000;
3730 end;
3732 procedure TPlayer.PrevWeapon();
3733 begin
3734 if g_Game_IsClient then Exit;
3735 FNextWeap := $4000;
3736 end;
3738 procedure TPlayer.SetWeapon(W: Byte);
3739 begin
3740 if FCurrWeap <> W then
3741 if W = WEAPON_SAW then
3742 FSawSoundSelect.PlayAt(FObj.X, FObj.Y);
3744 FCurrWeap := W;
3745 FModel.SetWeapon(CurrWeap);
3746 resetWeaponQueue();
3747 end;
3749 function TPlayer.PickItem(ItemType: Byte; arespawn: Boolean; var remove: Boolean): Boolean;
3751 function allowBerserkSwitching (): Boolean;
3752 begin
3753 if (FBFGFireCounter <> -1) then begin result := false; exit; end;
3754 result := true;
3755 if gBerserkAutoswitch then exit;
3756 if not conIsCheatsEnabled then exit;
3757 result := false;
3758 end;
3760 var
3761 a: Boolean;
3762 begin
3763 Result := False;
3764 if g_Game_IsClient then Exit;
3766 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3767 a := LongBool(gGameSettings.Options and GAME_OPTION_WEAPONSTAY) and arespawn;
3768 remove := not a;
3770 case ItemType of
3771 ITEM_MEDKIT_SMALL:
3772 if FHealth < PLAYER_HP_SOFT then
3773 begin
3774 IncMax(FHealth, 10, PLAYER_HP_SOFT);
3775 Result := True;
3776 remove := True;
3777 FFireTime := 0;
3778 if gFlash = 2 then Inc(FPickup, 5);
3779 end;
3781 ITEM_MEDKIT_LARGE:
3782 if FHealth < PLAYER_HP_SOFT then
3783 begin
3784 IncMax(FHealth, 25, PLAYER_HP_SOFT);
3785 Result := True;
3786 remove := True;
3787 FFireTime := 0;
3788 if gFlash = 2 then Inc(FPickup, 5);
3789 end;
3791 ITEM_ARMOR_GREEN:
3792 if FArmor < PLAYER_AP_SOFT then
3793 begin
3794 FArmor := PLAYER_AP_SOFT;
3795 Result := True;
3796 remove := True;
3797 if gFlash = 2 then Inc(FPickup, 5);
3798 end;
3800 ITEM_ARMOR_BLUE:
3801 if FArmor < PLAYER_AP_LIMIT then
3802 begin
3803 FArmor := PLAYER_AP_LIMIT;
3804 Result := True;
3805 remove := True;
3806 if gFlash = 2 then Inc(FPickup, 5);
3807 end;
3809 ITEM_SPHERE_BLUE:
3810 if FHealth < PLAYER_HP_LIMIT then
3811 begin
3812 IncMax(FHealth, 100, PLAYER_HP_LIMIT);
3813 Result := True;
3814 remove := True;
3815 FFireTime := 0;
3816 if gFlash = 2 then Inc(FPickup, 5);
3817 end;
3819 ITEM_SPHERE_WHITE:
3820 if (FHealth < PLAYER_HP_LIMIT) or (FArmor < PLAYER_AP_LIMIT) then
3821 begin
3822 if FHealth < PLAYER_HP_LIMIT then
3823 FHealth := PLAYER_HP_LIMIT;
3824 if FArmor < PLAYER_AP_LIMIT then
3825 FArmor := PLAYER_AP_LIMIT;
3826 Result := True;
3827 remove := True;
3828 FFireTime := 0;
3829 if gFlash = 2 then Inc(FPickup, 5);
3830 end;
3832 ITEM_WEAPON_SAW:
3833 if (not FWeapon[WEAPON_SAW]) or ((not arespawn) and (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF])) then
3834 begin
3835 FWeapon[WEAPON_SAW] := True;
3836 Result := True;
3837 if gFlash = 2 then Inc(FPickup, 5);
3838 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
3839 end;
3841 ITEM_WEAPON_SHOTGUN1:
3842 if (FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS]) or not FWeapon[WEAPON_SHOTGUN1] then
3843 begin
3844 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
3845 if a and FWeapon[WEAPON_SHOTGUN1] then Exit;
3847 IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
3848 FWeapon[WEAPON_SHOTGUN1] := True;
3849 Result := True;
3850 if gFlash = 2 then Inc(FPickup, 5);
3851 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
3852 end;
3854 ITEM_WEAPON_SHOTGUN2:
3855 if (FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS]) or not FWeapon[WEAPON_SHOTGUN2] then
3856 begin
3857 if a and FWeapon[WEAPON_SHOTGUN2] then Exit;
3859 IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
3860 FWeapon[WEAPON_SHOTGUN2] := True;
3861 Result := True;
3862 if gFlash = 2 then Inc(FPickup, 5);
3863 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
3864 end;
3866 ITEM_WEAPON_CHAINGUN:
3867 if (FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS]) or not FWeapon[WEAPON_CHAINGUN] then
3868 begin
3869 if a and FWeapon[WEAPON_CHAINGUN] then Exit;
3871 IncMax(FAmmo[A_BULLETS], 50, FMaxAmmo[A_BULLETS]);
3872 FWeapon[WEAPON_CHAINGUN] := True;
3873 Result := True;
3874 if gFlash = 2 then Inc(FPickup, 5);
3875 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
3876 end;
3878 ITEM_WEAPON_ROCKETLAUNCHER:
3879 if (FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS]) or not FWeapon[WEAPON_ROCKETLAUNCHER] then
3880 begin
3881 if a and FWeapon[WEAPON_ROCKETLAUNCHER] then Exit;
3883 IncMax(FAmmo[A_ROCKETS], 2, FMaxAmmo[A_ROCKETS]);
3884 FWeapon[WEAPON_ROCKETLAUNCHER] := True;
3885 Result := True;
3886 if gFlash = 2 then Inc(FPickup, 5);
3887 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
3888 end;
3890 ITEM_WEAPON_PLASMA:
3891 if (FAmmo[A_CELLS] < FMaxAmmo[A_CELLS]) or not FWeapon[WEAPON_PLASMA] then
3892 begin
3893 if a and FWeapon[WEAPON_PLASMA] then Exit;
3895 IncMax(FAmmo[A_CELLS], 40, FMaxAmmo[A_CELLS]);
3896 FWeapon[WEAPON_PLASMA] := True;
3897 Result := True;
3898 if gFlash = 2 then Inc(FPickup, 5);
3899 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
3900 end;
3902 ITEM_WEAPON_BFG:
3903 if (FAmmo[A_CELLS] < FMaxAmmo[A_CELLS]) or not FWeapon[WEAPON_BFG] then
3904 begin
3905 if a and FWeapon[WEAPON_BFG] then Exit;
3907 IncMax(FAmmo[A_CELLS], 40, FMaxAmmo[A_CELLS]);
3908 FWeapon[WEAPON_BFG] := True;
3909 Result := True;
3910 if gFlash = 2 then Inc(FPickup, 5);
3911 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
3912 end;
3914 ITEM_WEAPON_SUPERPULEMET:
3915 if (FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS]) or not FWeapon[WEAPON_SUPERPULEMET] then
3916 begin
3917 if a and FWeapon[WEAPON_SUPERPULEMET] then Exit;
3919 IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
3920 FWeapon[WEAPON_SUPERPULEMET] := True;
3921 Result := True;
3922 if gFlash = 2 then Inc(FPickup, 5);
3923 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
3924 end;
3926 ITEM_WEAPON_FLAMETHROWER:
3927 if (FAmmo[A_FUEL] < FMaxAmmo[A_FUEL]) or not FWeapon[WEAPON_FLAMETHROWER] then
3928 begin
3929 if a and FWeapon[WEAPON_FLAMETHROWER] then Exit;
3931 IncMax(FAmmo[A_FUEL], 100, FMaxAmmo[A_FUEL]);
3932 FWeapon[WEAPON_FLAMETHROWER] := True;
3933 Result := True;
3934 if gFlash = 2 then Inc(FPickup, 5);
3935 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
3936 end;
3938 ITEM_AMMO_BULLETS:
3939 if FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS] then
3940 begin
3941 IncMax(FAmmo[A_BULLETS], 10, FMaxAmmo[A_BULLETS]);
3942 Result := True;
3943 remove := True;
3944 if gFlash = 2 then Inc(FPickup, 5);
3945 end;
3947 ITEM_AMMO_BULLETS_BOX:
3948 if FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS] then
3949 begin
3950 IncMax(FAmmo[A_BULLETS], 50, FMaxAmmo[A_BULLETS]);
3951 Result := True;
3952 remove := True;
3953 if gFlash = 2 then Inc(FPickup, 5);
3954 end;
3956 ITEM_AMMO_SHELLS:
3957 if FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS] then
3958 begin
3959 IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
3960 Result := True;
3961 remove := True;
3962 if gFlash = 2 then Inc(FPickup, 5);
3963 end;
3965 ITEM_AMMO_SHELLS_BOX:
3966 if FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS] then
3967 begin
3968 IncMax(FAmmo[A_SHELLS], 25, FMaxAmmo[A_SHELLS]);
3969 Result := True;
3970 remove := True;
3971 if gFlash = 2 then Inc(FPickup, 5);
3972 end;
3974 ITEM_AMMO_ROCKET:
3975 if FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS] then
3976 begin
3977 IncMax(FAmmo[A_ROCKETS], 1, FMaxAmmo[A_ROCKETS]);
3978 Result := True;
3979 remove := True;
3980 if gFlash = 2 then Inc(FPickup, 5);
3981 end;
3983 ITEM_AMMO_ROCKET_BOX:
3984 if FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS] then
3985 begin
3986 IncMax(FAmmo[A_ROCKETS], 5, FMaxAmmo[A_ROCKETS]);
3987 Result := True;
3988 remove := True;
3989 if gFlash = 2 then Inc(FPickup, 5);
3990 end;
3992 ITEM_AMMO_CELL:
3993 if FAmmo[A_CELLS] < FMaxAmmo[A_CELLS] then
3994 begin
3995 IncMax(FAmmo[A_CELLS], 40, FMaxAmmo[A_CELLS]);
3996 Result := True;
3997 remove := True;
3998 if gFlash = 2 then Inc(FPickup, 5);
3999 end;
4001 ITEM_AMMO_CELL_BIG:
4002 if FAmmo[A_CELLS] < FMaxAmmo[A_CELLS] then
4003 begin
4004 IncMax(FAmmo[A_CELLS], 100, FMaxAmmo[A_CELLS]);
4005 Result := True;
4006 remove := True;
4007 if gFlash = 2 then Inc(FPickup, 5);
4008 end;
4010 ITEM_AMMO_FUELCAN:
4011 if FAmmo[A_FUEL] < FMaxAmmo[A_FUEL] then
4012 begin
4013 IncMax(FAmmo[A_FUEL], 100, FMaxAmmo[A_FUEL]);
4014 Result := True;
4015 remove := True;
4016 if gFlash = 2 then Inc(FPickup, 5);
4017 end;
4019 ITEM_AMMO_BACKPACK:
4020 if not(R_ITEM_BACKPACK in FRulez) or
4021 (FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS]) or
4022 (FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS]) or
4023 (FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS]) or
4024 (FAmmo[A_CELLS] < FMaxAmmo[A_CELLS]) or
4025 (FMaxAmmo[A_FUEL] < AmmoLimits[1, A_FUEL]) then
4026 begin
4027 FMaxAmmo[A_BULLETS] := AmmoLimits[1, A_BULLETS];
4028 FMaxAmmo[A_SHELLS] := AmmoLimits[1, A_SHELLS];
4029 FMaxAmmo[A_ROCKETS] := AmmoLimits[1, A_ROCKETS];
4030 FMaxAmmo[A_CELLS] := AmmoLimits[1, A_CELLS];
4031 FMaxAmmo[A_FUEL] := AmmoLimits[1, A_FUEL];
4033 if FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS] then
4034 IncMax(FAmmo[A_BULLETS], 10, FMaxAmmo[A_BULLETS]);
4035 if FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS] then
4036 IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
4037 if FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS] then
4038 IncMax(FAmmo[A_ROCKETS], 1, FMaxAmmo[A_ROCKETS]);
4039 if FAmmo[A_CELLS] < FMaxAmmo[A_CELLS] then
4040 IncMax(FAmmo[A_CELLS], 40, FMaxAmmo[A_CELLS]);
4042 FRulez := FRulez + [R_ITEM_BACKPACK];
4043 Result := True;
4044 remove := True;
4045 if gFlash = 2 then Inc(FPickup, 5);
4046 end;
4048 ITEM_KEY_RED:
4049 if not(R_KEY_RED in FRulez) then
4050 begin
4051 Include(FRulez, R_KEY_RED);
4052 Result := True;
4053 remove := (gGameSettings.GameMode <> GM_COOP) and (g_Player_GetCount() < 2);
4054 if gFlash = 2 then Inc(FPickup, 5);
4055 if (not remove) and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETITEM');
4056 end;
4058 ITEM_KEY_GREEN:
4059 if not(R_KEY_GREEN in FRulez) then
4060 begin
4061 Include(FRulez, R_KEY_GREEN);
4062 Result := True;
4063 remove := (gGameSettings.GameMode <> GM_COOP) and (g_Player_GetCount() < 2);
4064 if gFlash = 2 then Inc(FPickup, 5);
4065 if (not remove) and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETITEM');
4066 end;
4068 ITEM_KEY_BLUE:
4069 if not(R_KEY_BLUE in FRulez) then
4070 begin
4071 Include(FRulez, R_KEY_BLUE);
4072 Result := True;
4073 remove := (gGameSettings.GameMode <> GM_COOP) and (g_Player_GetCount() < 2);
4074 if gFlash = 2 then Inc(FPickup, 5);
4075 if (not remove) and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETITEM');
4076 end;
4078 ITEM_SUIT:
4079 if FMegaRulez[MR_SUIT] < gTime+PLAYER_SUIT_TIME then
4080 begin
4081 FMegaRulez[MR_SUIT] := gTime+PLAYER_SUIT_TIME;
4082 Result := True;
4083 remove := True;
4084 FFireTime := 0;
4085 if gFlash = 2 then Inc(FPickup, 5);
4086 end;
4088 ITEM_OXYGEN:
4089 if FAir < AIR_MAX then
4090 begin
4091 FAir := AIR_MAX;
4092 Result := True;
4093 remove := True;
4094 if gFlash = 2 then Inc(FPickup, 5);
4095 end;
4097 ITEM_MEDKIT_BLACK:
4098 begin
4099 if not (R_BERSERK in FRulez) then
4100 begin
4101 Include(FRulez, R_BERSERK);
4102 if allowBerserkSwitching then
4103 begin
4104 FCurrWeap := WEAPON_KASTET;
4105 resetWeaponQueue();
4106 FModel.SetWeapon(WEAPON_KASTET);
4107 end;
4108 if gFlash <> 0 then
4109 begin
4110 Inc(FPain, 100);
4111 if gFlash = 2 then Inc(FPickup, 5);
4112 end;
4113 FBerserk := gTime+30000;
4114 Result := True;
4115 remove := True;
4116 FFireTime := 0;
4117 end;
4118 if FHealth < PLAYER_HP_SOFT then
4119 begin
4120 FHealth := PLAYER_HP_SOFT;
4121 FBerserk := gTime+30000;
4122 Result := True;
4123 remove := True;
4124 FFireTime := 0;
4125 end;
4126 end;
4128 ITEM_INVUL:
4129 if FMegaRulez[MR_INVUL] < gTime+PLAYER_INVUL_TIME then
4130 begin
4131 FMegaRulez[MR_INVUL] := gTime+PLAYER_INVUL_TIME;
4132 Result := True;
4133 remove := True;
4134 if gFlash = 2 then Inc(FPickup, 5);
4135 end;
4137 ITEM_BOTTLE:
4138 if FHealth < PLAYER_HP_LIMIT then
4139 begin
4140 IncMax(FHealth, 4, PLAYER_HP_LIMIT);
4141 Result := True;
4142 remove := True;
4143 FFireTime := 0;
4144 if gFlash = 2 then Inc(FPickup, 5);
4145 end;
4147 ITEM_HELMET:
4148 if FArmor < PLAYER_AP_LIMIT then
4149 begin
4150 IncMax(FArmor, 5, PLAYER_AP_LIMIT);
4151 Result := True;
4152 remove := True;
4153 if gFlash = 2 then Inc(FPickup, 5);
4154 end;
4156 ITEM_JETPACK:
4157 if FJetFuel < JET_MAX then
4158 begin
4159 FJetFuel := JET_MAX;
4160 Result := True;
4161 remove := True;
4162 if gFlash = 2 then Inc(FPickup, 5);
4163 end;
4165 ITEM_INVIS:
4166 if FMegaRulez[MR_INVIS] < gTime+PLAYER_INVIS_TIME then
4167 begin
4168 FMegaRulez[MR_INVIS] := gTime+PLAYER_INVIS_TIME;
4169 Result := True;
4170 remove := True;
4171 if gFlash = 2 then Inc(FPickup, 5);
4172 end;
4173 end;
4174 end;
4176 procedure TPlayer.Touch();
4177 begin
4178 if not FAlive then
4179 Exit;
4180 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4181 if FIamBot then
4182 begin
4183 // Áðîñèòü ôëàã òîâàðèùó:
4184 if gGameSettings.GameMode = GM_CTF then
4185 DropFlag();
4186 end;
4187 end;
4189 procedure TPlayer.Push(vx, vy: Integer);
4190 begin
4191 if (not FPhysics) and FGhost then
4192 Exit;
4193 FObj.Accel.X := FObj.Accel.X + vx;
4194 FObj.Accel.Y := FObj.Accel.Y + vy;
4195 if g_Game_IsNet and g_Game_IsServer then
4196 MH_SEND_PlayerPos(True, FUID, NET_EVERYONE);
4197 end;
4199 procedure TPlayer.Reset(Force: Boolean);
4200 begin
4201 if Force then
4202 FAlive := False;
4204 FSpawned := False;
4205 FTime[T_RESPAWN] := 0;
4206 FTime[T_FLAGCAP] := 0;
4207 FGodMode := False;
4208 FNoTarget := False;
4209 FNoReload := False;
4210 FFrags := 0;
4211 FLastFrag := 0;
4212 FComboEvnt := -1;
4213 FKills := 0;
4214 FMonsterKills := 0;
4215 FDeath := 0;
4216 FSecrets := 0;
4217 if FNoRespawn then
4218 begin
4219 FSpectator := False;
4220 FGhost := False;
4221 FPhysics := True;
4222 FSpectatePlayer := -1;
4223 FNoRespawn := False;
4224 end;
4225 FLives := gGameSettings.MaxLives;
4227 SetFlag(FLAG_NONE);
4228 end;
4230 procedure TPlayer.SoftReset();
4231 begin
4232 ReleaseKeys();
4234 FDamageBuffer := 0;
4235 FIncCam := 0;
4236 FBFGFireCounter := -1;
4237 FShellTimer := -1;
4238 FPain := 0;
4239 FLastHit := 0;
4240 FLastFrag := 0;
4241 FComboEvnt := -1;
4243 SetFlag(FLAG_NONE);
4244 SetAction(A_STAND, True);
4245 end;
4247 function TPlayer.GetRespawnPoint(): Byte;
4248 var
4249 c: Byte;
4250 begin
4251 Result := 255;
4252 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4254 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4255 if gGameSettings.GameMode in [GM_COOP, GM_SINGLE] then
4256 begin
4257 if (Self = gPlayer1) or (Self = gPlayer2) then
4258 begin
4259 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
4260 if Self = gPlayer1 then
4261 c := RESPAWNPOINT_PLAYER1
4262 else
4263 c := RESPAWNPOINT_PLAYER2;
4264 if g_Map_GetPointCount(c) > 0 then
4265 begin
4266 Result := c;
4267 Exit;
4268 end;
4270 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
4271 if Self = gPlayer1 then
4272 c := RESPAWNPOINT_PLAYER2
4273 else
4274 c := RESPAWNPOINT_PLAYER1;
4275 if g_Map_GetPointCount(c) > 0 then
4276 begin
4277 Result := c;
4278 Exit;
4279 end;
4280 end else
4281 begin
4282 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
4283 if Random(2) = 0 then
4284 c := RESPAWNPOINT_PLAYER1
4285 else
4286 c := RESPAWNPOINT_PLAYER2;
4287 if g_Map_GetPointCount(c) > 0 then
4288 begin
4289 Result := c;
4290 Exit;
4291 end;
4292 end;
4294 // Òî÷êà ëþáîé èç êîìàíä
4295 if Random(2) = 0 then
4296 c := RESPAWNPOINT_RED
4297 else
4298 c := RESPAWNPOINT_BLUE;
4299 if g_Map_GetPointCount(c) > 0 then
4300 begin
4301 Result := c;
4302 Exit;
4303 end;
4305 // Òî÷êà DM
4306 c := RESPAWNPOINT_DM;
4307 if g_Map_GetPointCount(c) > 0 then
4308 begin
4309 Result := c;
4310 Exit;
4311 end;
4312 end;
4314 // Ìÿñîïîâàë
4315 if gGameSettings.GameMode = GM_DM then
4316 begin
4317 // Òî÷êà DM
4318 c := RESPAWNPOINT_DM;
4319 if g_Map_GetPointCount(c) > 0 then
4320 begin
4321 Result := c;
4322 Exit;
4323 end;
4325 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4326 if Random(2) = 0 then
4327 c := RESPAWNPOINT_PLAYER1
4328 else
4329 c := RESPAWNPOINT_PLAYER2;
4330 if g_Map_GetPointCount(c) > 0 then
4331 begin
4332 Result := c;
4333 Exit;
4334 end;
4336 // Òî÷êà ëþáîé èç êîìàíä
4337 if Random(2) = 0 then
4338 c := RESPAWNPOINT_RED
4339 else
4340 c := RESPAWNPOINT_BLUE;
4341 if g_Map_GetPointCount(c) > 0 then
4342 begin
4343 Result := c;
4344 Exit;
4345 end;
4346 end;
4348 // Êîìàíäíûå
4349 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
4350 begin
4351 // Òî÷êà ñâîåé êîìàíäû
4352 c := RESPAWNPOINT_DM;
4353 if FTeam = TEAM_RED then
4354 c := RESPAWNPOINT_RED;
4355 if FTeam = TEAM_BLUE then
4356 c := RESPAWNPOINT_BLUE;
4357 if g_Map_GetPointCount(c) > 0 then
4358 begin
4359 Result := c;
4360 Exit;
4361 end;
4363 // Òî÷êà DM
4364 c := RESPAWNPOINT_DM;
4365 if g_Map_GetPointCount(c) > 0 then
4366 begin
4367 Result := c;
4368 Exit;
4369 end;
4371 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4372 if Random(2) = 0 then
4373 c := RESPAWNPOINT_PLAYER1
4374 else
4375 c := RESPAWNPOINT_PLAYER2;
4376 if g_Map_GetPointCount(c) > 0 then
4377 begin
4378 Result := c;
4379 Exit;
4380 end;
4382 // Òî÷êà äðóãîé êîìàíäû
4383 c := RESPAWNPOINT_DM;
4384 if FTeam = TEAM_RED then
4385 c := RESPAWNPOINT_BLUE;
4386 if FTeam = TEAM_BLUE then
4387 c := RESPAWNPOINT_RED;
4388 if g_Map_GetPointCount(c) > 0 then
4389 begin
4390 Result := c;
4391 Exit;
4392 end;
4393 end;
4394 end;
4396 procedure TPlayer.Respawn(Silent: Boolean; Force: Boolean = False);
4397 var
4398 RespawnPoint: TRespawnPoint;
4399 a, b, c: Byte;
4400 Anim: TAnimation;
4401 ID: DWORD;
4402 begin
4403 FIncCam := 0;
4404 FBFGFireCounter := -1;
4405 FShellTimer := -1;
4406 FPain := 0;
4407 FLastHit := 0;
4409 if not g_Game_IsServer then
4410 Exit;
4411 if FDummy then
4412 Exit;
4413 FWantsInGame := True;
4414 FJustTeleported := True;
4415 if Force then
4416 begin
4417 FTime[T_RESPAWN] := 0;
4418 FAlive := False;
4419 end;
4420 FNetTime := 0;
4421 // if server changes MaxLives we gotta be ready
4422 if gGameSettings.MaxLives = 0 then FNoRespawn := False;
4424 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4425 if FTime[T_RESPAWN] > gTime then
4426 Exit;
4428 // Ïðîñðàë âñå æèçíè:
4429 if FNoRespawn then
4430 begin
4431 if not FSpectator then Spectate(True);
4432 FWantsInGame := True;
4433 Exit;
4434 end;
4436 if (gGameSettings.GameType <> GT_SINGLE) and (gGameSettings.GameMode <> GM_COOP) then
4437 begin // "Ñâîÿ èãðà"
4438 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4439 FRulez := FRulez-[R_BERSERK];
4440 end
4441 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4442 begin
4443 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4444 FRulez := FRulez-[R_KEY_RED, R_KEY_GREEN, R_KEY_BLUE, R_BERSERK];
4445 end;
4447 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4448 c := GetRespawnPoint();
4450 ReleaseKeys();
4451 SetFlag(FLAG_NONE);
4453 // Âîñêðåøåíèå áåç îðóæèÿ:
4454 if not FAlive then
4455 begin
4456 FHealth := PLAYER_HP_SOFT;
4457 FArmor := 0;
4458 FAlive := True;
4459 FAir := AIR_DEF;
4460 FJetFuel := 0;
4462 for a := WP_FIRST to WP_LAST do
4463 begin
4464 FWeapon[a] := False;
4465 FReloading[a] := 0;
4466 end;
4468 FWeapon[WEAPON_PISTOL] := True;
4469 FWeapon[WEAPON_KASTET] := True;
4470 FCurrWeap := WEAPON_PISTOL;
4471 resetWeaponQueue();
4473 FModel.SetWeapon(FCurrWeap);
4475 for b := A_BULLETS to A_HIGH do
4476 FAmmo[b] := 0;
4478 FAmmo[A_BULLETS] := 50;
4480 FMaxAmmo[A_BULLETS] := AmmoLimits[0, A_BULLETS];
4481 FMaxAmmo[A_SHELLS] := AmmoLimits[0, A_SHELLS];
4482 FMaxAmmo[A_ROCKETS] := AmmoLimits[0, A_SHELLS];
4483 FMaxAmmo[A_CELLS] := AmmoLimits[0, A_CELLS];
4484 FMaxAmmo[A_FUEL] := AmmoLimits[0, A_FUEL];
4486 if gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF] then
4487 FRulez := [R_KEY_RED, R_KEY_GREEN, R_KEY_BLUE]
4488 else
4489 FRulez := [];
4490 end;
4492 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4493 if not g_Map_GetPoint(c, RespawnPoint) then
4494 begin
4495 g_FatalError(_lc[I_GAME_ERROR_GET_SPAWN]);
4496 Exit;
4497 end;
4499 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4500 FObj.X := RespawnPoint.X-PLAYER_RECT.X;
4501 FObj.Y := RespawnPoint.Y-PLAYER_RECT.Y;
4502 FObj.Vel.X := 0;
4503 FObj.Vel.Y := 0;
4504 FObj.Accel.X := 0;
4505 FObj.Accel.Y := 0;
4507 FDirection := RespawnPoint.Direction;
4508 if FDirection = TDirection.D_LEFT then
4509 FAngle := 180
4510 else
4511 FAngle := 0;
4513 SetAction(A_STAND, True);
4514 FModel.Direction := FDirection;
4516 for a := Low(FTime) to High(FTime) do
4517 FTime[a] := 0;
4519 for a := Low(FMegaRulez) to High(FMegaRulez) do
4520 FMegaRulez[a] := 0;
4522 FDamageBuffer := 0;
4523 FJetpack := False;
4524 FCanJetpack := False;
4525 FFireTime := 0;
4526 FFirePainTime := 0;
4527 FFireAttacker := 0;
4529 // Àíèìàöèÿ âîçðîæäåíèÿ:
4530 if (not gLoadGameMode) and (not Silent) then
4531 if g_Frames_Get(ID, 'FRAMES_TELEPORT') then
4532 begin
4533 Anim := TAnimation.Create(ID, False, 3);
4534 g_GFX_OnceAnim(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
4535 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32, Anim);
4536 Anim.Free();
4537 end;
4539 FSpectator := False;
4540 FGhost := False;
4541 FPhysics := True;
4542 FSpectatePlayer := -1;
4543 FSpawned := True;
4545 if (gPlayer1 = nil) and (gLMSPID1 = FUID) then
4546 gPlayer1 := self;
4547 if (gPlayer2 = nil) and (gLMSPID2 = FUID) then
4548 gPlayer2 := self;
4550 if g_Game_IsNet then
4551 begin
4552 MH_SEND_PlayerPos(True, FUID, NET_EVERYONE);
4553 MH_SEND_PlayerStats(FUID, NET_EVERYONE);
4554 if not Silent then
4555 MH_SEND_Effect(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
4556 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32,
4557 0, NET_GFX_TELE);
4558 end;
4559 end;
4561 procedure TPlayer.Spectate(NoMove: Boolean = False);
4562 begin
4563 if FAlive then
4564 Kill(K_EXTRAHARDKILL, FUID, HIT_SOME)
4565 else if (not NoMove) then
4566 begin
4567 GameX := gMapInfo.Width div 2;
4568 GameY := gMapInfo.Height div 2;
4569 end;
4570 FXTo := GameX;
4571 FYTo := GameY;
4573 FAlive := False;
4574 FSpectator := True;
4575 FGhost := True;
4576 FPhysics := False;
4577 FWantsInGame := False;
4578 FSpawned := False;
4580 if FNoRespawn then
4581 begin
4582 if Self = gPlayer1 then
4583 begin
4584 gLMSPID1 := FUID;
4585 gPlayer1 := nil;
4586 end;
4587 if Self = gPlayer2 then
4588 begin
4589 gLMSPID2 := FUID;
4590 gPlayer2 := nil;
4591 end;
4592 end;
4594 if g_Game_IsNet then
4595 MH_SEND_PlayerStats(FUID);
4596 end;
4598 procedure TPlayer.SwitchNoClip;
4599 begin
4600 if not FAlive then
4601 Exit;
4602 FGhost := not FGhost;
4603 FPhysics := not FGhost;
4604 if FGhost then
4605 begin
4606 FXTo := FObj.X;
4607 FYTo := FObj.Y;
4608 end else
4609 begin
4610 FObj.Accel.X := 0;
4611 FObj.Accel.Y := 0;
4612 end;
4613 end;
4615 procedure TPlayer.Run(Direction: TDirection);
4616 var
4617 a, b: Integer;
4618 begin
4619 if MAX_RUNVEL > 8 then
4620 FlySmoke();
4622 // Áåæèì:
4623 if Direction = TDirection.D_LEFT then
4624 begin
4625 if FObj.Vel.X > -MAX_RUNVEL then
4626 FObj.Vel.X := FObj.Vel.X - (MAX_RUNVEL shr 3);
4627 end
4628 else
4629 if FObj.Vel.X < MAX_RUNVEL then
4630 FObj.Vel.X := FObj.Vel.X + (MAX_RUNVEL shr 3);
4632 // Âîçìîæíî, ïèíàåì êóñêè:
4633 if (FObj.Vel.X <> 0) and (gGibs <> nil) then
4634 begin
4635 b := Abs(FObj.Vel.X);
4636 if b > 1 then b := b * (Random(8 div b) + 1);
4637 for a := 0 to High(gGibs) do
4638 begin
4639 if gGibs[a].alive and
4640 g_Obj_Collide(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y+FObj.Rect.Height-4,
4641 FObj.Rect.Width, 8, @gGibs[a].Obj) and (Random(3) = 0) then
4642 begin
4643 // Ïèíàåì êóñêè
4644 if FObj.Vel.X < 0 then
4645 begin
4646 g_Obj_PushA(@gGibs[a].Obj, b, Random(61)+120) // íàëåâî
4647 end
4648 else
4649 begin
4650 g_Obj_PushA(@gGibs[a].Obj, b, Random(61)); // íàïðàâî
4651 end;
4652 gGibs[a].positionChanged(); // this updates spatial accelerators
4653 end;
4654 end;
4655 end;
4657 SetAction(A_WALK);
4658 end;
4660 procedure TPlayer.SeeDown();
4661 begin
4662 SetAction(A_SEEDOWN);
4664 if FDirection = TDirection.D_LEFT then FAngle := ANGLE_LEFTDOWN else FAngle := ANGLE_RIGHTDOWN;
4666 if FIncCam > -120 then DecMin(FIncCam, 5, -120);
4667 end;
4669 procedure TPlayer.SeeUp();
4670 begin
4671 SetAction(A_SEEUP);
4673 if FDirection = TDirection.D_LEFT then FAngle := ANGLE_LEFTUP else FAngle := ANGLE_RIGHTUP;
4675 if FIncCam < 120 then IncMax(FIncCam, 5, 120);
4676 end;
4678 procedure TPlayer.SetAction(Action: Byte; Force: Boolean = False);
4679 var
4680 Prior: Byte;
4681 begin
4682 case Action of
4683 A_WALK: Prior := 3;
4684 A_DIE1: Prior := 5;
4685 A_DIE2: Prior := 5;
4686 A_ATTACK: Prior := 2;
4687 A_SEEUP: Prior := 1;
4688 A_SEEDOWN: Prior := 1;
4689 A_ATTACKUP: Prior := 2;
4690 A_ATTACKDOWN: Prior := 2;
4691 A_PAIN: Prior := 4;
4692 else Prior := 0;
4693 end;
4695 if (Prior > FActionPrior) or Force then
4696 if not ((Prior = 2) and (FCurrWeap = WEAPON_SAW)) then
4697 begin
4698 FActionPrior := Prior;
4699 FActionAnim := Action;
4700 FActionForce := Force;
4701 FActionChanged := True;
4702 end;
4704 if Action in [A_ATTACK, A_ATTACKUP, A_ATTACKDOWN] then FModel.SetFire(True);
4705 end;
4707 function TPlayer.StayOnStep(XInc, YInc: Integer): Boolean;
4708 begin
4709 Result := not g_Map_CollidePanel(FObj.X+PLAYER_RECT.X, FObj.Y+YInc+PLAYER_RECT.Y+PLAYER_RECT.Height-1,
4710 PLAYER_RECT.Width, 1, PANEL_STEP, False)
4711 and g_Map_CollidePanel(FObj.X+PLAYER_RECT.X, FObj.Y+YInc+PLAYER_RECT.Y+PLAYER_RECT.Height,
4712 PLAYER_RECT.Width, 1, PANEL_STEP, False);
4713 end;
4715 function TPlayer.TeleportTo(X, Y: Integer; silent: Boolean; dir: Byte): Boolean;
4716 var
4717 Anim: TAnimation;
4718 ID: DWORD;
4719 begin
4720 Result := False;
4722 if g_CollideLevel(X, Y, PLAYER_RECT.Width, PLAYER_RECT.Height) then
4723 begin
4724 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj.X, FObj.Y);
4725 if g_Game_IsServer and g_Game_IsNet then
4726 MH_SEND_Sound(FObj.X, FObj.Y, 'SOUND_GAME_NOTELEPORT');
4727 Exit;
4728 end;
4730 FJustTeleported := True;
4732 Anim := nil;
4733 if not silent then
4734 begin
4735 if g_Frames_Get(ID, 'FRAMES_TELEPORT') then
4736 begin
4737 Anim := TAnimation.Create(ID, False, 3);
4738 end;
4740 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj.X, FObj.Y);
4741 g_GFX_OnceAnim(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
4742 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32, Anim);
4743 if g_Game_IsServer and g_Game_IsNet then
4744 MH_SEND_Effect(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
4745 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32, 1,
4746 NET_GFX_TELE);
4747 end;
4749 FObj.X := X-PLAYER_RECT.X;
4750 FObj.Y := Y-PLAYER_RECT.Y;
4751 if FAlive and FGhost then
4752 begin
4753 FXTo := FObj.X;
4754 FYTo := FObj.Y;
4755 end;
4757 if not g_Game_IsNet then
4758 begin
4759 if dir = 1 then
4760 begin
4761 SetDirection(TDirection.D_LEFT);
4762 FAngle := 180;
4763 end
4764 else
4765 if dir = 2 then
4766 begin
4767 SetDirection(TDirection.D_RIGHT);
4768 FAngle := 0;
4769 end
4770 else
4771 if dir = 3 then
4772 begin // îáðàòíîå
4773 if FDirection = TDirection.D_RIGHT then
4774 begin
4775 SetDirection(TDirection.D_LEFT);
4776 FAngle := 180;
4777 end
4778 else
4779 begin
4780 SetDirection(TDirection.D_RIGHT);
4781 FAngle := 0;
4782 end;
4783 end;
4784 end;
4786 if not silent and (Anim <> nil) then
4787 begin
4788 g_GFX_OnceAnim(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
4789 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32, Anim);
4790 Anim.Free();
4792 if g_Game_IsServer and g_Game_IsNet then
4793 MH_SEND_Effect(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
4794 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32, 0,
4795 NET_GFX_TELE);
4796 end;
4798 Result := True;
4799 end;
4801 function nonz(a: Single): Single;
4802 begin
4803 if a <> 0 then
4804 Result := a
4805 else
4806 Result := 1;
4807 end;
4809 function TPlayer.followCorpse(): Boolean;
4810 var
4811 i: Integer;
4812 begin
4813 Result := False;
4814 if FAlive or FSpectator then
4815 Exit;
4816 if (gCorpses = nil) or (Length(gCorpses) = 0) then
4817 Exit;
4818 for i := 0 to High(gCorpses) do
4819 if gCorpses[i] <> nil then
4820 if gCorpses[i].FPlayerUID = FUID then
4821 begin
4822 Result := True;
4823 FObj.X := gCorpses[i].FObj.X;
4824 FObj.Y := gCorpses[i].FObj.Y;
4825 FObj.Vel.X := gCorpses[i].FObj.Vel.X;
4826 FObj.Vel.Y := gCorpses[i].FObj.Vel.Y;
4827 FObj.Accel.X := gCorpses[i].FObj.Accel.X;
4828 FObj.Accel.Y := gCorpses[i].FObj.Accel.Y;
4829 break;
4830 end;
4831 end;
4833 procedure TPlayer.Update();
4834 var
4835 b: Byte;
4836 i, ii, wx, wy, xd, yd, k: Integer;
4837 blockmon, headwater, dospawn: Boolean;
4838 NetServer: Boolean;
4839 AnyServer: Boolean;
4840 SetSpect: Boolean;
4841 begin
4842 NetServer := g_Game_IsNet and g_Game_IsServer;
4843 AnyServer := g_Game_IsServer;
4845 if g_Game_IsClient and (NetInterpLevel > 0) then
4846 DoLerp(NetInterpLevel + 1)
4847 else
4848 if FGhost then
4849 DoLerp(4);
4851 if NetServer then
4852 if FClientID >= 0 then
4853 begin
4854 FPing := NetClients[FClientID].Peer^.lastRoundTripTime;
4855 if NetClients[FClientID].Peer^.packetsSent > 0 then
4856 FLoss := Round(100*NetClients[FClientID].Peer^.packetsLost/NetClients[FClientID].Peer^.packetsSent)
4857 else
4858 FLoss := 0;
4859 end else
4860 begin
4861 FPing := 0;
4862 FLoss := 0;
4863 end;
4865 if FAlive and (FPunchAnim <> nil) then
4866 FPunchAnim.Update();
4868 if FAlive and (gFly or FJetpack) then
4869 FlySmoke();
4871 if FDirection = TDirection.D_LEFT then
4872 FAngle := 180
4873 else
4874 FAngle := 0;
4876 if FAlive and (not FGhost) then
4877 begin
4878 if FKeys[KEY_UP].Pressed then
4879 SeeUp();
4880 if FKeys[KEY_DOWN].Pressed then
4881 SeeDown();
4882 end;
4884 if (not (FKeys[KEY_UP].Pressed or FKeys[KEY_DOWN].Pressed)) and
4885 (FIncCam <> 0) then
4886 begin
4887 i := g_basic.Sign(FIncCam);
4888 FIncCam := Abs(FIncCam);
4889 DecMin(FIncCam, 5, 0);
4890 FIncCam := FIncCam*i;
4891 end;
4893 // no need to do that each second frame, weapon queue will take care of it
4894 if FAlive and FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
4895 if FAlive and FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
4897 if gTime mod (GAME_TICK*2) <> 0 then
4898 begin
4899 if (FObj.Vel.X = 0) and FAlive then
4900 begin
4901 if FKeys[KEY_LEFT].Pressed then
4902 Run(TDirection.D_LEFT);
4903 if FKeys[KEY_RIGHT].Pressed then
4904 Run(TDirection.D_RIGHT);
4905 end;
4907 if FPhysics then
4908 begin
4909 if not followCorpse() then
4910 g_Obj_Move(@FObj, True, True, True);
4911 positionChanged(); // this updates spatial accelerators
4912 end;
4914 Exit;
4915 end;
4917 FActionChanged := False;
4919 if FAlive then
4920 begin
4921 // Let alive player do some actions
4922 if FKeys[KEY_LEFT].Pressed then Run(TDirection.D_LEFT);
4923 if FKeys[KEY_RIGHT].Pressed then Run(TDirection.D_RIGHT);
4924 //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
4925 //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
4926 if FKeys[KEY_FIRE].Pressed and AnyServer then Fire();
4927 if FKeys[KEY_OPEN].Pressed and AnyServer then Use();
4928 if FKeys[KEY_JUMP].Pressed then Jump()
4929 else
4930 begin
4931 if AnyServer and FJetpack then
4932 begin
4933 FJetpack := False;
4934 JetpackOff;
4935 if NetServer then MH_SEND_PlayerStats(FUID);
4936 end;
4937 FCanJetpack := True;
4938 end;
4939 end
4940 else // Dead
4941 begin
4942 dospawn := False;
4943 if not FGhost then
4944 for k := Low(FKeys) to KEY_CHAT-1 do
4945 begin
4946 if FKeys[k].Pressed then
4947 begin
4948 dospawn := True;
4949 break;
4950 end;
4951 end;
4952 if dospawn then
4953 begin
4954 if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
4955 Respawn(False)
4956 else // Single
4957 if (FTime[T_RESPAWN] <= gTime) and
4958 gGameOn and (not FAlive) then
4959 begin
4960 if (g_Player_GetCount() > 1) then
4961 Respawn(False)
4962 else
4963 begin
4964 gExit := EXIT_RESTART;
4965 Exit;
4966 end;
4967 end;
4968 end;
4969 // Dead spectator actions
4970 if FGhost then
4971 begin
4972 if FKeys[KEY_OPEN].Pressed and AnyServer then Fire();
4973 if FKeys[KEY_FIRE].Pressed and AnyServer then
4974 begin
4975 if FSpectator then
4976 begin
4977 if (FSpectatePlayer >= High(gPlayers)) then
4978 FSpectatePlayer := -1
4979 else
4980 begin
4981 SetSpect := False;
4982 for I := FSpectatePlayer + 1 to High(gPlayers) do
4983 if gPlayers[I] <> nil then
4984 if gPlayers[I].alive then
4985 if gPlayers[I].UID <> FUID then
4986 begin
4987 FSpectatePlayer := I;
4988 SetSpect := True;
4989 break;
4990 end;
4992 if not SetSpect then FSpectatePlayer := -1;
4993 end;
4995 ReleaseKeys;
4996 end;
4997 end;
4998 end;
4999 end;
5000 // No clipping
5001 if FGhost then
5002 begin
5003 if FKeys[KEY_UP].Pressed or FKeys[KEY_JUMP].Pressed then
5004 begin
5005 FYTo := FObj.Y - 32;
5006 FSpectatePlayer := -1;
5007 end;
5008 if FKeys[KEY_DOWN].Pressed then
5009 begin
5010 FYTo := FObj.Y + 32;
5011 FSpectatePlayer := -1;
5012 end;
5013 if FKeys[KEY_LEFT].Pressed then
5014 begin
5015 FXTo := FObj.X - 32;
5016 FSpectatePlayer := -1;
5017 end;
5018 if FKeys[KEY_RIGHT].Pressed then
5019 begin
5020 FXTo := FObj.X + 32;
5021 FSpectatePlayer := -1;
5022 end;
5024 if (FXTo < -64) then
5025 FXTo := -64
5026 else if (FXTo > gMapInfo.Width + 32) then
5027 FXTo := gMapInfo.Width + 32;
5028 if (FYTo < -72) then
5029 FYTo := -72
5030 else if (FYTo > gMapInfo.Height + 32) then
5031 FYTo := gMapInfo.Height + 32;
5032 end;
5034 if FPhysics then
5035 begin
5036 if not followCorpse() then
5037 g_Obj_Move(@FObj, True, True, True);
5038 positionChanged(); // this updates spatial accelerators
5039 end
5040 else
5041 begin
5042 FObj.Vel.X := 0;
5043 FObj.Vel.Y := 0;
5044 if FSpectator then
5045 if (FSpectatePlayer <= High(gPlayers)) and (FSpectatePlayer >= 0) then
5046 if gPlayers[FSpectatePlayer] <> nil then
5047 if gPlayers[FSpectatePlayer].alive then
5048 begin
5049 FXTo := gPlayers[FSpectatePlayer].GameX;
5050 FYTo := gPlayers[FSpectatePlayer].GameY;
5051 end;
5052 end;
5054 blockmon := g_Map_CollidePanel(FObj.X+PLAYER_HEADRECT.X, FObj.Y+PLAYER_HEADRECT.Y,
5055 PLAYER_HEADRECT.Width, PLAYER_HEADRECT.Height,
5056 PANEL_BLOCKMON, True);
5057 headwater := HeadInLiquid(0, 0);
5059 // Ñîïðîòèâëåíèå âîçäóõà:
5060 if (not FAlive) or not (FKeys[KEY_LEFT].Pressed or FKeys[KEY_RIGHT].Pressed) then
5061 if FObj.Vel.X <> 0 then
5062 FObj.Vel.X := z_dec(FObj.Vel.X, 1);
5064 if (FLastHit = HIT_TRAP) and (FPain > 90) then FPain := 90;
5065 DecMin(FPain, 5, 0);
5066 DecMin(FPickup, 1, 0);
5068 if FAlive and (FObj.Y > Integer(gMapInfo.Height)+128) and AnyServer then
5069 begin
5070 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
5071 FMegaRulez[MR_SUIT] := 0;
5072 FMegaRulez[MR_INVUL] := 0;
5073 FMegaRulez[MR_INVIS] := 0;
5074 Kill(K_FALLKILL, 0, HIT_FALL);
5075 end;
5077 i := 9;
5079 if FAlive then
5080 begin
5081 if FCurrWeap = WEAPON_SAW then
5082 if not (FSawSound.IsPlaying() or FSawSoundHit.IsPlaying() or
5083 FSawSoundSelect.IsPlaying()) then
5084 FSawSoundIdle.PlayAt(FObj.X, FObj.Y);
5086 if FJetpack then
5087 if (not FJetSoundFly.IsPlaying()) and (not FJetSoundOn.IsPlaying()) and
5088 (not FJetSoundOff.IsPlaying()) then
5089 begin
5090 FJetSoundFly.SetPosition(0);
5091 FJetSoundFly.PlayAt(FObj.X, FObj.Y);
5092 end;
5094 for b := WP_FIRST to WP_LAST do
5095 if FReloading[b] > 0 then
5096 if FNoReload then
5097 FReloading[b] := 0
5098 else
5099 Dec(FReloading[b]);
5101 if FShellTimer > -1 then
5102 if FShellTimer = 0 then
5103 begin
5104 if FShellType = SHELL_SHELL then
5105 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
5106 GameVelX, GameVelY-2, SHELL_SHELL)
5107 else if FShellType = SHELL_DBLSHELL then
5108 begin
5109 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
5110 GameVelX+1, GameVelY-2, SHELL_SHELL);
5111 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
5112 GameVelX-1, GameVelY-2, SHELL_SHELL);
5113 end;
5114 FShellTimer := -1;
5115 end else Dec(FShellTimer);
5117 if (FBFGFireCounter > -1) then
5118 if FBFGFireCounter = 0 then
5119 begin
5120 if AnyServer then
5121 begin
5122 wx := FObj.X+WEAPONPOINT[FDirection].X;
5123 wy := FObj.Y+WEAPONPOINT[FDirection].Y;
5124 xd := wx+IfThen(FDirection = TDirection.D_LEFT, -30, 30);
5125 yd := wy+firediry();
5126 g_Weapon_bfgshot(wx, wy, xd, yd, FUID);
5127 if NetServer then MH_SEND_PlayerFire(FUID, WEAPON_BFG, wx, wy, xd, yd);
5128 if (FAngle = 0) or (FAngle = 180) then SetAction(A_ATTACK)
5129 else if (FAngle = ANGLE_LEFTDOWN) or (FAngle = ANGLE_RIGHTDOWN) then SetAction(A_ATTACKDOWN)
5130 else if (FAngle = ANGLE_LEFTUP) or (FAngle = ANGLE_RIGHTUP) then SetAction(A_ATTACKUP);
5131 end;
5133 FReloading[WEAPON_BFG] := WEAPON_RELOAD[WEAPON_BFG];
5134 FBFGFireCounter := -1;
5135 end else
5136 if FNoReload then
5137 FBFGFireCounter := 0
5138 else
5139 Dec(FBFGFireCounter);
5141 if (FMegaRulez[MR_SUIT] < gTime) and AnyServer then
5142 begin
5143 b := g_GetAcidHit(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width, PLAYER_RECT.Height);
5145 if (b > 0) and (gTime mod (15*GAME_TICK) = 0) then Damage(b, 0, 0, 0, HIT_ACID);
5146 end;
5148 if (headwater or blockmon) then
5149 begin
5150 Dec(FAir);
5152 if FAir < -9 then
5153 begin
5154 if AnyServer then Damage(10, 0, 0, 0, HIT_WATER);
5155 FAir := 0;
5156 end
5157 else if (FAir mod 31 = 0) and not blockmon then
5158 begin
5159 g_GFX_Bubbles(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2), FObj.Y+PLAYER_RECT.Y-4, 5+Random(6), 8, 4);
5160 if Random(2) = 0 then
5161 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj.X, FObj.Y)
5162 else
5163 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj.X, FObj.Y);
5164 end;
5165 end else if FAir < AIR_DEF then
5166 FAir := AIR_DEF;
5168 if FFireTime > 0 then
5169 begin
5170 if BodyInLiquid(0, 0) then
5171 begin
5172 FFireTime := 0;
5173 FFirePainTime := 0;
5174 end
5175 else if FMegaRulez[MR_SUIT] >= gTime then
5176 begin
5177 if FMegaRulez[MR_SUIT] = gTime then
5178 FFireTime := 1;
5179 FFirePainTime := 0;
5180 end
5181 else
5182 begin
5183 OnFireFlame(1);
5184 if FFirePainTime <= 0 then
5185 begin
5186 if g_Game_IsServer then
5187 Damage(5, FFireAttacker, 0, 0, HIT_FLAME);
5188 FFirePainTime := 18;
5189 end;
5190 FFirePainTime := FFirePainTime - 1;
5191 FFireTime := FFireTime - 1;
5192 if (FFireTime = 0) and g_Game_IsNet and g_Game_IsServer then
5193 MH_SEND_PlayerStats(FUID);
5194 end;
5195 end;
5197 if FDamageBuffer > 0 then
5198 begin
5199 if FDamageBuffer >= 9 then
5200 begin
5201 SetAction(A_PAIN);
5203 if FDamageBuffer < 30 then i := 9
5204 else if FDamageBuffer < 100 then i := 18
5205 else i := 27;
5206 end;
5208 ii := Round(FDamageBuffer*FHealth / nonz(FArmor*(3/4)+FHealth));
5209 FArmor := FArmor-(FDamageBuffer-ii);
5210 FHealth := FHealth-ii;
5211 if FArmor < 0 then
5212 begin
5213 FHealth := FHealth+FArmor;
5214 FArmor := 0;
5215 end;
5217 if AnyServer then
5218 if FHealth <= 0 then
5219 if FHealth > -30 then Kill(K_SIMPLEKILL, FLastSpawnerUID, FLastHit)
5220 else if FHealth > -50 then Kill(K_HARDKILL, FLastSpawnerUID, FLastHit)
5221 else Kill(K_EXTRAHARDKILL, FLastSpawnerUID, FLastHit);
5223 if FAlive then
5224 begin
5225 if FDamageBuffer <= 20 then FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y)
5226 else if FDamageBuffer <= 55 then FModel.PlaySound(MODELSOUND_PAIN, 2, FObj.X, FObj.Y)
5227 else if FDamageBuffer <= 120 then FModel.PlaySound(MODELSOUND_PAIN, 3, FObj.X, FObj.Y)
5228 else FModel.PlaySound(MODELSOUND_PAIN, 4, FObj.X, FObj.Y);
5229 end;
5231 FDamageBuffer := 0;
5232 end;
5234 {CollideItem();}
5235 end; // if FAlive then ...
5237 if (FActionAnim = A_PAIN) and (FModel.Animation <> A_PAIN) then
5238 begin
5239 FModel.ChangeAnimation(FActionAnim, FActionForce);
5240 FModel.GetCurrentAnimation.MinLength := i;
5241 FModel.GetCurrentAnimationMask.MinLength := i;
5242 end else FModel.ChangeAnimation(FActionAnim, FActionForce and (FModel.Animation <> A_STAND));
5244 if (FModel.GetCurrentAnimation.Played or ((not FActionChanged) and (FModel.Animation = A_WALK)))
5245 then SetAction(A_STAND, True);
5247 if not ((FModel.Animation = A_WALK) and (Abs(FObj.Vel.X) < 4) and not FModel.Fire) then FModel.Update;
5249 for b := Low(FKeys) to High(FKeys) do
5250 if FKeys[b].Time = 0 then FKeys[b].Pressed := False else Dec(FKeys[b].Time);
5251 end;
5254 procedure TPlayer.getMapBox (out x, y, w, h: Integer); inline;
5255 begin
5256 x := FObj.X+PLAYER_RECT.X;
5257 y := FObj.Y+PLAYER_RECT.Y;
5258 w := PLAYER_RECT.Width;
5259 h := PLAYER_RECT.Height;
5260 end;
5263 procedure TPlayer.moveBy (dx, dy: Integer); inline;
5264 begin
5265 if (dx <> 0) or (dy <> 0) then
5266 begin
5267 FObj.X += dx;
5268 FObj.Y += dy;
5269 positionChanged();
5270 end;
5271 end;
5274 function TPlayer.Collide(X, Y: Integer; Width, Height: Word): Boolean;
5275 begin
5276 Result := g_Collide(FObj.X+PLAYER_RECT.X,
5277 FObj.Y+PLAYER_RECT.Y,
5278 PLAYER_RECT.Width,
5279 PLAYER_RECT.Height,
5280 X, Y,
5281 Width, Height);
5282 end;
5284 function TPlayer.Collide(Panel: TPanel): Boolean;
5285 begin
5286 Result := g_Collide(FObj.X+PLAYER_RECT.X,
5287 FObj.Y+PLAYER_RECT.Y,
5288 PLAYER_RECT.Width,
5289 PLAYER_RECT.Height,
5290 Panel.X, Panel.Y,
5291 Panel.Width, Panel.Height);
5292 end;
5294 function TPlayer.Collide(X, Y: Integer): Boolean;
5295 begin
5296 X := X-FObj.X-PLAYER_RECT.X;
5297 Y := Y-FObj.Y-PLAYER_RECT.Y;
5298 Result := (x >= 0) and (x <= PLAYER_RECT.Width) and
5299 (y >= 0) and (y <= PLAYER_RECT.Height);
5300 end;
5302 function g_Player_ValidName(Name: string): Boolean;
5303 var
5304 a: Integer;
5305 begin
5306 Result := True;
5308 if gPlayers = nil then Exit;
5310 for a := 0 to High(gPlayers) do
5311 if gPlayers[a] <> nil then
5312 if LowerCase(Name) = LowerCase(gPlayers[a].FName) then
5313 begin
5314 Result := False;
5315 Exit;
5316 end;
5317 end;
5319 procedure TPlayer.SetDirection(Direction: TDirection);
5320 var
5321 d: TDirection;
5322 begin
5323 d := FModel.Direction;
5325 FModel.Direction := Direction;
5326 if d <> Direction then FModel.ChangeAnimation(FModel.Animation, True);
5328 FDirection := Direction;
5329 end;
5331 function TPlayer.GetKeys(): Byte;
5332 begin
5333 Result := 0;
5335 if R_KEY_RED in FRulez then Result := KEY_RED;
5336 if R_KEY_GREEN in FRulez then Result := Result or KEY_GREEN;
5337 if R_KEY_BLUE in FRulez then Result := Result or KEY_BLUE;
5339 if FTeam = TEAM_RED then Result := Result or KEY_REDTEAM;
5340 if FTeam = TEAM_BLUE then Result := Result or KEY_BLUETEAM;
5341 end;
5343 procedure TPlayer.Use();
5344 var
5345 a: Integer;
5346 begin
5347 if FTime[T_USE] > gTime then Exit;
5349 g_Triggers_PressR(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
5350 PLAYER_RECT.Height, FUID, ACTIVATE_PLAYERPRESS);
5352 for a := 0 to High(gPlayers) do
5353 if (gPlayers[a] <> nil) and (gPlayers[a] <> Self) and
5354 gPlayers[a].alive and SameTeam(FUID, gPlayers[a].FUID) and
5355 g_Obj_Collide(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y,
5356 FObj.Rect.Width, FObj.Rect.Height, @gPlayers[a].FObj) then
5357 begin
5358 gPlayers[a].Touch();
5359 if g_Game_IsNet and g_Game_IsServer then
5360 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH, gPlayers[a].FUID);
5361 end;
5363 FTime[T_USE] := gTime+120;
5364 end;
5366 procedure TPlayer.NetFire(Wpn: Byte; X, Y, AX, AY: Integer; WID: Integer = -1);
5367 var
5368 locObj: TObj;
5369 F: Boolean;
5370 WX, WY, XD, YD: Integer;
5371 begin
5372 F := False;
5373 WX := X;
5374 WY := Y;
5375 XD := AX;
5376 YD := AY;
5378 case FCurrWeap of
5379 WEAPON_KASTET:
5380 begin
5381 DoPunch();
5382 if R_BERSERK in FRulez then
5383 begin
5384 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5385 locobj.X := FObj.X+FObj.Rect.X;
5386 locobj.Y := FObj.Y+FObj.Rect.Y;
5387 locobj.rect.X := 0;
5388 locobj.rect.Y := 0;
5389 locobj.rect.Width := 39;
5390 locobj.rect.Height := 52;
5391 locobj.Vel.X := (xd-wx) div 2;
5392 locobj.Vel.Y := (yd-wy) div 2;
5393 locobj.Accel.X := xd-wx;
5394 locobj.Accel.y := yd-wy;
5396 if g_Weapon_Hit(@locobj, 50, FUID, HIT_SOME) <> 0 then
5397 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj.X, FObj.Y)
5398 else
5399 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj.X, FObj.Y);
5401 if gFlash = 1 then
5402 if FPain < 50 then
5403 FPain := min(FPain + 25, 50);
5404 end else
5405 g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 3, FUID);
5406 end;
5408 WEAPON_SAW:
5409 begin
5410 if g_Weapon_chainsaw(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y,
5411 IfThen(gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF], 9, 3), FUID) <> 0 then
5412 begin
5413 FSawSoundSelect.Stop();
5414 FSawSound.Stop();
5415 FSawSoundHit.PlayAt(FObj.X, FObj.Y);
5416 end
5417 else if not FSawSoundHit.IsPlaying() then
5418 begin
5419 FSawSoundSelect.Stop();
5420 FSawSound.PlayAt(FObj.X, FObj.Y);
5421 end;
5422 f := True;
5423 end;
5425 WEAPON_PISTOL:
5426 begin
5427 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX, Gamey);
5428 FFireAngle := FAngle;
5429 f := True;
5430 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
5431 GameVelX, GameVelY-2, SHELL_BULLET);
5432 end;
5434 WEAPON_SHOTGUN1:
5435 begin
5436 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex, Gamey);
5437 FFireAngle := FAngle;
5438 f := True;
5439 FShellTimer := 10;
5440 FShellType := SHELL_SHELL;
5441 end;
5443 WEAPON_SHOTGUN2:
5444 begin
5445 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex, Gamey);
5446 FFireAngle := FAngle;
5447 f := True;
5448 FShellTimer := 13;
5449 FShellType := SHELL_DBLSHELL;
5450 end;
5452 WEAPON_CHAINGUN:
5453 begin
5454 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex, Gamey);
5455 FFireAngle := FAngle;
5456 f := True;
5457 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
5458 GameVelX, GameVelY-2, SHELL_BULLET);
5459 end;
5461 WEAPON_ROCKETLAUNCHER:
5462 begin
5463 g_Weapon_Rocket(wx, wy, xd, yd, FUID, WID);
5464 FFireAngle := FAngle;
5465 f := True;
5466 end;
5468 WEAPON_PLASMA:
5469 begin
5470 g_Weapon_Plasma(wx, wy, xd, yd, FUID, WID);
5471 FFireAngle := FAngle;
5472 f := True;
5473 end;
5475 WEAPON_BFG:
5476 begin
5477 g_Weapon_BFGShot(wx, wy, xd, yd, FUID, WID);
5478 FFireAngle := FAngle;
5479 f := True;
5480 end;
5482 WEAPON_SUPERPULEMET:
5483 begin
5484 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex, Gamey);
5485 FFireAngle := FAngle;
5486 f := True;
5487 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
5488 GameVelX, GameVelY-2, SHELL_SHELL);
5489 end;
5491 WEAPON_FLAMETHROWER:
5492 begin
5493 g_Weapon_flame(wx, wy, xd, yd, FUID, WID);
5494 FFireAngle := FAngle;
5495 f := True;
5496 end;
5497 end;
5499 if not f then Exit;
5501 if (FAngle = 0) or (FAngle = 180) then SetAction(A_ATTACK)
5502 else if (FAngle = ANGLE_LEFTDOWN) or (FAngle = ANGLE_RIGHTDOWN) then SetAction(A_ATTACKDOWN)
5503 else if (FAngle = ANGLE_LEFTUP) or (FAngle = ANGLE_RIGHTUP) then SetAction(A_ATTACKUP);
5504 end;
5506 procedure TPlayer.DoLerp(Level: Integer = 2);
5507 begin
5508 if FObj.X <> FXTo then FObj.X := Lerp(FObj.X, FXTo, Level);
5509 if FObj.Y <> FYTo then FObj.Y := Lerp(FObj.Y, FYTo, Level);
5510 end;
5512 procedure TPlayer.SetLerp(XTo, YTo: Integer);
5513 var
5514 AX, AY: Integer;
5515 begin
5516 if NetInterpLevel < 1 then
5517 begin
5518 FObj.X := XTo;
5519 FObj.Y := YTo;
5520 end
5521 else
5522 begin
5523 FXTo := XTo;
5524 FYTo := YTo;
5526 AX := Abs(FXTo - FObj.X);
5527 AY := Abs(FYTo - FObj.Y);
5528 if (AX > 32) or (AX <= NetInterpLevel) then
5529 FObj.X := FXTo;
5530 if (AY > 32) or (AY <= NetInterpLevel) then
5531 FObj.Y := FYTo;
5532 end;
5533 end;
5535 function TPlayer.FullInLift(XInc, YInc: Integer): Integer;
5536 begin
5537 if g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc,
5538 PLAYER_RECT.Width, PLAYER_RECT.Height-8,
5539 PANEL_LIFTUP, False) then Result := -1
5540 else
5541 if g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc,
5542 PLAYER_RECT.Width, PLAYER_RECT.Height-8,
5543 PANEL_LIFTDOWN, False) then Result := 1
5544 else Result := 0;
5545 end;
5547 function TPlayer.GetFlag(Flag: Byte): Boolean;
5548 var
5549 s, ts: String;
5550 evtype, a: Byte;
5551 begin
5552 Result := False;
5554 if Flag = FLAG_NONE then
5555 Exit;
5557 if not g_Game_IsServer then Exit;
5559 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5560 if (Flag = FTeam) and
5561 (gFlags[Flag].State = FLAG_STATE_NORMAL) and
5562 (FFlag <> FLAG_NONE) then
5563 begin
5564 if FFlag = FLAG_RED then
5565 s := _lc[I_PLAYER_FLAG_RED]
5566 else
5567 s := _lc[I_PLAYER_FLAG_BLUE];
5569 evtype := FLAG_STATE_SCORED;
5571 ts := Format('%.4d', [gFlags[FFlag].CaptureTime]);
5572 Insert('.', ts, Length(ts) + 1 - 3);
5573 g_Console_Add(Format(_lc[I_PLAYER_FLAG_CAPTURE], [FName, s, ts]), True);
5575 g_Map_ResetFlag(FFlag);
5576 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_CAPTURE], [AnsiUpperCase(s)]), 144);
5578 if ((Self = gPlayer1) or (Self = gPlayer2)
5579 or ((gPlayer1 <> nil) and (gPlayer1.Team = FTeam))
5580 or ((gPlayer2 <> nil) and (gPlayer2.Team = FTeam))) then
5581 a := 0
5582 else
5583 a := 1;
5585 if not sound_cap_flag[a].IsPlaying() then
5586 sound_cap_flag[a].Play();
5588 gTeamStat[FTeam].Goals := gTeamStat[FTeam].Goals + 1;
5590 Result := True;
5591 if g_Game_IsNet then
5592 begin
5593 MH_SEND_FlagEvent(evtype, FFlag, FUID, False);
5594 MH_SEND_GameStats;
5595 end;
5597 gFlags[FFlag].CaptureTime := 0;
5598 SetFlag(FLAG_NONE);
5599 Exit;
5600 end;
5602 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5603 if (Flag = FTeam) and
5604 (gFlags[Flag].State = FLAG_STATE_DROPPED) then
5605 begin
5606 if Flag = FLAG_RED then
5607 s := _lc[I_PLAYER_FLAG_RED]
5608 else
5609 s := _lc[I_PLAYER_FLAG_BLUE];
5611 evtype := FLAG_STATE_RETURNED;
5612 gFlags[Flag].CaptureTime := 0;
5614 g_Console_Add(Format(_lc[I_PLAYER_FLAG_RETURN], [FName, s]), True);
5616 g_Map_ResetFlag(Flag);
5617 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_RETURN], [AnsiUpperCase(s)]), 144);
5619 if ((Self = gPlayer1) or (Self = gPlayer2)
5620 or ((gPlayer1 <> nil) and (gPlayer1.Team = FTeam))
5621 or ((gPlayer2 <> nil) and (gPlayer2.Team = FTeam))) then
5622 a := 0
5623 else
5624 a := 1;
5626 if not sound_ret_flag[a].IsPlaying() then
5627 sound_ret_flag[a].Play();
5629 Result := True;
5630 if g_Game_IsNet then
5631 begin
5632 MH_SEND_FlagEvent(evtype, Flag, FUID, False);
5633 MH_SEND_GameStats;
5634 end;
5635 Exit;
5636 end;
5638 // Ïîäîáðàë ÷óæîé ôëàã:
5639 if (Flag <> FTeam) and (FTime[T_FLAGCAP] <= gTime) then
5640 begin
5641 SetFlag(Flag);
5643 if Flag = FLAG_RED then
5644 s := _lc[I_PLAYER_FLAG_RED]
5645 else
5646 s := _lc[I_PLAYER_FLAG_BLUE];
5648 evtype := FLAG_STATE_CAPTURED;
5650 g_Console_Add(Format(_lc[I_PLAYER_FLAG_GET], [FName, s]), True);
5652 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_GET], [AnsiUpperCase(s)]), 144);
5654 gFlags[Flag].State := FLAG_STATE_CAPTURED;
5656 if ((Self = gPlayer1) or (Self = gPlayer2)
5657 or ((gPlayer1 <> nil) and (gPlayer1.Team = FTeam))
5658 or ((gPlayer2 <> nil) and (gPlayer2.Team = FTeam))) then
5659 a := 0
5660 else
5661 a := 1;
5663 if not sound_get_flag[a].IsPlaying() then
5664 sound_get_flag[a].Play();
5666 Result := True;
5667 if g_Game_IsNet then
5668 begin
5669 MH_SEND_FlagEvent(evtype, Flag, FUID, False);
5670 MH_SEND_GameStats;
5671 end;
5672 end;
5673 end;
5675 procedure TPlayer.SetFlag(Flag: Byte);
5676 begin
5677 FFlag := Flag;
5678 if FModel <> nil then
5679 FModel.SetFlag(FFlag);
5680 end;
5682 function TPlayer.DropFlag(Silent: Boolean = True): Boolean;
5683 var
5684 s: String;
5685 a: Byte;
5686 begin
5687 Result := False;
5688 if (not g_Game_IsServer) or (FFlag = FLAG_NONE) then
5689 Exit;
5690 FTime[T_FLAGCAP] := gTime + 2000;
5691 with gFlags[FFlag] do
5692 begin
5693 Obj.X := FObj.X;
5694 Obj.Y := FObj.Y;
5695 Direction := FDirection;
5696 State := FLAG_STATE_DROPPED;
5697 Count := FLAG_TIME;
5698 g_Obj_Push(@Obj, (FObj.Vel.X div 2)-2+Random(5),
5699 (FObj.Vel.Y div 2)-2+Random(5));
5700 positionChanged(); // this updates spatial accelerators
5702 if FFlag = FLAG_RED then
5703 s := _lc[I_PLAYER_FLAG_RED]
5704 else
5705 s := _lc[I_PLAYER_FLAG_BLUE];
5707 g_Console_Add(Format(_lc[I_PLAYER_FLAG_DROP], [FName, s]), True);
5708 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_DROP], [AnsiUpperCase(s)]), 144);
5710 if ((Self = gPlayer1) or (Self = gPlayer2)
5711 or ((gPlayer1 <> nil) and (gPlayer1.Team = FTeam))
5712 or ((gPlayer2 <> nil) and (gPlayer2.Team = FTeam))) then
5713 a := 0
5714 else
5715 a := 1;
5717 if (not Silent) and (not sound_lost_flag[a].IsPlaying()) then
5718 sound_lost_flag[a].Play();
5720 if g_Game_IsNet then
5721 MH_SEND_FlagEvent(FLAG_STATE_DROPPED, Flag, FUID, False);
5722 end;
5723 SetFlag(FLAG_NONE);
5724 Result := True;
5725 end;
5727 procedure TPlayer.GetSecret();
5728 begin
5729 Inc(FSecrets);
5730 end;
5732 procedure TPlayer.PressKey(Key: Byte; Time: Word = 1);
5733 begin
5734 Assert(Key <= High(FKeys));
5736 FKeys[Key].Pressed := True;
5737 FKeys[Key].Time := Time;
5738 end;
5740 function TPlayer.IsKeyPressed(K: Byte): Boolean;
5741 begin
5742 Result := FKeys[K].Pressed;
5743 end;
5745 procedure TPlayer.ReleaseKeys();
5746 var
5747 a: Integer;
5748 begin
5749 for a := Low(FKeys) to High(FKeys) do
5750 begin
5751 FKeys[a].Pressed := False;
5752 FKeys[a].Time := 0;
5753 end;
5754 end;
5756 procedure TPlayer.OnDamage(Angle: SmallInt);
5757 begin
5758 end;
5760 function TPlayer.firediry(): Integer;
5761 begin
5762 if FKeys[KEY_UP].Pressed then Result := -42
5763 else if FKeys[KEY_DOWN].Pressed then Result := 19
5764 else Result := 0;
5765 end;
5767 procedure TPlayer.RememberState();
5768 var
5769 i: Integer;
5770 begin
5771 FSavedState.Health := FHealth;
5772 FSavedState.Armor := FArmor;
5773 FSavedState.Air := FAir;
5774 FSavedState.JetFuel := FJetFuel;
5775 FSavedState.CurrWeap := FCurrWeap;
5776 FSavedState.NextWeap := FNextWeap;
5777 FSavedState.NextWeapDelay := FNextWeapDelay;
5779 for i := 0 to 3 do
5780 FSavedState.Ammo[i] := FAmmo[i];
5781 for i := 0 to 3 do
5782 FSavedState.MaxAmmo[i] := FMaxAmmo[i];
5784 FSavedState.Rulez := FRulez;
5785 FSavedState.WaitRecall := True;
5786 end;
5788 procedure TPlayer.RecallState();
5789 var
5790 i: Integer;
5791 begin
5792 if not FSavedState.WaitRecall then Exit;
5794 FHealth := FSavedState.Health;
5795 FArmor := FSavedState.Armor;
5796 FAir := FSavedState.Air;
5797 FJetFuel := FSavedState.JetFuel;
5798 FCurrWeap := FSavedState.CurrWeap;
5799 FNextWeap := FSavedState.NextWeap;
5800 FNextWeapDelay := FSavedState.NextWeapDelay;
5802 for i := 0 to 3 do
5803 FAmmo[i] := FSavedState.Ammo[i];
5804 for i := 0 to 3 do
5805 FMaxAmmo[i] := FSavedState.MaxAmmo[i];
5807 FRulez := FSavedState.Rulez;
5808 FSavedState.WaitRecall := False;
5810 if gGameSettings.GameType = GT_SERVER then
5811 MH_SEND_PlayerStats(FUID);
5812 end;
5814 procedure TPlayer.SaveState (st: TStream);
5815 var
5816 i: Integer;
5817 b: Byte;
5818 begin
5819 // Ñèãíàòóðà èãðîêà
5820 utils.writeSign(st, 'PLYR');
5821 utils.writeInt(st, Byte(PLR_SAVE_VERSION)); // version
5822 // Áîò èëè ÷åëîâåê
5823 utils.writeBool(st, FIamBot);
5824 // UID èãðîêà
5825 utils.writeInt(st, Word(FUID));
5826 // Èìÿ èãðîêà
5827 utils.writeStr(st, FName);
5828 // Êîìàíäà
5829 utils.writeInt(st, Byte(FTeam));
5830 // Æèâ ëè
5831 utils.writeBool(st, FAlive);
5832 // Èçðàñõîäîâàë ëè âñå æèçíè
5833 utils.writeBool(st, FNoRespawn);
5834 // Íàïðàâëåíèå
5835 if FDirection = TDirection.D_LEFT then b := 1 else b := 2; // D_RIGHT
5836 utils.writeInt(st, Byte(b));
5837 // Çäîðîâüå
5838 utils.writeInt(st, LongInt(FHealth));
5839 // Æèçíè
5840 utils.writeInt(st, Byte(FLives));
5841 // Áðîíÿ
5842 utils.writeInt(st, LongInt(FArmor));
5843 // Çàïàñ âîçäóõà
5844 utils.writeInt(st, LongInt(FAir));
5845 // Çàïàñ ãîðþ÷åãî
5846 utils.writeInt(st, LongInt(FJetFuel));
5847 // Áîëü
5848 utils.writeInt(st, LongInt(FPain));
5849 // Óáèë
5850 utils.writeInt(st, LongInt(FKills));
5851 // Óáèë ìîíñòðîâ
5852 utils.writeInt(st, LongInt(FMonsterKills));
5853 // Ôðàãîâ
5854 utils.writeInt(st, LongInt(FFrags));
5855 // Ôðàãîâ ïîäðÿä
5856 utils.writeInt(st, Byte(FFragCombo));
5857 // Âðåìÿ ïîñëåäíåãî ôðàãà
5858 utils.writeInt(st, LongWord(FLastFrag));
5859 // Ñìåðòåé
5860 utils.writeInt(st, LongInt(FDeath));
5861 // Êàêîé ôëàã íåñåò
5862 utils.writeInt(st, Byte(FFlag));
5863 // Íàøåë ñåêðåòîâ
5864 utils.writeInt(st, LongInt(FSecrets));
5865 // Òåêóùåå îðóæèå
5866 utils.writeInt(st, Byte(FCurrWeap));
5867 // Æåëàåìîå îðóæèå
5868 utils.writeInt(st, Word(FNextWeap));
5869 // ...è ïàóçà
5870 utils.writeInt(st, Byte(FNextWeapDelay));
5871 // Âðåìÿ çàðÿäêè BFG
5872 utils.writeInt(st, SmallInt(FBFGFireCounter));
5873 // Áóôåð óðîíà
5874 utils.writeInt(st, LongInt(FDamageBuffer));
5875 // Ïîñëåäíèé óäàðèâøèé
5876 utils.writeInt(st, Word(FLastSpawnerUID));
5877 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
5878 utils.writeInt(st, Byte(FLastHit));
5879 // Îáúåêò èãðîêà
5880 Obj_SaveState(st, @FObj);
5881 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
5882 for i := A_BULLETS to A_HIGH do utils.writeInt(st, Word(FAmmo[i]));
5883 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
5884 for i := A_BULLETS to A_HIGH do utils.writeInt(st, Word(FMaxAmmo[i]));
5885 // Íàëè÷èå îðóæèÿ
5886 for i := WP_FIRST to WP_LAST do utils.writeBool(st, FWeapon[i]);
5887 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
5888 for i := WP_FIRST to WP_LAST do utils.writeInt(st, Word(FReloading[i]));
5889 // Íàëè÷èå ðþêçàêà
5890 utils.writeBool(st, (R_ITEM_BACKPACK in FRulez));
5891 // Íàëè÷èå êðàñíîãî êëþ÷à
5892 utils.writeBool(st, (R_KEY_RED in FRulez));
5893 // Íàëè÷èå çåëåíîãî êëþ÷à
5894 utils.writeBool(st, (R_KEY_GREEN in FRulez));
5895 // Íàëè÷èå ñèíåãî êëþ÷à
5896 utils.writeBool(st, (R_KEY_BLUE in FRulez));
5897 // Íàëè÷èå áåðñåðêà
5898 utils.writeBool(st, (R_BERSERK in FRulez));
5899 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
5900 for i := MR_SUIT to MR_MAX do utils.writeInt(st, LongWord(FMegaRulez[i]));
5901 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
5902 for i := T_RESPAWN to T_FLAGCAP do utils.writeInt(st, LongWord(FTime[i]));
5903 // Íàçâàíèå ìîäåëè
5904 utils.writeStr(st, FModel.Name);
5905 // Öâåò ìîäåëè
5906 utils.writeInt(st, Byte(FColor.R));
5907 utils.writeInt(st, Byte(FColor.G));
5908 utils.writeInt(st, Byte(FColor.B));
5909 end;
5912 procedure TPlayer.LoadState (st: TStream);
5913 var
5914 i: Integer;
5915 str: String;
5916 b: Byte;
5917 begin
5918 assert(st <> nil);
5920 // Ñèãíàòóðà èãðîêà
5921 if not utils.checkSign(st, 'PLYR') then raise XStreamError.Create('invalid player signature');
5922 if (utils.readByte(st) <> PLR_SAVE_VERSION) then raise XStreamError.Create('invalid player version');
5923 // Áîò èëè ÷åëîâåê:
5924 FIamBot := utils.readBool(st);
5925 // UID èãðîêà
5926 FUID := utils.readWord(st);
5927 // Èìÿ èãðîêà
5928 str := utils.readStr(st);
5929 if (self <> gPlayer1) and (self <> gPlayer2) then FName := str;
5930 // Êîìàíäà
5931 FTeam := utils.readByte(st);
5932 // Æèâ ëè
5933 FAlive := utils.readBool(st);
5934 // Èçðàñõîäîâàë ëè âñå æèçíè
5935 FNoRespawn := utils.readBool(st);
5936 // Íàïðàâëåíèå
5937 b := utils.readByte(st);
5938 if b = 1 then FDirection := TDirection.D_LEFT else FDirection := TDirection.D_RIGHT; // b = 2
5939 // Çäîðîâüå
5940 FHealth := utils.readLongInt(st);
5941 // Æèçíè
5942 FLives := utils.readByte(st);
5943 // Áðîíÿ
5944 FArmor := utils.readLongInt(st);
5945 // Çàïàñ âîçäóõà
5946 FAir := utils.readLongInt(st);
5947 // Çàïàñ ãîðþ÷åãî
5948 FJetFuel := utils.readLongInt(st);
5949 // Áîëü
5950 FPain := utils.readLongInt(st);
5951 // Óáèë
5952 FKills := utils.readLongInt(st);
5953 // Óáèë ìîíñòðîâ
5954 FMonsterKills := utils.readLongInt(st);
5955 // Ôðàãîâ
5956 FFrags := utils.readLongInt(st);
5957 // Ôðàãîâ ïîäðÿä
5958 FFragCombo := utils.readByte(st);
5959 // Âðåìÿ ïîñëåäíåãî ôðàãà
5960 FLastFrag := utils.readLongWord(st);
5961 // Ñìåðòåé
5962 FDeath := utils.readLongInt(st);
5963 // Êàêîé ôëàã íåñåò
5964 FFlag := utils.readByte(st);
5965 // Íàøåë ñåêðåòîâ
5966 FSecrets := utils.readLongInt(st);
5967 // Òåêóùåå îðóæèå
5968 FCurrWeap := utils.readByte(st);
5969 // Æåëàåìîå îðóæèå
5970 FNextWeap := utils.readWord(st);
5971 // ...è ïàóçà
5972 FNextWeapDelay := utils.readByte(st);
5973 // Âðåìÿ çàðÿäêè BFG
5974 FBFGFireCounter := utils.readSmallInt(st);
5975 // Áóôåð óðîíà
5976 FDamageBuffer := utils.readLongInt(st);
5977 // Ïîñëåäíèé óäàðèâøèé
5978 FLastSpawnerUID := utils.readWord(st);
5979 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
5980 FLastHit := utils.readByte(st);
5981 // Îáúåêò èãðîêà
5982 Obj_LoadState(@FObj, st);
5983 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
5984 for i := A_BULLETS to A_HIGH do FAmmo[i] := utils.readWord(st);
5985 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
5986 for i := A_BULLETS to A_HIGH do FMaxAmmo[i] := utils.readWord(st);
5987 // Íàëè÷èå îðóæèÿ
5988 for i := WP_FIRST to WP_LAST do FWeapon[i] := utils.readBool(st);
5989 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
5990 for i := WP_FIRST to WP_LAST do FReloading[i] := utils.readWord(st);
5991 // Íàëè÷èå ðþêçàêà
5992 if utils.readBool(st) then Include(FRulez, R_ITEM_BACKPACK);
5993 // Íàëè÷èå êðàñíîãî êëþ÷à
5994 if utils.readBool(st) then Include(FRulez, R_KEY_RED);
5995 // Íàëè÷èå çåëåíîãî êëþ÷à
5996 if utils.readBool(st) then Include(FRulez, R_KEY_GREEN);
5997 // Íàëè÷èå ñèíåãî êëþ÷à
5998 if utils.readBool(st) then Include(FRulez, R_KEY_BLUE);
5999 // Íàëè÷èå áåðñåðêà
6000 if utils.readBool(st) then Include(FRulez, R_BERSERK);
6001 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6002 for i := MR_SUIT to MR_MAX do FMegaRulez[i] := utils.readLongWord(st);
6003 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6004 for i := T_RESPAWN to T_FLAGCAP do FTime[i] := utils.readLongWord(st);
6005 // Íàçâàíèå ìîäåëè
6006 str := utils.readStr(st);
6007 // Öâåò ìîäåëè
6008 FColor.R := utils.readByte(st);
6009 FColor.G := utils.readByte(st);
6010 FColor.B := utils.readByte(st);
6011 if (self = gPlayer1) then
6012 begin
6013 str := gPlayer1Settings.Model;
6014 FColor := gPlayer1Settings.Color;
6015 end
6016 else if (self = gPlayer2) then
6017 begin
6018 str := gPlayer2Settings.Model;
6019 FColor := gPlayer2Settings.Color;
6020 end;
6021 // Îáíîâëÿåì ìîäåëü èãðîêà
6022 SetModel(str);
6023 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
6024 FModel.Color := TEAMCOLOR[FTeam]
6025 else
6026 FModel.Color := FColor;
6027 end;
6030 procedure TPlayer.AllRulez(Health: Boolean);
6031 var
6032 a: Integer;
6033 begin
6034 if Health then
6035 begin
6036 FHealth := PLAYER_HP_LIMIT;
6037 FArmor := PLAYER_AP_LIMIT;
6038 Exit;
6039 end;
6041 for a := WP_FIRST to WP_LAST do FWeapon[a] := True;
6042 for a := A_BULLETS to A_HIGH do FAmmo[a] := 30000;
6043 FRulez := FRulez+[R_KEY_RED, R_KEY_GREEN, R_KEY_BLUE];
6044 end;
6046 procedure TPlayer.RestoreHealthArmor();
6047 begin
6048 FHealth := PLAYER_HP_LIMIT;
6049 FArmor := PLAYER_AP_LIMIT;
6050 end;
6052 procedure TPlayer.FragCombo();
6053 var
6054 Param: Integer;
6055 begin
6056 if (gGameSettings.GameMode in [GM_COOP, GM_SINGLE]) or g_Game_IsClient then
6057 Exit;
6058 if gTime - FLastFrag < FRAG_COMBO_TIME then
6059 begin
6060 if FFragCombo < 5 then
6061 Inc(FFragCombo);
6062 Param := FUID or (FFragCombo shl 16);
6063 if (FComboEvnt >= Low(gDelayedEvents)) and
6064 (FComboEvnt <= High(gDelayedEvents)) and
6065 gDelayedEvents[FComboEvnt].Pending and
6066 (gDelayedEvents[FComboEvnt].DEType = DE_KILLCOMBO) and
6067 (gDelayedEvents[FComboEvnt].DENum and $FFFF = FUID) then
6068 begin
6069 gDelayedEvents[FComboEvnt].Time := gTime + 500;
6070 gDelayedEvents[FComboEvnt].DENum := Param;
6071 end
6072 else
6073 FComboEvnt := g_Game_DelayEvent(DE_KILLCOMBO, 500, Param);
6074 end
6075 else
6076 FFragCombo := 1;
6078 FLastFrag := gTime;
6079 end;
6081 procedure TPlayer.GiveItem(ItemType: Byte);
6082 begin
6083 case ItemType of
6084 ITEM_SUIT:
6085 if FMegaRulez[MR_SUIT] < gTime+PLAYER_SUIT_TIME then
6086 begin
6087 FMegaRulez[MR_SUIT] := gTime+PLAYER_SUIT_TIME;
6088 end;
6090 ITEM_OXYGEN:
6091 if FAir < AIR_MAX then
6092 begin
6093 FAir := AIR_MAX;
6094 end;
6096 ITEM_MEDKIT_BLACK:
6097 begin
6098 if not (R_BERSERK in FRulez) then
6099 begin
6100 Include(FRulez, R_BERSERK);
6101 if FBFGFireCounter < 1 then
6102 begin
6103 FCurrWeap := WEAPON_KASTET;
6104 resetWeaponQueue();
6105 FModel.SetWeapon(WEAPON_KASTET);
6106 end;
6107 if gFlash <> 0 then
6108 Inc(FPain, 100);
6109 FBerserk := gTime+30000;
6110 end;
6111 if FHealth < PLAYER_HP_SOFT then
6112 begin
6113 FHealth := PLAYER_HP_SOFT;
6114 FBerserk := gTime+30000;
6115 end;
6116 end;
6118 ITEM_INVUL:
6119 if FMegaRulez[MR_INVUL] < gTime+PLAYER_INVUL_TIME then
6120 begin
6121 FMegaRulez[MR_INVUL] := gTime+PLAYER_INVUL_TIME;
6122 end;
6124 ITEM_INVIS:
6125 if FMegaRulez[MR_INVIS] < gTime+PLAYER_INVIS_TIME then
6126 begin
6127 FMegaRulez[MR_INVIS] := gTime+PLAYER_INVIS_TIME;
6128 end;
6130 ITEM_JETPACK:
6131 if FJetFuel < JET_MAX then
6132 begin
6133 FJetFuel := JET_MAX;
6134 end;
6136 ITEM_MEDKIT_SMALL: if FHealth < PLAYER_HP_SOFT then IncMax(FHealth, 10, PLAYER_HP_SOFT);
6137 ITEM_MEDKIT_LARGE: if FHealth < PLAYER_HP_SOFT then IncMax(FHealth, 25, PLAYER_HP_SOFT);
6139 ITEM_ARMOR_GREEN: if FArmor < PLAYER_AP_SOFT then FArmor := PLAYER_AP_SOFT;
6140 ITEM_ARMOR_BLUE: if FArmor < PLAYER_AP_LIMIT then FArmor := PLAYER_AP_LIMIT;
6142 ITEM_SPHERE_BLUE: if FHealth < PLAYER_HP_LIMIT then IncMax(FHealth, 100, PLAYER_HP_LIMIT);
6143 ITEM_SPHERE_WHITE:
6144 if (FHealth < PLAYER_HP_LIMIT) or (FArmor < PLAYER_AP_LIMIT) then
6145 begin
6146 if FHealth < PLAYER_HP_LIMIT then FHealth := PLAYER_HP_LIMIT;
6147 if FArmor < PLAYER_AP_LIMIT then FArmor := PLAYER_AP_LIMIT;
6148 end;
6150 ITEM_WEAPON_SAW: FWeapon[WEAPON_SAW] := True;
6151 ITEM_WEAPON_SHOTGUN1: FWeapon[WEAPON_SHOTGUN1] := True;
6152 ITEM_WEAPON_SHOTGUN2: FWeapon[WEAPON_SHOTGUN2] := True;
6153 ITEM_WEAPON_CHAINGUN: FWeapon[WEAPON_CHAINGUN] := True;
6154 ITEM_WEAPON_ROCKETLAUNCHER: FWeapon[WEAPON_ROCKETLAUNCHER] := True;
6155 ITEM_WEAPON_PLASMA: FWeapon[WEAPON_PLASMA] := True;
6156 ITEM_WEAPON_BFG: FWeapon[WEAPON_BFG] := True;
6157 ITEM_WEAPON_SUPERPULEMET: FWeapon[WEAPON_SUPERPULEMET] := True;
6158 ITEM_WEAPON_FLAMETHROWER: FWeapon[WEAPON_FLAMETHROWER] := True;
6160 ITEM_AMMO_BULLETS: if FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS] then IncMax(FAmmo[A_BULLETS], 10, FMaxAmmo[A_BULLETS]);
6161 ITEM_AMMO_BULLETS_BOX: if FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS] then IncMax(FAmmo[A_BULLETS], 50, FMaxAmmo[A_BULLETS]);
6162 ITEM_AMMO_SHELLS: if FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS] then IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
6163 ITEM_AMMO_SHELLS_BOX: if FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS] then IncMax(FAmmo[A_SHELLS], 25, FMaxAmmo[A_SHELLS]);
6164 ITEM_AMMO_ROCKET: if FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS] then IncMax(FAmmo[A_ROCKETS], 1, FMaxAmmo[A_ROCKETS]);
6165 ITEM_AMMO_ROCKET_BOX: if FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS] then IncMax(FAmmo[A_ROCKETS], 5, FMaxAmmo[A_ROCKETS]);
6166 ITEM_AMMO_CELL: if FAmmo[A_CELLS] < FMaxAmmo[A_CELLS] then IncMax(FAmmo[A_CELLS], 40, FMaxAmmo[A_CELLS]);
6167 ITEM_AMMO_CELL_BIG: if FAmmo[A_CELLS] < FMaxAmmo[A_CELLS] then IncMax(FAmmo[A_CELLS], 100, FMaxAmmo[A_CELLS]);
6168 ITEM_AMMO_FUELCAN: if FAmmo[A_FUEL] < FMaxAmmo[A_FUEL] then IncMax(FAmmo[A_FUEL], 100, FMaxAmmo[A_FUEL]);
6170 ITEM_AMMO_BACKPACK:
6171 if (FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS]) or
6172 (FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS]) or
6173 (FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS]) or
6174 (FAmmo[A_CELLS] < FMaxAmmo[A_CELLS]) or
6175 (FMaxAmmo[A_FUEL] < AmmoLimits[1, A_FUEL]) then
6176 begin
6177 FMaxAmmo[A_BULLETS] := AmmoLimits[1, A_BULLETS];
6178 FMaxAmmo[A_SHELLS] := AmmoLimits[1, A_SHELLS];
6179 FMaxAmmo[A_ROCKETS] := AmmoLimits[1, A_ROCKETS];
6180 FMaxAmmo[A_CELLS] := AmmoLimits[1, A_CELLS];
6181 FMaxAmmo[A_FUEL] := AmmoLimits[1, A_FUEL];
6183 if FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS] then IncMax(FAmmo[A_BULLETS], 10, FMaxAmmo[A_BULLETS]);
6184 if FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS] then IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
6185 if FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS] then IncMax(FAmmo[A_ROCKETS], 1, FMaxAmmo[A_ROCKETS]);
6186 if FAmmo[A_CELLS] < FMaxAmmo[A_CELLS] then IncMax(FAmmo[A_CELLS], 40, FMaxAmmo[A_CELLS]);
6188 FRulez := FRulez + [R_ITEM_BACKPACK];
6189 end;
6191 ITEM_KEY_RED: if not (R_KEY_RED in FRulez) then Include(FRulez, R_KEY_RED);
6192 ITEM_KEY_GREEN: if not (R_KEY_GREEN in FRulez) then Include(FRulez, R_KEY_GREEN);
6193 ITEM_KEY_BLUE: if not (R_KEY_BLUE in FRulez) then Include(FRulez, R_KEY_BLUE);
6195 ITEM_BOTTLE: if FHealth < PLAYER_HP_LIMIT then IncMax(FHealth, 4, PLAYER_HP_LIMIT);
6196 ITEM_HELMET: if FArmor < PLAYER_AP_LIMIT then IncMax(FArmor, 5, PLAYER_AP_LIMIT);
6198 else
6199 Exit;
6200 end;
6201 if g_Game_IsNet and g_Game_IsServer then
6202 MH_SEND_PlayerStats(FUID);
6203 end;
6205 procedure TPlayer.FlySmoke(Times: DWORD = 1);
6206 var
6207 id, i: DWORD;
6208 Anim: TAnimation;
6209 begin
6210 if (Random(5) = 1) and (Times = 1) then
6211 Exit;
6213 if BodyInLiquid(0, 0) then
6214 begin
6215 g_GFX_Bubbles(Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2)+Random(3)-1,
6216 Obj.Y+Obj.Rect.Height+8, 1, 8, 4);
6217 if Random(2) = 0 then
6218 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj.X, FObj.Y)
6219 else
6220 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj.X, FObj.Y);
6221 Exit;
6222 end;
6224 if g_Frames_Get(id, 'FRAMES_SMOKE') then
6225 begin
6226 for i := 1 to Times do
6227 begin
6228 Anim := TAnimation.Create(id, False, 3);
6229 Anim.Alpha := 150;
6230 g_GFX_OnceAnim(Obj.X+Obj.Rect.X+Random(Obj.Rect.Width+Times*2)-(Anim.Width div 2),
6231 Obj.Y+Obj.Rect.Height-4+Random(8+Times*2), Anim, ONCEANIM_SMOKE);
6232 Anim.Free();
6233 end;
6234 end;
6235 end;
6237 procedure TPlayer.OnFireFlame(Times: DWORD = 1);
6238 var
6239 id, i: DWORD;
6240 Anim: TAnimation;
6241 begin
6242 if (Random(10) = 1) and (Times = 1) then
6243 Exit;
6245 if g_Frames_Get(id, 'FRAMES_FLAME') then
6246 begin
6247 for i := 1 to Times do
6248 begin
6249 Anim := TAnimation.Create(id, False, 3);
6250 Anim.Alpha := 0;
6251 g_GFX_OnceAnim(Obj.X+Obj.Rect.X+Random(Obj.Rect.Width+Times*2)-(Anim.Width div 2),
6252 Obj.Y+8+Random(8+Times*2), Anim, ONCEANIM_SMOKE);
6253 Anim.Free();
6254 end;
6255 end;
6256 end;
6258 procedure TPlayer.PauseSounds(Enable: Boolean);
6259 begin
6260 FSawSound.Pause(Enable);
6261 FSawSoundIdle.Pause(Enable);
6262 FSawSoundHit.Pause(Enable);
6263 FSawSoundSelect.Pause(Enable);
6264 FJetSoundFly.Pause(Enable);
6265 FJetSoundOn.Pause(Enable);
6266 FJetSoundOff.Pause(Enable);
6267 end;
6269 { T C o r p s e : }
6271 constructor TCorpse.Create(X, Y: Integer; ModelName: String; aMess: Boolean);
6272 begin
6273 g_Obj_Init(@FObj);
6274 FObj.X := X;
6275 FObj.Y := Y;
6276 FObj.Rect := PLAYER_CORPSERECT;
6277 FModelName := ModelName;
6278 FMess := aMess;
6280 if FMess then
6281 begin
6282 FState := CORPSE_STATE_MESS;
6283 g_PlayerModel_GetAnim(ModelName, A_DIE2, FAnimation, FAnimationMask);
6284 end
6285 else
6286 begin
6287 FState := CORPSE_STATE_NORMAL;
6288 g_PlayerModel_GetAnim(ModelName, A_DIE1, FAnimation, FAnimationMask);
6289 end;
6290 end;
6292 destructor TCorpse.Destroy();
6293 begin
6294 FAnimation.Free();
6296 inherited;
6297 end;
6299 function TCorpse.ObjPtr (): PObj; inline; begin result := @FObj; end;
6301 procedure TCorpse.positionChanged (); inline; begin end;
6303 procedure TCorpse.moveBy (dx, dy: Integer); inline;
6304 begin
6305 if (dx <> 0) or (dy <> 0) then
6306 begin
6307 FObj.X += dx;
6308 FObj.Y += dy;
6309 positionChanged();
6310 end;
6311 end;
6314 procedure TCorpse.getMapBox (out x, y, w, h: Integer); inline;
6315 begin
6316 x := FObj.X+PLAYER_CORPSERECT.X;
6317 y := FObj.Y+PLAYER_CORPSERECT.Y;
6318 w := PLAYER_CORPSERECT.Width;
6319 h := PLAYER_CORPSERECT.Height;
6320 end;
6323 procedure TCorpse.Damage(Value: Word; vx, vy: Integer);
6324 var
6325 pm: TPlayerModel;
6326 Blood: TModelBlood;
6327 begin
6328 if FState = CORPSE_STATE_REMOVEME then
6329 Exit;
6331 FDamage := FDamage + Value;
6333 if FDamage > 150 then
6334 begin
6335 if FAnimation <> nil then
6336 begin
6337 FAnimation.Free();
6338 FAnimation := nil;
6340 FState := CORPSE_STATE_REMOVEME;
6342 g_Player_CreateGibs(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
6343 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
6344 FModelName, FColor);
6345 // Çâóê ìÿñà îò òðóïà:
6346 pm := g_PlayerModel_Get(FModelName);
6347 pm.PlaySound(MODELSOUND_DIE, 5, FObj.X, FObj.Y);
6348 pm.Free;
6350 // Çëîâåùèé ñìåõ:
6351 if (gBodyKillEvent <> -1)
6352 and gDelayedEvents[gBodyKillEvent].Pending then
6353 gDelayedEvents[gBodyKillEvent].Pending := False;
6354 gBodyKillEvent := g_Game_DelayEvent(DE_BODYKILL, 1050, 0);
6355 end;
6356 end
6357 else
6358 begin
6359 Blood := g_PlayerModel_GetBlood(FModelName);
6360 FObj.Vel.X := FObj.Vel.X + vx;
6361 FObj.Vel.Y := FObj.Vel.Y + vy;
6362 g_GFX_Blood(FObj.X+PLAYER_CORPSERECT.X+(PLAYER_CORPSERECT.Width div 2),
6363 FObj.Y+PLAYER_CORPSERECT.Y+(PLAYER_CORPSERECT.Height div 2),
6364 Value, vx, vy, 16, (PLAYER_CORPSERECT.Height*2) div 3,
6365 Blood.R, Blood.G, Blood.B, Blood.Kind);
6366 end;
6367 end;
6369 procedure TCorpse.Draw();
6370 begin
6371 if FState = CORPSE_STATE_REMOVEME then
6372 Exit;
6374 if FAnimation <> nil then
6375 FAnimation.Draw(FObj.X, FObj.Y, TMirrorType.None);
6377 if FAnimationMask <> nil then
6378 begin
6379 e_Colors := FColor;
6380 FAnimationMask.Draw(FObj.X, FObj.Y, TMirrorType.None);
6381 e_Colors.R := 255;
6382 e_Colors.G := 255;
6383 e_Colors.B := 255;
6384 end;
6385 end;
6387 procedure TCorpse.Update();
6388 var
6389 st: Word;
6390 begin
6391 if FState = CORPSE_STATE_REMOVEME then
6392 Exit;
6394 if gTime mod (GAME_TICK*2) <> 0 then
6395 begin
6396 g_Obj_Move(@FObj, True, True, True);
6397 positionChanged(); // this updates spatial accelerators
6398 Exit;
6399 end;
6401 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6402 FObj.Vel.X := z_dec(FObj.Vel.X, 1);
6404 st := g_Obj_Move(@FObj, True, True, True);
6405 positionChanged(); // this updates spatial accelerators
6407 if WordBool(st and MOVE_FALLOUT) then
6408 begin
6409 FState := CORPSE_STATE_REMOVEME;
6410 Exit;
6411 end;
6413 if FAnimation <> nil then
6414 FAnimation.Update();
6415 if FAnimationMask <> nil then
6416 FAnimationMask.Update();
6417 end;
6420 procedure TCorpse.SaveState (st: TStream);
6421 var
6422 anim: Boolean;
6423 begin
6424 assert(st <> nil);
6426 // Ñèãíàòóðà òðóïà
6427 utils.writeSign(st, 'CORP');
6428 utils.writeInt(st, Byte(0));
6429 // Ñîñòîÿíèå
6430 utils.writeInt(st, Byte(FState));
6431 // Íàêîïëåííûé óðîí
6432 utils.writeInt(st, Byte(FDamage));
6433 // Öâåò
6434 utils.writeInt(st, Byte(FColor.R));
6435 utils.writeInt(st, Byte(FColor.G));
6436 utils.writeInt(st, Byte(FColor.B));
6437 // Îáúåêò òðóïà
6438 Obj_SaveState(st, @FObj);
6439 utils.writeInt(st, Word(FPlayerUID));
6440 // Åñòü ëè àíèìàöèÿ
6441 anim := (FAnimation <> nil);
6442 utils.writeBool(st, anim);
6443 // Åñëè åñòü - ñîõðàíÿåì
6444 if anim then FAnimation.SaveState(st);
6445 // Åñòü ëè ìàñêà àíèìàöèè
6446 anim := (FAnimationMask <> nil);
6447 utils.writeBool(st, anim);
6448 // Åñëè åñòü - ñîõðàíÿåì
6449 if anim then FAnimationMask.SaveState(st);
6450 end;
6453 procedure TCorpse.LoadState (st: TStream);
6454 var
6455 anim: Boolean;
6456 begin
6457 assert(st <> nil);
6459 // Ñèãíàòóðà òðóïà
6460 if not utils.checkSign(st, 'CORP') then raise XStreamError.Create('invalid corpse signature');
6461 if (utils.readByte(st) <> 0) then raise XStreamError.Create('invalid corpse version');
6462 // Ñîñòîÿíèå
6463 FState := utils.readByte(st);
6464 // Íàêîïëåííûé óðîí
6465 FDamage := utils.readByte(st);
6466 // Öâåò
6467 FColor.R := utils.readByte(st);
6468 FColor.G := utils.readByte(st);
6469 FColor.B := utils.readByte(st);
6470 // Îáúåêò òðóïà
6471 Obj_LoadState(@FObj, st);
6472 FPlayerUID := utils.readWord(st);
6473 // Åñòü ëè àíèìàöèÿ
6474 anim := utils.readBool(st);
6475 // Åñëè åñòü - çàãðóæàåì
6476 if anim then
6477 begin
6478 Assert(FAnimation <> nil, 'TCorpse.LoadState: no FAnimation');
6479 FAnimation.LoadState(st);
6480 end;
6481 // Åñòü ëè ìàñêà àíèìàöèè
6482 anim := utils.readBool(st);
6483 // Åñëè åñòü - çàãðóæàåì
6484 if anim then
6485 begin
6486 Assert(FAnimationMask <> nil, 'TCorpse.LoadState: no FAnimationMask');
6487 FAnimationMask.LoadState(st);
6488 end;
6489 end;
6491 { T B o t : }
6493 constructor TBot.Create();
6494 var
6495 a: Integer;
6496 begin
6497 inherited Create();
6499 FPhysics := True;
6500 FSpectator := False;
6501 FGhost := False;
6503 FIamBot := True;
6505 Inc(gNumBots);
6507 for a := WP_FIRST to WP_LAST do
6508 begin
6509 FDifficult.WeaponPrior[a] := WEAPON_PRIOR1[a];
6510 FDifficult.CloseWeaponPrior[a] := WEAPON_PRIOR2[a];
6511 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6512 end;
6513 end;
6515 destructor TBot.Destroy();
6516 begin
6517 Dec(gNumBots);
6518 inherited Destroy();
6519 end;
6521 procedure TBot.Draw();
6522 begin
6523 inherited Draw();
6525 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6526 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6527 end;
6529 procedure TBot.Respawn(Silent: Boolean; Force: Boolean = False);
6530 begin
6531 inherited Respawn(Silent, Force);
6533 FAIFlags := nil;
6534 FSelectedWeapon := FCurrWeap;
6535 resetWeaponQueue();
6536 FTargetUID := 0;
6537 end;
6539 procedure TBot.UpdateCombat();
6540 type
6541 TTarget = record
6542 UID: Word;
6543 X, Y: Integer;
6544 Rect: TRectWH;
6545 cX, cY: Integer;
6546 Dist: Word;
6547 Line: Boolean;
6548 Visible: Boolean;
6549 IsPlayer: Boolean;
6550 end;
6552 TTargetRecord = array of TTarget;
6554 function Compare(a, b: TTarget): Integer;
6555 begin
6556 if a.Line and not b.Line then // A íà ëèíèè îãíÿ
6557 Result := -1
6558 else
6559 if not a.Line and b.Line then // B íà ëèíèè îãíÿ
6560 Result := 1
6561 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6562 if (a.Line and b.Line) or ((not a.Line) and (not b.Line)) then
6563 begin
6564 if a.Dist > b.Dist then // B áëèæå
6565 Result := 1
6566 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6567 Result := -1;
6568 end
6569 else // Ñòðàííî -> A
6570 Result := -1;
6571 end;
6573 var
6574 a, x1, y1, x2, y2: Integer;
6575 targets: TTargetRecord;
6576 ammo: Word;
6577 Target, BestTarget: TTarget;
6578 firew, fireh: Integer;
6579 angle: SmallInt;
6580 mon: TMonster;
6581 pla, tpla: TPlayer;
6582 vsPlayer, vsMonster, ok: Boolean;
6585 function monsUpdate (mon: TMonster): Boolean;
6586 begin
6587 result := false; // don't stop
6588 if mon.alive and (mon.MonsterType <> MONSTER_BARREL) then
6589 begin
6590 if not TargetOnScreen(mon.Obj.X+mon.Obj.Rect.X, mon.Obj.Y+mon.Obj.Rect.Y) then exit;
6592 x2 := mon.Obj.X+mon.Obj.Rect.X+(mon.Obj.Rect.Width div 2);
6593 y2 := mon.Obj.Y+mon.Obj.Rect.Y+(mon.Obj.Rect.Height div 2);
6595 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6596 if g_TraceVector(x1, y1, x2, y2) then
6597 begin
6598 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6599 SetLength(targets, Length(targets)+1);
6600 with targets[High(targets)] do
6601 begin
6602 UID := mon.UID;
6603 X := mon.Obj.X;
6604 Y := mon.Obj.Y;
6605 cX := x2;
6606 cY := y2;
6607 Rect := mon.Obj.Rect;
6608 Dist := g_PatchLength(x1, y1, x2, y2);
6609 Line := (y1+4 < Target.Y + mon.Obj.Rect.Y + mon.Obj.Rect.Height) and
6610 (y1-4 > Target.Y + mon.Obj.Rect.Y);
6611 Visible := True;
6612 IsPlayer := False;
6613 end;
6614 end;
6615 end;
6616 end;
6618 begin
6619 vsPlayer := LongBool(gGameSettings.Options and GAME_OPTION_BOTVSPLAYER);
6620 vsMonster := LongBool(gGameSettings.Options and GAME_OPTION_BOTVSMONSTER);
6622 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6623 if FCurrWeap <> FSelectedWeapon then
6624 NextWeapon();
6626 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6627 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap = FSelectedWeapon) then
6628 begin
6629 RemoveAIFlag('NEEDFIRE');
6631 case FCurrWeap of
6632 WEAPON_PLASMA, WEAPON_SUPERPULEMET, WEAPON_CHAINGUN: PressKey(KEY_FIRE, 20);
6633 WEAPON_SAW, WEAPON_KASTET, WEAPON_FLAMETHROWER: PressKey(KEY_FIRE, 40);
6634 else PressKey(KEY_FIRE);
6635 end;
6636 end;
6638 // Êîîðäèíàòû ñòâîëà:
6639 x1 := FObj.X + WEAPONPOINT[FDirection].X;
6640 y1 := FObj.Y + WEAPONPOINT[FDirection].Y;
6642 Target.UID := FTargetUID;
6644 ok := False;
6645 if Target.UID <> 0 then
6646 begin // Öåëü åñòü - íàñòðàèâàåì
6647 if (g_GetUIDType(Target.UID) = UID_PLAYER) and
6648 vsPlayer then
6649 begin // Èãðîê
6650 tpla := g_Player_Get(Target.UID);
6651 if tpla <> nil then
6652 with tpla do
6653 begin
6654 if (@FObj) <> nil then
6655 begin
6656 Target.X := FObj.X;
6657 Target.Y := FObj.Y;
6658 end;
6659 end;
6661 Target.cX := Target.X + PLAYER_RECT_CX;
6662 Target.cY := Target.Y + PLAYER_RECT_CY;
6663 Target.Rect := PLAYER_RECT;
6664 Target.Visible := g_TraceVector(x1, y1, Target.cX, Target.cY);
6665 Target.Line := (y1+4 < Target.Y+PLAYER_RECT.Y+PLAYER_RECT.Height) and
6666 (y1-4 > Target.Y+PLAYER_RECT.Y);
6667 Target.IsPlayer := True;
6668 ok := True;
6669 end
6670 else
6671 if (g_GetUIDType(Target.UID) = UID_MONSTER) and
6672 vsMonster then
6673 begin // Ìîíñòð
6674 mon := g_Monsters_ByUID(Target.UID);
6675 if mon <> nil then
6676 begin
6677 Target.X := mon.Obj.X;
6678 Target.Y := mon.Obj.Y;
6680 Target.cX := Target.X + mon.Obj.Rect.X + (mon.Obj.Rect.Width div 2);
6681 Target.cY := Target.Y + mon.Obj.Rect.Y + (mon.Obj.Rect.Height div 2);
6682 Target.Rect := mon.Obj.Rect;
6683 Target.Visible := g_TraceVector(x1, y1, Target.cX, Target.cY);
6684 Target.Line := (y1+4 < Target.Y + mon.Obj.Rect.Y + mon.Obj.Rect.Height) and
6685 (y1-4 > Target.Y + mon.Obj.Rect.Y);
6686 Target.IsPlayer := False;
6687 ok := True;
6688 end;
6689 end;
6690 end;
6692 if not ok then
6693 begin // Öåëè íåò - îáíóëÿåì
6694 Target.X := 0;
6695 Target.Y := 0;
6696 Target.cX := 0;
6697 Target.cY := 0;
6698 Target.Visible := False;
6699 Target.Line := False;
6700 Target.IsPlayer := False;
6701 end;
6703 targets := nil;
6705 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6706 if (not Target.Line) or (not Target.Visible) then
6707 begin
6708 // Èãðîêè:
6709 if vsPlayer then
6710 for a := 0 to High(gPlayers) do
6711 if (gPlayers[a] <> nil) and (gPlayers[a].alive) and
6712 (gPlayers[a].FUID <> FUID) and
6713 (not SameTeam(FUID, gPlayers[a].FUID)) and
6714 (not gPlayers[a].NoTarget) and
6715 (gPlayers[a].FMegaRulez[MR_INVIS] < gTime) then
6716 begin
6717 if not TargetOnScreen(gPlayers[a].FObj.X + PLAYER_RECT.X,
6718 gPlayers[a].FObj.Y + PLAYER_RECT.Y) then
6719 Continue;
6721 x2 := gPlayers[a].FObj.X + PLAYER_RECT_CX;
6722 y2 := gPlayers[a].FObj.Y + PLAYER_RECT_CY;
6724 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6725 if g_TraceVector(x1, y1, x2, y2) then
6726 begin
6727 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6728 SetLength(targets, Length(targets)+1);
6729 with targets[High(targets)] do
6730 begin
6731 UID := gPlayers[a].FUID;
6732 X := gPlayers[a].FObj.X;
6733 Y := gPlayers[a].FObj.Y;
6734 cX := x2;
6735 cY := y2;
6736 Rect := PLAYER_RECT;
6737 Dist := g_PatchLength(x1, y1, x2, y2);
6738 Line := (y1+4 < Target.Y+PLAYER_RECT.Y+PLAYER_RECT.Height) and
6739 (y1-4 > Target.Y+PLAYER_RECT.Y);
6740 Visible := True;
6741 IsPlayer := True;
6742 end;
6743 end;
6744 end;
6746 // Ìîíñòðû:
6747 if vsMonster then g_Mons_ForEach(monsUpdate);
6748 end;
6750 // Åñëè åñòü âîçìîæíûå öåëè:
6751 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6752 if targets <> nil then
6753 begin
6754 // Âûáèðàåì íàèëó÷øóþ öåëü:
6755 BestTarget := targets[0];
6756 if Length(targets) > 1 then
6757 for a := 1 to High(targets) do
6758 if Compare(BestTarget, targets[a]) = 1 then
6759 BestTarget := targets[a];
6761 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6762 if ((not Target.Visible) and BestTarget.Visible and (Target.UID <> BestTarget.UID)) or
6763 ((not Target.Line) and BestTarget.Line and BestTarget.Visible) then
6764 begin
6765 Target := BestTarget;
6767 if (Healthy() = 3) or ((Healthy() = 2)) then
6768 begin // Åñëè çäîðîâû - äîãîíÿåì
6769 if ((RunDirection() = TDirection.D_LEFT) and (Target.X > FObj.X)) then
6770 SetAIFlag('GORIGHT', '1');
6771 if ((RunDirection() = TDirection.D_RIGHT) and (Target.X < FObj.X)) then
6772 SetAIFlag('GOLEFT', '1');
6773 end
6774 else
6775 begin // Åñëè ïîáèòû - óáåãàåì
6776 if ((RunDirection() = TDirection.D_LEFT) and (Target.X < FObj.X)) then
6777 SetAIFlag('GORIGHT', '1');
6778 if ((RunDirection() = TDirection.D_RIGHT) and (Target.X > FObj.X)) then
6779 SetAIFlag('GOLEFT', '1');
6780 end;
6782 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6783 SelectWeapon(Abs(x1-Target.cX));
6784 end;
6785 end;
6787 // Åñëè åñòü öåëü:
6788 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6789 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6790 if Target.UID <> 0 then
6791 begin
6792 if not TargetOnScreen(Target.X + Target.Rect.X,
6793 Target.Y + Target.Rect.Y) then
6794 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6795 if (Healthy() = 3) or ((Healthy() = 2)) then
6796 begin // Åñëè çäîðîâû - äîãîíÿåì
6797 if ((RunDirection() = TDirection.D_LEFT) and (Target.X > FObj.X)) then
6798 SetAIFlag('GORIGHT', '1');
6799 if ((RunDirection() = TDirection.D_RIGHT) and (Target.X < FObj.X)) then
6800 SetAIFlag('GOLEFT', '1');
6801 end
6802 else
6803 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6804 Target.UID := 0;
6805 if ((RunDirection() = TDirection.D_LEFT) and (Target.X < FObj.X)) then
6806 SetAIFlag('GORIGHT', '1');
6807 if ((RunDirection() = TDirection.D_RIGHT) and (Target.X > FObj.X)) then
6808 SetAIFlag('GOLEFT', '1');
6809 end;
6810 end
6811 else
6812 begin // Öåëü ïîêà íà "ýêðàíå"
6813 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
6814 if g_TraceVector(x1, y1, Target.cX, Target.cY) then
6815 FLastVisible := gTime;
6816 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
6817 if (Abs(FObj.Y-Target.Y) <= 128) then
6818 begin
6819 if ((RunDirection() = TDirection.D_LEFT) and (Target.X > FObj.X)) then
6820 SetAIFlag('GORIGHT', '1');
6821 if ((RunDirection() = TDirection.D_RIGHT) and (Target.X < FObj.X)) then
6822 SetAIFlag('GOLEFT', '1');
6823 end;
6824 end;
6826 // Âûáèðàåì óãîë ââåðõ:
6827 if FDirection = TDirection.D_LEFT then
6828 angle := ANGLE_LEFTUP
6829 else
6830 angle := ANGLE_RIGHTUP;
6832 firew := Trunc(Cos(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
6833 fireh := Trunc(Sin(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
6835 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6836 if g_CollideLine(x1, y1, x1+firew, y1+fireh,
6837 Target.X+Target.Rect.X+GetInterval(FDifficult.DiagPrecision, 128), //96
6838 Target.Y+Target.Rect.Y+GetInterval(FDifficult.DiagPrecision, 128),
6839 Target.Rect.Width, Target.Rect.Height) and
6840 g_TraceVector(x1, y1, Target.cX, Target.cY) then
6841 begin // òî íóæíî ñòðåëÿòü ââåðõ
6842 SetAIFlag('NEEDFIRE', '1');
6843 SetAIFlag('NEEDSEEUP', '1');
6844 end;
6846 // Âûáèðàåì óãîë âíèç:
6847 if FDirection = TDirection.D_LEFT then
6848 angle := ANGLE_LEFTDOWN
6849 else
6850 angle := ANGLE_RIGHTDOWN;
6852 firew := Trunc(Cos(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
6853 fireh := Trunc(Sin(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
6855 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6856 if g_CollideLine(x1, y1, x1+firew, y1+fireh,
6857 Target.X+Target.Rect.X+GetInterval(FDifficult.DiagPrecision, 128),
6858 Target.Y+Target.Rect.Y+GetInterval(FDifficult.DiagPrecision, 128),
6859 Target.Rect.Width, Target.Rect.Height) and
6860 g_TraceVector(x1, y1, Target.cX, Target.cY) then
6861 begin // òî íóæíî ñòðåëÿòü âíèç
6862 SetAIFlag('NEEDFIRE', '1');
6863 SetAIFlag('NEEDSEEDOWN', '1');
6864 end;
6866 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
6867 if Target.Visible and
6868 (y1+4 < Target.Y+Target.Rect.Y+Target.Rect.Height) and
6869 (y1-4 > Target.Y+Target.Rect.Y) then
6870 begin
6871 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
6872 if ((FDirection = TDirection.D_LEFT) and (Target.X < FObj.X)) or
6873 ((FDirection = TDirection.D_RIGHT) and (Target.X > FObj.X)) then
6874 begin // òî íóæíî ñòðåëÿòü âïåðåä
6875 SetAIFlag('NEEDFIRE', '1');
6876 SetAIFlag('NEEDSEEDOWN', '');
6877 SetAIFlag('NEEDSEEUP', '');
6878 end;
6879 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
6880 if Abs(FObj.X-Target.X) < Trunc(gPlayerScreenSize.X*0.75) then
6881 if GetRnd(FDifficult.CloseJump) then
6882 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
6883 if Abs(FObj.X-Target.X) < 128 then
6884 a := 4
6885 else
6886 a := 30;
6887 if Random(a) = 0 then
6888 SetAIFlag('NEEDJUMP', '1');
6889 end;
6890 end;
6892 // Åñëè öåëü âñå åùå åñòü:
6893 if Target.UID <> 0 then
6894 if gTime-FLastVisible > 2000 then // Åñëè âèäåëè äàâíî
6895 Target.UID := 0 // òî çàáûòü öåëü
6896 else // Åñëè âèäåëè íåäàâíî
6897 begin // íî öåëü óáèëè
6898 if Target.IsPlayer then
6899 begin // Öåëü - èãðîê
6900 pla := g_Player_Get(Target.UID);
6901 if (pla = nil) or (not pla.alive) or pla.NoTarget or
6902 (pla.FMegaRulez[MR_INVIS] >= gTime) then
6903 Target.UID := 0; // òî çàáûòü öåëü
6904 end
6905 else
6906 begin // Öåëü - ìîíñòð
6907 mon := g_Monsters_ByUID(Target.UID);
6908 if (mon = nil) or (not mon.alive) then
6909 Target.UID := 0; // òî çàáûòü öåëü
6910 end;
6911 end;
6912 end; // if Target.UID <> 0
6914 FTargetUID := Target.UID;
6916 // Åñëè âîçìîæíûõ öåëåé íåò:
6917 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
6918 if targets = nil then
6919 if GetAIFlag('ATTACKLEFT') <> '' then
6920 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
6921 RemoveAIFlag('ATTACKLEFT');
6923 SetAIFlag('NEEDJUMP', '1');
6925 if RunDirection() = TDirection.D_RIGHT then
6926 begin // Èäåì íå â òó ñòîðîíó
6927 if (Healthy() > 1) and GetRnd(FDifficult.InvisFire) then
6928 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
6929 SetAIFlag('NEEDFIRE', '1');
6930 SetAIFlag('GOLEFT', '1');
6931 end;
6932 end
6933 else
6934 begin // Èäåì â íóæíóþ ñòîðîíó
6935 if GetRnd(FDifficult.InvisFire) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6936 SetAIFlag('NEEDFIRE', '1');
6937 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6938 SetAIFlag('GORIGHT', '1');
6939 end;
6940 end
6941 else
6942 if GetAIFlag('ATTACKRIGHT') <> '' then
6943 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
6944 RemoveAIFlag('ATTACKRIGHT');
6946 SetAIFlag('NEEDJUMP', '1');
6948 if RunDirection() = TDirection.D_LEFT then
6949 begin // Èäåì íå â òó ñòîðîíó
6950 if (Healthy() > 1) and GetRnd(FDifficult.InvisFire) then
6951 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
6952 SetAIFlag('NEEDFIRE', '1');
6953 SetAIFlag('GORIGHT', '1');
6954 end;
6955 end
6956 else
6957 begin
6958 if GetRnd(FDifficult.InvisFire) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6959 SetAIFlag('NEEDFIRE', '1');
6960 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6961 SetAIFlag('GOLEFT', '1');
6962 end;
6963 end;
6965 //HACK! (does it belongs there?)
6966 RealizeCurrentWeapon();
6968 // Åñëè åñòü âîçìîæíûå öåëè:
6969 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
6970 if (targets <> nil) and (GetAIFlag('NEEDFIRE') <> '') then
6971 for a := 0 to High(targets) do
6972 begin
6973 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
6974 if GetRnd(FDifficult.DiagFire) then
6975 begin
6976 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
6977 if FDirection = TDirection.D_LEFT then
6978 angle := ANGLE_LEFTUP
6979 else
6980 angle := ANGLE_RIGHTUP;
6982 firew := Trunc(Cos(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
6983 fireh := Trunc(Sin(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
6985 if g_CollideLine(x1, y1, x1+firew, y1+fireh,
6986 targets[a].X+targets[a].Rect.X+GetInterval(FDifficult.DiagPrecision, 128),
6987 targets[a].Y+targets[a].Rect.Y+GetInterval(FDifficult.DiagPrecision, 128),
6988 targets[a].Rect.Width, targets[a].Rect.Height) and
6989 g_TraceVector(x1, y1, targets[a].cX, targets[a].cY) then
6990 begin
6991 SetAIFlag('NEEDFIRE', '1');
6992 SetAIFlag('NEEDSEEUP', '1');
6993 end;
6995 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
6996 if FDirection = TDirection.D_LEFT then
6997 angle := ANGLE_LEFTDOWN
6998 else
6999 angle := ANGLE_RIGHTDOWN;
7001 firew := Trunc(Cos(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
7002 fireh := Trunc(Sin(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
7004 if g_CollideLine(x1, y1, x1+firew, y1+fireh,
7005 targets[a].X+targets[a].Rect.X+GetInterval(FDifficult.DiagPrecision, 128),
7006 targets[a].Y+targets[a].Rect.Y+GetInterval(FDifficult.DiagPrecision, 128),
7007 targets[a].Rect.Width, targets[a].Rect.Height) and
7008 g_TraceVector(x1, y1, targets[a].cX, targets[a].cY) then
7009 begin
7010 SetAIFlag('NEEDFIRE', '1');
7011 SetAIFlag('NEEDSEEDOWN', '1');
7012 end;
7013 end;
7015 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
7016 if targets[a].Line and targets[a].Visible and
7017 (((FDirection = TDirection.D_LEFT) and (targets[a].X < FObj.X)) or
7018 ((FDirection = TDirection.D_RIGHT) and (targets[a].X > FObj.X))) then
7019 begin
7020 SetAIFlag('NEEDFIRE', '1');
7021 Break;
7022 end;
7023 end;
7025 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
7026 if g_Weapon_Danger(FUID, FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y,
7027 PLAYER_RECT.Width, PLAYER_RECT.Height,
7028 40+GetInterval(FDifficult.Cover, 40)) then
7029 SetAIFlag('NEEDJUMP', '1');
7031 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
7032 ammo := GetAmmoByWeapon(FCurrWeap);
7033 if ((FCurrWeap = WEAPON_SHOTGUN2) and (ammo < 2)) or
7034 ((FCurrWeap = WEAPON_BFG) and (ammo < 40)) or
7035 (ammo = 0) then
7036 SetAIFlag('SELECTWEAPON', '1');
7038 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
7039 if GetAIFlag('SELECTWEAPON') = '1' then
7040 begin
7041 SelectWeapon(-1);
7042 RemoveAIFlag('SELECTWEAPON');
7043 end;
7044 end;
7046 procedure TBot.Update();
7047 var
7048 EnableAI: Boolean;
7049 begin
7050 if not FAlive then
7051 begin // Respawn
7052 ReleaseKeys();
7053 PressKey(KEY_UP);
7054 end
7055 else
7056 begin
7057 EnableAI := True;
7059 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
7060 if (g_debug_BotAIOff = 1) and (Team = TEAM_RED) then
7061 EnableAI := False;
7062 if (g_debug_BotAIOff = 2) and (Team = TEAM_BLUE) then
7063 EnableAI := False;
7064 if g_debug_BotAIOff = 3 then
7065 EnableAI := False;
7067 if EnableAI then
7068 begin
7069 UpdateMove();
7070 UpdateCombat();
7071 end
7072 else
7073 begin
7074 RealizeCurrentWeapon();
7075 end;
7076 end;
7078 inherited Update();
7079 end;
7081 procedure TBot.ReleaseKey(Key: Byte);
7082 begin
7083 with FKeys[Key] do
7084 begin
7085 Pressed := False;
7086 Time := 0;
7087 end;
7088 end;
7090 function TBot.KeyPressed(Key: Word): Boolean;
7091 begin
7092 Result := FKeys[Key].Pressed;
7093 end;
7095 function TBot.GetAIFlag(aName: String20): String20;
7096 var
7097 a: Integer;
7098 begin
7099 Result := '';
7101 aName := LowerCase(aName);
7103 if FAIFlags <> nil then
7104 for a := 0 to High(FAIFlags) do
7105 if LowerCase(FAIFlags[a].Name) = aName then
7106 begin
7107 Result := FAIFlags[a].Value;
7108 Break;
7109 end;
7110 end;
7112 procedure TBot.RemoveAIFlag(aName: String20);
7113 var
7114 a, b: Integer;
7115 begin
7116 if FAIFlags = nil then Exit;
7118 aName := LowerCase(aName);
7120 for a := 0 to High(FAIFlags) do
7121 if LowerCase(FAIFlags[a].Name) = aName then
7122 begin
7123 if a <> High(FAIFlags) then
7124 for b := a to High(FAIFlags)-1 do
7125 FAIFlags[b] := FAIFlags[b+1];
7127 SetLength(FAIFlags, Length(FAIFlags)-1);
7128 Break;
7129 end;
7130 end;
7132 procedure TBot.SetAIFlag(aName, fValue: String20);
7133 var
7134 a: Integer;
7135 ok: Boolean;
7136 begin
7137 a := 0;
7138 ok := False;
7140 aName := LowerCase(aName);
7142 if FAIFlags <> nil then
7143 for a := 0 to High(FAIFlags) do
7144 if LowerCase(FAIFlags[a].Name) = aName then
7145 begin
7146 ok := True;
7147 Break;
7148 end;
7150 if ok then FAIFlags[a].Value := fValue
7151 else
7152 begin
7153 SetLength(FAIFlags, Length(FAIFlags)+1);
7154 with FAIFlags[High(FAIFlags)] do
7155 begin
7156 Name := aName;
7157 Value := fValue;
7158 end;
7159 end;
7160 end;
7162 procedure TBot.UpdateMove;
7164 procedure GoLeft(Time: Word = 1);
7165 begin
7166 ReleaseKey(KEY_LEFT);
7167 ReleaseKey(KEY_RIGHT);
7168 PressKey(KEY_LEFT, Time);
7169 SetDirection(TDirection.D_LEFT);
7170 end;
7172 procedure GoRight(Time: Word = 1);
7173 begin
7174 ReleaseKey(KEY_LEFT);
7175 ReleaseKey(KEY_RIGHT);
7176 PressKey(KEY_RIGHT, Time);
7177 SetDirection(TDirection.D_RIGHT);
7178 end;
7180 function Rnd(a: Word): Boolean;
7181 begin
7182 Result := Random(a) = 0;
7183 end;
7185 procedure Turn(Time: Word = 1200);
7186 begin
7187 if RunDirection() = TDirection.D_LEFT then GoRight(Time) else GoLeft(Time);
7188 end;
7190 procedure Stop();
7191 begin
7192 ReleaseKey(KEY_LEFT);
7193 ReleaseKey(KEY_RIGHT);
7194 end;
7196 function CanRunLeft(): Boolean;
7197 begin
7198 Result := not CollideLevel(-1, 0);
7199 end;
7201 function CanRunRight(): Boolean;
7202 begin
7203 Result := not CollideLevel(1, 0);
7204 end;
7206 function CanRun(): Boolean;
7207 begin
7208 if RunDirection() = TDirection.D_LEFT then Result := CanRunLeft() else Result := CanRunRight();
7209 end;
7211 procedure Jump(Time: Word = 30);
7212 begin
7213 PressKey(KEY_JUMP, Time);
7214 end;
7216 function NearHole(): Boolean;
7217 var
7218 x, sx: Integer;
7219 begin
7220 { TODO 5 : Ëåñòíèöû }
7221 sx := IfThen(RunDirection() = TDirection.D_LEFT, -1, 1);
7222 for x := 1 to PLAYER_RECT.Width do
7223 if (not StayOnStep(x*sx, 0)) and
7224 (not CollideLevel(x*sx, PLAYER_RECT.Height)) and
7225 (not CollideLevel(x*sx, PLAYER_RECT.Height*2)) then
7226 begin
7227 Result := True;
7228 Exit;
7229 end;
7231 Result := False;
7232 end;
7234 function BorderHole(): Boolean;
7235 var
7236 x, sx, xx: Integer;
7237 begin
7238 { TODO 5 : Ëåñòíèöû }
7239 sx := IfThen(RunDirection() = TDirection.D_LEFT, -1, 1);
7240 for x := 1 to PLAYER_RECT.Width do
7241 if (not StayOnStep(x*sx, 0)) and
7242 (not CollideLevel(x*sx, PLAYER_RECT.Height)) and
7243 (not CollideLevel(x*sx, PLAYER_RECT.Height*2)) then
7244 begin
7245 for xx := x to x+32 do
7246 if CollideLevel(xx*sx, PLAYER_RECT.Height) then
7247 begin
7248 Result := True;
7249 Exit;
7250 end;
7251 end;
7253 Result := False;
7254 end;
7256 function NearDeepHole(): Boolean;
7257 var
7258 x, sx, y: Integer;
7259 begin
7260 Result := False;
7262 sx := IfThen(RunDirection() = TDirection.D_LEFT, -1, 1);
7263 y := 3;
7265 for x := 1 to PLAYER_RECT.Width do
7266 if (not StayOnStep(x*sx, 0)) and
7267 (not CollideLevel(x*sx, PLAYER_RECT.Height)) and
7268 (not CollideLevel(x*sx, PLAYER_RECT.Height*2)) then
7269 begin
7270 while FObj.Y+y*PLAYER_RECT.Height < gMapInfo.Height do
7271 begin
7272 if CollideLevel(x*sx, PLAYER_RECT.Height*y) then Exit;
7273 y := y+1;
7274 end;
7276 Result := True;
7277 end else Result := False;
7278 end;
7280 function OverDeepHole(): Boolean;
7281 var
7282 y: Integer;
7283 begin
7284 Result := False;
7286 y := 1;
7287 while FObj.Y+y*PLAYER_RECT.Height < gMapInfo.Height do
7288 begin
7289 if CollideLevel(0, PLAYER_RECT.Height*y) then Exit;
7290 y := y+1;
7291 end;
7293 Result := True;
7294 end;
7296 function OnGround(): Boolean;
7297 begin
7298 Result := StayOnStep(0, 0) or CollideLevel(0, 1);
7299 end;
7301 function OnLadder(): Boolean;
7302 begin
7303 Result := FullInStep(0, 0);
7304 end;
7306 function BelowLadder(): Boolean;
7307 begin
7308 Result := (FullInStep(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -PLAYER_RECT.Height) and
7309 not CollideLevel(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -PLAYER_RECT.Height)) or
7310 (FullInStep(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -BOT_MAXJUMP) and
7311 not CollideLevel(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -BOT_MAXJUMP));
7312 end;
7314 function BelowLiftUp(): Boolean;
7315 begin
7316 Result := ((FullInLift(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -PLAYER_RECT.Height) = -1) and
7317 not CollideLevel(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -PLAYER_RECT.Height)) or
7318 ((FullInLift(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -BOT_MAXJUMP) = -1) and
7319 not CollideLevel(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -BOT_MAXJUMP));
7320 end;
7322 function OnTopLift(): Boolean;
7323 begin
7324 Result := (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7325 end;
7327 function CanJumpOver(): Boolean;
7328 var
7329 sx, y: Integer;
7330 begin
7331 sx := IfThen(RunDirection() = TDirection.D_LEFT, -1, 1);
7333 Result := False;
7335 if not CollideLevel(sx, 0) then Exit;
7337 for y := 1 to BOT_MAXJUMP do
7338 if CollideLevel(0, -y) then Exit else
7339 if not CollideLevel(sx, -y) then
7340 begin
7341 Result := True;
7342 Exit;
7343 end;
7344 end;
7346 function CanJumpUp(Dist: ShortInt): Boolean;
7347 var
7348 y, yy: Integer;
7349 c: Boolean;
7350 begin
7351 Result := False;
7353 if CollideLevel(Dist, 0) then Exit;
7355 c := False;
7356 for y := 0 to BOT_MAXJUMP do
7357 if CollideLevel(Dist, -y) then
7358 begin
7359 c := True;
7360 Break;
7361 end;
7363 if not c then Exit;
7365 c := False;
7366 for yy := y+1 to BOT_MAXJUMP do
7367 if not CollideLevel(Dist, -yy) then
7368 begin
7369 c := True;
7370 Break;
7371 end;
7373 if not c then Exit;
7375 c := False;
7376 for y := 0 to BOT_MAXJUMP do
7377 if CollideLevel(0, -y) then
7378 begin
7379 c := True;
7380 Break;
7381 end;
7383 if c then Exit;
7385 if y < yy then Exit;
7387 Result := True;
7388 end;
7390 function IsSafeTrigger(): Boolean;
7391 var
7392 a: Integer;
7393 begin
7394 Result := True;
7395 if gTriggers = nil then
7396 Exit;
7397 for a := 0 to High(gTriggers) do
7398 if Collide(gTriggers[a].X,
7399 gTriggers[a].Y,
7400 gTriggers[a].Width,
7401 gTriggers[a].Height) and
7402 (gTriggers[a].TriggerType in [TRIGGER_EXIT, TRIGGER_CLOSEDOOR,
7403 TRIGGER_CLOSETRAP, TRIGGER_TRAP,
7404 TRIGGER_PRESS, TRIGGER_ON, TRIGGER_OFF,
7405 TRIGGER_ONOFF, TRIGGER_SPAWNMONSTER,
7406 TRIGGER_DAMAGE, TRIGGER_SHOT]) then
7407 Result := False;
7408 end;
7410 begin
7411 // Âîçìîæíî, íàæèìàåì êíîïêó:
7412 if Rnd(16) and IsSafeTrigger() then
7413 PressKey(KEY_OPEN);
7415 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7416 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7417 begin
7418 ReleaseKey(KEY_LEFT);
7419 ReleaseKey(KEY_RIGHT);
7420 Jump();
7421 end;
7423 // Èäåì âëåâî, åñëè íàäî áûëî:
7424 if GetAIFlag('GOLEFT') <> '' then
7425 begin
7426 RemoveAIFlag('GOLEFT');
7427 if CanRunLeft() then
7428 GoLeft(360);
7429 end;
7431 // Èäåì âïðàâî, åñëè íàäî áûëî:
7432 if GetAIFlag('GORIGHT') <> '' then
7433 begin
7434 RemoveAIFlag('GORIGHT');
7435 if CanRunRight() then
7436 GoRight(360);
7437 end;
7439 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7440 if FObj.X < -32 then
7441 GoRight(360)
7442 else
7443 if FObj.X+32 > gMapInfo.Width then
7444 GoLeft(360);
7446 // Ïðûãàåì, åñëè íàäî áûëî:
7447 if GetAIFlag('NEEDJUMP') <> '' then
7448 begin
7449 Jump(0);
7450 RemoveAIFlag('NEEDJUMP');
7451 end;
7453 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7454 if GetAIFlag('NEEDSEEUP') <> '' then
7455 begin
7456 ReleaseKey(KEY_UP);
7457 ReleaseKey(KEY_DOWN);
7458 PressKey(KEY_UP, 20);
7459 RemoveAIFlag('NEEDSEEUP');
7460 end;
7462 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7463 if GetAIFlag('NEEDSEEDOWN') <> '' then
7464 begin
7465 ReleaseKey(KEY_UP);
7466 ReleaseKey(KEY_DOWN);
7467 PressKey(KEY_DOWN, 20);
7468 RemoveAIFlag('NEEDSEEDOWN');
7469 end;
7471 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7472 if GetAIFlag('GOINHOLE') <> '' then
7473 if not OnGround() then
7474 begin
7475 ReleaseKey(KEY_LEFT);
7476 ReleaseKey(KEY_RIGHT);
7477 RemoveAIFlag('GOINHOLE');
7478 SetAIFlag('FALLINHOLE', '1');
7479 end;
7481 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7482 if GetAIFlag('FALLINHOLE') <> '' then
7483 if OnGround() then
7484 RemoveAIFlag('FALLINHOLE');
7486 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7487 if not (KeyPressed(KEY_LEFT) or KeyPressed(KEY_RIGHT)) then
7488 if GetAIFlag('FALLINHOLE') = '' then
7489 if (not OnLadder()) or (FObj.Vel.Y >= 0) or (OnTopLift()) then
7490 if Rnd(2) then
7491 GoLeft(360)
7492 else
7493 GoRight(360);
7495 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7496 if OnGround() and
7497 CanJumpUp(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*32) and
7498 Rnd(8) then
7499 Jump();
7501 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7502 if OnGround() and NearHole() then
7503 if NearDeepHole() then // Åñëè ýòî áåçäíà
7504 case Random(6) of
7505 0..3: Turn(); // Áåæèì îáðàòíî
7506 4: Jump(); // Ïðûãàåì
7507 5: begin // Ïðûãàåì îáðàòíî
7508 Turn();
7509 Jump();
7510 end;
7511 end
7512 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7513 if GetAIFlag('GOINHOLE') = '' then
7514 case Random(6) of
7515 0: Turn(); // Íå íóæíî òóäà
7516 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7517 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7518 if BorderHole() then
7519 SetAIFlag('GOINHOLE', '1');
7520 end;
7522 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7523 if (not CanRun()) and OnGround() then
7524 begin
7525 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7526 if CanJumpOver() or OnLadder() then
7527 Jump()
7528 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7529 if Random(2) = 0 then
7530 begin
7531 if IsSafeTrigger() then
7532 PressKey(KEY_OPEN);
7533 end else
7534 Turn();
7535 end;
7537 // Îñòàëîñü ìàëî âîçäóõà:
7538 if FAir < 36 * 2 then
7539 Jump(20);
7541 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7542 if (FMegaRulez[MR_SUIT] < gTime) and ((FLastHit = HIT_ACID) or (Healthy() <= 1)) then
7543 if BodyInAcid(0, 0) then
7544 Jump();
7545 end;
7547 function TBot.FullInStep(XInc, YInc: Integer): Boolean;
7548 begin
7549 Result := g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc,
7550 PLAYER_RECT.Width, PLAYER_RECT.Height, PANEL_STEP, False);
7551 end;
7553 {function TBot.NeedItem(Item: Byte): Byte;
7554 begin
7555 Result := 4;
7556 end;}
7558 procedure TBot.SelectWeapon(Dist: Integer);
7559 var
7560 a: Integer;
7562 function HaveAmmo(weapon: Byte): Boolean;
7563 begin
7564 case weapon of
7565 WEAPON_PISTOL: Result := FAmmo[A_BULLETS] >= 1;
7566 WEAPON_SHOTGUN1: Result := FAmmo[A_SHELLS] >= 1;
7567 WEAPON_SHOTGUN2: Result := FAmmo[A_SHELLS] >= 2;
7568 WEAPON_CHAINGUN: Result := FAmmo[A_BULLETS] >= 10;
7569 WEAPON_ROCKETLAUNCHER: Result := FAmmo[A_ROCKETS] >= 1;
7570 WEAPON_PLASMA: Result := FAmmo[A_CELLS] >= 10;
7571 WEAPON_BFG: Result := FAmmo[A_CELLS] >= 40;
7572 WEAPON_SUPERPULEMET: Result := FAmmo[A_SHELLS] >= 1;
7573 WEAPON_FLAMETHROWER: Result := FAmmo[A_FUEL] >= 1;
7574 else Result := True;
7575 end;
7576 end;
7578 begin
7579 if Dist = -1 then Dist := BOT_LONGDIST;
7581 if Dist > BOT_LONGDIST then
7582 begin // Äàëüíèé áîé
7583 for a := 0 to 9 do
7584 if FWeapon[FDifficult.WeaponPrior[a]] and HaveAmmo(FDifficult.WeaponPrior[a]) then
7585 begin
7586 FSelectedWeapon := FDifficult.WeaponPrior[a];
7587 Break;
7588 end;
7589 end
7590 else //if Dist > BOT_UNSAFEDIST then
7591 begin // Áëèæíèé áîé
7592 for a := 0 to 9 do
7593 if FWeapon[FDifficult.CloseWeaponPrior[a]] and HaveAmmo(FDifficult.CloseWeaponPrior[a]) then
7594 begin
7595 FSelectedWeapon := FDifficult.CloseWeaponPrior[a];
7596 Break;
7597 end;
7598 end;
7599 { else
7600 begin
7601 for a := 0 to 9 do
7602 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7603 begin
7604 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7605 Break;
7606 end;
7607 end;}
7608 end;
7610 function TBot.PickItem(ItemType: Byte; force: Boolean; var remove: Boolean): Boolean;
7611 begin
7612 Result := inherited PickItem(ItemType, force, remove);
7614 if Result then SetAIFlag('SELECTWEAPON', '1');
7615 end;
7617 function TBot.Heal(value: Word; Soft: Boolean): Boolean;
7618 begin
7619 Result := inherited Heal(value, Soft);
7620 end;
7622 function TBot.Healthy(): Byte;
7623 begin
7624 if FMegaRulez[MR_INVUL] >= gTime then Result := 3
7625 else if (FHealth > 80) or ((FHealth > 50) and (FArmor > 20)) then Result := 3
7626 else if (FHealth > 50) then Result := 2
7627 else if (FHealth > 20) then Result := 1
7628 else Result := 0;
7629 end;
7631 function TBot.TargetOnScreen(TX, TY: Integer): Boolean;
7632 begin
7633 Result := (Abs(FObj.X-TX) <= Trunc(gPlayerScreenSize.X*0.6)) and
7634 (Abs(FObj.Y-TY) <= Trunc(gPlayerScreenSize.Y*0.6));
7635 end;
7637 procedure TBot.OnDamage(Angle: SmallInt);
7638 var
7639 pla: TPlayer;
7640 mon: TMonster;
7641 ok: Boolean;
7642 begin
7643 inherited;
7645 if (Angle = 0) or (Angle = 180) then
7646 begin
7647 ok := False;
7648 if (g_GetUIDType(FLastSpawnerUID) = UID_PLAYER) and
7649 LongBool(gGameSettings.Options and GAME_OPTION_BOTVSPLAYER) then
7650 begin // Èãðîê
7651 pla := g_Player_Get(FLastSpawnerUID);
7652 ok := not TargetOnScreen(pla.FObj.X + PLAYER_RECT.X,
7653 pla.FObj.Y + PLAYER_RECT.Y);
7654 end
7655 else
7656 if (g_GetUIDType(FLastSpawnerUID) = UID_MONSTER) and
7657 LongBool(gGameSettings.Options and GAME_OPTION_BOTVSMONSTER) then
7658 begin // Ìîíñòð
7659 mon := g_Monsters_ByUID(FLastSpawnerUID);
7660 ok := not TargetOnScreen(mon.Obj.X + mon.Obj.Rect.X,
7661 mon.Obj.Y + mon.Obj.Rect.Y);
7662 end;
7664 if ok then
7665 if Angle = 0 then
7666 SetAIFlag('ATTACKLEFT', '1')
7667 else
7668 SetAIFlag('ATTACKRIGHT', '1');
7669 end;
7670 end;
7672 function TBot.RunDirection(): TDirection;
7673 begin
7674 if Abs(Vel.X) >= 1 then
7675 begin
7676 if Vel.X > 0 then Result := TDirection.D_RIGHT else Result := TDirection.D_LEFT;
7677 end else
7678 Result := FDirection;
7679 end;
7681 function TBot.GetRnd(a: Byte): Boolean;
7682 begin
7683 if a = 0 then Result := False
7684 else if a = 255 then Result := True
7685 else Result := Random(256) > 255-a;
7686 end;
7688 function TBot.GetInterval(a: Byte; radius: SmallInt): SmallInt;
7689 begin
7690 Result := Round((255-a)/255*radius*(Random(2)-1));
7691 end;
7694 procedure TDifficult.save (st: TStream);
7695 begin
7696 utils.writeInt(st, Byte(DiagFire));
7697 utils.writeInt(st, Byte(InvisFire));
7698 utils.writeInt(st, Byte(DiagPrecision));
7699 utils.writeInt(st, Byte(FlyPrecision));
7700 utils.writeInt(st, Byte(Cover));
7701 utils.writeInt(st, Byte(CloseJump));
7702 st.WriteBuffer(WeaponPrior[Low(WeaponPrior)], sizeof(WeaponPrior));
7703 st.WriteBuffer(CloseWeaponPrior[Low(CloseWeaponPrior)], sizeof(CloseWeaponPrior));
7704 end;
7706 procedure TDifficult.load (st: TStream);
7707 begin
7708 DiagFire := utils.readByte(st);
7709 InvisFire := utils.readByte(st);
7710 DiagPrecision := utils.readByte(st);
7711 FlyPrecision := utils.readByte(st);
7712 Cover := utils.readByte(st);
7713 CloseJump := utils.readByte(st);
7714 st.ReadBuffer(WeaponPrior[Low(WeaponPrior)], sizeof(WeaponPrior));
7715 st.ReadBuffer(CloseWeaponPrior[Low(CloseWeaponPrior)], sizeof(CloseWeaponPrior));
7716 end;
7719 procedure TBot.SaveState (st: TStream);
7720 var
7721 i: Integer;
7722 dw: Integer;
7723 begin
7724 inherited SaveState(st);
7725 utils.writeSign(st, 'BOT0');
7726 // Âûáðàííîå îðóæèå
7727 utils.writeInt(st, Byte(FSelectedWeapon));
7728 // UID öåëè
7729 utils.writeInt(st, Word(FTargetUID));
7730 // Âðåìÿ ïîòåðè öåëè
7731 utils.writeInt(st, LongWord(FLastVisible));
7732 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7733 dw := Length(FAIFlags);
7734 utils.writeInt(st, LongInt(dw));
7735 // Ôëàãè ÈÈ
7736 for i := 0 to dw-1 do
7737 begin
7738 utils.writeStr(st, FAIFlags[i].Name, 20);
7739 utils.writeStr(st, FAIFlags[i].Value, 20);
7740 end;
7741 // Íàñòðîéêè ñëîæíîñòè
7742 FDifficult.save(st);
7743 end;
7746 procedure TBot.LoadState (st: TStream);
7747 var
7748 i: Integer;
7749 dw: Integer;
7750 begin
7751 inherited LoadState(st);
7752 if not utils.checkSign(st, 'BOT0') then raise XStreamError.Create('invalid bot signature');
7753 // Âûáðàííîå îðóæèå
7754 FSelectedWeapon := utils.readByte(st);
7755 // UID öåëè
7756 FTargetUID := utils.readWord(st);
7757 // Âðåìÿ ïîòåðè öåëè
7758 FLastVisible := utils.readLongWord(st);
7759 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7760 dw := utils.readLongInt(st);
7761 if (dw < 0) or (dw > 16384) then raise XStreamError.Create('invalid number of bot AI flags');
7762 SetLength(FAIFlags, dw);
7763 // Ôëàãè ÈÈ
7764 for i := 0 to dw-1 do
7765 begin
7766 FAIFlags[i].Name := utils.readStr(st, 20);
7767 FAIFlags[i].Value := utils.readStr(st, 20);
7768 end;
7769 // Íàñòðîéêè ñëîæíîñòè
7770 FDifficult.load(st);
7771 end;
7774 begin
7775 conRegVar('cheat_berserk_autoswitch', @gBerserkAutoswitch, 'autoswitch to fist when berserk pack taken', '', true, true);
7776 end.