DEADSOFTWARE

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