DEADSOFTWARE

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