DEADSOFTWARE

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