DEADSOFTWARE

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