DEADSOFTWARE

FreeBSD build fixes
[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 {$MODE DELPHI}
17 unit g_player;
19 interface
21 uses
22 e_graphics, g_playermodel, g_basic, g_textures,
23 g_weapons, g_phys, g_sound, g_saveload, MAPSTRUCT,
24 BinEditor, g_panel;
26 const
27 KEY_LEFT = 1;
28 KEY_RIGHT = 2;
29 KEY_UP = 3;
30 KEY_DOWN = 4;
31 KEY_FIRE = 5;
32 KEY_NEXTWEAPON = 6;
33 KEY_PREVWEAPON = 7;
34 KEY_OPEN = 8;
35 KEY_JUMP = 9;
36 KEY_CHAT = 10;
38 R_ITEM_BACKPACK = 0;
39 R_KEY_RED = 1;
40 R_KEY_GREEN = 2;
41 R_KEY_BLUE = 3;
42 R_BERSERK = 4;
44 MR_SUIT = 0;
45 MR_INVUL = 1;
46 MR_INVIS = 2;
47 MR_MAX = 2;
49 A_BULLETS = 0;
50 A_SHELLS = 1;
51 A_ROCKETS = 2;
52 A_CELLS = 3;
54 K_SIMPLEKILL = 0;
55 K_HARDKILL = 1;
56 K_EXTRAHARDKILL = 2;
57 K_FALLKILL = 3;
59 T_RESPAWN = 0;
60 T_SWITCH = 1;
61 T_USE = 2;
62 T_FLAGCAP = 3;
64 TEAM_NONE = 0;
65 TEAM_RED = 1;
66 TEAM_BLUE = 2;
67 TEAM_COOP = 3;
69 SHELL_BULLET = 0;
70 SHELL_SHELL = 1;
71 SHELL_DBLSHELL = 2;
73 ANGLE_NONE = Low(SmallInt);
75 CORPSE_STATE_REMOVEME = 0;
76 CORPSE_STATE_NORMAL = 1;
77 CORPSE_STATE_MESS = 2;
79 PLAYER_RECT: TRectWH = (X:15; Y:12; Width:34; Height:52);
80 PLAYER_RECT_CX = 15+(34 div 2);
81 PLAYER_RECT_CY = 12+(52 div 2);
82 PLAYER_CORPSERECT: TRectWH = (X:15; Y:48; Width:34; Height:16);
84 PLAYER_HP_SOFT = 100;
85 PLAYER_HP_LIMIT = 200;
86 PLAYER_AP_SOFT = 100;
87 PLAYER_AP_LIMIT = 200;
88 SUICIDE_DAMAGE = 112;
90 PLAYER1_DEF_COLOR: TRGB = (R:64; G:175; B:48);
91 PLAYER2_DEF_COLOR: TRGB = (R:96; G:96; B:96);
93 type
94 TPlayerStat = record
95 Ping: Word;
96 Loss: Byte;
97 Name: String;
98 Team: Byte;
99 Frags: SmallInt;
100 Deaths: SmallInt;
101 Lives: Byte;
102 Kills: Word;
103 Color: TRGB;
104 Spectator: Boolean;
105 end;
107 TPlayerStatArray = Array of TPlayerStat;
109 TPlayerSavedState = record
110 Health: Integer;
111 Armor: Integer;
112 Air: Integer;
113 JetFuel: Integer;
114 CurrWeap: Byte;
115 Ammo: Array [A_BULLETS..A_CELLS] of Word;
116 MaxAmmo: Array [A_BULLETS..A_CELLS] of Word;
117 Weapon: Array [WEAPON_KASTET..WEAPON_SUPERPULEMET] of Boolean;
118 Rulez: Set of R_ITEM_BACKPACK..R_BERSERK;
119 WaitRecall: Boolean;
120 end;
122 TKeyState = record
123 Pressed: Boolean;
124 Time: Word;
125 end;
127 TPlayer = class (TObject)
128 private
129 FIamBot: Boolean;
130 FUID: Word;
131 FName: String;
132 FTeam: Byte;
133 FLive: Boolean;
134 FSpawned: Boolean;
135 FDirection: TDirection;
136 FHealth: Integer;
137 FLives: Byte;
138 FArmor: Integer;
139 FAir: Integer;
140 FPain: Integer;
141 FPickup: Integer;
142 FKills: Integer;
143 FMonsterKills: Integer;
144 FFrags: Integer;
145 FFragCombo: Byte;
146 FLastFrag: LongWord;
147 FComboEvnt: Integer;
148 FDeath: Integer;
149 FCanJetpack: Boolean;
150 FJetFuel: Integer;
151 FFlag: Byte;
152 FSecrets: Integer;
153 FCurrWeap: Byte;
154 FBFGFireCounter: SmallInt;
155 FLastSpawnerUID: Word;
156 FLastHit: Byte;
157 FObj: TObj;
158 FXTo, FYTo: Integer;
159 FSpectatePlayer: Integer;
161 FSavedState: TPlayerSavedState;
163 FModel: TPlayerModel;
164 FActionPrior: Byte;
165 FActionAnim: Byte;
166 FActionForce: Boolean;
167 FActionChanged: Boolean;
168 FAngle: SmallInt;
169 FFireAngle: SmallInt;
170 FIncCam: Integer;
171 FShellTimer: Integer;
172 FShellType: Byte;
173 FSawSound: TPlayableSound;
174 FSawSoundIdle: TPlayableSound;
175 FSawSoundHit: TPlayableSound;
176 FSawSoundSelect: TPlayableSound;
177 FJetSoundOn: TPlayableSound;
178 FJetSoundOff: TPlayableSound;
179 FJetSoundFly: TPlayableSound;
180 FGodMode: Boolean;
181 FNoTarget: Boolean;
182 FNoReload: Boolean;
183 FJustTeleported: Boolean;
184 FNetTime: LongWord;
186 function CollideLevel(XInc, YInc: Integer): Boolean;
187 function StayOnStep(XInc, YInc: Integer): Boolean;
188 function HeadInLiquid(XInc, YInc: Integer): Boolean;
189 function BodyInLiquid(XInc, YInc: Integer): Boolean;
190 function BodyInAcid(XInc, YInc: Integer): Boolean;
191 function FullInLift(XInc, YInc: Integer): Integer;
192 {procedure CollideItem();}
193 procedure FlySmoke(Times: DWORD = 1);
194 function GetAmmoByWeapon(Weapon: Byte): Word;
195 procedure SetAction(Action: Byte; Force: Boolean = False);
196 procedure OnDamage(Angle: SmallInt); virtual;
197 function firediry(): Integer;
199 procedure Run(Direction: TDirection);
200 procedure NextWeapon();
201 procedure PrevWeapon();
202 procedure SeeUp();
203 procedure SeeDown();
204 procedure Fire();
205 procedure Jump();
206 procedure Use();
208 public
209 FDamageBuffer: Integer;
211 FAmmo: Array [A_BULLETS..A_CELLS] of Word;
212 FMaxAmmo: Array [A_BULLETS..A_CELLS] of Word;
213 FWeapon: Array [WEAPON_KASTET..WEAPON_SUPERPULEMET] of Boolean;
214 FRulez: Set of R_ITEM_BACKPACK..R_BERSERK;
215 FBerserk: Integer;
216 FMegaRulez: Array [MR_SUIT..MR_MAX] of DWORD;
217 FReloading: Array [WEAPON_KASTET..WEAPON_SUPERPULEMET] of Word;
218 FTime: Array [T_RESPAWN..T_FLAGCAP] of DWORD;
219 FKeys: Array [KEY_LEFT..KEY_CHAT] of TKeyState;
220 FColor: TRGB;
221 FPreferredTeam: Byte;
222 FSpectator: Boolean;
223 FNoRespawn: Boolean;
224 FWantsInGame: Boolean;
225 FGhost: Boolean;
226 FPhysics: Boolean;
227 FJetpack: Boolean;
228 FActualModelName: string;
229 FClientID: SmallInt;
230 FPing: Word;
231 FLoss: Byte;
232 FDummy: Boolean;
234 constructor Create(); virtual;
235 destructor Destroy(); override;
236 procedure Respawn(Silent: Boolean; Force: Boolean = False); virtual;
237 function GetRespawnPoint(): Byte;
238 procedure PressKey(Key: Byte; Time: Word = 1);
239 procedure ReleaseKeys();
240 procedure SetModel(ModelName: String);
241 procedure SetColor(Color: TRGB);
242 procedure SetWeapon(W: Byte);
243 function IsKeyPressed(K: Byte): Boolean;
244 function GetKeys(): Byte;
245 function PickItem(ItemType: Byte; respawn: Boolean; var remove: Boolean): Boolean; virtual;
246 function Collide(X, Y: Integer; Width, Height: Word): Boolean; overload;
247 function Collide(Panel: TPanel): Boolean; overload;
248 function Collide(X, Y: Integer): Boolean; overload;
249 procedure SetDirection(Direction: TDirection);
250 procedure GetSecret();
251 function TeleportTo(X, Y: Integer; silent: Boolean; dir: Byte): Boolean;
252 procedure Touch();
253 procedure Push(vx, vy: Integer);
254 procedure ChangeModel(ModelName: String);
255 procedure SwitchTeam;
256 procedure ChangeTeam(Team: Byte);
257 procedure BFGHit();
258 function GetFlag(Flag: Byte): Boolean;
259 procedure SetFlag(Flag: Byte);
260 function DropFlag(): Boolean;
261 procedure AllRulez(Health: Boolean);
262 procedure RestoreHealthArmor();
263 procedure FragCombo();
264 procedure GiveItem(ItemType: Byte);
265 procedure Damage(value: Word; SpawnerUID: Word; vx, vy: Integer; t: Byte); virtual;
266 function Heal(value: Word; Soft: Boolean): Boolean; virtual;
267 procedure MakeBloodVector(Count: Word; VelX, VelY: Integer);
268 procedure MakeBloodSimple(Count: Word);
269 procedure Kill(KillType: Byte; SpawnerUID: Word; t: Byte);
270 procedure Reset(Force: Boolean);
271 procedure Spectate(NoMove: Boolean = False);
272 procedure SwitchNoClip;
273 procedure SoftReset();
274 procedure Draw(); virtual;
275 procedure DrawPain();
276 procedure DrawPickup();
277 procedure DrawRulez();
278 procedure DrawAim();
279 procedure DrawBubble();
280 procedure DrawGUI();
281 procedure Update(); virtual;
282 procedure RememberState();
283 procedure RecallState();
284 procedure SaveState(var Mem: TBinMemoryWriter); virtual;
285 procedure LoadState(var Mem: TBinMemoryReader); virtual;
286 procedure PauseSounds(Enable: Boolean);
287 procedure NetFire(Wpn: Byte; X, Y, AX, AY: Integer; WID: Integer = -1);
288 procedure DoLerp(Level: Integer = 2);
289 procedure SetLerp(XTo, YTo: Integer);
290 procedure JetpackOn;
291 procedure JetpackOff;
293 property Name: String read FName write FName;
294 property Model: TPlayerModel read FModel;
295 property Health: Integer read FHealth write FHealth;
296 property Lives: Byte read FLives write FLives;
297 property Armor: Integer read FArmor write FArmor;
298 property Air: Integer read FAir write FAir;
299 property JetFuel: Integer read FJetFuel write FJetFuel;
300 property Frags: Integer read FFrags write FFrags;
301 property Death: Integer read FDeath write FDeath;
302 property Kills: Integer read FKills write FKills;
303 property CurrWeap: Byte read FCurrWeap write FCurrWeap;
304 property MonsterKills: Integer read FMonsterKills write FMonsterKills;
305 property Secrets: Integer read FSecrets;
306 property GodMode: Boolean read FGodMode write FGodMode;
307 property NoTarget: Boolean read FNoTarget write FNoTarget;
308 property NoReload: Boolean read FNoReload write FNoReload;
309 property Live: Boolean read FLive write FLive;
310 property Flag: Byte read FFlag;
311 property Team: Byte read FTeam write FTeam;
312 property Direction: TDirection read FDirection;
313 property GameX: Integer read FObj.X write FObj.X;
314 property GameY: Integer read FObj.Y write FObj.Y;
315 property GameVelX: Integer read FObj.Vel.X write FObj.Vel.X;
316 property GameVelY: Integer read FObj.Vel.Y write FObj.Vel.Y;
317 property GameAccelX: Integer read FObj.Accel.X write FObj.Accel.X;
318 property GameAccelY: Integer read FObj.Accel.Y write FObj.Accel.Y;
319 property Vel: TPoint2i read FObj.Vel;
320 property Obj: TObj read FObj;
321 property IncCam: Integer read FIncCam write FIncCam;
322 property UID: Word read FUID write FUID;
323 property JustTeleported: Boolean read FJustTeleported write FJustTeleported;
324 property NetTime: LongWord read FNetTime write FNetTime;
325 end;
327 TDifficult = record
328 DiagFire: Byte;
329 InvisFire: Byte;
330 DiagPrecision: Byte;
331 FlyPrecision: Byte;
332 Cover: Byte;
333 CloseJump: Byte;
334 WeaponPrior: Array [WEAPON_KASTET..WEAPON_SUPERPULEMET] of Byte;
335 CloseWeaponPrior: Array [WEAPON_KASTET..WEAPON_SUPERPULEMET] of Byte;
336 //SafeWeaponPrior: Array [WEAPON_KASTET..WEAPON_SUPERPULEMET] of Byte;
337 end;
339 TAIFlag = record
340 Name: String;
341 Value: String;
342 end;
344 TBot = class (TPlayer)
345 private
346 FSelectedWeapon: Byte;
347 FTargetUID: Word;
348 FLastVisible: DWORD;
349 FAIFlags: Array of TAIFlag;
350 FDifficult: TDifficult;
352 function GetRnd(a: Byte): Boolean;
353 function GetInterval(a: Byte; radius: SmallInt): SmallInt;
354 function RunDirection(): TDirection;
355 function FullInStep(XInc, YInc: Integer): Boolean;
356 //function NeedItem(Item: Byte): Byte;
357 procedure SelectWeapon(Dist: Integer);
358 procedure SetAIFlag(fName, fValue: String20);
359 function GetAIFlag(fName: String20): String20;
360 procedure RemoveAIFlag(fName: String20);
361 function Healthy(): Byte;
362 procedure UpdateMove();
363 procedure UpdateCombat();
364 function KeyPressed(Key: Word): Boolean;
365 procedure ReleaseKey(Key: Byte);
366 function TargetOnScreen(TX, TY: Integer): Boolean;
367 procedure OnDamage(Angle: SmallInt); override;
369 public
370 procedure Respawn(Silent: Boolean; Force: Boolean = False); override;
371 constructor Create(); override;
372 destructor Destroy(); override;
373 procedure Draw(); override;
374 function PickItem(ItemType: Byte; force: Boolean; var remove: Boolean): Boolean; override;
375 function Heal(value: Word; Soft: Boolean): Boolean; override;
376 procedure Update(); override;
377 procedure SaveState(var Mem: TBinMemoryWriter); override;
378 procedure LoadState(var Mem: TBinMemoryReader); override;
379 end;
381 TGib = record
382 Live: Boolean;
383 ID: DWORD;
384 MaskID: DWORD;
385 RAngle: Integer;
386 Color: TRGB;
387 Obj: TObj;
388 end;
390 TShell = record
391 SpriteID: DWORD;
392 Live: Boolean;
393 SType: Byte;
394 RAngle: Integer;
395 Timeout: Cardinal;
396 CX, CY: Integer;
397 Obj: TObj;
398 end;
400 TCorpse = class (TObject)
401 private
402 FModelName: String;
403 FMess: Boolean;
404 FState: Byte;
405 FDamage: Byte;
406 FColor: TRGB;
407 FObj: TObj;
408 FAnimation: TAnimation;
409 FAnimationMask: TAnimation;
411 public
412 constructor Create(X, Y: Integer; ModelName: String; aMess: Boolean);
413 destructor Destroy(); override;
414 procedure Damage(Value: Word; vx, vy: Integer);
415 procedure Update();
416 procedure Draw();
417 procedure SaveState(var Mem: TBinMemoryWriter);
418 procedure LoadState(var Mem: TBinMemoryReader);
420 property Obj: TObj read FObj;
421 property State: Byte read FState;
422 property Mess: Boolean read FMess;
423 end;
425 TTeamStat = Array [TEAM_RED..TEAM_BLUE] of
426 record
427 Goals: SmallInt;
428 end;
430 var
431 gPlayers: Array of TPlayer;
432 gCorpses: Array of TCorpse;
433 gGibs: Array of TGib;
434 gShells: Array of TShell;
435 gTeamStat: TTeamStat;
436 gFly: Boolean = False;
437 gAimLine: Boolean = False;
438 gChatBubble: Byte = 0;
439 gNumBots: Word = 0;
440 gLMSPID1: Word = 0;
441 gLMSPID2: Word = 0;
442 MAX_RUNVEL: Integer = 8;
443 VEL_JUMP: Integer = 10;
444 SHELL_TIMEOUT: Cardinal = 60000;
446 function Lerp(X, Y, Factor: Integer): Integer;
448 procedure g_Gibs_SetMax(Count: Word);
449 function g_Gibs_GetMax(): Word;
450 procedure g_Corpses_SetMax(Count: Word);
451 function g_Corpses_GetMax(): Word;
452 procedure g_Shells_SetMax(Count: Word);
453 function g_Shells_GetMax(): Word;
455 procedure g_Player_Init();
456 procedure g_Player_Free();
457 function g_Player_Create(ModelName: String; Color: TRGB; Team: Byte; Bot: Boolean): Word;
458 function g_Player_CreateFromState(var Mem: TBinMemoryReader): Word;
459 procedure g_Player_Remove(UID: Word);
460 procedure g_Player_ResetTeams();
461 procedure g_Player_UpdateAll();
462 procedure g_Player_DrawAll();
463 procedure g_Player_DrawDebug(p: TPlayer);
464 procedure g_Player_DrawHealth();
465 procedure g_Player_RememberAll();
466 procedure g_Player_ResetAll(Force, Silent: Boolean);
467 function g_Player_Get(UID: Word): TPlayer;
468 function g_Player_GetCount(): Byte;
469 function g_Player_GetStats(): TPlayerStatArray;
470 function g_Player_ValidName(Name: String): Boolean;
471 procedure g_Player_CreateCorpse(Player: TPlayer);
472 procedure g_Player_CreateGibs(fX, fY: Integer; ModelName: String; fColor: TRGB);
473 procedure g_Player_CreateShell(fX, fY, dX, dY: Integer; T: Byte);
474 procedure g_Player_UpdatePhysicalObjects();
475 procedure g_Player_DrawCorpses();
476 procedure g_Player_DrawShells();
477 procedure g_Player_RemoveAllCorpses();
478 procedure g_Player_Corpses_SaveState(var Mem: TBinMemoryWriter);
479 procedure g_Player_Corpses_LoadState(var Mem: TBinMemoryReader);
480 procedure g_Bot_Add(Team, Difficult: Byte);
481 procedure g_Bot_AddList(Team: Byte; lname: ShortString; num: Integer = -1);
482 procedure g_Bot_MixNames();
483 procedure g_Bot_RemoveAll();
485 implementation
487 uses
488 e_log, g_map, g_items, g_console, SysUtils, g_gfx, Math,
489 g_options, g_triggers, g_menu, MAPDEF, g_game,
490 wadreader, g_main, g_monsters, CONFIG, g_language, g_net, g_netmsg;
492 type
493 TBotProfile = record
494 name: ShortString;
495 model: ShortString;
496 team: Byte;
497 color: TRGB;
498 diag_fire: Byte;
499 invis_fire: Byte;
500 diag_precision: Byte;
501 fly_precision: Byte;
502 cover: Byte;
503 close_jump: Byte;
504 w_prior1: Array [WEAPON_KASTET..WEAPON_SUPERPULEMET] of Byte;
505 w_prior2: Array [WEAPON_KASTET..WEAPON_SUPERPULEMET] of Byte;
506 w_prior3: Array [WEAPON_KASTET..WEAPON_SUPERPULEMET] of Byte;
507 end;
509 const
510 TIME_RESPAWN1 = 1500;
511 TIME_RESPAWN2 = 2000;
512 TIME_RESPAWN3 = 3000;
513 AIR_DEF = 360;
514 AIR_MAX = 1091;
515 JET_MAX = 540; // ~30 sec
516 PLAYER_SUIT_TIME = 30000;
517 PLAYER_INVUL_TIME = 30000;
518 PLAYER_INVIS_TIME = 35000;
519 FRAG_COMBO_TIME = 3000;
520 VEL_SW = 4;
521 VEL_FLY = 6;
522 ANGLE_RIGHTUP = 55;
523 ANGLE_RIGHTDOWN = -35;
524 ANGLE_LEFTUP = 125;
525 ANGLE_LEFTDOWN = -145;
526 PLAYER_HEADRECT: TRectWH = (X:24; Y:12; Width:20; Height:12);
527 WEAPONPOINT: Array [TDirection] of TPoint = ((X:16; Y:32), (X:47; Y:32));
528 BOT_MAXJUMP = 84;
529 BOT_LONGDIST = 300;
530 BOT_UNSAFEDIST = 128;
531 TEAMCOLOR: Array [TEAM_RED..TEAM_BLUE] of TRGB = ((R:255; G:0; B:0),
532 (R:0; G:0; B:255));
533 DIFFICULT_EASY: TDifficult = (DiagFire: 32; InvisFire: 32; DiagPrecision: 32;
534 FlyPrecision: 32; Cover: 32; CloseJump: 32;
535 WeaponPrior:(0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior:(0,0,0,0,0,0,0,0,0,0));
536 DIFFICULT_MEDIUM: TDifficult = (DiagFire: 127; InvisFire: 127; DiagPrecision: 127;
537 FlyPrecision: 127; Cover: 127; CloseJump: 127;
538 WeaponPrior:(0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior:(0,0,0,0,0,0,0,0,0,0));
539 DIFFICULT_HARD: TDifficult = (DiagFire: 255; InvisFire: 255; DiagPrecision: 255;
540 FlyPrecision: 255; Cover: 255; CloseJump: 255;
541 WeaponPrior:(0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior:(0,0,0,0,0,0,0,0,0,0));
542 WEAPON_PRIOR1: Array [WEAPON_KASTET..WEAPON_SUPERPULEMET] of Byte =
543 (WEAPON_SUPERPULEMET, WEAPON_SHOTGUN2, WEAPON_SHOTGUN1,
544 WEAPON_CHAINGUN, WEAPON_PLASMA, WEAPON_ROCKETLAUNCHER,
545 WEAPON_BFG, WEAPON_PISTOL, WEAPON_SAW, WEAPON_KASTET);
546 WEAPON_PRIOR2: Array [WEAPON_KASTET..WEAPON_SUPERPULEMET] of Byte =
547 (WEAPON_SUPERPULEMET, WEAPON_BFG, WEAPON_ROCKETLAUNCHER,
548 WEAPON_SHOTGUN2, WEAPON_PLASMA, WEAPON_SHOTGUN1,
549 WEAPON_CHAINGUN, WEAPON_PISTOL, WEAPON_SAW, WEAPON_KASTET);
550 //WEAPON_PRIOR3: Array [WEAPON_KASTET..WEAPON_SUPERPULEMET] of Byte =
551 // (WEAPON_SUPERPULEMET, WEAPON_BFG, WEAPON_PLASMA,
552 // WEAPON_SHOTGUN2, WEAPON_CHAINGUN, WEAPON_SHOTGUN1,
553 // WEAPON_SAW, WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
554 WEAPON_RELOAD: Array [WEAPON_KASTET..WEAPON_SUPERPULEMET] of Byte =
555 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2);
557 PLAYER_SIGNATURE = $52594C50; // 'PLYR'
558 CORPSE_SIGNATURE = $50524F43; // 'CORP'
560 BOTNAMES_FILENAME = 'botnames.txt';
561 BOTLIST_FILENAME = 'botlist.txt';
563 var
564 MaxGibs: Word = 150;
565 MaxCorpses: Word = 20;
566 MaxShells: Word = 300;
567 CurrentGib: Integer = 0;
568 CurrentShell: Integer = 0;
569 BotNames: Array of String;
570 BotList: Array of TBotProfile;
572 function Lerp(X, Y, Factor: Integer): Integer;
573 begin
574 Result := X + ((Y - X) div Factor);
575 end;
577 function SameTeam(UID1, UID2: Word): Boolean;
578 begin
579 Result := False;
581 if (UID1 > UID_MAX_PLAYER) or (UID1 <= UID_MAX_GAME) or
582 (UID2 > UID_MAX_PLAYER) or (UID2 <= UID_MAX_GAME) then Exit;
584 if (g_Player_Get(UID1) = nil) or (g_Player_Get(UID2) = nil) then Exit;
586 if ((g_Player_Get(UID1).Team = TEAM_NONE) or
587 (g_Player_Get(UID2).Team = TEAM_NONE)) then Exit;
589 Result := g_Player_Get(UID1).FTeam = g_Player_Get(UID2).FTeam;
590 end;
592 procedure g_Gibs_SetMax(Count: Word);
593 begin
594 MaxGibs := Count;
595 SetLength(gGibs, Count);
597 if CurrentGib >= Count then
598 CurrentGib := 0;
599 end;
601 function g_Gibs_GetMax(): Word;
602 begin
603 Result := MaxGibs;
604 end;
606 procedure g_Shells_SetMax(Count: Word);
607 begin
608 MaxShells := Count;
609 SetLength(gShells, Count);
611 if CurrentShell >= Count then
612 CurrentShell := 0;
613 end;
615 function g_Shells_GetMax(): Word;
616 begin
617 Result := MaxShells;
618 end;
621 procedure g_Corpses_SetMax(Count: Word);
622 begin
623 MaxCorpses := Count;
624 SetLength(gCorpses, Count);
625 end;
627 function g_Corpses_GetMax(): Word;
628 begin
629 Result := MaxCorpses;
630 end;
632 function g_Player_Create(ModelName: String; Color: TRGB; Team: Byte; Bot: Boolean): Word;
633 var
634 a: Integer;
635 ok: Boolean;
636 begin
637 Result := 0;
639 ok := False;
640 a := 0;
642 // Åñòü ëè ìåñòî â gPlayers:
643 if gPlayers <> nil then
644 for a := 0 to High(gPlayers) do
645 if gPlayers[a] = nil then
646 begin
647 ok := True;
648 Break;
649 end;
651 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
652 if not ok then
653 begin
654 SetLength(gPlayers, Length(gPlayers)+1);
655 a := High(gPlayers);
656 end;
658 // Ñîçäàåì îáúåêò èãðîêà:
659 if Bot then
660 gPlayers[a] := TBot.Create()
661 else
662 gPlayers[a] := TPlayer.Create();
665 gPlayers[a].FActualModelName := ModelName;
666 gPlayers[a].SetModel(ModelName);
668 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
669 if gPlayers[a].FModel = nil then
670 begin
671 gPlayers[a].Free();
672 gPlayers[a] := nil;
673 g_FatalError(Format(_lc[I_GAME_ERROR_MODEL], [ModelName]));
674 Exit;
675 end;
677 if not (Team in [TEAM_RED, TEAM_BLUE]) then
678 if Random(2) = 0 then
679 Team := TEAM_RED
680 else
681 Team := TEAM_BLUE;
682 gPlayers[a].FPreferredTeam := Team;
684 case gGameSettings.GameMode of
685 GM_DM: gPlayers[a].FTeam := TEAM_NONE;
686 GM_TDM,
687 GM_CTF: gPlayers[a].FTeam := gPlayers[a].FPreferredTeam;
688 GM_SINGLE,
689 GM_COOP: gPlayers[a].FTeam := TEAM_COOP;
690 end;
692 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
693 gPlayers[a].FColor := Color;
694 if gPlayers[a].FTeam in [TEAM_RED, TEAM_BLUE] then
695 gPlayers[a].FModel.Color := TEAMCOLOR[gPlayers[a].FTeam]
696 else
697 gPlayers[a].FModel.Color := Color;
699 gPlayers[a].FUID := g_CreateUID(UID_PLAYER);
700 gPlayers[a].FLive := False;
702 Result := gPlayers[a].FUID;
703 end;
705 function g_Player_CreateFromState(var Mem: TBinMemoryReader): Word;
706 var
707 a, i: Integer;
708 ok, Bot: Boolean;
709 sig: DWORD;
710 b: Byte;
711 begin
712 Result := 0;
713 if Mem = nil then
714 Exit;
716 // Ñèãíàòóðà èãðîêà:
717 Mem.ReadDWORD(sig);
718 if sig <> PLAYER_SIGNATURE then // 'PLYR'
719 begin
720 raise EBinSizeError.Create('g_Player_CreateFromState: Wrong Player Signature');
721 end;
723 // Áîò èëè ÷åëîâåê:
724 Mem.ReadBoolean(Bot);
726 ok := False;
727 a := 0;
729 // Åñòü ëè ìåñòî â gPlayers:
730 if gPlayers <> nil then
731 for a := 0 to High(gPlayers) do
732 if gPlayers[a] = nil then
733 begin
734 ok := True;
735 Break;
736 end;
738 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
739 if not ok then
740 begin
741 SetLength(gPlayers, Length(gPlayers)+1);
742 a := High(gPlayers);
743 end;
745 // Ñîçäàåì îáúåêò èãðîêà:
746 if Bot then
747 gPlayers[a] := TBot.Create()
748 else
749 gPlayers[a] := TPlayer.Create();
750 gPlayers[a].FIamBot := Bot;
751 gPlayers[a].FPhysics := True;
753 // UID èãðîêà:
754 Mem.ReadWord(gPlayers[a].FUID);
755 // Èìÿ èãðîêà:
756 Mem.ReadString(gPlayers[a].FName);
757 // Êîìàíäà:
758 Mem.ReadByte(gPlayers[a].FTeam);
759 gPlayers[a].FPreferredTeam := gPlayers[a].FTeam;
760 // Æèâ ëè:
761 Mem.ReadBoolean(gPlayers[a].FLive);
762 // Èçðàñõîäîâàë ëè âñå æèçíè:
763 Mem.ReadBoolean(gPlayers[a].FNoRespawn);
764 // Íàïðàâëåíèå:
765 Mem.ReadByte(b);
766 if b = 1 then
767 gPlayers[a].FDirection := D_LEFT
768 else // b = 2
769 gPlayers[a].FDirection := D_RIGHT;
770 // Çäîðîâüå:
771 Mem.ReadInt(gPlayers[a].FHealth);
772 // Æèçíè:
773 Mem.ReadByte(gPlayers[a].FLives);
774 // Áðîíÿ:
775 Mem.ReadInt(gPlayers[a].FArmor);
776 // Çàïàñ âîçäóõà:
777 Mem.ReadInt(gPlayers[a].FAir);
778 // Çàïàñ ãîðþ÷åãî:
779 Mem.ReadInt(gPlayers[a].FJetFuel);
780 // Áîëü:
781 Mem.ReadInt(gPlayers[a].FPain);
782 // Óáèë:
783 Mem.ReadInt(gPlayers[a].FKills);
784 // Óáèë ìîíñòðîâ:
785 Mem.ReadInt(gPlayers[a].FMonsterKills);
786 // Ôðàãîâ:
787 Mem.ReadInt(gPlayers[a].FFrags);
788 // Ôðàãîâ ïîäðÿä:
789 Mem.ReadByte(gPlayers[a].FFragCombo);
790 // Âðåìÿ ïîñëåäíåãî ôðàãà:
791 Mem.ReadDWORD(gPlayers[a].FLastFrag);
792 // Ñìåðòåé:
793 Mem.ReadInt(gPlayers[a].FDeath);
794 // Êàêîé ôëàã íåñåò:
795 Mem.ReadByte(gPlayers[a].FFlag);
796 // Íàøåë ñåêðåòîâ:
797 Mem.ReadInt(gPlayers[a].FSecrets);
798 // Òåêóùåå îðóæèå:
799 Mem.ReadByte(gPlayers[a].FCurrWeap);
800 // Âðåìÿ çàðÿäêè BFG:
801 Mem.ReadSmallInt(gPlayers[a].FBFGFireCounter);
802 // Áóôåð óðîíà:
803 Mem.ReadInt(gPlayers[a].FDamageBuffer);
804 // Ïîñëåäíèé óäàðèâøèé:
805 Mem.ReadWord(gPlayers[a].FLastSpawnerUID);
806 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
807 Mem.ReadByte(gPlayers[a].FLastHit);
808 // Îáúåêò èãðîêà:
809 Obj_LoadState(@gPlayers[a].FObj, Mem);
810 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
811 for i := A_BULLETS to A_CELLS do
812 Mem.ReadWord(gPlayers[a].FAmmo[i]);
813 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
814 for i := A_BULLETS to A_CELLS do
815 Mem.ReadWord(gPlayers[a].FMaxAmmo[i]);
816 // Íàëè÷èå îðóæèÿ:
817 for i := WEAPON_KASTET to WEAPON_SUPERPULEMET do
818 Mem.ReadBoolean(gPlayers[a].FWeapon[i]);
819 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
820 for i := WEAPON_KASTET to WEAPON_SUPERPULEMET do
821 Mem.ReadWord(gPlayers[a].FReloading[i]);
822 // Íàëè÷èå ðþêçàêà:
823 Mem.ReadByte(b);
824 if b = 1 then
825 Include(gPlayers[a].FRulez, R_ITEM_BACKPACK);
826 // Íàëè÷èå êðàñíîãî êëþ÷à:
827 Mem.ReadByte(b);
828 if b = 1 then
829 Include(gPlayers[a].FRulez, R_KEY_RED);
830 // Íàëè÷èå çåëåíîãî êëþ÷à:
831 Mem.ReadByte(b);
832 if b = 1 then
833 Include(gPlayers[a].FRulez, R_KEY_GREEN);
834 // Íàëè÷èå ñèíåãî êëþ÷à:
835 Mem.ReadByte(b);
836 if b = 1 then
837 Include(gPlayers[a].FRulez, R_KEY_BLUE);
838 // Íàëè÷èå áåðñåðêà:
839 Mem.ReadByte(b);
840 if b = 1 then
841 Include(gPlayers[a].FRulez, R_BERSERK);
842 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
843 for i := MR_SUIT to MR_MAX do
844 Mem.ReadDWORD(gPlayers[a].FMegaRulez[i]);
845 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
846 for i := T_RESPAWN to T_FLAGCAP do
847 Mem.ReadDWORD(gPlayers[a].FTime[i]);
849 // Íàçâàíèå ìîäåëè:
850 Mem.ReadString(gPlayers[a].FActualModelName);
851 // Öâåò ìîäåëè:
852 Mem.ReadByte(gPlayers[a].FColor.R);
853 Mem.ReadByte(gPlayers[a].FColor.G);
854 Mem.ReadByte(gPlayers[a].FColor.B);
855 // Îáíîâëÿåì ìîäåëü èãðîêà:
856 gPlayers[a].SetModel(gPlayers[a].FActualModelName);
858 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
859 if gPlayers[a].FModel = nil then
860 begin
861 gPlayers[a].Free();
862 gPlayers[a] := nil;
863 g_FatalError(Format(_lc[I_GAME_ERROR_MODEL], [gPlayers[a].FActualModelName]));
864 Exit;
865 end;
867 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
868 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
869 gPlayers[a].FModel.Color := TEAMCOLOR[gPlayers[a].FTeam]
870 else
871 gPlayers[a].FModel.Color := gPlayers[a].FColor;
873 Result := gPlayers[a].FUID;
874 end;
876 procedure g_Player_ResetTeams();
877 var
878 a: Integer;
879 begin
880 if g_Game_IsClient then
881 Exit;
882 if gPlayers = nil then
883 Exit;
884 for a := Low(gPlayers) to High(gPlayers) do
885 if gPlayers[a] <> nil then
886 case gGameSettings.GameMode of
887 GM_DM:
888 gPlayers[a].ChangeTeam(TEAM_NONE);
889 GM_TDM, GM_CTF:
890 if not (gPlayers[a].Team in [TEAM_RED, TEAM_BLUE]) then
891 if gPlayers[a].FPreferredTeam in [TEAM_RED, TEAM_BLUE] then
892 gPlayers[a].ChangeTeam(gPlayers[a].FPreferredTeam)
893 else
894 if a mod 2 = 0 then
895 gPlayers[a].ChangeTeam(TEAM_RED)
896 else
897 gPlayers[a].ChangeTeam(TEAM_BLUE);
898 GM_SINGLE,
899 GM_COOP:
900 gPlayers[a].ChangeTeam(TEAM_COOP);
901 end;
902 end;
904 procedure g_Bot_Add(Team, Difficult: Byte);
905 var
906 m: SArray;
907 _name, _model: String;
908 a, tr, tb: Integer;
909 begin
910 if not g_Game_IsServer then Exit;
912 // Ñïèñîê íàçâàíèé ìîäåëåé:
913 m := g_PlayerModel_GetNames();
914 if m = nil then
915 Exit;
917 // Êîìàíäà:
918 if (gGameSettings.GameType = GT_SINGLE) or (gGameSettings.GameMode = GM_COOP) then
919 Team := TEAM_COOP // COOP
920 else
921 if gGameSettings.GameMode = GM_DM then
922 Team := TEAM_NONE // DM
923 else
924 if Team = TEAM_NONE then // CTF / TDM
925 begin
926 // Àâòîáàëàíñ êîìàíä:
927 tr := 0;
928 tb := 0;
930 for a := 0 to High(gPlayers) do
931 if gPlayers[a] <> nil then
932 begin
933 if gPlayers[a].Team = TEAM_RED then
934 Inc(tr)
935 else
936 if gPlayers[a].Team = TEAM_BLUE then
937 Inc(tb);
938 end;
940 if tr > tb then
941 Team := TEAM_BLUE
942 else
943 if tb > tr then
944 Team := TEAM_RED
945 else // tr = tb
946 if Random(2) = 0 then
947 Team := TEAM_RED
948 else
949 Team := TEAM_BLUE;
950 end;
952 // Âûáèðàåì áîòó èìÿ:
953 _name := '';
954 if BotNames <> nil then
955 for a := 0 to High(BotNames) do
956 if g_Player_ValidName(BotNames[a]) then
957 begin
958 _name := BotNames[a];
959 Break;
960 end;
962 // Èìåíè íåò, çàäàåì ñëó÷àéíîå:
963 if _name = '' then
964 repeat
965 _name := Format('DFBOT%.2d', [Random(100)]);
966 until g_Player_ValidName(_name);
968 // Âûáèðàåì ñëó÷àéíóþ ìîäåëü:
969 _model := m[Random(Length(m))];
971 // Ñîçäàåì áîòà:
972 with g_Player_Get(g_Player_Create(_model,
973 _RGB(Min(Random(9)*32, 255),
974 Min(Random(9)*32, 255),
975 Min(Random(9)*32, 255)),
976 Team, True)) as TBot do
977 begin
978 Name := _name;
980 case Difficult of
981 1: FDifficult := DIFFICULT_EASY;
982 2: FDifficult := DIFFICULT_MEDIUM;
983 else FDifficult := DIFFICULT_HARD;
984 end;
986 for a := WEAPON_KASTET to WEAPON_SUPERPULEMET do
987 begin
988 FDifficult.WeaponPrior[a] := WEAPON_PRIOR1[a];
989 FDifficult.CloseWeaponPrior[a] := WEAPON_PRIOR2[a];
990 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
991 end;
993 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [Name]), True);
995 if g_Game_IsNet then MH_SEND_PlayerCreate(UID);
996 if g_Game_IsServer and (gGameSettings.MaxLives > 0) then
997 Spectate();
998 end;
999 end;
1001 procedure g_Bot_AddList(Team: Byte; lName: ShortString; num: Integer = -1);
1002 var
1003 m: SArray;
1004 _name, _model: String;
1005 a: Integer;
1006 begin
1007 if not g_Game_IsServer then Exit;
1009 // Ñïèñîê íàçâàíèé ìîäåëåé:
1010 m := g_PlayerModel_GetNames();
1011 if m = nil then
1012 Exit;
1014 // Êîìàíäà:
1015 if (gGameSettings.GameType = GT_SINGLE) or (gGameSettings.GameMode = GM_COOP) then
1016 Team := TEAM_COOP // COOP
1017 else
1018 if gGameSettings.GameMode = GM_DM then
1019 Team := TEAM_NONE // DM
1020 else
1021 if Team = TEAM_NONE then
1022 Team := BotList[num].team; // CTF / TDM
1024 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1025 lName := AnsiLowerCase(lName);
1026 if (num < 0) or (num > Length(BotList)-1) then
1027 num := -1;
1028 if (num = -1) and (lName <> '') and (BotList <> nil) then
1029 for a := 0 to High(BotList) do
1030 if AnsiLowerCase(BotList[a].name) = lName then
1031 begin
1032 num := a;
1033 Break;
1034 end;
1035 if num = -1 then
1036 Exit;
1038 // Èìÿ áîòà:
1039 _name := BotList[num].name;
1040 // Çàíÿòî - âûáèðàåì ñëó÷àéíîå:
1041 if not g_Player_ValidName(_name) then
1042 repeat
1043 _name := Format('DFBOT%.2d', [Random(100)]);
1044 until g_Player_ValidName(_name);
1046 // Ìîäåëü:
1047 _model := BotList[num].model;
1048 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1049 if not InSArray(_model, m) then
1050 _model := m[Random(Length(m))];
1052 // Ñîçäàåì áîòà:
1053 with g_Player_Get(g_Player_Create(_model, BotList[num].color, Team, True)) as TBot do
1054 begin
1055 Name := _name;
1057 FDifficult.DiagFire := BotList[num].diag_fire;
1058 FDifficult.InvisFire := BotList[num].invis_fire;
1059 FDifficult.DiagPrecision := BotList[num].diag_precision;
1060 FDifficult.FlyPrecision := BotList[num].fly_precision;
1061 FDifficult.Cover := BotList[num].cover;
1062 FDifficult.CloseJump := BotList[num].close_jump;
1064 for a := WEAPON_KASTET to WEAPON_SUPERPULEMET do
1065 begin
1066 FDifficult.WeaponPrior[a] := BotList[num].w_prior1[a];
1067 FDifficult.CloseWeaponPrior[a] := BotList[num].w_prior2[a];
1068 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1069 end;
1071 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [Name]), True);
1073 if g_Game_IsNet then MH_SEND_PlayerCreate(UID);
1074 end;
1075 end;
1077 procedure g_Bot_RemoveAll();
1078 var
1079 a: Integer;
1080 begin
1081 if not g_Game_IsServer then Exit;
1082 if gPlayers = nil then Exit;
1084 for a := 0 to High(gPlayers) do
1085 if gPlayers[a] <> nil then
1086 if gPlayers[a] is TBot then
1087 begin
1088 gPlayers[a].Lives := 0;
1089 gPlayers[a].Kill(K_SIMPLEKILL, 0, HIT_DISCON);
1090 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [gPlayers[a].Name]), True);
1091 g_Player_Remove(gPlayers[a].FUID);
1092 end;
1094 g_Bot_MixNames();
1095 end;
1097 procedure g_Bot_MixNames();
1098 var
1099 s: String;
1100 a, b: Integer;
1101 begin
1102 if BotNames <> nil then
1103 for a := 0 to High(BotNames) do
1104 begin
1105 b := Random(Length(BotNames));
1106 s := BotNames[a];
1107 Botnames[a] := BotNames[b];
1108 BotNames[b] := s;
1109 end;
1110 end;
1112 procedure g_Player_Remove(UID: Word);
1113 var
1114 i: Integer;
1115 begin
1116 if gPlayers = nil then Exit;
1118 if g_Game_IsServer and g_Game_IsNet then
1119 MH_SEND_PlayerDelete(UID);
1121 for i := 0 to High(gPlayers) do
1122 if gPlayers[i] <> nil then
1123 if gPlayers[i].FUID = UID then
1124 begin
1125 if gPlayers[i] is TPlayer then
1126 TPlayer(gPlayers[i]).Free()
1127 else
1128 TBot(gPlayers[i]).Free();
1129 gPlayers[i] := nil;
1130 Exit;
1131 end;
1132 end;
1134 procedure g_Player_Init();
1135 var
1136 F: TextFile;
1137 s: String;
1138 a, b: Integer;
1139 config: TConfig;
1140 sa: SArray;
1141 begin
1142 BotNames := nil;
1144 if not FileExists(DataDir + BOTNAMES_FILENAME) then
1145 Exit;
1147 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1148 AssignFile(F, DataDir + BOTNAMES_FILENAME);
1149 Reset(F);
1151 while not EOF(F) do
1152 begin
1153 ReadLn(F, s);
1155 s := Trim(s);
1156 if s = '' then
1157 Continue;
1159 SetLength(BotNames, Length(BotNames)+1);
1160 BotNames[High(BotNames)] := s;
1161 end;
1163 CloseFile(F);
1165 // Ïåðåìåøèâàåì èõ:
1166 g_Bot_MixNames();
1168 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1169 config := TConfig.CreateFile(DataDir + BOTLIST_FILENAME);
1170 BotList := nil;
1171 a := 0;
1173 while config.SectionExists(IntToStr(a)) do
1174 begin
1175 SetLength(BotList, Length(BotList)+1);
1177 with BotList[High(BotList)] do
1178 begin
1179 // Èìÿ áîòà:
1180 name := config.ReadStr(IntToStr(a), 'name', '');
1181 // Ìîäåëü:
1182 model := config.ReadStr(IntToStr(a), 'model', '');
1183 // Êîìàíäà:
1184 if config.ReadStr(IntToStr(a), 'team', 'red') = 'red' then
1185 team := TEAM_RED
1186 else
1187 team := TEAM_BLUE;
1188 // Öâåò ìîäåëè:
1189 sa := parse(config.ReadStr(IntToStr(a), 'color', ''));
1190 color.R := StrToIntDef(sa[0], 0);
1191 color.G := StrToIntDef(sa[1], 0);
1192 color.B := StrToIntDef(sa[2], 0);
1193 // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì:
1194 diag_fire := config.ReadInt(IntToStr(a), 'diag_fire', 0);
1195 // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó:
1196 invis_fire := config.ReadInt(IntToStr(a), 'invis_fire', 0);
1197 // Òî÷íîñòü ñòðåëüáû ïîä óãëîì:
1198 diag_precision := config.ReadInt(IntToStr(a), 'diag_precision', 0);
1199 // Òî÷íîñòü ñòðåëüáû â ïîëåòå:
1200 fly_precision := config.ReadInt(IntToStr(a), 'fly_precision', 0);
1201 // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ:
1202 cover := config.ReadInt(IntToStr(a), 'cover', 0);
1203 // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà:
1204 close_jump := config.ReadInt(IntToStr(a), 'close_jump', 0);
1205 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ:
1206 sa := parse(config.ReadStr(IntToStr(a), 'w_prior1', ''));
1207 if Length(sa) = 10 then
1208 for b := 0 to 9 do
1209 w_prior1[b] := EnsureRange(StrToInt(sa[b]), 0, 9);
1210 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ:
1211 sa := parse(config.ReadStr(IntToStr(a), 'w_prior2', ''));
1212 if Length(sa) = 10 then
1213 for b := 0 to 9 do
1214 w_prior2[b] := EnsureRange(StrToInt(sa[b]), 0, 9);
1216 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1217 if Length(sa) = 10 then
1218 for b := 0 to 9 do
1219 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1220 end;
1222 a := a + 1;
1223 end;
1225 config.Free();
1226 end;
1228 procedure g_Player_Free();
1229 var
1230 i: Integer;
1231 begin
1232 if gPlayers <> nil then
1233 begin
1234 for i := 0 to High(gPlayers) do
1235 if gPlayers[i] <> nil then
1236 begin
1237 if gPlayers[i] is TPlayer then
1238 TPlayer(gPlayers[i]).Free()
1239 else
1240 TBot(gPlayers[i]).Free();
1241 gPlayers[i] := nil;
1242 end;
1244 gPlayers := nil;
1245 end;
1247 gPlayer1 := nil;
1248 gPlayer2 := nil;
1249 end;
1251 procedure g_Player_UpdateAll();
1252 var
1253 i: Integer;
1254 begin
1255 if gPlayers = nil then Exit;
1257 for i := 0 to High(gPlayers) do
1258 if gPlayers[i] <> nil then
1259 if gPlayers[i] is TPlayer then gPlayers[i].Update()
1260 else TBot(gPlayers[i]).Update();
1261 end;
1263 procedure g_Player_DrawAll();
1264 var
1265 i: Integer;
1266 begin
1267 if gPlayers = nil then Exit;
1269 for i := 0 to High(gPlayers) do
1270 if gPlayers[i] <> nil then
1271 if gPlayers[i] is TPlayer then gPlayers[i].Draw()
1272 else TBot(gPlayers[i]).Draw();
1273 end;
1275 procedure g_Player_DrawDebug(p: TPlayer);
1276 var
1277 fW, fH: Byte;
1278 begin
1279 if p = nil then Exit;
1280 if (@p.FObj) = nil then Exit;
1282 e_TextureFontGetSize(gStdFont, fW, fH);
1284 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p.FObj.X), gStdFont);
1285 e_TextureFontPrint(0, fH , 'Pos Y: ' + IntToStr(p.FObj.Y), gStdFont);
1286 e_TextureFontPrint(0, fH * 2, 'Vel X: ' + IntToStr(p.FObj.Vel.X), gStdFont);
1287 e_TextureFontPrint(0, fH * 3, 'Vel Y: ' + IntToStr(p.FObj.Vel.Y), gStdFont);
1288 e_TextureFontPrint(0, fH * 4, 'Acc X: ' + IntToStr(p.FObj.Accel.X), gStdFont);
1289 e_TextureFontPrint(0, fH * 5, 'Acc Y: ' + IntToStr(p.FObj.Accel.Y), gStdFont);
1290 end;
1292 procedure g_Player_DrawHealth();
1293 var
1294 i: Integer;
1295 fW, fH: Byte;
1296 begin
1297 if gPlayers = nil then Exit;
1298 e_TextureFontGetSize(gStdFont, fW, fH);
1300 for i := 0 to High(gPlayers) do
1301 if gPlayers[i] <> nil then
1302 begin
1303 e_TextureFontPrint(gPlayers[i].FObj.X + gPlayers[i].FObj.Rect.X,
1304 gPlayers[i].FObj.Y + gPlayers[i].FObj.Rect.Y + gPlayers[i].FObj.Rect.Height - fH * 2,
1305 IntToStr(gPlayers[i].FHealth), gStdFont);
1306 e_TextureFontPrint(gPlayers[i].FObj.X + gPlayers[i].FObj.Rect.X,
1307 gPlayers[i].FObj.Y + gPlayers[i].FObj.Rect.Y + gPlayers[i].FObj.Rect.Height - fH,
1308 IntToStr(gPlayers[i].FArmor), gStdFont);
1309 end;
1310 end;
1312 function g_Player_Get(UID: Word): TPlayer;
1313 var
1314 a: Integer;
1315 begin
1316 Result := nil;
1318 if gPlayers = nil then
1319 Exit;
1321 for a := 0 to High(gPlayers) do
1322 if gPlayers[a] <> nil then
1323 if gPlayers[a].FUID = UID then
1324 begin
1325 Result := gPlayers[a];
1326 Exit;
1327 end;
1328 end;
1330 function g_Player_GetCount(): Byte;
1331 var
1332 a: Integer;
1333 begin
1334 Result := 0;
1336 if gPlayers = nil then
1337 Exit;
1339 for a := 0 to High(gPlayers) do
1340 if gPlayers[a] <> nil then
1341 Result := Result + 1;
1342 end;
1344 function g_Player_GetStats(): TPlayerStatArray;
1345 var
1346 a: Integer;
1347 begin
1348 Result := nil;
1350 if gPlayers = nil then Exit;
1352 for a := 0 to High(gPlayers) do
1353 if gPlayers[a] <> nil then
1354 begin
1355 SetLength(Result, Length(Result)+1);
1356 with Result[High(Result)] do
1357 begin
1358 Ping := gPlayers[a].FPing;
1359 Loss := gPlayers[a].FLoss;
1360 Name := gPlayers[a].FName;
1361 Team := gPlayers[a].FTeam;
1362 Frags := gPlayers[a].FFrags;
1363 Deaths := gPlayers[a].FDeath;
1364 Kills := gPlayers[a].FKills;
1365 Color := gPlayers[a].FModel.Color;
1366 Lives := gPlayers[a].FLives;
1367 Spectator := gPlayers[a].FSpectator;
1368 end;
1369 end;
1370 end;
1372 procedure g_Player_RememberAll;
1373 var
1374 i: Integer;
1375 begin
1376 for i := Low(gPlayers) to High(gPlayers) do
1377 if (gPlayers[i] <> nil) and gPlayers[i].Live then
1378 gPlayers[i].RememberState;
1379 end;
1381 procedure g_Player_ResetAll(Force, Silent: Boolean);
1382 var
1383 i: Integer;
1384 begin
1385 gTeamStat[TEAM_RED].Goals := 0;
1386 gTeamStat[TEAM_BLUE].Goals := 0;
1388 if gPlayers <> nil then
1389 for i := 0 to High(gPlayers) do
1390 if gPlayers[i] <> nil then
1391 begin
1392 gPlayers[i].Reset(Force);
1394 if gPlayers[i] is TPlayer then
1395 begin
1396 if (not gPlayers[i].FSpectator) or gPlayers[i].FWantsInGame then
1397 gPlayers[i].Respawn(Silent)
1398 else
1399 gPlayers[i].Spectate();
1400 end
1401 else
1402 TBot(gPlayers[i]).Respawn(Silent);
1403 end;
1404 end;
1406 procedure g_Player_CreateCorpse(Player: TPlayer);
1407 var
1408 find_id: DWORD;
1409 ok: Boolean;
1410 begin
1411 if Player.Live then
1412 Exit;
1413 if Player.FObj.Y >= gMapInfo.Height+128 then
1414 Exit;
1416 with Player do
1417 begin
1418 if (FHealth >= -50) or (gGibsCount = 0) then
1419 begin
1420 if (gCorpses = nil) or (Length(gCorpses) = 0) then
1421 Exit;
1423 ok := False;
1424 for find_id := 0 to High(gCorpses) do
1425 if gCorpses[find_id] = nil then
1426 begin
1427 ok := True;
1428 Break;
1429 end;
1431 if not ok then
1432 find_id := Random(Length(gCorpses));
1434 gCorpses[find_id] := TCorpse.Create(FObj.X, FObj.Y, FModel.Name, FHealth < -20);
1435 gCorpses[find_id].FColor := FModel.Color;
1436 gCorpses[find_id].FObj.Vel := FObj.Vel;
1437 gCorpses[find_id].FObj.Accel := FObj.Accel;
1438 end
1439 else
1440 g_Player_CreateGibs(FObj.X + PLAYER_RECT_CX,
1441 FObj.Y + PLAYER_RECT_CY,
1442 FModel.Name, FModel.Color);
1443 end;
1444 end;
1446 procedure g_Player_CreateShell(fX, fY, dX, dY: Integer; T: Byte);
1447 var
1448 SID: DWORD;
1449 begin
1450 if (gShells = nil) or (Length(gShells) = 0) then
1451 Exit;
1453 with gShells[CurrentShell] do
1454 begin
1455 SpriteID := 0;
1456 g_Obj_Init(@Obj);
1457 Obj.Rect.X := 0;
1458 Obj.Rect.Y := 0;
1459 if T = SHELL_BULLET then
1460 begin
1461 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID) then
1462 SpriteID := SID;
1463 CX := 2;
1464 CY := 1;
1465 Obj.Rect.Width := 4;
1466 Obj.Rect.Height := 2;
1467 end
1468 else
1469 begin
1470 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID) then
1471 SpriteID := SID;
1472 CX := 4;
1473 CY := 2;
1474 Obj.Rect.Width := 7;
1475 Obj.Rect.Height := 3;
1476 end;
1477 SType := T;
1478 Live := True;
1479 Obj.X := fX;
1480 Obj.Y := fY;
1481 g_Obj_Push(@Obj, dX + Random(4)-Random(4), dY-Random(4));
1482 RAngle := Random(360);
1483 Timeout := gTime + SHELL_TIMEOUT;
1485 if CurrentShell >= High(gShells) then
1486 CurrentShell := 0
1487 else
1488 Inc(CurrentShell);
1489 end;
1490 end;
1492 procedure g_Player_CreateGibs(fX, fY: Integer; ModelName: string; fColor: TRGB);
1493 var
1494 a: Integer;
1495 GibsArray: TGibsArray;
1496 begin
1497 if (gGibs = nil) or (Length(gGibs) = 0) then
1498 Exit;
1499 if not g_PlayerModel_GetGibs(ModelName, GibsArray) then
1500 Exit;
1502 for a := 0 to High(GibsArray) do
1503 with gGibs[CurrentGib] do
1504 begin
1505 Color := fColor;
1506 ID := GibsArray[a].ID;
1507 MaskID := GibsArray[a].MaskID;
1508 Live := True;
1509 g_Obj_Init(@Obj);
1510 Obj.Rect := GibsArray[a].Rect;
1511 Obj.X := fX-GibsArray[a].Rect.X-(GibsArray[a].Rect.Width div 2);
1512 Obj.Y := fY-GibsArray[a].Rect.Y-(GibsArray[a].Rect.Height div 2);
1513 g_Obj_PushA(@Obj, 25 + Random(10), Random(361));
1514 RAngle := Random(360);
1516 if gBloodCount > 0 then
1517 g_GFX_Blood(fX, fY, 16*gBloodCount+Random(5*gBloodCount), -16+Random(33), -16+Random(33),
1518 Random(48), Random(48), 150, 0, 0);
1520 if CurrentGib >= High(gGibs) then
1521 CurrentGib := 0
1522 else
1523 Inc(CurrentGib);
1524 end;
1525 end;
1527 procedure g_Player_UpdatePhysicalObjects();
1528 var
1529 i: Integer;
1530 vel: TPoint2i;
1531 mr: Word;
1533 procedure ShellSound_Bounce(X, Y: Integer; T: Byte);
1534 var
1535 k: Integer;
1536 begin
1537 k := 1 + Random(2);
1538 if T = SHELL_BULLET then
1539 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k), X, Y)
1540 else
1541 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k), X, Y);
1542 end;
1544 begin
1545 // Êóñêè ìÿñà:
1546 if gGibs <> nil then
1547 for i := 0 to High(gGibs) do
1548 if gGibs[i].Live then
1549 with gGibs[i] do
1550 begin
1551 vel := Obj.Vel;
1552 mr := g_Obj_Move(@Obj, True, False, True);
1554 if WordBool(mr and MOVE_FALLOUT) then
1555 begin
1556 Live := False;
1557 Continue;
1558 end;
1560 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1561 if WordBool(mr and MOVE_HITWALL) then
1562 Obj.Vel.X := -(vel.X div 2);
1563 if WordBool(mr and (MOVE_HITCEIL or MOVE_HITLAND)) then
1564 Obj.Vel.Y := -(vel.Y div 2);
1566 if (Obj.Vel.X >= 0) then
1567 begin // Clockwise
1568 RAngle := RAngle + Abs(Obj.Vel.X)*6 + Abs(Obj.Vel.Y);
1569 if RAngle >= 360 then
1570 RAngle := RAngle mod 360;
1571 end else begin // Counter-clockwise
1572 RAngle := RAngle - Abs(Obj.Vel.X)*6 - Abs(Obj.Vel.Y);
1573 if RAngle < 0 then
1574 RAngle := (360 - (Abs(RAngle) mod 360)) mod 360;
1575 end;
1577 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1578 if gTime mod (GAME_TICK*3) = 0 then
1579 Obj.Vel.X := z_dec(Obj.Vel.X, 1);
1580 end;
1582 // Òðóïû:
1583 if gCorpses <> nil then
1584 for i := 0 to High(gCorpses) do
1585 if gCorpses[i] <> nil then
1586 if gCorpses[i].State = CORPSE_STATE_REMOVEME then
1587 begin
1588 gCorpses[i].Free();
1589 gCorpses[i] := nil;
1590 end
1591 else
1592 gCorpses[i].Update();
1594 // Ãèëüçû:
1595 if gShells <> nil then
1596 for i := 0 to High(gShells) do
1597 if gShells[i].Live then
1598 with gShells[i] do
1599 begin
1600 vel := Obj.Vel;
1601 mr := g_Obj_Move(@Obj, True, False, True);
1603 if WordBool(mr and MOVE_FALLOUT) or (gShells[i].Timeout < gTime) then
1604 begin
1605 Live := False;
1606 Continue;
1607 end;
1609 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1610 if WordBool(mr and MOVE_HITWALL) then
1611 begin
1612 Obj.Vel.X := -(vel.X div 2);
1613 if not WordBool(mr and MOVE_INWATER) then
1614 ShellSound_Bounce(Obj.X, Obj.Y, SType);
1615 end;
1616 if WordBool(mr and (MOVE_HITCEIL or MOVE_HITLAND)) then
1617 begin
1618 Obj.Vel.Y := -(vel.Y div 2);
1619 if Obj.Vel.X <> 0 then Obj.Vel.X := Obj.Vel.X div 2;
1620 if (Obj.Vel.X = 0) and (Obj.Vel.Y = 0) then
1621 begin
1622 if RAngle mod 90 <> 0 then
1623 RAngle := (RAngle div 90) * 90;
1624 end
1625 else if not WordBool(mr and MOVE_INWATER) then
1626 ShellSound_Bounce(Obj.X, Obj.Y, SType);
1627 end;
1629 if (Obj.Vel.X >= 0) then
1630 begin // Clockwise
1631 RAngle := RAngle + Abs(Obj.Vel.X)*8 + Abs(Obj.Vel.Y);
1632 if RAngle >= 360 then
1633 RAngle := RAngle mod 360;
1634 end else begin // Counter-clockwise
1635 RAngle := RAngle - Abs(Obj.Vel.X)*8 - Abs(Obj.Vel.Y);
1636 if RAngle < 0 then
1637 RAngle := (360 - (Abs(RAngle) mod 360)) mod 360;
1638 end;
1639 end;
1640 end;
1642 procedure g_Player_DrawCorpses();
1643 var
1644 i: Integer;
1645 a: TPoint;
1646 begin
1647 if gGibs <> nil then
1648 for i := 0 to High(gGibs) do
1649 if gGibs[i].Live then
1650 with gGibs[i] do
1651 begin
1652 if not g_Obj_Collide(sX, sY, sWidth, sHeight, @Obj) then
1653 Continue;
1655 a.X := Obj.Rect.X+(Obj.Rect.Width div 2);
1656 a.y := Obj.Rect.Y+(Obj.Rect.Height div 2);
1658 e_DrawAdv(ID, Obj.X, Obj.Y, 0, True, False, RAngle, @a, M_NONE);
1660 e_Colors := Color;
1661 e_DrawAdv(MaskID, Obj.X, Obj.Y, 0, True, False, RAngle, @a, M_NONE);
1662 e_Colors.R := 255;
1663 e_Colors.G := 255;
1664 e_Colors.B := 255;
1665 end;
1667 if gCorpses <> nil then
1668 for i := 0 to High(gCorpses) do
1669 if gCorpses[i] <> nil then
1670 gCorpses[i].Draw();
1671 end;
1673 procedure g_Player_DrawShells();
1674 var
1675 i: Integer;
1676 a: TPoint;
1677 begin
1678 if gShells <> nil then
1679 for i := 0 to High(gShells) do
1680 if gShells[i].Live then
1681 with gShells[i] do
1682 begin
1683 if not g_Obj_Collide(sX, sY, sWidth, sHeight, @Obj) then
1684 Continue;
1686 a.X := CX;
1687 a.Y := CY;
1689 e_DrawAdv(SpriteID, Obj.X, Obj.Y, 0, True, False, RAngle, @a, M_NONE);
1690 end;
1691 end;
1693 procedure g_Player_RemoveAllCorpses();
1694 var
1695 i: Integer;
1696 begin
1697 gGibs := nil;
1698 gShells := nil;
1699 SetLength(gGibs, MaxGibs);
1700 SetLength(gShells, MaxGibs);
1701 CurrentGib := 0;
1702 CurrentShell := 0;
1704 if gCorpses <> nil then
1705 for i := 0 to High(gCorpses) do
1706 gCorpses[i].Free();
1708 gCorpses := nil;
1709 SetLength(gCorpses, MaxCorpses);
1710 end;
1712 procedure g_Player_Corpses_SaveState(var Mem: TBinMemoryWriter);
1713 var
1714 count, i: Integer;
1715 b: Boolean;
1716 begin
1717 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ:
1718 count := 0;
1719 if gCorpses <> nil then
1720 for i := 0 to High(gCorpses) do
1721 if gCorpses[i] <> nil then
1722 count := count + 1;
1724 Mem := TBinMemoryWriter.Create((count+1) * 128);
1726 // Êîëè÷åñòâî òðóïîâ:
1727 Mem.WriteInt(count);
1729 if count = 0 then
1730 Exit;
1732 // Ñîõðàíÿåì òðóïû:
1733 for i := 0 to High(gCorpses) do
1734 if gCorpses[i] <> nil then
1735 begin
1736 // Íàçâàíèå ìîäåëè:
1737 Mem.WriteString(gCorpses[i].FModelName);
1738 // Òèï ñìåðòè:
1739 b := gCorpses[i].Mess;
1740 Mem.WriteBoolean(b);
1741 // Ñîõðàíÿåì äàííûå òðóïà:
1742 gCorpses[i].SaveState(Mem);
1743 end;
1744 end;
1746 procedure g_Player_Corpses_LoadState(var Mem: TBinMemoryReader);
1747 var
1748 count, i: Integer;
1749 str: String;
1750 b: Boolean;
1751 begin
1752 if Mem = nil then
1753 Exit;
1755 g_Player_RemoveAllCorpses();
1757 // Êîëè÷åñòâî òðóïîâ:
1758 Mem.ReadInt(count);
1760 if count > Length(gCorpses) then
1761 begin
1762 raise EBinSizeError.Create('g_Player_Corpses_LoadState: Too Many Corpses');
1763 end;
1765 if count = 0 then
1766 Exit;
1768 // Çàãðóæàåì òðóïû:
1769 for i := 0 to count-1 do
1770 begin
1771 // Íàçâàíèå ìîäåëè:
1772 Mem.ReadString(str);
1773 // Òèï ñìåðòè:
1774 Mem.ReadBoolean(b);
1775 // Ñîçäàåì òðóï:
1776 gCorpses[i] := TCorpse.Create(0, 0, str, b);
1777 // Çàãðóæàåì äàííûå òðóïà:
1778 gCorpses[i].LoadState(Mem);
1779 end;
1780 end;
1782 { T P l a y e r : }
1784 procedure TPlayer.BFGHit();
1785 begin
1786 g_Weapon_BFGHit(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
1787 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2));
1788 if g_Game_IsServer and g_Game_IsNet then
1789 MH_SEND_Effect(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
1790 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
1791 0, NET_GFX_BFGHIT);
1792 end;
1794 procedure TPlayer.ChangeModel(ModelName: string);
1795 var
1796 Model: TPlayerModel;
1797 begin
1798 Model := g_PlayerModel_Get(ModelName);
1799 if Model = nil then Exit;
1801 FModel.Free();
1802 FModel := Model;
1803 end;
1805 procedure TPlayer.SetModel(ModelName: string);
1806 var
1807 m: TPlayerModel;
1808 begin
1809 m := g_PlayerModel_Get(ModelName);
1810 if m = nil then
1811 begin
1812 g_SimpleError(Format(_lc[I_GAME_ERROR_MODEL_FALLBACK], [ModelName]));
1813 m := g_PlayerModel_Get('doomer');
1814 if m = nil then
1815 begin
1816 g_FatalError(Format(_lc[I_GAME_ERROR_MODEL], ['doomer']));
1817 Exit;
1818 end;
1819 end;
1821 if FModel <> nil then
1822 FModel.Free();
1824 FModel := m;
1826 if not (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
1827 FModel.Color := FColor
1828 else
1829 FModel.Color := TEAMCOLOR[FTeam];
1830 FModel.SetWeapon(FCurrWeap);
1831 FModel.SetFlag(FFlag);
1832 SetDirection(FDirection);
1833 end;
1835 procedure TPlayer.SetColor(Color: TRGB);
1836 begin
1837 FColor := Color;
1838 if not (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
1839 if FModel <> nil then FModel.Color := Color;
1840 end;
1842 procedure TPlayer.SwitchTeam;
1843 begin
1844 if g_Game_IsClient then
1845 Exit;
1846 if not (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then Exit;
1848 if gGameOn and FLive then
1849 Kill(K_SIMPLEKILL, FUID, HIT_SELF);
1851 if FTeam = TEAM_RED then
1852 begin
1853 ChangeTeam(TEAM_BLUE);
1854 g_Console_Add(Format(_lc[I_PLAYER_CHTEAM_BLUE], [FName]), True);
1855 if g_Game_IsNet then
1856 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM, TEAM_BLUE, FName);
1857 end
1858 else
1859 begin
1860 ChangeTeam(TEAM_RED);
1861 g_Console_Add(Format(_lc[I_PLAYER_CHTEAM_RED], [FName]), True);
1862 if g_Game_IsNet then
1863 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM, TEAM_RED, FName);
1864 end;
1865 FPreferredTeam := FTeam;
1866 end;
1868 procedure TPlayer.ChangeTeam(Team: Byte);
1869 var
1870 OldTeam: Byte;
1871 begin
1872 OldTeam := FTeam;
1873 FTeam := Team;
1874 case Team of
1875 TEAM_RED, TEAM_BLUE:
1876 FModel.Color := TEAMCOLOR[Team];
1877 else
1878 FModel.Color := FColor;
1879 end;
1880 if (FTeam <> OldTeam) and g_Game_IsNet and g_Game_IsServer then
1881 MH_SEND_PlayerStats(FUID);
1882 end;
1885 procedure TPlayer.CollideItem();
1886 var
1887 i: Integer;
1888 r: Boolean;
1889 begin
1890 if gItems = nil then Exit;
1891 if not FLive then Exit;
1893 for i := 0 to High(gItems) do
1894 with gItems[i] do
1895 begin
1896 if (ItemType <> ITEM_NONE) and Live then
1897 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
1898 PLAYER_RECT.Height, @Obj) then
1899 begin
1900 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
1902 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
1903 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
1904 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
1905 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
1906 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
1908 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
1909 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
1910 (gGameSettings.GameType = GT_SINGLE) and
1911 (g_Player_GetCount() > 1)) then
1912 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
1913 end;
1914 end;
1915 end;
1918 function TPlayer.CollideLevel(XInc, YInc: Integer): Boolean;
1919 begin
1920 Result := g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc,
1921 PLAYER_RECT.Width, PLAYER_RECT.Height, PANEL_WALL,
1922 False);
1923 end;
1925 constructor TPlayer.Create();
1926 begin
1927 FIamBot := False;
1928 FDummy := False;
1929 FSpawned := False;
1931 FSawSound := TPlayableSound.Create();
1932 FSawSoundIdle := TPlayableSound.Create();
1933 FSawSoundHit := TPlayableSound.Create();
1934 FSawSoundSelect := TPlayableSound.Create();
1935 FJetSoundFly := TPlayableSound.Create();
1936 FJetSoundOn := TPlayableSound.Create();
1937 FJetSoundOff := TPlayableSound.Create();
1939 FSawSound.SetByName('SOUND_WEAPON_FIRESAW');
1940 FSawSoundIdle.SetByName('SOUND_WEAPON_IDLESAW');
1941 FSawSoundHit.SetByName('SOUND_WEAPON_HITSAW');
1942 FSawSoundSelect.SetByName('SOUND_WEAPON_SELECTSAW');
1943 FJetSoundFly.SetByName('SOUND_PLAYER_JETFLY');
1944 FJetSoundOn.SetByName('SOUND_PLAYER_JETON');
1945 FJetSoundOff.SetByName('SOUND_PLAYER_JETOFF');
1947 FSpectatePlayer := -1;
1948 FClientID := -1;
1949 FPing := 0;
1950 FLoss := 0;
1951 FSavedState.WaitRecall := False;
1952 FShellTimer := -1;
1954 FActualModelName := 'doomer';
1956 g_Obj_Init(@FObj);
1957 FObj.Rect := PLAYER_RECT;
1959 FBFGFireCounter := -1;
1960 FJustTeleported := False;
1961 FNetTime := 0;
1962 end;
1964 procedure TPlayer.Damage(value: Word; SpawnerUID: Word; vx, vy: Integer; t: Byte);
1965 var
1966 c: Word;
1967 begin
1968 if (not g_Game_IsClient) and (not FLive) then
1969 Exit;
1971 FLastHit := t;
1973 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
1974 if ((t = HIT_TRAP) or (t = HIT_SELF)) and (not FGodMode) then
1975 begin
1976 if not g_Game_IsClient then
1977 begin
1978 FArmor := 0;
1979 if t = HIT_TRAP then
1980 begin
1981 // Ëîâóøêà óáèâàåò ñðàçó:
1982 FHealth := -100;
1983 Kill(K_EXTRAHARDKILL, SpawnerUID, t);
1984 end;
1985 if t = HIT_SELF then
1986 begin
1987 // Ñàìîóáèéñòâî:
1988 FHealth := 0;
1989 Kill(K_SIMPLEKILL, SpawnerUID, t);
1990 end;
1991 end;
1992 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
1993 FMegaRulez[MR_SUIT] := 0;
1994 FMegaRulez[MR_INVUL] := 0;
1995 FMegaRulez[MR_INVIS] := 0;
1996 FBerserk := 0;
1997 end;
1999 // Íî îò îñòàëüíîãî ñïàñàåò:
2000 if FMegaRulez[MR_INVUL] >= gTime then
2001 Exit;
2003 // ×èò-êîä "ÃÎÐÅÖ":
2004 if FGodMode then
2005 Exit;
2007 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2008 if LongBool(gGameSettings.Options and GAME_OPTION_TEAMDAMAGE) or
2009 (SpawnerUID = FUID) or
2010 (not SameTeam(FUID, SpawnerUID)) then
2011 begin
2012 FLastSpawnerUID := SpawnerUID;
2014 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2015 if gBloodCount > 0 then
2016 begin
2017 c := Min(value, 200)*gBloodCount + Random(Min(value, 200) div 2);
2018 if value div 4 <= c then
2019 c := c - (value div 4)
2020 else
2021 c := 0;
2023 if (t = HIT_SOME) and (vx = 0) and (vy = 0) then
2024 MakeBloodSimple(c)
2025 else
2026 case t of
2027 HIT_TRAP, HIT_ACID, HIT_FLAME, HIT_SELF: MakeBloodSimple(c);
2028 HIT_BFG, HIT_ROCKET, HIT_SOME: MakeBloodVector(c, vx, vy);
2029 end;
2031 if t = HIT_WATER then
2032 g_GFX_Bubbles(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2),
2033 FObj.Y+PLAYER_RECT.Y-4, value div 2, 8, 4);
2034 end;
2036 // Áóôåð óðîíà:
2037 if FLive then
2038 Inc(FDamageBuffer, value);
2040 // Âñïûøêà áîëè:
2041 if gFlash <> 0 then
2042 FPain := FPain + value;
2043 end;
2045 if g_Game_IsServer and g_Game_IsNet then
2046 begin
2047 MH_SEND_PlayerDamage(FUID, t, SpawnerUID, value, vx, vy);
2048 MH_SEND_PlayerStats(FUID);
2049 MH_SEND_PlayerPos(False, FUID);
2050 end;
2051 end;
2053 function TPlayer.Heal(value: Word; Soft: Boolean): Boolean;
2054 begin
2055 Result := False;
2056 if g_Game_IsClient then
2057 Exit;
2058 if not FLive then
2059 Exit;
2061 if Soft and (FHealth < PLAYER_HP_SOFT) then
2062 begin
2063 IncMax(FHealth, value, PLAYER_HP_SOFT);
2064 Result := True;
2065 end;
2066 if (not Soft) and (FHealth < PLAYER_HP_LIMIT) then
2067 begin
2068 IncMax(FHealth, value, PLAYER_HP_LIMIT);
2069 Result := True;
2070 end;
2072 if Result and g_Game_IsServer and g_Game_IsNet then
2073 MH_SEND_PlayerStats(FUID);
2074 end;
2076 destructor TPlayer.Destroy();
2077 begin
2078 if (gPlayer1 <> nil) and (gPlayer1.FUID = FUID) then
2079 gPlayer1 := nil;
2080 if (gPlayer2 <> nil) and (gPlayer2.FUID = FUID) then
2081 gPlayer2 := nil;
2083 FSawSound.Free();
2084 FSawSoundIdle.Free();
2085 FSawSoundHit.Free();
2086 FJetSoundFly.Free();
2087 FJetSoundOn.Free();
2088 FJetSoundOff.Free();
2089 FModel.Free();
2091 inherited;
2092 end;
2094 procedure TPlayer.DrawBubble();
2095 var
2096 bubX, bubY: Integer;
2097 ID: LongWord;
2098 Rb, Gb, Bb,
2099 Rw, Gw, Bw: SmallInt;
2100 Dot: Byte;
2101 begin
2102 bubX := FObj.X+FObj.Rect.X + IfThen(FDirection = D_LEFT, -4, 18);
2103 bubY := FObj.Y+FObj.Rect.Y - 18;
2104 Rb := 64;
2105 Gb := 64;
2106 Bb := 64;
2107 Rw := 240;
2108 Gw := 240;
2109 Bw := 240;
2110 case gChatBubble of
2111 1: // simple textual non-bubble
2112 begin
2113 bubX := FObj.X+FObj.Rect.X - 11;
2114 bubY := FObj.Y+FObj.Rect.Y - 17;
2115 e_TextureFontPrint(bubX, bubY, '[...]', gStdFont);
2116 Exit;
2117 end;
2118 2: // advanced pixel-perfect bubble
2119 begin
2120 if FTeam = TEAM_RED then
2121 Rb := 255
2122 else
2123 if FTeam = TEAM_BLUE then
2124 Bb := 255;
2125 end;
2126 3: // colored bubble
2127 begin
2128 Rb := FModel.Color.R;
2129 Gb := FModel.Color.G;
2130 Bb := FModel.Color.B;
2131 Rw := Min(Rb * 2 + 64, 255);
2132 Gw := Min(Gb * 2 + 64, 255);
2133 Bw := Min(Bb * 2 + 64, 255);
2134 if (Abs(Rw - Rb) < 32)
2135 or (Abs(Gw - Gb) < 32)
2136 or (Abs(Bw - Bb) < 32) then
2137 begin
2138 Rb := Max(Rw div 2 - 16, 0);
2139 Gb := Max(Gw div 2 - 16, 0);
2140 Bb := Max(Bw div 2 - 16, 0);
2141 end;
2142 end;
2143 4: // custom textured bubble
2144 begin
2145 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID) then
2146 if FDirection = D_RIGHT then
2147 e_Draw(ID, bubX - 6, bubY - 7, 0, True, False)
2148 else
2149 e_Draw(ID, bubX - 6, bubY - 7, 0, True, False, M_HORIZONTAL);
2150 Exit;
2151 end;
2152 end;
2154 // Outer borders
2155 e_DrawQuad(bubX + 1, bubY , bubX + 18, bubY + 13, Rb, Gb, Bb);
2156 e_DrawQuad(bubX , bubY + 1, bubX + 19, bubY + 12, Rb, Gb, Bb);
2157 // Inner box
2158 e_DrawFillQuad(bubX + 1, bubY + 1, bubX + 18, bubY + 12, Rw, Gw, Bw, 0);
2160 // Tail
2161 Dot := IfThen(FDirection = D_LEFT, 14, 5);
2162 e_DrawLine(1, bubX + Dot, bubY + 14, bubX + Dot, bubY + 16, Rb, Gb, Bb);
2163 e_DrawLine(1, bubX + IfThen(FDirection = D_LEFT, Dot - 1, Dot + 1), bubY + 13, bubX + IfThen(FDirection = D_LEFT, Dot - 1, Dot + 1), bubY + 15, Rw, Gw, Bw);
2164 e_DrawLine(1, bubX + IfThen(FDirection = D_LEFT, Dot - 2, Dot + 2), bubY + 13, bubX + IfThen(FDirection = D_LEFT, Dot - 2, Dot + 2), bubY + 14, Rw, Gw, Bw);
2165 e_DrawLine(1, bubX + IfThen(FDirection = D_LEFT, Dot - 3, Dot + 3), bubY + 13, bubX + IfThen(FDirection = D_LEFT, Dot - 3, Dot + 3), bubY + 13, Rw, Gw, Bw);
2166 e_DrawLine(1, bubX + IfThen(FDirection = D_LEFT, Dot - 3, Dot + 3), bubY + 14, bubX + IfThen(FDirection = D_LEFT, Dot - 1, Dot + 1), bubY + 16, Rb, Gb, Bb);
2168 // Dots
2169 Dot := 6;
2170 e_DrawFillQuad(bubX + Dot, bubY + 8, bubX + Dot + 1, bubY + 9, Rb, Gb, Bb, 0);
2171 e_DrawFillQuad(bubX + Dot + 3, bubY + 8, bubX + Dot + 4, bubY + 9, Rb, Gb, Bb, 0);
2172 e_DrawFillQuad(bubX + Dot + 6, bubY + 8, bubX + Dot + 7, bubY + 9, Rb, Gb, Bb, 0);
2173 end;
2175 procedure TPlayer.Draw();
2176 var
2177 ID: DWORD;
2178 w, h: Word;
2179 dr: Boolean;
2180 begin
2181 if FLive then
2182 begin
2183 if (FMegaRulez[MR_INVUL] > gTime) and (gPlayerDrawn <> Self) then
2184 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID) then
2185 begin
2186 e_GetTextureSize(ID, @w, @h);
2187 if FDirection = D_LEFT then
2188 e_Draw(ID, FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2)-(w div 2)+4,
2189 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2)-(h div 2)-7, 0, True, False)
2190 else
2191 e_Draw(ID, FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2)-(w div 2)-2,
2192 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2)-(h div 2)-7, 0, True, False);
2193 end;
2195 if FMegaRulez[MR_INVIS] > gTime then
2196 begin
2197 if (gPlayerDrawn <> nil) and ((Self = gPlayerDrawn) or
2198 ((FTeam = gPlayerDrawn.Team) and (gGameSettings.GameMode <> GM_DM))) then
2199 begin
2200 if (FMegaRulez[MR_INVIS] - gTime) <= 2100 then
2201 dr := not Odd((FMegaRulez[MR_INVIS] - gTime) div 300)
2202 else
2203 dr := True;
2204 if dr then
2205 FModel.Draw(FObj.X, FObj.Y, 200)
2206 else
2207 FModel.Draw(FObj.X, FObj.Y);
2208 end
2209 else
2210 FModel.Draw(FObj.X, FObj.Y, 254);
2211 end
2212 else
2213 FModel.Draw(FObj.X, FObj.Y);
2214 end;
2216 if g_debug_Frames then
2217 begin
2218 e_DrawQuad(FObj.X+FObj.Rect.X,
2219 FObj.Y+FObj.Rect.Y,
2220 FObj.X+FObj.Rect.X+FObj.Rect.Width-1,
2221 FObj.Y+FObj.Rect.Y+FObj.Rect.Height-1,
2222 0, 255, 0);
2223 end;
2225 if (gChatBubble > 0) and (FKeys[KEY_CHAT].Pressed) and not FGhost then
2226 DrawBubble();
2227 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2228 if gAimLine and Live and
2229 ((Self = gPlayer1) or (Self = gPlayer2)) then
2230 DrawAim();
2231 end;
2233 procedure TPlayer.DrawAim();
2234 var
2235 wx, wy, xx, yy: Integer;
2236 angle: SmallInt;
2237 sz, len: Word;
2238 begin
2239 wx := FObj.X + WEAPONPOINT[FDirection].X + IfThen(FDirection = D_LEFT, 7, -7);
2240 wy := FObj.Y + WEAPONPOINT[FDirection].Y;
2241 angle := FAngle;
2242 len := 1024;
2243 sz := 2;
2244 case FCurrWeap of
2245 0: begin // Punch
2246 len := 12;
2247 sz := 4;
2248 end;
2249 1: begin // Chainsaw
2250 len := 24;
2251 sz := 6;
2252 end;
2253 2: begin // Pistol
2254 len := 1024;
2255 sz := 2;
2256 if angle = ANGLE_RIGHTUP then Dec(angle, 2);
2257 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2258 if angle = ANGLE_LEFTUP then Inc(angle, 2);
2259 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2260 end;
2261 3: begin // Shotgun
2262 len := 1024;
2263 sz := 3;
2264 if angle = ANGLE_RIGHTUP then Dec(angle, 2);
2265 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2266 if angle = ANGLE_LEFTUP then Inc(angle, 2);
2267 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2268 end;
2269 4: begin // Double Shotgun
2270 len := 1024;
2271 sz := 4;
2272 if angle = ANGLE_RIGHTUP then Dec(angle, 2);
2273 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2274 if angle = ANGLE_LEFTUP then Inc(angle, 2);
2275 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2276 end;
2277 5: begin // Chaingun
2278 len := 1024;
2279 sz := 3;
2280 if angle = ANGLE_RIGHTUP then Dec(angle, 2);
2281 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2282 if angle = ANGLE_LEFTUP then Inc(angle, 2);
2283 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2284 end;
2285 6: begin // Rocket Launcher
2286 len := 1024;
2287 sz := 7;
2288 if angle = ANGLE_RIGHTUP then Inc(angle, 2);
2289 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2290 if angle = ANGLE_LEFTUP then Dec(angle, 2);
2291 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2292 end;
2293 7: begin // Plasmagun
2294 len := 1024;
2295 sz := 5;
2296 if angle = ANGLE_RIGHTUP then Inc(angle);
2297 if angle = ANGLE_RIGHTDOWN then Inc(angle, 3);
2298 if angle = ANGLE_LEFTUP then Dec(angle);
2299 if angle = ANGLE_LEFTDOWN then Dec(angle, 3);
2300 end;
2301 8: begin // BFG
2302 len := 1024;
2303 sz := 12;
2304 if angle = ANGLE_RIGHTUP then Inc(angle, 1);
2305 if angle = ANGLE_RIGHTDOWN then Inc(angle, 2);
2306 if angle = ANGLE_LEFTUP then Dec(angle, 1);
2307 if angle = ANGLE_LEFTDOWN then Dec(angle, 2);
2308 end;
2309 9: begin // Super Chaingun
2310 len := 1024;
2311 sz := 4;
2312 if angle = ANGLE_RIGHTUP then Dec(angle, 2);
2313 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2314 if angle = ANGLE_LEFTUP then Inc(angle, 2);
2315 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2316 end;
2317 end;
2318 xx := Trunc(Cos(-DegToRad(angle)) * len) + wx;
2319 yy := Trunc(Sin(-DegToRad(angle)) * len) + wy;
2320 e_DrawLine(sz, wx, wy, xx, yy, 255, 0, 0, 96);
2321 end;
2323 procedure TPlayer.DrawGUI();
2324 var
2325 ID: DWORD;
2326 X, Y, SY, a, p, m: Integer;
2327 tw, th: Word;
2328 cw, ch: Byte;
2329 s: string;
2330 stat: TPlayerStatArray;
2331 begin
2332 X := gPlayerScreenSize.X;
2333 SY := gPlayerScreenSize.Y;
2334 Y := 0;
2336 if gShowGoals and (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
2337 begin
2338 if gGameSettings.GameMode = GM_CTF then
2339 a := 32 + 8
2340 else
2341 a := 0;
2342 if gGameSettings.GameMode = GM_CTF then
2343 begin
2344 s := 'TEXTURE_PLAYER_REDFLAG';
2345 if gFlags[FLAG_RED].State = FLAG_STATE_CAPTURED then
2346 s := 'TEXTURE_PLAYER_REDFLAG_S';
2347 if gFlags[FLAG_RED].State = FLAG_STATE_DROPPED then
2348 s := 'TEXTURE_PLAYER_REDFLAG_D';
2349 if g_Texture_Get(s, ID) then
2350 e_Draw(ID, X-16-32, 240-72-4, 0, True, False);
2351 end;
2353 s := IntToStr(gTeamStat[TEAM_RED].Goals);
2354 e_CharFont_GetSize(gMenuFont, s, tw, th);
2355 e_CharFont_PrintEx(gMenuFont, X-16-a-tw, 240-72-4, s, TEAMCOLOR[TEAM_RED]);
2357 if gGameSettings.GameMode = GM_CTF then
2358 begin
2359 s := 'TEXTURE_PLAYER_BLUEFLAG';
2360 if gFlags[FLAG_BLUE].State = FLAG_STATE_CAPTURED then
2361 s := 'TEXTURE_PLAYER_BLUEFLAG_S';
2362 if gFlags[FLAG_BLUE].State = FLAG_STATE_DROPPED then
2363 s := 'TEXTURE_PLAYER_BLUEFLAG_D';
2364 if g_Texture_Get(s, ID) then
2365 e_Draw(ID, X-16-32, 240-32-4, 0, True, False);
2366 end;
2368 s := IntToStr(gTeamStat[TEAM_BLUE].Goals);
2369 e_CharFont_GetSize(gMenuFont, s, tw, th);
2370 e_CharFont_PrintEx(gMenuFont, X-16-a-tw, 240-32-4, s, TEAMCOLOR[TEAM_BLUE]);
2371 end;
2373 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID) then
2374 e_DrawFill(ID, X, 0, 1, (gPlayerScreenSize.Y div 256)+IfThen(gPlayerScreenSize.Y mod 256 > 0, 1, 0),
2375 0, False, False);
2377 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID) then
2378 e_Draw(ID, X+2, Y, 0, True, False);
2380 if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
2381 begin
2382 if gShowStat then
2383 begin
2384 s := IntToStr(Frags);
2385 e_CharFont_GetSize(gMenuFont, s, tw, th);
2386 e_CharFont_PrintEx(gMenuFont, X-16-tw, Y, s, _RGB(255, 0, 0));
2388 s := '';
2389 p := 1;
2390 m := 0;
2391 stat := g_Player_GetStats();
2392 if stat <> nil then
2393 begin
2394 p := 1;
2396 for a := 0 to High(stat) do
2397 if stat[a].Name <> Name then
2398 begin
2399 if stat[a].Frags > m then m := stat[a].Frags;
2400 if stat[a].Frags > Frags then p := p+1;
2401 end;
2402 end;
2404 s := IntToStr(p)+' / '+IntToStr(Length(stat))+' ';
2405 if Frags >= m then s := s+'+' else s := s+'-';
2406 s := s+IntToStr(Abs(Frags-m));
2408 e_CharFont_GetSize(gMenuSmallFont, s, tw, th);
2409 e_CharFont_PrintEx(gMenuSmallFont, X-16-tw, Y+32, s, _RGB(255, 0, 0));
2410 end;
2412 if gShowLives and (gGameSettings.MaxLives > 0) then
2413 begin
2414 s := IntToStr(Lives);
2415 e_CharFont_GetSize(gMenuFont, s, tw, th);
2416 e_CharFont_PrintEx(gMenuFont, X-16-tw, SY-32, s, _RGB(0, 255, 0));
2417 end;
2418 end;
2420 e_CharFont_GetSize(gMenuSmallFont, FName, tw, th);
2421 e_CharFont_PrintEx(gMenuSmallFont, X+98-(tw div 2), Y+8, FName, _RGB(255, 0, 0));
2423 if R_BERSERK in FRulez then
2424 e_Draw(gItemsTexturesID[ITEM_MEDKIT_BLACK], X+37, Y+45, 0, True, False)
2425 else
2426 e_Draw(gItemsTexturesID[ITEM_MEDKIT_LARGE], X+37, Y+45, 0, True, False);
2428 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID) then
2429 e_Draw(ID, X+36, Y+77, 0, True, False);
2431 s := IntToStr(IfThen(FHealth > 0, FHealth, 0));
2432 e_CharFont_GetSize(gMenuFont, s, tw, th);
2433 e_CharFont_PrintEx(gMenuFont, X+178-tw, Y+40, s, _RGB(255, 0, 0));
2435 s := IntToStr(FArmor);
2436 e_CharFont_GetSize(gMenuFont, s, tw, th);
2437 e_CharFont_PrintEx(gMenuFont, X+178-tw, Y+68, s, _RGB(255, 0, 0));
2439 s := IntToStr(GetAmmoByWeapon(FCurrWeap));
2441 case FCurrWeap of
2442 WEAPON_KASTET:
2443 begin
2444 s := '--';
2445 ID := gItemsTexturesID[ITEM_WEAPON_KASTET];
2446 end;
2447 WEAPON_SAW:
2448 begin
2449 s := '--';
2450 ID := gItemsTexturesID[ITEM_WEAPON_SAW];
2451 end;
2452 WEAPON_PISTOL: ID := gItemsTexturesID[ITEM_WEAPON_PISTOL];
2453 WEAPON_CHAINGUN: ID := gItemsTexturesID[ITEM_WEAPON_CHAINGUN];
2454 WEAPON_SHOTGUN1: ID := gItemsTexturesID[ITEM_WEAPON_SHOTGUN1];
2455 WEAPON_SHOTGUN2: ID := gItemsTexturesID[ITEM_WEAPON_SHOTGUN2];
2456 WEAPON_SUPERPULEMET: ID := gItemsTexturesID[ITEM_WEAPON_SUPERPULEMET];
2457 WEAPON_ROCKETLAUNCHER: ID := gItemsTexturesID[ITEM_WEAPON_ROCKETLAUNCHER];
2458 WEAPON_PLASMA: ID := gItemsTexturesID[ITEM_WEAPON_PLASMA];
2459 WEAPON_BFG: ID := gItemsTexturesID[ITEM_WEAPON_BFG];
2460 end;
2462 e_CharFont_GetSize(gMenuFont, s, tw, th);
2463 e_CharFont_PrintEx(gMenuFont, X+178-tw, Y+158, s, _RGB(255, 0, 0));
2464 e_Draw(ID, X+20, Y+160, 0, True, False);
2466 if R_KEY_RED in FRulez then
2467 e_Draw(gItemsTexturesID[ITEM_KEY_RED], X+78, Y+214, 0, True, False);
2469 if R_KEY_GREEN in FRulez then
2470 e_Draw(gItemsTexturesID[ITEM_KEY_GREEN], X+95, Y+214, 0, True, False);
2472 if R_KEY_BLUE in FRulez then
2473 e_Draw(gItemsTexturesID[ITEM_KEY_BLUE], X+112, Y+214, 0, True, False);
2475 if FJetFuel > 0 then
2476 begin
2477 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID) then
2478 e_Draw(ID, X+2, Y+116, 0, True, False);
2479 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID) then
2480 e_Draw(ID, X+2, Y+126, 0, True, False);
2481 e_DrawLine(4, X+16, Y+122, X+16+Trunc(168*IfThen(FAir > 0, FAir, 0)/AIR_MAX), Y+122, 0, 0, 196);
2482 e_DrawLine(4, X+16, Y+132, X+16+Trunc(168*FJetFuel/JET_MAX), Y+132, 208, 0, 0);
2483 end
2484 else
2485 begin
2486 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID) then
2487 e_Draw(ID, X+2, Y+124, 0, True, False);
2488 e_DrawLine(4, X+16, Y+130, X+16+Trunc(168*IfThen(FAir > 0, FAir, 0)/AIR_MAX), Y+130, 0, 0, 196);
2489 end;
2491 if gShowPing and g_Game_IsClient then
2492 begin
2493 s := _lc[I_GAME_PING_HUD] + IntToStr(NetPeer.lastRoundTripTime) + _lc[I_NET_SLIST_PING_MS];
2494 e_TextureFontPrint(X + 4, Y + 242, s, gStdFont);
2495 Y := Y + 16;
2496 end;
2498 if FSpectator then
2499 begin
2500 e_TextureFontPrint(X + 4, Y + 242, _lc[I_PLAYER_SPECT], gStdFont);
2501 e_TextureFontPrint(X + 4, Y + 258, _lc[I_PLAYER_SPECT2], gStdFont);
2502 e_TextureFontPrint(X + 4, Y + 274, _lc[I_PLAYER_SPECT1], gStdFont);
2503 if FNoRespawn then
2504 begin
2505 e_TextureFontGetSize(gStdFont, cw, ch);
2506 s := _lc[I_PLAYER_SPECT4];
2507 e_TextureFontPrintEx(gScreenWidth div 2 - cw*(Length(s) div 2),
2508 gScreenHeight-4-ch, s, gStdFont, 255, 255, 255, 1, True);
2509 e_TextureFontPrint(X + 4, Y + 290, _lc[I_PLAYER_SPECT1S], gStdFont);
2510 end;
2512 end;
2513 end;
2515 procedure TPlayer.DrawRulez();
2516 var
2517 dr: Boolean;
2518 begin
2519 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2520 if FMegaRulez[MR_INVUL] >= gTime then
2521 begin
2522 if (FMegaRulez[MR_INVUL]-gTime) <= 2100 then
2523 dr := not Odd((FMegaRulez[MR_INVUL]-gTime) div 300)
2524 else
2525 dr := True;
2527 if dr then
2528 e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1,
2529 191, 191, 191, 0, B_INVERT);
2530 end;
2532 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2533 if FMegaRulez[MR_SUIT] >= gTime then
2534 begin
2535 if (FMegaRulez[MR_SUIT]-gTime) <= 2100 then
2536 dr := not Odd((FMegaRulez[MR_SUIT]-gTime) div 300)
2537 else
2538 dr := True;
2540 if dr then
2541 e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1,
2542 0, 96, 0, 200, B_NONE);
2543 end;
2545 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2546 if (FBerserk >= 0) and (LongWord(FBerserk) >= gTime) and (gFlash = 2) then
2547 begin
2548 e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1,
2549 255, 0, 0, 200, B_NONE);
2550 end;
2551 end;
2553 procedure TPlayer.DrawPain();
2554 var
2555 a, h: Integer;
2556 begin
2557 if FPain = 0 then Exit;
2559 a := FPain;
2561 if a < 15 then h := 0
2562 else if a < 35 then h := 1
2563 else if a < 55 then h := 2
2564 else if a < 75 then h := 3
2565 else if a < 95 then h := 4
2566 else h := 5;
2568 //if a > 255 then a := 255;
2570 e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255, 0, 0, 255-h*50);
2571 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2572 end;
2574 procedure TPlayer.DrawPickup();
2575 var
2576 a, h: Integer;
2577 begin
2578 if FPickup = 0 then Exit;
2580 a := FPickup;
2582 if a < 15 then h := 1
2583 else if a < 35 then h := 2
2584 else if a < 55 then h := 3
2585 else if a < 75 then h := 4
2586 else h := 5;
2588 e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 150, 200, 150, 255-h*50);
2589 end;
2591 procedure TPlayer.Fire();
2592 var
2593 f, DidFire: Boolean;
2594 wx, wy, xd, yd: Integer;
2595 obj: TObj;
2596 begin
2597 if g_Game_IsClient then Exit;
2598 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
2599 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
2601 if FSpectator then
2602 begin
2603 Respawn(False);
2604 Exit;
2605 end;
2607 if FReloading[FCurrWeap] <> 0 then Exit;
2609 DidFire := False;
2611 f := False;
2612 wx := FObj.X+WEAPONPOINT[FDirection].X;
2613 wy := FObj.Y+WEAPONPOINT[FDirection].Y;
2614 xd := wx+IfThen(FDirection = D_LEFT, -30, 30);
2615 yd := wy+firediry();
2617 case FCurrWeap of
2618 WEAPON_KASTET:
2619 begin
2620 if R_BERSERK in FRulez then
2621 begin
2622 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2623 obj.X := FObj.X+FObj.Rect.X;
2624 obj.Y := FObj.Y+FObj.Rect.Y;
2625 obj.rect.X := 0;
2626 obj.rect.Y := 0;
2627 obj.rect.Width := 39;
2628 obj.rect.Height := 52;
2629 obj.Vel.X := (xd-wx) div 2;
2630 obj.Vel.Y := (yd-wy) div 2;
2631 obj.Accel.X := xd-wx;
2632 obj.Accel.y := yd-wy;
2634 if g_Weapon_Hit(@obj, 50, FUID, HIT_SOME) <> 0 then
2635 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj.X, FObj.Y)
2636 else
2637 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj.X, FObj.Y);
2639 if gFlash = 1 then
2640 if FPain < 50 then
2641 FPain := min(FPain + 25, 50);
2642 end else g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 3, FUID);
2644 DidFire := True;
2645 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
2646 end;
2648 WEAPON_SAW:
2649 begin
2650 if g_Weapon_chainsaw(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y,
2651 IfThen(gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF], 9, 3), FUID) <> 0 then
2652 begin
2653 FSawSoundSelect.Stop();
2654 FSawSound.Stop();
2655 FSawSoundHit.PlayAt(FObj.X, FObj.Y);
2656 end
2657 else if not FSawSoundHit.IsPlaying() then
2658 begin
2659 FSawSoundSelect.Stop();
2660 FSawSound.PlayAt(FObj.X, FObj.Y);
2661 end;
2663 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
2664 DidFire := True;
2665 f := True;
2666 end;
2668 WEAPON_PISTOL:
2669 if FAmmo[A_BULLETS] > 0 then
2670 begin
2671 g_Weapon_pistol(wx, wy, xd, yd, FUID);
2672 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
2673 Dec(FAmmo[A_BULLETS]);
2674 FFireAngle := FAngle;
2675 f := True;
2676 DidFire := True;
2677 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
2678 GameVelX, GameVelY-2, SHELL_BULLET);
2679 end;
2681 WEAPON_SHOTGUN1:
2682 if FAmmo[A_SHELLS] > 0 then
2683 begin
2684 g_Weapon_shotgun(wx, wy, xd, yd, FUID);
2685 if not gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx, wy);
2686 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
2687 Dec(FAmmo[A_SHELLS]);
2688 FFireAngle := FAngle;
2689 f := True;
2690 DidFire := True;
2691 FShellTimer := 10;
2692 FShellType := SHELL_SHELL;
2693 end;
2695 WEAPON_SHOTGUN2:
2696 if FAmmo[A_SHELLS] >= 2 then
2697 begin
2698 g_Weapon_dshotgun(wx, wy, xd, yd, FUID);
2699 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
2700 Dec(FAmmo[A_SHELLS], 2);
2701 FFireAngle := FAngle;
2702 f := True;
2703 DidFire := True;
2704 FShellTimer := 13;
2705 FShellType := SHELL_DBLSHELL;
2706 end;
2708 WEAPON_CHAINGUN:
2709 if FAmmo[A_BULLETS] > 0 then
2710 begin
2711 g_Weapon_mgun(wx, wy, xd, yd, FUID);
2712 if not gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx, wy);
2713 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
2714 Dec(FAmmo[A_BULLETS]);
2715 FFireAngle := FAngle;
2716 f := True;
2717 DidFire := True;
2718 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
2719 GameVelX, GameVelY-2, SHELL_BULLET);
2720 end;
2722 WEAPON_ROCKETLAUNCHER:
2723 if FAmmo[A_ROCKETS] > 0 then
2724 begin
2725 g_Weapon_rocket(wx, wy, xd, yd, FUID);
2726 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
2727 Dec(FAmmo[A_ROCKETS]);
2728 FFireAngle := FAngle;
2729 f := True;
2730 DidFire := True;
2731 end;
2733 WEAPON_PLASMA:
2734 if FAmmo[A_CELLS] > 0 then
2735 begin
2736 g_Weapon_plasma(wx, wy, xd, yd, FUID);
2737 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
2738 Dec(FAmmo[A_CELLS]);
2739 FFireAngle := FAngle;
2740 f := True;
2741 DidFire := True;
2742 end;
2744 WEAPON_BFG:
2745 if (FAmmo[A_CELLS] >= 40) and (FBFGFireCounter = -1) then
2746 begin
2747 FBFGFireCounter := 17;
2748 if not FNoReload then
2749 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj.X, FObj.Y);
2750 Dec(FAmmo[A_CELLS], 40);
2751 DidFire := True;
2752 end;
2754 WEAPON_SUPERPULEMET:
2755 if FAmmo[A_SHELLS] > 0 then
2756 begin
2757 g_Weapon_shotgun(wx, wy, xd, yd, FUID);
2758 if not gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx, wy);
2759 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
2760 Dec(FAmmo[A_SHELLS]);
2761 FFireAngle := FAngle;
2762 f := True;
2763 DidFire := True;
2764 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
2765 GameVelX, GameVelY-2, SHELL_SHELL);
2766 end;
2767 end;
2769 if g_Game_IsNet then
2770 begin
2771 if DidFire then
2772 begin
2773 if FCurrWeap <> WEAPON_BFG then
2774 MH_SEND_PlayerFire(FUID, FCurrWeap, wx, wy, xd, yd, LastShotID)
2775 else
2776 if not FNoReload then
2777 MH_SEND_Sound(FObj.X, FObj.Y, 'SOUND_WEAPON_STARTFIREBFG');
2778 end;
2780 MH_SEND_PlayerStats(FUID);
2781 end;
2783 if not f then Exit;
2785 if (FAngle = 0) or (FAngle = 180) then SetAction(A_ATTACK)
2786 else if (FAngle = ANGLE_LEFTDOWN) or (FAngle = ANGLE_RIGHTDOWN) then SetAction(A_ATTACKDOWN)
2787 else if (FAngle = ANGLE_LEFTUP) or (FAngle = ANGLE_RIGHTUP) then SetAction(A_ATTACKUP);
2788 end;
2790 function TPlayer.GetAmmoByWeapon(Weapon: Byte): Word;
2791 begin
2792 case Weapon of
2793 WEAPON_PISTOL, WEAPON_CHAINGUN: Result := FAmmo[A_BULLETS];
2794 WEAPON_SHOTGUN1, WEAPON_SHOTGUN2, WEAPON_SUPERPULEMET: Result := FAmmo[A_SHELLS];
2795 WEAPON_ROCKETLAUNCHER: Result := FAmmo[A_ROCKETS];
2796 WEAPON_PLASMA, WEAPON_BFG: Result := FAmmo[A_CELLS];
2797 else Result := 0;
2798 end;
2799 end;
2801 function TPlayer.HeadInLiquid(XInc, YInc: Integer): Boolean;
2802 begin
2803 Result := g_Map_CollidePanel(FObj.X+PLAYER_HEADRECT.X+XInc, FObj.Y+PLAYER_HEADRECT.Y+YInc,
2804 PLAYER_HEADRECT.Width, PLAYER_HEADRECT.Height,
2805 PANEL_WATER or PANEL_ACID1 or PANEL_ACID2, True);
2806 end;
2808 procedure TPlayer.JetpackOn;
2809 begin
2810 FJetSoundFly.Stop;
2811 FJetSoundOff.Stop;
2812 FJetSoundOn.SetPosition(0);
2813 FJetSoundOn.PlayAt(FObj.X, FObj.Y);
2814 FlySmoke(8);
2815 end;
2817 procedure TPlayer.JetpackOff;
2818 begin
2819 FJetSoundFly.Stop;
2820 FJetSoundOn.Stop;
2821 FJetSoundOff.SetPosition(0);
2822 FJetSoundOff.PlayAt(FObj.X, FObj.Y);
2823 end;
2825 procedure TPlayer.Jump();
2826 begin
2827 if gFly or FJetpack then
2828 begin
2829 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
2830 if FObj.Vel.Y > -VEL_FLY then
2831 FObj.Vel.Y := FObj.Vel.Y - 3;
2832 if FJetpack then
2833 begin
2834 if FJetFuel > 0 then
2835 Dec(FJetFuel);
2836 if (FJetFuel < 1) and g_Game_IsServer then
2837 begin
2838 FJetpack := False;
2839 JetpackOff;
2840 if g_Game_IsNet then
2841 MH_SEND_PlayerStats(FUID);
2842 end;
2843 end;
2844 Exit;
2845 end;
2847 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
2848 if FGhost then
2849 FCanJetpack := False;
2851 // Ïðûãàåì èëè âñïëûâàåì:
2852 if (CollideLevel(0, 1) or
2853 g_Map_CollidePanel(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y+36, PLAYER_RECT.Width,
2854 PLAYER_RECT.Height-33, PANEL_STEP, False)
2855 ) and (FObj.Accel.Y = 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
2856 begin
2857 FObj.Vel.Y := -VEL_JUMP;
2858 FCanJetpack := False;
2859 end
2860 else
2861 begin
2862 if BodyInLiquid(0, 0) then
2863 FObj.Vel.Y := -VEL_SW
2864 else if (FJetFuel > 0) and FCanJetpack and
2865 g_Game_IsServer and (not g_Obj_CollideLiquid(@FObj, 0, 0)) then
2866 begin
2867 FJetpack := True;
2868 JetpackOn;
2869 if g_Game_IsNet then
2870 MH_SEND_PlayerStats(FUID);
2871 end;
2872 end;
2873 end;
2875 procedure TPlayer.Kill(KillType: Byte; SpawnerUID: Word; t: Byte);
2876 var
2877 a, i, k, ab, ar: Byte;
2878 s: String;
2879 mon: TMonster;
2880 plr: TPlayer;
2881 srv, netsrv: Boolean;
2882 DoFrags: Boolean;
2883 OldLR: Byte;
2884 KP: TPlayer;
2886 procedure PushItem(t: Byte);
2887 var
2888 id: DWORD;
2889 begin
2890 id := g_Items_Create(FObj.X, FObj.Y, t, True, False);
2891 if KillType = K_EXTRAHARDKILL then // -7..+7; -8..0
2892 g_Obj_Push(@gItems[id].Obj, (FObj.Vel.X div 2)-7+Random(15),
2893 (FObj.Vel.Y div 2)-Random(9))
2894 else
2895 if KillType = K_HARDKILL then // -5..+5; -5..0
2896 g_Obj_Push(@gItems[id].Obj, (FObj.Vel.X div 2)-5+Random(11),
2897 (FObj.Vel.Y div 2)-Random(6))
2898 else // -3..+3; -3..0
2899 g_Obj_Push(@gItems[id].Obj, (FObj.Vel.X div 2)-3+Random(7),
2900 (FObj.Vel.Y div 2)-Random(4));
2902 if g_Game_IsNet and g_Game_IsServer then
2903 MH_SEND_ItemSpawn(True, id);
2904 end;
2906 begin
2907 DoFrags := (gGameSettings.MaxLives = 0) or (gGameSettings.GameMode = GM_COOP);
2908 Srv := g_Game_IsServer;
2909 Netsrv := g_Game_IsServer and g_Game_IsNet;
2910 if Srv then FDeath := FDeath + 1;
2911 if FLive then
2912 begin
2913 if FGhost then
2914 FGhost := False;
2915 if not FPhysics then
2916 FPhysics := True;
2917 FLive := False;
2918 end;
2919 FShellTimer := -1;
2921 if (gGameSettings.MaxLives > 0) and Srv and (gLMSRespawn = LMS_RESPAWN_NONE) then
2922 begin
2923 if FLives > 0 then FLives := FLives - 1;
2924 if FLives = 0 then FNoRespawn := True;
2925 end;
2927 // Íîìåð òèïà ñìåðòè:
2928 a := 1;
2929 case KillType of
2930 K_SIMPLEKILL: a := 1;
2931 K_HARDKILL: a := 2;
2932 K_EXTRAHARDKILL: a := 3;
2933 K_FALLKILL: a := 4;
2934 end;
2936 // Çâóê ñìåðòè:
2937 if not FModel.PlaySound(MODELSOUND_DIE, a, FObj.X, FObj.Y) then
2938 for i := 1 to 3 do
2939 if FModel.PlaySound(MODELSOUND_DIE, i, FObj.X, FObj.Y) then
2940 Break;
2942 // Âðåìÿ ðåñïàóíà:
2943 if Srv then
2944 case KillType of
2945 K_SIMPLEKILL:
2946 FTime[T_RESPAWN] := gTime + TIME_RESPAWN1;
2947 K_HARDKILL:
2948 FTime[T_RESPAWN] := gTime + TIME_RESPAWN2;
2949 K_EXTRAHARDKILL, K_FALLKILL:
2950 FTime[T_RESPAWN] := gTime + TIME_RESPAWN3;
2951 end;
2953 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
2954 case KillType of
2955 K_SIMPLEKILL:
2956 SetAction(A_DIE1);
2957 K_HARDKILL, K_EXTRAHARDKILL:
2958 SetAction(A_DIE2);
2959 end;
2961 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
2962 if (KillType <> K_FALLKILL) and (Srv) then
2963 g_Monsters_killedp();
2965 if SpawnerUID = FUID then
2966 begin // Ñàìîóáèëñÿ
2967 if Srv and (DoFrags or (gGameSettings.GameMode = GM_TDM)) then
2968 begin
2969 Dec(FFrags);
2970 FLastFrag := 0;
2971 end;
2972 g_Console_Add(Format(_lc[I_PLAYER_KILL_SELF], [FName]), True);
2973 end
2974 else
2975 if g_GetUIDType(SpawnerUID) = UID_PLAYER then
2976 begin // Óáèò äðóãèì èãðîêîì
2977 KP := g_Player_Get(SpawnerUID);
2978 if (KP <> nil) and Srv then
2979 begin
2980 if (DoFrags or (gGameSettings.GameMode = GM_TDM)) then
2981 if SameTeam(FUID, SpawnerUID) then
2982 begin
2983 Dec(KP.FFrags);
2984 KP.FLastFrag := 0;
2985 end else
2986 begin
2987 Inc(KP.FFrags);
2988 KP.FragCombo();
2989 end;
2991 if (gGameSettings.GameMode = GM_TDM) and DoFrags then
2992 Inc(gTeamStat[KP.Team].Goals,
2993 IfThen(SameTeam(FUID, SpawnerUID), -1, 1));
2995 if netsrv then MH_SEND_PlayerStats(SpawnerUID);
2996 end;
2998 plr := g_Player_Get(SpawnerUID);
2999 if plr = nil then
3000 s := '?'
3001 else
3002 s := plr.FName;
3004 case KillType of
3005 K_HARDKILL:
3006 g_Console_Add(Format(_lc[I_PLAYER_KILL_EXTRAHARD_2],
3007 [FName, s]),
3008 gShowKillMsg);
3009 K_EXTRAHARDKILL:
3010 g_Console_Add(Format(_lc[I_PLAYER_KILL_EXTRAHARD_1],
3011 [FName, s]),
3012 gShowKillMsg);
3013 else
3014 g_Console_Add(Format(_lc[I_PLAYER_KILL],
3015 [FName, s]),
3016 gShowKillMsg);
3017 end;
3018 end
3019 else if g_GetUIDType(SpawnerUID) = UID_MONSTER then
3020 begin // Óáèò ìîíñòðîì
3021 mon := g_Monsters_Get(SpawnerUID);
3022 if mon = nil then
3023 s := '?'
3024 else
3025 s := g_Monsters_GetKilledBy(mon.MonsterType);
3027 case KillType of
3028 K_HARDKILL:
3029 g_Console_Add(Format(_lc[I_PLAYER_KILL_EXTRAHARD_2],
3030 [FName, s]),
3031 gShowKillMsg);
3032 K_EXTRAHARDKILL:
3033 g_Console_Add(Format(_lc[I_PLAYER_KILL_EXTRAHARD_1],
3034 [FName, s]),
3035 gShowKillMsg);
3036 else
3037 g_Console_Add(Format(_lc[I_PLAYER_KILL],
3038 [FName, s]),
3039 gShowKillMsg);
3040 end;
3041 end
3042 else // Îñîáûå òèïû ñìåðòè
3043 case t of
3044 HIT_DISCON: ;
3045 HIT_SELF: g_Console_Add(Format(_lc[I_PLAYER_KILL_SELF], [FName]), True);
3046 HIT_FALL: g_Console_Add(Format(_lc[I_PLAYER_KILL_FALL], [FName]), True);
3047 HIT_WATER: g_Console_Add(Format(_lc[I_PLAYER_KILL_WATER], [FName]), True);
3048 HIT_ACID: g_Console_Add(Format(_lc[I_PLAYER_KILL_ACID], [FName]), True);
3049 HIT_TRAP: g_Console_Add(Format(_lc[I_PLAYER_KILL_TRAP], [FName]), True);
3050 else g_Console_Add(Format(_lc[I_PLAYER_DIED], [FName]), True);
3051 end;
3053 if Srv then
3054 begin
3055 // Âûáðîñ îðóæèÿ:
3056 for a := WEAPON_KASTET to WEAPON_SUPERPULEMET do
3057 if FWeapon[a] then
3058 begin
3059 case a of
3060 WEAPON_SAW: i := ITEM_WEAPON_SAW;
3061 WEAPON_SHOTGUN1: i := ITEM_WEAPON_SHOTGUN1;
3062 WEAPON_SHOTGUN2: i := ITEM_WEAPON_SHOTGUN2;
3063 WEAPON_CHAINGUN: i := ITEM_WEAPON_CHAINGUN;
3064 WEAPON_ROCKETLAUNCHER: i := ITEM_WEAPON_ROCKETLAUNCHER;
3065 WEAPON_PLASMA: i := ITEM_WEAPON_PLASMA;
3066 WEAPON_BFG: i := ITEM_WEAPON_BFG;
3067 WEAPON_SUPERPULEMET: i := ITEM_WEAPON_SUPERPULEMET;
3068 else i := 0;
3069 end;
3071 if i <> 0 then
3072 PushItem(i);
3073 end;
3075 // Âûáðîñ ðþêçàêà:
3076 if R_ITEM_BACKPACK in FRulez then
3077 PushItem(ITEM_AMMO_BACKPACK);
3079 // Âûáðîñ ðàêåòíîãî ðàíöà:
3080 if FJetFuel > 0 then
3081 PushItem(ITEM_JETPACK);
3083 // Âûáðîñ êëþ÷åé:
3084 if not (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF]) then
3085 begin
3086 if R_KEY_RED in FRulez then
3087 PushItem(ITEM_KEY_RED);
3089 if R_KEY_GREEN in FRulez then
3090 PushItem(ITEM_KEY_GREEN);
3092 if R_KEY_BLUE in FRulez then
3093 PushItem(ITEM_KEY_BLUE);
3094 end;
3096 // Âûáðîñ ôëàãà:
3097 DropFlag();
3098 end;
3100 g_Player_CreateCorpse(Self);
3102 if Srv and (gGameSettings.MaxLives > 0) and FNoRespawn and
3103 (gLMSRespawn = LMS_RESPAWN_NONE) then
3104 begin
3105 a := 0;
3106 k := 0;
3107 ar := 0;
3108 ab := 0;
3109 for i := Low(gPlayers) to High(gPlayers) do
3110 begin
3111 if gPlayers[i] = nil then continue;
3112 if (not gPlayers[i].FNoRespawn) and (not gPlayers[i].FSpectator) then
3113 begin
3114 Inc(a);
3115 if gPlayers[i].FTeam = TEAM_RED then Inc(ar)
3116 else if gPlayers[i].FTeam = TEAM_BLUE then Inc(ab);
3117 k := i;
3118 end;
3119 end;
3121 OldLR := gLMSRespawn;
3122 if (gGameSettings.GameMode = GM_COOP) then
3123 begin
3124 if (a = 0) then
3125 begin
3126 // everyone is dead, restart the map
3127 g_Game_Message(_lc[I_MESSAGE_LMS_LOSE], 144);
3128 if Netsrv then
3129 MH_SEND_GameEvent(NET_EV_LMS_LOSE);
3130 gLMSRespawn := LMS_RESPAWN_FINAL;
3131 gLMSRespawnTime := gTime + 5000;
3132 end
3133 else if (a = 1) then
3134 begin
3135 if (gPlayers[k] <> nil) and not (gPlayers[k] is TBot) then
3136 if (gPlayers[k] = gPlayer1) or
3137 (gPlayers[k] = gPlayer2) then
3138 g_Console_Add('*** ' + _lc[I_MESSAGE_LMS_SURVIVOR] + ' ***', True)
3139 else if Netsrv and (gPlayers[k].FClientID >= 0) then
3140 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR, 0, 'N', gPlayers[k].FClientID);
3141 end;
3142 end
3143 else if (gGameSettings.GameMode = GM_TDM) then
3144 begin
3145 if (ab = 0) and (ar <> 0) then
3146 begin
3147 // blu team ded
3148 g_Game_Message(Format(_lc[I_MESSAGE_TLMS_WIN], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 144);
3149 if Netsrv then
3150 MH_SEND_GameEvent(NET_EV_TLMS_WIN, TEAM_RED);
3151 Inc(gTeamStat[TEAM_RED].Goals);
3152 gLMSRespawn := LMS_RESPAWN_FINAL;
3153 gLMSRespawnTime := gTime + 5000;
3154 end
3155 else if (ar = 0) and (ab <> 0) then
3156 begin
3157 // red team ded
3158 g_Game_Message(Format(_lc[I_MESSAGE_TLMS_WIN], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 144);
3159 if Netsrv then
3160 MH_SEND_GameEvent(NET_EV_TLMS_WIN, TEAM_BLUE);
3161 Inc(gTeamStat[TEAM_BLUE].Goals);
3162 gLMSRespawn := LMS_RESPAWN_FINAL;
3163 gLMSRespawnTime := gTime + 5000;
3164 end
3165 else if (ar = 0) and (ab = 0) then
3166 begin
3167 // everyone ded
3168 g_Game_Message(_lc[I_GAME_WIN_DRAW], 144);
3169 if Netsrv then
3170 MH_SEND_GameEvent(NET_EV_LMS_DRAW, 0, FName);
3171 gLMSRespawn := LMS_RESPAWN_FINAL;
3172 gLMSRespawnTime := gTime + 5000;
3173 end;
3174 end
3175 else if (gGameSettings.GameMode = GM_DM) then
3176 begin
3177 if (a = 1) then
3178 begin
3179 if gPlayers[k] <> nil then
3180 with gPlayers[k] do
3181 begin
3182 // survivor is the winner
3183 g_Game_Message(Format(_lc[I_MESSAGE_LMS_WIN], [AnsiUpperCase(FName)]), 144);
3184 if Netsrv then
3185 MH_SEND_GameEvent(NET_EV_LMS_WIN, 0, FName);
3186 Inc(FFrags);
3187 end;
3188 gLMSRespawn := LMS_RESPAWN_FINAL;
3189 gLMSRespawnTime := gTime + 5000;
3190 end
3191 else if (a = 0) then
3192 begin
3193 // everyone is dead, restart the map
3194 g_Game_Message(_lc[I_GAME_WIN_DRAW], 144);
3195 if Netsrv then
3196 MH_SEND_GameEvent(NET_EV_LMS_DRAW, 0, FName);
3197 gLMSRespawn := LMS_RESPAWN_FINAL;
3198 gLMSRespawnTime := gTime + 5000;
3199 end;
3200 end;
3201 if srv and (OldLR = LMS_RESPAWN_NONE) and (gLMSRespawn > LMS_RESPAWN_NONE) then
3202 begin
3203 if NetMode = NET_SERVER then
3204 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, (gLMSRespawnTime - gTime) div 1000)
3205 else
3206 g_Console_Add(Format(_lc[I_MSG_WARMUP_START], [(gLMSRespawnTime - gTime) div 1000]), True);
3207 end;
3208 end;
3210 if Netsrv then
3211 begin
3212 MH_SEND_PlayerStats(FUID);
3213 MH_SEND_PlayerDeath(FUID, KillType, t, SpawnerUID);
3214 if gGameSettings.GameMode = GM_TDM then MH_SEND_GameStats;
3215 end;
3217 if srv and FNoRespawn then Spectate(True);
3218 FWantsInGame := True;
3219 end;
3221 function TPlayer.BodyInLiquid(XInc, YInc: Integer): Boolean;
3222 begin
3223 Result := g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc, PLAYER_RECT.Width,
3224 PLAYER_RECT.Height-20, PANEL_WATER or PANEL_ACID1 or PANEL_ACID2, False);
3225 end;
3227 function TPlayer.BodyInAcid(XInc, YInc: Integer): Boolean;
3228 begin
3229 Result := g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc, PLAYER_RECT.Width,
3230 PLAYER_RECT.Height-20, PANEL_ACID1 or PANEL_ACID2, False);
3231 end;
3233 procedure TPlayer.MakeBloodSimple(Count: Word);
3234 begin
3235 g_GFX_Blood(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)+8,
3236 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2),
3237 Count div 2, 3, -1, 16, (PLAYER_RECT.Height*2 div 3),
3238 150, 0, 0);
3239 g_GFX_Blood(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-8,
3240 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2),
3241 Count div 2, -3, -1, 16, (PLAYER_RECT.Height*2) div 3,
3242 150, 0, 0);
3243 end;
3245 procedure TPlayer.MakeBloodVector(Count: Word; VelX, VelY: Integer);
3246 begin
3247 g_GFX_Blood(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2),
3248 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2),
3249 Count, VelX, VelY, 16, (PLAYER_RECT.Height*2) div 3,
3250 150, 0, 0);
3251 end;
3253 procedure TPlayer.NextWeapon();
3254 var
3255 i: Byte;
3256 ok: Boolean;
3257 begin
3258 if g_Game_IsClient then Exit;
3259 if FBFGFireCounter <> -1 then Exit;
3261 if FTime[T_SWITCH] > gTime then Exit;
3263 for i := WEAPON_KASTET to WEAPON_SUPERPULEMET do
3264 if FReloading[i] > 0 then Exit;
3266 ok := False;
3268 for i := FCurrWeap+1 to WEAPON_SUPERPULEMET do
3269 if FWeapon[i] then
3270 begin
3271 FCurrWeap := i;
3272 ok := True;
3273 Break;
3274 end;
3276 if not ok then
3277 for i := WEAPON_KASTET to FCurrWeap-1 do
3278 if FWeapon[i] then
3279 begin
3280 FCurrWeap := i;
3281 Break;
3282 end;
3284 FTime[T_SWITCH] := gTime+156;
3286 if FCurrWeap = WEAPON_SAW then
3287 FSawSoundSelect.PlayAt(FObj.X, FObj.Y);
3289 FModel.SetWeapon(FCurrWeap);
3291 if g_Game_IsNet then MH_SEND_PlayerStats(FUID);
3292 end;
3294 procedure TPlayer.PrevWeapon();
3295 var
3296 i: Byte;
3297 ok: Boolean;
3298 begin
3299 if g_Game_IsClient then Exit;
3300 if FBFGFireCounter <> -1 then Exit;
3302 if FTime[T_SWITCH] > gTime then Exit;
3304 for i := WEAPON_KASTET to WEAPON_SUPERPULEMET do
3305 if FReloading[i] > 0 then Exit;
3307 ok := False;
3309 if FCurrWeap > 0 then
3310 for i := FCurrWeap-1 downto WEAPON_KASTET do
3311 if FWeapon[i] then
3312 begin
3313 FCurrWeap := i;
3314 ok := True;
3315 Break;
3316 end;
3318 if not ok then
3319 for i := WEAPON_SUPERPULEMET downto FCurrWeap+1 do
3320 if FWeapon[i] then
3321 begin
3322 FCurrWeap := i;
3323 Break;
3324 end;
3326 FTime[T_SWITCH] := gTime+156;
3328 if FCurrWeap = WEAPON_SAW then
3329 FSawSoundSelect.PlayAt(FObj.X, FObj.Y);
3331 FModel.SetWeapon(FCurrWeap);
3333 if g_Game_IsNet then MH_SEND_PlayerStats(FUID);
3334 end;
3336 procedure TPlayer.SetWeapon(W: Byte);
3337 begin
3338 if FCurrWeap <> W then
3339 if W = WEAPON_SAW then
3340 FSawSoundSelect.PlayAt(FObj.X, FObj.Y);
3342 FCurrWeap := W;
3343 FModel.SetWeapon(CurrWeap);
3344 end;
3346 function TPlayer.PickItem(ItemType: Byte; respawn: Boolean; var remove: Boolean): Boolean;
3347 var
3348 a: Boolean;
3349 begin
3350 Result := False;
3351 if g_Game_IsClient then Exit;
3353 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3354 a := LongBool(gGameSettings.Options and GAME_OPTION_WEAPONSTAY) and respawn;
3355 remove := not a;
3357 case ItemType of
3358 ITEM_MEDKIT_SMALL:
3359 if FHealth < PLAYER_HP_SOFT then
3360 begin
3361 IncMax(FHealth, 10, PLAYER_HP_SOFT);
3362 Result := True;
3363 remove := True;
3364 if gFlash = 2 then Inc(FPickup, 5);
3365 end;
3367 ITEM_MEDKIT_LARGE:
3368 if FHealth < PLAYER_HP_SOFT then
3369 begin
3370 IncMax(FHealth, 25, PLAYER_HP_SOFT);
3371 Result := True;
3372 remove := True;
3373 if gFlash = 2 then Inc(FPickup, 5);
3374 end;
3376 ITEM_ARMOR_GREEN:
3377 if FArmor < PLAYER_AP_SOFT then
3378 begin
3379 FArmor := PLAYER_AP_SOFT;
3380 Result := True;
3381 remove := True;
3382 if gFlash = 2 then Inc(FPickup, 5);
3383 end;
3385 ITEM_ARMOR_BLUE:
3386 if FArmor < PLAYER_AP_LIMIT then
3387 begin
3388 FArmor := PLAYER_AP_LIMIT;
3389 Result := True;
3390 remove := True;
3391 if gFlash = 2 then Inc(FPickup, 5);
3392 end;
3394 ITEM_SPHERE_BLUE:
3395 if FHealth < PLAYER_HP_LIMIT then
3396 begin
3397 IncMax(FHealth, 100, PLAYER_HP_LIMIT);
3398 Result := True;
3399 remove := True;
3400 if gFlash = 2 then Inc(FPickup, 5);
3401 end;
3403 ITEM_SPHERE_WHITE:
3404 if (FHealth < PLAYER_HP_LIMIT) or (FArmor < PLAYER_AP_LIMIT) then
3405 begin
3406 if FHealth < PLAYER_HP_LIMIT then
3407 FHealth := PLAYER_HP_LIMIT;
3408 if FArmor < PLAYER_AP_LIMIT then
3409 FArmor := PLAYER_AP_LIMIT;
3410 Result := True;
3411 remove := True;
3412 if gFlash = 2 then Inc(FPickup, 5);
3413 end;
3415 ITEM_WEAPON_SAW:
3416 if (not FWeapon[WEAPON_SAW]) or ((not respawn) and (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF])) then
3417 begin
3418 FWeapon[WEAPON_SAW] := True;
3419 Result := True;
3420 if gFlash = 2 then Inc(FPickup, 5);
3421 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
3422 end;
3424 ITEM_WEAPON_SHOTGUN1:
3425 if (FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS]) or not FWeapon[WEAPON_SHOTGUN1] then
3426 begin
3427 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
3428 if a and FWeapon[WEAPON_SHOTGUN1] then Exit;
3430 IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
3431 FWeapon[WEAPON_SHOTGUN1] := True;
3432 Result := True;
3433 if gFlash = 2 then Inc(FPickup, 5);
3434 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
3435 end;
3437 ITEM_WEAPON_SHOTGUN2:
3438 if (FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS]) or not FWeapon[WEAPON_SHOTGUN2] then
3439 begin
3440 if a and FWeapon[WEAPON_SHOTGUN2] then Exit;
3442 IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
3443 FWeapon[WEAPON_SHOTGUN2] := True;
3444 Result := True;
3445 if gFlash = 2 then Inc(FPickup, 5);
3446 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
3447 end;
3449 ITEM_WEAPON_CHAINGUN:
3450 if (FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS]) or not FWeapon[WEAPON_CHAINGUN] then
3451 begin
3452 if a and FWeapon[WEAPON_CHAINGUN] then Exit;
3454 IncMax(FAmmo[A_BULLETS], 50, FMaxAmmo[A_BULLETS]);
3455 FWeapon[WEAPON_CHAINGUN] := True;
3456 Result := True;
3457 if gFlash = 2 then Inc(FPickup, 5);
3458 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
3459 end;
3461 ITEM_WEAPON_ROCKETLAUNCHER:
3462 if (FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS]) or not FWeapon[WEAPON_ROCKETLAUNCHER] then
3463 begin
3464 if a and FWeapon[WEAPON_ROCKETLAUNCHER] then Exit;
3466 IncMax(FAmmo[A_ROCKETS], 2, FMaxAmmo[A_ROCKETS]);
3467 FWeapon[WEAPON_ROCKETLAUNCHER] := True;
3468 Result := True;
3469 if gFlash = 2 then Inc(FPickup, 5);
3470 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
3471 end;
3473 ITEM_WEAPON_PLASMA:
3474 if (FAmmo[A_CELLS] < FMaxAmmo[A_CELLS]) or not FWeapon[WEAPON_PLASMA] then
3475 begin
3476 if a and FWeapon[WEAPON_PLASMA] then Exit;
3478 IncMax(FAmmo[A_CELLS], 40, FMaxAmmo[A_CELLS]);
3479 FWeapon[WEAPON_PLASMA] := True;
3480 Result := True;
3481 if gFlash = 2 then Inc(FPickup, 5);
3482 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
3483 end;
3485 ITEM_WEAPON_BFG:
3486 if (FAmmo[A_CELLS] < FMaxAmmo[A_CELLS]) or not FWeapon[WEAPON_BFG] then
3487 begin
3488 if a and FWeapon[WEAPON_BFG] then Exit;
3490 IncMax(FAmmo[A_CELLS], 40, FMaxAmmo[A_CELLS]);
3491 FWeapon[WEAPON_BFG] := True;
3492 Result := True;
3493 if gFlash = 2 then Inc(FPickup, 5);
3494 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
3495 end;
3497 ITEM_WEAPON_SUPERPULEMET:
3498 if (FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS]) or not FWeapon[WEAPON_SUPERPULEMET] then
3499 begin
3500 if a and FWeapon[WEAPON_SUPERPULEMET] then Exit;
3502 IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
3503 FWeapon[WEAPON_SUPERPULEMET] := True;
3504 Result := True;
3505 if gFlash = 2 then Inc(FPickup, 5);
3506 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
3507 end;
3509 ITEM_AMMO_BULLETS:
3510 if FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS] then
3511 begin
3512 IncMax(FAmmo[A_BULLETS], 10, FMaxAmmo[A_BULLETS]);
3513 Result := True;
3514 remove := True;
3515 if gFlash = 2 then Inc(FPickup, 5);
3516 end;
3518 ITEM_AMMO_BULLETS_BOX:
3519 if FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS] then
3520 begin
3521 IncMax(FAmmo[A_BULLETS], 50, FMaxAmmo[A_BULLETS]);
3522 Result := True;
3523 remove := True;
3524 if gFlash = 2 then Inc(FPickup, 5);
3525 end;
3527 ITEM_AMMO_SHELLS:
3528 if FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS] then
3529 begin
3530 IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
3531 Result := True;
3532 remove := True;
3533 if gFlash = 2 then Inc(FPickup, 5);
3534 end;
3536 ITEM_AMMO_SHELLS_BOX:
3537 if FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS] then
3538 begin
3539 IncMax(FAmmo[A_SHELLS], 25, FMaxAmmo[A_SHELLS]);
3540 Result := True;
3541 remove := True;
3542 if gFlash = 2 then Inc(FPickup, 5);
3543 end;
3545 ITEM_AMMO_ROCKET:
3546 if FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS] then
3547 begin
3548 IncMax(FAmmo[A_ROCKETS], 1, FMaxAmmo[A_ROCKETS]);
3549 Result := True;
3550 remove := True;
3551 if gFlash = 2 then Inc(FPickup, 5);
3552 end;
3554 ITEM_AMMO_ROCKET_BOX:
3555 if FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS] then
3556 begin
3557 IncMax(FAmmo[A_ROCKETS], 5, FMaxAmmo[A_ROCKETS]);
3558 Result := True;
3559 remove := True;
3560 if gFlash = 2 then Inc(FPickup, 5);
3561 end;
3563 ITEM_AMMO_CELL:
3564 if FAmmo[A_CELLS] < FMaxAmmo[A_CELLS] then
3565 begin
3566 IncMax(FAmmo[A_CELLS], 40, FMaxAmmo[A_CELLS]);
3567 Result := True;
3568 remove := True;
3569 if gFlash = 2 then Inc(FPickup, 5);
3570 end;
3572 ITEM_AMMO_CELL_BIG:
3573 if FAmmo[A_CELLS] < FMaxAmmo[A_CELLS] then
3574 begin
3575 IncMax(FAmmo[A_CELLS], 100, FMaxAmmo[A_CELLS]);
3576 Result := True;
3577 remove := True;
3578 if gFlash = 2 then Inc(FPickup, 5);
3579 end;
3581 ITEM_AMMO_BACKPACK:
3582 if not(R_ITEM_BACKPACK in FRulez) or
3583 (FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS]) or
3584 (FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS]) or
3585 (FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS]) or
3586 (FAmmo[A_CELLS] < FMaxAmmo[A_CELLS]) then
3587 begin
3588 FMaxAmmo[A_BULLETS] := 400;
3589 FMaxAmmo[A_SHELLS] := 100;
3590 FMaxAmmo[A_ROCKETS] := 100;
3591 FMaxAmmo[A_CELLS] := 600;
3593 if FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS] then
3594 IncMax(FAmmo[A_BULLETS], 10, FMaxAmmo[A_BULLETS]);
3595 if FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS] then
3596 IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
3597 if FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS] then
3598 IncMax(FAmmo[A_ROCKETS], 1, FMaxAmmo[A_ROCKETS]);
3599 if FAmmo[A_CELLS] < FMaxAmmo[A_CELLS] then
3600 IncMax(FAmmo[A_CELLS], 40, FMaxAmmo[A_CELLS]);
3602 FRulez := FRulez + [R_ITEM_BACKPACK];
3603 Result := True;
3604 remove := True;
3605 if gFlash = 2 then Inc(FPickup, 5);
3606 end;
3608 ITEM_KEY_RED:
3609 if not(R_KEY_RED in FRulez) then
3610 begin
3611 Include(FRulez, R_KEY_RED);
3612 Result := True;
3613 remove := (gGameSettings.GameMode <> GM_COOP) and (g_Player_GetCount() < 2);
3614 if gFlash = 2 then Inc(FPickup, 5);
3615 if (not remove) and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETITEM');
3616 end;
3618 ITEM_KEY_GREEN:
3619 if not(R_KEY_GREEN in FRulez) then
3620 begin
3621 Include(FRulez, R_KEY_GREEN);
3622 Result := True;
3623 remove := (gGameSettings.GameMode <> GM_COOP) and (g_Player_GetCount() < 2);
3624 if gFlash = 2 then Inc(FPickup, 5);
3625 if (not remove) and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETITEM');
3626 end;
3628 ITEM_KEY_BLUE:
3629 if not(R_KEY_BLUE in FRulez) then
3630 begin
3631 Include(FRulez, R_KEY_BLUE);
3632 Result := True;
3633 remove := (gGameSettings.GameMode <> GM_COOP) and (g_Player_GetCount() < 2);
3634 if gFlash = 2 then Inc(FPickup, 5);
3635 if (not remove) and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETITEM');
3636 end;
3638 ITEM_SUIT:
3639 if FMegaRulez[MR_SUIT] < gTime+PLAYER_SUIT_TIME then
3640 begin
3641 FMegaRulez[MR_SUIT] := gTime+PLAYER_SUIT_TIME;
3642 Result := True;
3643 remove := True;
3644 if gFlash = 2 then Inc(FPickup, 5);
3645 end;
3647 ITEM_OXYGEN:
3648 if FAir < AIR_MAX then
3649 begin
3650 FAir := AIR_MAX;
3651 Result := True;
3652 remove := True;
3653 if gFlash = 2 then Inc(FPickup, 5);
3654 end;
3656 ITEM_MEDKIT_BLACK:
3657 begin
3658 if not (R_BERSERK in FRulez) then
3659 begin
3660 Include(FRulez, R_BERSERK);
3661 if FBFGFireCounter = -1 then
3662 begin
3663 FCurrWeap := WEAPON_KASTET;
3664 FModel.SetWeapon(WEAPON_KASTET);
3665 end;
3666 if gFlash <> 0 then
3667 Inc(FPain, 100);
3668 if gFlash = 2 then Inc(FPickup, 5);
3669 FBerserk := gTime+30000;
3670 Result := True;
3671 remove := True;
3672 end;
3673 if FHealth < PLAYER_HP_SOFT then
3674 begin
3675 FHealth := PLAYER_HP_SOFT;
3676 FBerserk := gTime+30000;
3677 Result := True;
3678 remove := True;
3679 end;
3680 end;
3682 ITEM_INVUL:
3683 if FMegaRulez[MR_INVUL] < gTime+PLAYER_INVUL_TIME then
3684 begin
3685 FMegaRulez[MR_INVUL] := gTime+PLAYER_INVUL_TIME;
3686 Result := True;
3687 remove := True;
3688 if gFlash = 2 then Inc(FPickup, 5);
3689 end;
3691 ITEM_BOTTLE:
3692 if FHealth < PLAYER_HP_LIMIT then
3693 begin
3694 IncMax(FHealth, 4, PLAYER_HP_LIMIT);
3695 Result := True;
3696 remove := True;
3697 if gFlash = 2 then Inc(FPickup, 5);
3698 end;
3700 ITEM_HELMET:
3701 if FArmor < PLAYER_AP_LIMIT then
3702 begin
3703 IncMax(FArmor, 5, PLAYER_AP_LIMIT);
3704 Result := True;
3705 remove := True;
3706 if gFlash = 2 then Inc(FPickup, 5);
3707 end;
3709 ITEM_JETPACK:
3710 if FJetFuel < JET_MAX then
3711 begin
3712 FJetFuel := JET_MAX;
3713 Result := True;
3714 remove := True;
3715 if gFlash = 2 then Inc(FPickup, 5);
3716 end;
3718 ITEM_INVIS:
3719 if FMegaRulez[MR_INVIS] < gTime+PLAYER_INVIS_TIME then
3720 begin
3721 FMegaRulez[MR_INVIS] := gTime+PLAYER_INVIS_TIME;
3722 Result := True;
3723 remove := True;
3724 if gFlash = 2 then Inc(FPickup, 5);
3725 end;
3726 end;
3727 end;
3729 procedure TPlayer.Touch();
3730 begin
3731 if not FLive then
3732 Exit;
3733 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
3734 if FIamBot then
3735 begin
3736 // Áðîñèòü ôëàã òîâàðèùó:
3737 if gGameSettings.GameMode = GM_CTF then
3738 DropFlag();
3739 end;
3740 end;
3742 procedure TPlayer.Push(vx, vy: Integer);
3743 begin
3744 if (not FPhysics) and FGhost then
3745 Exit;
3746 FObj.Accel.X := FObj.Accel.X + vx;
3747 FObj.Accel.Y := FObj.Accel.Y + vy;
3748 if g_Game_IsNet and g_Game_IsServer then
3749 MH_SEND_PlayerPos(True, FUID, NET_EVERYONE);
3750 end;
3752 procedure TPlayer.Reset(Force: Boolean);
3753 begin
3754 if Force then
3755 FLive := False;
3757 FSpawned := False;
3758 FTime[T_RESPAWN] := 0;
3759 FTime[T_FLAGCAP] := 0;
3760 FGodMode := False;
3761 FNoTarget := False;
3762 FNoReload := False;
3763 FFrags := 0;
3764 FLastFrag := 0;
3765 FComboEvnt := -1;
3766 FKills := 0;
3767 FMonsterKills := 0;
3768 FDeath := 0;
3769 FSecrets := 0;
3770 if FNoRespawn then
3771 begin
3772 FSpectator := False;
3773 FGhost := False;
3774 FPhysics := True;
3775 FSpectatePlayer := -1;
3776 FNoRespawn := False;
3777 end;
3778 FLives := gGameSettings.MaxLives;
3780 SetFlag(FLAG_NONE);
3781 end;
3783 procedure TPlayer.SoftReset();
3784 begin
3785 ReleaseKeys();
3787 FDamageBuffer := 0;
3788 FIncCam := 0;
3789 FBFGFireCounter := -1;
3790 FShellTimer := -1;
3791 FPain := 0;
3792 FLastHit := 0;
3793 FLastFrag := 0;
3794 FComboEvnt := -1;
3796 SetFlag(FLAG_NONE);
3797 SetAction(A_STAND, True);
3798 end;
3800 function TPlayer.GetRespawnPoint(): Byte;
3801 var
3802 c: Byte;
3803 begin
3804 Result := 255;
3805 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
3807 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
3808 if gGameSettings.GameMode in [GM_COOP, GM_SINGLE] then
3809 begin
3810 if (Self = gPlayer1) or (Self = gPlayer2) then
3811 begin
3812 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
3813 if Self = gPlayer1 then
3814 c := RESPAWNPOINT_PLAYER1
3815 else
3816 c := RESPAWNPOINT_PLAYER2;
3817 if g_Map_GetPointCount(c) > 0 then
3818 begin
3819 Result := c;
3820 Exit;
3821 end;
3823 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
3824 if Self = gPlayer1 then
3825 c := RESPAWNPOINT_PLAYER2
3826 else
3827 c := RESPAWNPOINT_PLAYER1;
3828 if g_Map_GetPointCount(c) > 0 then
3829 begin
3830 Result := c;
3831 Exit;
3832 end;
3833 end else
3834 begin
3835 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
3836 if Random(2) = 0 then
3837 c := RESPAWNPOINT_PLAYER1
3838 else
3839 c := RESPAWNPOINT_PLAYER2;
3840 if g_Map_GetPointCount(c) > 0 then
3841 begin
3842 Result := c;
3843 Exit;
3844 end;
3845 end;
3847 // Òî÷êà ëþáîé èç êîìàíä
3848 if Random(2) = 0 then
3849 c := RESPAWNPOINT_RED
3850 else
3851 c := RESPAWNPOINT_BLUE;
3852 if g_Map_GetPointCount(c) > 0 then
3853 begin
3854 Result := c;
3855 Exit;
3856 end;
3858 // Òî÷êà DM
3859 c := RESPAWNPOINT_DM;
3860 if g_Map_GetPointCount(c) > 0 then
3861 begin
3862 Result := c;
3863 Exit;
3864 end;
3865 end;
3867 // Ìÿñîïîâàë
3868 if gGameSettings.GameMode = GM_DM then
3869 begin
3870 // Òî÷êà DM
3871 c := RESPAWNPOINT_DM;
3872 if g_Map_GetPointCount(c) > 0 then
3873 begin
3874 Result := c;
3875 Exit;
3876 end;
3878 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
3879 if Random(2) = 0 then
3880 c := RESPAWNPOINT_PLAYER1
3881 else
3882 c := RESPAWNPOINT_PLAYER2;
3883 if g_Map_GetPointCount(c) > 0 then
3884 begin
3885 Result := c;
3886 Exit;
3887 end;
3889 // Òî÷êà ëþáîé èç êîìàíä
3890 if Random(2) = 0 then
3891 c := RESPAWNPOINT_RED
3892 else
3893 c := RESPAWNPOINT_BLUE;
3894 if g_Map_GetPointCount(c) > 0 then
3895 begin
3896 Result := c;
3897 Exit;
3898 end;
3899 end;
3901 // Êîìàíäíûå
3902 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
3903 begin
3904 // Òî÷êà ñâîåé êîìàíäû
3905 c := RESPAWNPOINT_DM;
3906 if FTeam = TEAM_RED then
3907 c := RESPAWNPOINT_RED;
3908 if FTeam = TEAM_BLUE then
3909 c := RESPAWNPOINT_BLUE;
3910 if g_Map_GetPointCount(c) > 0 then
3911 begin
3912 Result := c;
3913 Exit;
3914 end;
3916 // Òî÷êà DM
3917 c := RESPAWNPOINT_DM;
3918 if g_Map_GetPointCount(c) > 0 then
3919 begin
3920 Result := c;
3921 Exit;
3922 end;
3924 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
3925 if Random(2) = 0 then
3926 c := RESPAWNPOINT_PLAYER1
3927 else
3928 c := RESPAWNPOINT_PLAYER2;
3929 if g_Map_GetPointCount(c) > 0 then
3930 begin
3931 Result := c;
3932 Exit;
3933 end;
3935 // Òî÷êà äðóãîé êîìàíäû
3936 c := RESPAWNPOINT_DM;
3937 if FTeam = TEAM_RED then
3938 c := RESPAWNPOINT_BLUE;
3939 if FTeam = TEAM_BLUE then
3940 c := RESPAWNPOINT_RED;
3941 if g_Map_GetPointCount(c) > 0 then
3942 begin
3943 Result := c;
3944 Exit;
3945 end;
3946 end;
3947 end;
3949 procedure TPlayer.Respawn(Silent: Boolean; Force: Boolean = False);
3950 var
3951 RespawnPoint: TRespawnPoint;
3952 a, b, c: Byte;
3953 Anim: TAnimation;
3954 ID: DWORD;
3955 begin
3956 if not g_Game_IsServer then
3957 Exit;
3958 if FDummy then
3959 Exit;
3960 FWantsInGame := True;
3961 FJustTeleported := True;
3962 if Force then
3963 begin
3964 FTime[T_RESPAWN] := 0;
3965 FLive := False;
3966 end;
3967 FNetTime := 0;
3968 // if server changes MaxLives we gotta be ready
3969 if gGameSettings.MaxLives = 0 then FNoRespawn := False;
3971 // Åùå íåëüçÿ âîçðîäèòüñÿ:
3972 if FTime[T_RESPAWN] > gTime then
3973 Exit;
3975 // Ïðîñðàë âñå æèçíè:
3976 if FNoRespawn then
3977 begin
3978 if not FSpectator then Spectate(True);
3979 FWantsInGame := True;
3980 Exit;
3981 end;
3983 if (gGameSettings.GameType <> GT_SINGLE) and (gGameSettings.GameMode <> GM_COOP) then
3984 begin // "Ñâîÿ èãðà"
3985 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
3986 FRulez := FRulez-[R_BERSERK];
3987 end
3988 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
3989 begin
3990 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
3991 FRulez := FRulez-[R_KEY_RED, R_KEY_GREEN, R_KEY_BLUE, R_BERSERK];
3992 end;
3994 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
3995 c := GetRespawnPoint();
3997 ReleaseKeys();
3998 SetFlag(FLAG_NONE);
4000 // Âîñêðåøåíèå áåç îðóæèÿ:
4001 if not FLive then
4002 begin
4003 FHealth := PLAYER_HP_SOFT;
4004 FArmor := 0;
4005 FLive := True;
4006 FAir := AIR_DEF;
4007 FJetFuel := 0;
4009 for a := WEAPON_KASTET to WEAPON_SUPERPULEMET do
4010 begin
4011 FWeapon[a] := False;
4012 FReloading[a] := 0;
4013 end;
4015 FWeapon[WEAPON_PISTOL] := True;
4016 FWeapon[WEAPON_KASTET] := True;
4017 FCurrWeap := WEAPON_PISTOL;
4019 FModel.SetWeapon(FCurrWeap);
4021 for b := A_BULLETS to A_CELLS do
4022 FAmmo[b] := 0;
4024 FAmmo[A_BULLETS] := 50;
4026 FMaxAmmo[A_BULLETS] := 200;
4027 FMaxAmmo[A_SHELLS] := 50;
4028 FMaxAmmo[A_ROCKETS] := 50;
4029 FMaxAmmo[A_CELLS] := 300;
4031 if gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF] then
4032 FRulez := [R_KEY_RED, R_KEY_GREEN, R_KEY_BLUE]
4033 else
4034 FRulez := [];
4035 end;
4037 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4038 if not g_Map_GetPoint(c, RespawnPoint) then
4039 begin
4040 g_FatalError(_lc[I_GAME_ERROR_GET_SPAWN]);
4041 Exit;
4042 end;
4044 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4045 FObj.X := RespawnPoint.X-PLAYER_RECT.X;
4046 FObj.Y := RespawnPoint.Y-PLAYER_RECT.Y;
4047 FObj.Vel.X := 0;
4048 FObj.Vel.Y := 0;
4049 FObj.Accel.X := 0;
4050 FObj.Accel.Y := 0;
4052 FDirection := RespawnPoint.Direction;
4053 if FDirection = D_LEFT then
4054 FAngle := 180
4055 else
4056 FAngle := 0;
4058 FIncCam := 0;
4059 FBFGFireCounter := -1;
4060 FShellTimer := -1;
4061 FPain := 0;
4062 FLastHit := 0;
4064 SetAction(A_STAND, True);
4065 FModel.Direction := FDirection;
4067 for a := Low(FTime) to High(FTime) do
4068 FTime[a] := 0;
4070 for a := Low(FMegaRulez) to High(FMegaRulez) do
4071 FMegaRulez[a] := 0;
4073 FDamageBuffer := 0;
4074 FJetpack := False;
4075 FCanJetpack := False;
4077 // Àíèìàöèÿ âîçðîæäåíèÿ:
4078 if (not gLoadGameMode) and (not Silent) then
4079 if g_Frames_Get(ID, 'FRAMES_TELEPORT') then
4080 begin
4081 Anim := TAnimation.Create(ID, False, 3);
4082 g_GFX_OnceAnim(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
4083 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32, Anim);
4084 Anim.Free();
4085 end;
4087 FSpectator := False;
4088 FGhost := False;
4089 FPhysics := True;
4090 FSpectatePlayer := -1;
4091 FSpawned := True;
4093 if g_Game_IsNet then
4094 begin
4095 MH_SEND_PlayerPos(True, FUID, NET_EVERYONE);
4096 MH_SEND_PlayerStats(FUID, NET_EVERYONE);
4097 if not Silent then
4098 MH_SEND_Effect(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
4099 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32,
4100 0, NET_GFX_TELE);
4101 end;
4102 end;
4104 procedure TPlayer.Spectate(NoMove: Boolean = False);
4105 begin
4106 if FLive then
4107 Kill(K_EXTRAHARDKILL, FUID, HIT_SOME)
4108 else if (not NoMove) then
4109 begin
4110 GameX := gMapInfo.Width div 2;
4111 GameY := gMapInfo.Height div 2;
4112 end;
4113 FXTo := GameX;
4114 FYTo := GameY;
4116 FLive := False;
4117 FSpectator := True;
4118 FGhost := True;
4119 FPhysics := False;
4120 FWantsInGame := False;
4121 FSpawned := False;
4123 if FNoRespawn then
4124 begin
4125 if Self = gPlayer1 then
4126 begin
4127 gLMSPID1 := FUID;
4128 gPlayer1 := nil;
4129 end;
4130 if Self = gPlayer2 then
4131 begin
4132 gLMSPID2 := FUID;
4133 gPlayer2 := nil;
4134 end;
4135 end;
4137 if g_Game_IsNet then
4138 MH_SEND_PlayerStats(FUID);
4139 end;
4141 procedure TPlayer.SwitchNoClip;
4142 begin
4143 if not FLive then
4144 Exit;
4145 FGhost := not FGhost;
4146 FPhysics := not FGhost;
4147 if FGhost then
4148 begin
4149 FXTo := FObj.X;
4150 FYTo := FObj.Y;
4151 end else
4152 begin
4153 FObj.Accel.X := 0;
4154 FObj.Accel.Y := 0;
4155 end;
4156 end;
4158 procedure TPlayer.Run(Direction: TDirection);
4159 var
4160 a, b: Integer;
4161 begin
4162 if MAX_RUNVEL > 8 then
4163 FlySmoke();
4165 // Áåæèì:
4166 if Direction = D_LEFT then
4167 begin
4168 if FObj.Vel.X > -MAX_RUNVEL then
4169 FObj.Vel.X := FObj.Vel.X - (MAX_RUNVEL shr 3);
4170 end
4171 else
4172 if FObj.Vel.X < MAX_RUNVEL then
4173 FObj.Vel.X := FObj.Vel.X + (MAX_RUNVEL shr 3);
4175 // Âîçìîæíî, ïèíàåì êóñêè:
4176 if (FObj.Vel.X <> 0) and (gGibs <> nil) then
4177 begin
4178 b := Abs(FObj.Vel.X);
4179 if b > 1 then b := b * (Random(8 div b) + 1);
4180 for a := 0 to High(gGibs) do
4181 if gGibs[a].Live and
4182 g_Obj_Collide(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y+FObj.Rect.Height-4,
4183 FObj.Rect.Width, 8, @gGibs[a].Obj) and (Random(3) = 0) then
4184 // Ïèíàåì êóñêè
4185 if FObj.Vel.X < 0 then
4186 g_Obj_PushA(@gGibs[a].Obj, b, Random(61)+120) // íàëåâî
4187 else
4188 g_Obj_PushA(@gGibs[a].Obj, b, Random(61)); // íàïðàâî
4189 end;
4191 SetAction(A_WALK);
4192 end;
4194 procedure TPlayer.SeeDown();
4195 begin
4196 SetAction(A_SEEDOWN);
4198 if FDirection = D_LEFT then FAngle := ANGLE_LEFTDOWN else FAngle := ANGLE_RIGHTDOWN;
4200 if FIncCam > -120 then DecMin(FIncCam, 5, -120);
4201 end;
4203 procedure TPlayer.SeeUp();
4204 begin
4205 SetAction(A_SEEUP);
4207 if FDirection = D_LEFT then FAngle := ANGLE_LEFTUP else FAngle := ANGLE_RIGHTUP;
4209 if FIncCam < 120 then IncMax(FIncCam, 5, 120);
4210 end;
4212 procedure TPlayer.SetAction(Action: Byte; Force: Boolean = False);
4213 var
4214 Prior: Byte;
4215 begin
4216 case Action of
4217 A_WALK: Prior := 3;
4218 A_DIE1: Prior := 5;
4219 A_DIE2: Prior := 5;
4220 A_ATTACK: Prior := 2;
4221 A_SEEUP: Prior := 1;
4222 A_SEEDOWN: Prior := 1;
4223 A_ATTACKUP: Prior := 2;
4224 A_ATTACKDOWN: Prior := 2;
4225 A_PAIN: Prior := 4;
4226 else Prior := 0;
4227 end;
4229 if (Prior > FActionPrior) or Force then
4230 if not ((Prior = 2) and (FCurrWeap = WEAPON_SAW)) then
4231 begin
4232 FActionPrior := Prior;
4233 FActionAnim := Action;
4234 FActionForce := Force;
4235 FActionChanged := True;
4236 end;
4238 if Action in [A_ATTACK, A_ATTACKUP, A_ATTACKDOWN] then FModel.SetFire(True);
4239 end;
4241 function TPlayer.StayOnStep(XInc, YInc: Integer): Boolean;
4242 begin
4243 Result := not g_Map_CollidePanel(FObj.X+PLAYER_RECT.X, FObj.Y+YInc+PLAYER_RECT.Y+PLAYER_RECT.Height-1,
4244 PLAYER_RECT.Width, 1, PANEL_STEP, False)
4245 and g_Map_CollidePanel(FObj.X+PLAYER_RECT.X, FObj.Y+YInc+PLAYER_RECT.Y+PLAYER_RECT.Height,
4246 PLAYER_RECT.Width, 1, PANEL_STEP, False);
4247 end;
4249 function TPlayer.TeleportTo(X, Y: Integer; silent: Boolean; dir: Byte): Boolean;
4250 var
4251 Anim: TAnimation;
4252 ID: DWORD;
4253 begin
4254 Result := False;
4256 if g_CollideLevel(X, Y, PLAYER_RECT.Width, PLAYER_RECT.Height) then
4257 begin
4258 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj.X, FObj.Y);
4259 if g_Game_IsServer and g_Game_IsNet then
4260 MH_SEND_Sound(FObj.X, FObj.Y, 'SOUND_GAME_NOTELEPORT');
4261 Exit;
4262 end;
4264 FJustTeleported := True;
4266 Anim := nil;
4267 if not silent then
4268 begin
4269 if g_Frames_Get(ID, 'FRAMES_TELEPORT') then
4270 begin
4271 Anim := TAnimation.Create(ID, False, 3);
4272 end;
4274 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj.X, FObj.Y);
4275 g_GFX_OnceAnim(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
4276 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32, Anim);
4277 if g_Game_IsServer and g_Game_IsNet then
4278 MH_SEND_Effect(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
4279 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32, 1,
4280 NET_GFX_TELE);
4281 end;
4283 FObj.X := X-PLAYER_RECT.X;
4284 FObj.Y := Y-PLAYER_RECT.Y;
4285 if FLive and FGhost then
4286 begin
4287 FXTo := FObj.X;
4288 FYTo := FObj.Y;
4289 end;
4291 if not g_Game_IsNet then
4292 begin
4293 if dir = 1 then
4294 begin
4295 SetDirection(D_LEFT);
4296 FAngle := 180;
4297 end
4298 else
4299 if dir = 2 then
4300 begin
4301 SetDirection(D_RIGHT);
4302 FAngle := 0;
4303 end
4304 else
4305 if dir = 3 then
4306 begin // îáðàòíîå
4307 if FDirection = D_RIGHT then
4308 begin
4309 SetDirection(D_LEFT);
4310 FAngle := 180;
4311 end
4312 else
4313 begin
4314 SetDirection(D_RIGHT);
4315 FAngle := 0;
4316 end;
4317 end;
4318 end;
4320 if not silent and (Anim <> nil) then
4321 begin
4322 g_GFX_OnceAnim(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
4323 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32, Anim);
4324 Anim.Free();
4326 if g_Game_IsServer and g_Game_IsNet then
4327 MH_SEND_Effect(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
4328 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32, 0,
4329 NET_GFX_TELE);
4330 end;
4332 Result := True;
4333 end;
4335 function nonz(a: Single): Single;
4336 begin
4337 if a <> 0 then
4338 Result := a
4339 else
4340 Result := 1;
4341 end;
4343 procedure TPlayer.Update();
4344 var
4345 b: Byte;
4346 i, ii, wx, wy, xd, yd, k: Integer;
4347 blockmon, headwater, dospawn: Boolean;
4348 NetServer: Boolean;
4349 AnyServer: Boolean;
4350 SetSpect: Boolean;
4351 begin
4352 NetServer := g_Game_IsNet and g_Game_IsServer;
4353 AnyServer := g_Game_IsServer;
4355 if g_Game_IsClient and (NetInterpLevel > 0) then
4356 DoLerp(NetInterpLevel + 1)
4357 else
4358 if FGhost then
4359 DoLerp(4);
4361 if NetServer then
4362 if FClientID >= 0 then
4363 begin
4364 FPing := NetClients[FClientID].Peer^.lastRoundTripTime;
4365 if NetClients[FClientID].Peer^.packetsSent > 0 then
4366 FLoss := Round(100*NetClients[FClientID].Peer^.packetsLost/NetClients[FClientID].Peer^.packetsSent)
4367 else
4368 FLoss := 0;
4369 end else
4370 begin
4371 FPing := 0;
4372 FLoss := 0;
4373 end;
4375 if FLive and (gFly or FJetpack) then
4376 FlySmoke();
4378 if FDirection = D_LEFT then
4379 FAngle := 180
4380 else
4381 FAngle := 0;
4383 if FLive and (not FGhost) then
4384 begin
4385 if FKeys[KEY_UP].Pressed then
4386 SeeUp();
4387 if FKeys[KEY_DOWN].Pressed then
4388 SeeDown();
4389 end;
4391 if (not (FKeys[KEY_UP].Pressed or FKeys[KEY_DOWN].Pressed)) and
4392 (FIncCam <> 0) then
4393 begin
4394 i := g_basic.Sign(FIncCam);
4395 FIncCam := Abs(FIncCam);
4396 DecMin(FIncCam, 5, 0);
4397 FIncCam := FIncCam*i;
4398 end;
4400 if gTime mod (GAME_TICK*2) <> 0 then
4401 begin
4402 if (FObj.Vel.X = 0) and FLive then
4403 begin
4404 if FKeys[KEY_LEFT].Pressed then
4405 Run(D_LEFT);
4406 if FKeys[KEY_RIGHT].Pressed then
4407 Run(D_RIGHT);
4408 end;
4410 if FPhysics then
4411 g_Obj_Move(@FObj, True, True, True);
4413 Exit;
4414 end;
4416 FActionChanged := False;
4418 if FLive then
4419 begin
4420 // Let alive player do some actions
4421 if FKeys[KEY_LEFT].Pressed then Run(D_LEFT);
4422 if FKeys[KEY_RIGHT].Pressed then Run(D_RIGHT);
4423 if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
4424 if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
4425 if FKeys[KEY_FIRE].Pressed and AnyServer then Fire();
4426 if FKeys[KEY_OPEN].Pressed and AnyServer then Use();
4427 if FKeys[KEY_JUMP].Pressed then Jump()
4428 else
4429 begin
4430 if AnyServer and FJetpack then
4431 begin
4432 FJetpack := False;
4433 JetpackOff;
4434 if NetServer then MH_SEND_PlayerStats(FUID);
4435 end;
4436 FCanJetpack := True;
4437 end;
4438 end
4439 else // Dead
4440 begin
4441 dospawn := False;
4442 if not FGhost then
4443 for k := Low(FKeys) to KEY_CHAT-1 do
4444 begin
4445 if FKeys[k].Pressed then
4446 begin
4447 dospawn := True;
4448 break;
4449 end;
4450 end;
4451 if dospawn then
4452 begin
4453 if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
4454 Respawn(False)
4455 else // Single
4456 if (FTime[T_RESPAWN] <= gTime) and
4457 gGameOn and (not FLive) then
4458 begin
4459 if (g_Player_GetCount() > 1) then
4460 Respawn(False)
4461 else
4462 begin
4463 gExit := EXIT_RESTART;
4464 Exit;
4465 end;
4466 end;
4467 end;
4468 // Dead spectator actions
4469 if FGhost then
4470 begin
4471 if FKeys[KEY_OPEN].Pressed and AnyServer then Fire();
4472 if FKeys[KEY_FIRE].Pressed and AnyServer then
4473 begin
4474 if FSpectator then
4475 begin
4476 if (FSpectatePlayer >= High(gPlayers)) then
4477 FSpectatePlayer := -1
4478 else
4479 begin
4480 SetSpect := False;
4481 for I := FSpectatePlayer + 1 to High(gPlayers) do
4482 if gPlayers[I] <> nil then
4483 if gPlayers[I].Live then
4484 if gPlayers[I].UID <> FUID then
4485 begin
4486 FSpectatePlayer := I;
4487 SetSpect := True;
4488 break;
4489 end;
4491 if not SetSpect then FSpectatePlayer := -1;
4492 end;
4494 ReleaseKeys;
4495 end;
4496 end;
4497 end;
4498 end;
4499 // No clipping
4500 if FGhost then
4501 begin
4502 if FKeys[KEY_UP].Pressed or FKeys[KEY_JUMP].Pressed then
4503 begin
4504 FYTo := FObj.Y - 32;
4505 FSpectatePlayer := -1;
4506 end;
4507 if FKeys[KEY_DOWN].Pressed then
4508 begin
4509 FYTo := FObj.Y + 32;
4510 FSpectatePlayer := -1;
4511 end;
4512 if FKeys[KEY_LEFT].Pressed then
4513 begin
4514 FXTo := FObj.X - 32;
4515 FSpectatePlayer := -1;
4516 end;
4517 if FKeys[KEY_RIGHT].Pressed then
4518 begin
4519 FXTo := FObj.X + 32;
4520 FSpectatePlayer := -1;
4521 end;
4523 if (FXTo < -64) then
4524 FXTo := -64
4525 else if (FXTo > gMapInfo.Width + 32) then
4526 FXTo := gMapInfo.Width + 32;
4527 if (FYTo < -72) then
4528 FYTo := -72
4529 else if (FYTo > gMapInfo.Height + 32) then
4530 FYTo := gMapInfo.Height + 32;
4531 end;
4533 if FPhysics then
4534 g_Obj_Move(@FObj, True, True, True)
4535 else
4536 begin
4537 FObj.Vel.X := 0;
4538 FObj.Vel.Y := 0;
4539 if FSpectator then
4540 if (FSpectatePlayer <= High(gPlayers)) and (FSpectatePlayer >= 0) then
4541 if gPlayers[FSpectatePlayer] <> nil then
4542 if gPlayers[FSpectatePlayer].Live then
4543 begin
4544 FXTo := gPlayers[FSpectatePlayer].GameX;
4545 FYTo := gPlayers[FSpectatePlayer].GameY;
4546 end;
4547 end;
4549 blockmon := g_Map_CollidePanel(FObj.X+PLAYER_HEADRECT.X, FObj.Y+PLAYER_HEADRECT.Y,
4550 PLAYER_HEADRECT.Width, PLAYER_HEADRECT.Height,
4551 PANEL_BLOCKMON, True);
4552 headwater := HeadInLiquid(0, 0);
4554 // Ñîïðîòèâëåíèå âîçäóõà:
4555 if (not FLive) or not (FKeys[KEY_LEFT].Pressed or FKeys[KEY_RIGHT].Pressed) then
4556 if FObj.Vel.X <> 0 then
4557 FObj.Vel.X := z_dec(FObj.Vel.X, 1);
4559 if (FLastHit = HIT_TRAP) and (FPain > 90) then FPain := 90;
4560 DecMin(FPain, 5, 0);
4561 DecMin(FPickup, 1, 0);
4563 if FLive and (FObj.Y > gMapInfo.Height+128) and AnyServer then
4564 begin
4565 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
4566 FMegaRulez[MR_SUIT] := 0;
4567 FMegaRulez[MR_INVUL] := 0;
4568 FMegaRulez[MR_INVIS] := 0;
4569 Kill(K_FALLKILL, 0, HIT_FALL);
4570 end;
4572 i := 9;
4574 if FLive then
4575 begin
4576 if FCurrWeap = WEAPON_SAW then
4577 if not (FSawSound.IsPlaying() or FSawSoundHit.IsPlaying() or
4578 FSawSoundSelect.IsPlaying()) then
4579 FSawSoundIdle.PlayAt(FObj.X, FObj.Y);
4581 if FJetpack then
4582 if (not FJetSoundFly.IsPlaying()) and (not FJetSoundOn.IsPlaying()) and
4583 (not FJetSoundOff.IsPlaying()) then
4584 begin
4585 FJetSoundFly.SetPosition(0);
4586 FJetSoundFly.PlayAt(FObj.X, FObj.Y);
4587 end;
4589 for b := WEAPON_KASTET to WEAPON_SUPERPULEMET do
4590 if FReloading[b] > 0 then
4591 if FNoReload then
4592 FReloading[b] := 0
4593 else
4594 Dec(FReloading[b]);
4596 if FShellTimer > -1 then
4597 if FShellTimer = 0 then
4598 begin
4599 if FShellType = SHELL_SHELL then
4600 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
4601 GameVelX, GameVelY-2, SHELL_SHELL)
4602 else if FShellType = SHELL_DBLSHELL then
4603 begin
4604 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
4605 GameVelX+1, GameVelY-2, SHELL_SHELL);
4606 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
4607 GameVelX-1, GameVelY-2, SHELL_SHELL);
4608 end;
4609 FShellTimer := -1;
4610 end else Dec(FShellTimer);
4612 if (FBFGFireCounter > -1) then
4613 if FBFGFireCounter = 0 then
4614 begin
4615 if AnyServer then
4616 begin
4617 wx := FObj.X+WEAPONPOINT[FDirection].X;
4618 wy := FObj.Y+WEAPONPOINT[FDirection].Y;
4619 xd := wx+IfThen(FDirection = D_LEFT, -30, 30);
4620 yd := wy+firediry();
4621 g_Weapon_bfgshot(wx, wy, xd, yd, FUID);
4622 if NetServer then MH_SEND_PlayerFire(FUID, WEAPON_BFG, wx, wy, xd, yd);
4623 if (FAngle = 0) or (FAngle = 180) then SetAction(A_ATTACK)
4624 else if (FAngle = ANGLE_LEFTDOWN) or (FAngle = ANGLE_RIGHTDOWN) then SetAction(A_ATTACKDOWN)
4625 else if (FAngle = ANGLE_LEFTUP) or (FAngle = ANGLE_RIGHTUP) then SetAction(A_ATTACKUP);
4626 end;
4628 FReloading[WEAPON_BFG] := WEAPON_RELOAD[WEAPON_BFG];
4629 FBFGFireCounter := -1;
4630 end else
4631 if FNoReload then
4632 FBFGFireCounter := 0
4633 else
4634 Dec(FBFGFireCounter);
4636 if (FMegaRulez[MR_SUIT] < gTime) and AnyServer then
4637 begin
4638 b := g_GetAcidHit(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width, PLAYER_RECT.Height);
4640 if (b > 0) and (gTime mod (15*GAME_TICK) = 0) then Damage(b, 0, 0, 0, HIT_ACID);
4641 end;
4643 if (headwater or blockmon) then
4644 begin
4645 Dec(FAir);
4647 if FAir < -9 then
4648 begin
4649 if AnyServer then Damage(10, 0, 0, 0, HIT_WATER);
4650 FAir := 0;
4651 end
4652 else if (FAir mod 31 = 0) and not blockmon then
4653 begin
4654 g_GFX_Bubbles(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2), FObj.Y+PLAYER_RECT.Y-4, 5+Random(6), 8, 4);
4655 if Random(2) = 0 then
4656 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj.X, FObj.Y)
4657 else
4658 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj.X, FObj.Y);
4659 end;
4660 end else if FAir < AIR_DEF then
4661 FAir := AIR_DEF;
4663 if FDamageBuffer > 0 then
4664 begin
4665 if FDamageBuffer >= 9 then
4666 begin
4667 SetAction(A_PAIN);
4669 if FDamageBuffer < 30 then i := 9
4670 else if FDamageBuffer < 100 then i := 18
4671 else i := 27;
4672 end;
4674 ii := Round(FDamageBuffer*FHealth / nonz(FArmor*(3/4)+FHealth));
4675 FArmor := FArmor-(FDamageBuffer-ii);
4676 FHealth := FHealth-ii;
4677 if FArmor < 0 then
4678 begin
4679 FHealth := FHealth+FArmor;
4680 FArmor := 0;
4681 end;
4683 if AnyServer then
4684 if FHealth <= 0 then
4685 if FHealth > -30 then Kill(K_SIMPLEKILL, FLastSpawnerUID, FLastHit)
4686 else if FHealth > -50 then Kill(K_HARDKILL, FLastSpawnerUID, FLastHit)
4687 else Kill(K_EXTRAHARDKILL, FLastSpawnerUID, FLastHit);
4689 if FLive then
4690 begin
4691 if FDamageBuffer <= 20 then FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y)
4692 else if FDamageBuffer <= 55 then FModel.PlaySound(MODELSOUND_PAIN, 2, FObj.X, FObj.Y)
4693 else if FDamageBuffer <= 120 then FModel.PlaySound(MODELSOUND_PAIN, 3, FObj.X, FObj.Y)
4694 else FModel.PlaySound(MODELSOUND_PAIN, 4, FObj.X, FObj.Y);
4695 end;
4697 FDamageBuffer := 0;
4698 end;
4700 {CollideItem();}
4701 end; // if FLive then ...
4703 if (FActionAnim = A_PAIN) and (FModel.Animation <> A_PAIN) then
4704 begin
4705 FModel.ChangeAnimation(FActionAnim, FActionForce);
4706 FModel.GetCurrentAnimation.MinLength := i;
4707 FModel.GetCurrentAnimationMask.MinLength := i;
4708 end else FModel.ChangeAnimation(FActionAnim, FActionForce and (FModel.Animation <> A_STAND));
4710 if (FModel.GetCurrentAnimation.Played or ((not FActionChanged) and (FModel.Animation = A_WALK)))
4711 then SetAction(A_STAND, True);
4713 if not ((FModel.Animation = A_WALK) and (Abs(FObj.Vel.X) < 4) and not FModel.Fire) then FModel.Update;
4715 for b := Low(FKeys) to High(FKeys) do
4716 if FKeys[b].Time = 0 then FKeys[b].Pressed := False else Dec(FKeys[b].Time);
4717 end;
4719 function TPlayer.Collide(X, Y: Integer; Width, Height: Word): Boolean;
4720 begin
4721 Result := g_Collide(FObj.X+PLAYER_RECT.X,
4722 FObj.Y+PLAYER_RECT.Y,
4723 PLAYER_RECT.Width,
4724 PLAYER_RECT.Height,
4725 X, Y,
4726 Width, Height);
4727 end;
4729 function TPlayer.Collide(Panel: TPanel): Boolean;
4730 begin
4731 Result := g_Collide(FObj.X+PLAYER_RECT.X,
4732 FObj.Y+PLAYER_RECT.Y,
4733 PLAYER_RECT.Width,
4734 PLAYER_RECT.Height,
4735 Panel.X, Panel.Y,
4736 Panel.Width, Panel.Height);
4737 end;
4739 function TPlayer.Collide(X, Y: Integer): Boolean;
4740 begin
4741 X := X-FObj.X-PLAYER_RECT.X;
4742 Y := Y-FObj.Y-PLAYER_RECT.Y;
4743 Result := (x >= 0) and (x <= PLAYER_RECT.Width) and
4744 (y >= 0) and (y <= PLAYER_RECT.Height);
4745 end;
4747 function g_Player_ValidName(Name: string): Boolean;
4748 var
4749 a: Integer;
4750 begin
4751 Result := True;
4753 if gPlayers = nil then Exit;
4755 for a := 0 to High(gPlayers) do
4756 if gPlayers[a] <> nil then
4757 if LowerCase(Name) = LowerCase(gPlayers[a].FName) then
4758 begin
4759 Result := False;
4760 Exit;
4761 end;
4762 end;
4764 procedure TPlayer.SetDirection(Direction: TDirection);
4765 var
4766 d: TDirection;
4767 begin
4768 d := FModel.Direction;
4770 FModel.Direction := Direction;
4771 if d <> Direction then FModel.ChangeAnimation(FModel.Animation, True);
4773 FDirection := Direction;
4774 end;
4776 function TPlayer.GetKeys(): Byte;
4777 begin
4778 Result := 0;
4780 if R_KEY_RED in FRulez then Result := KEY_RED;
4781 if R_KEY_GREEN in FRulez then Result := Result or KEY_GREEN;
4782 if R_KEY_BLUE in FRulez then Result := Result or KEY_BLUE;
4784 if FTeam = TEAM_RED then Result := Result or KEY_REDTEAM;
4785 if FTeam = TEAM_BLUE then Result := Result or KEY_BLUETEAM;
4786 end;
4788 procedure TPlayer.Use();
4789 var
4790 a: Integer;
4791 begin
4792 if FTime[T_USE] > gTime then Exit;
4794 g_Triggers_PressR(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
4795 PLAYER_RECT.Height, FUID, ACTIVATE_PLAYERPRESS);
4797 for a := 0 to High(gPlayers) do
4798 if (gPlayers[a] <> nil) and (gPlayers[a] <> Self) and
4799 gPlayers[a].Live and SameTeam(FUID, gPlayers[a].FUID) and
4800 g_Obj_Collide(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y,
4801 FObj.Rect.Width, FObj.Rect.Height, @gPlayers[a].FObj) then
4802 begin
4803 gPlayers[a].Touch();
4804 if g_Game_IsNet and g_Game_IsServer then
4805 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH, gPlayers[a].FUID);
4806 end;
4808 FTime[T_USE] := gTime+120;
4809 end;
4811 procedure TPlayer.NetFire(Wpn: Byte; X, Y, AX, AY: Integer; WID: Integer = -1);
4812 var
4813 Obj: TObj;
4814 F: Boolean;
4815 WX, WY, XD, YD: Integer;
4816 begin
4817 F := False;
4818 WX := X;
4819 WY := Y;
4820 XD := AX;
4821 YD := AY;
4823 case FCurrWeap of
4824 WEAPON_KASTET:
4825 begin
4826 if R_BERSERK in FRulez then
4827 begin
4828 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
4829 obj.X := FObj.X+FObj.Rect.X;
4830 obj.Y := FObj.Y+FObj.Rect.Y;
4831 obj.rect.X := 0;
4832 obj.rect.Y := 0;
4833 obj.rect.Width := 39;
4834 obj.rect.Height := 52;
4835 obj.Vel.X := (xd-wx) div 2;
4836 obj.Vel.Y := (yd-wy) div 2;
4837 obj.Accel.X := xd-wx;
4838 obj.Accel.y := yd-wy;
4840 if g_Weapon_Hit(@obj, 50, FUID, HIT_SOME) <> 0 then
4841 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj.X, FObj.Y)
4842 else
4843 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj.X, FObj.Y);
4845 if gFlash = 1 then
4846 if FPain < 50 then
4847 FPain := min(FPain + 25, 50);
4848 end else
4849 g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 3, FUID);
4850 end;
4852 WEAPON_SAW:
4853 begin
4854 if g_Weapon_chainsaw(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y,
4855 IfThen(gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF], 9, 3), FUID) <> 0 then
4856 begin
4857 FSawSoundSelect.Stop();
4858 FSawSound.Stop();
4859 FSawSoundHit.PlayAt(FObj.X, FObj.Y);
4860 end
4861 else if not FSawSoundHit.IsPlaying() then
4862 begin
4863 FSawSoundSelect.Stop();
4864 FSawSound.PlayAt(FObj.X, FObj.Y);
4865 end;
4866 f := True;
4867 end;
4869 WEAPON_PISTOL:
4870 begin
4871 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX, Gamey);
4872 FFireAngle := FAngle;
4873 f := True;
4874 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
4875 GameVelX, GameVelY-2, SHELL_BULLET);
4876 end;
4878 WEAPON_SHOTGUN1:
4879 begin
4880 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex, Gamey);
4881 FFireAngle := FAngle;
4882 f := True;
4883 FShellTimer := 10;
4884 FShellType := SHELL_SHELL;
4885 end;
4887 WEAPON_SHOTGUN2:
4888 begin
4889 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex, Gamey);
4890 FFireAngle := FAngle;
4891 f := True;
4892 FShellTimer := 13;
4893 FShellType := SHELL_DBLSHELL;
4894 end;
4896 WEAPON_CHAINGUN:
4897 begin
4898 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex, Gamey);
4899 FFireAngle := FAngle;
4900 f := True;
4901 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
4902 GameVelX, GameVelY-2, SHELL_BULLET);
4903 end;
4905 WEAPON_ROCKETLAUNCHER:
4906 begin
4907 g_Weapon_Rocket(wx, wy, xd, yd, FUID, WID);
4908 FFireAngle := FAngle;
4909 f := True;
4910 end;
4912 WEAPON_PLASMA:
4913 begin
4914 g_Weapon_Plasma(wx, wy, xd, yd, FUID, WID);
4915 FFireAngle := FAngle;
4916 f := True;
4917 end;
4919 WEAPON_BFG:
4920 begin
4921 g_Weapon_BFGShot(wx, wy, xd, yd, FUID, WID);
4922 FFireAngle := FAngle;
4923 f := True;
4924 end;
4926 WEAPON_SUPERPULEMET:
4927 begin
4928 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex, Gamey);
4929 FFireAngle := FAngle;
4930 f := True;
4931 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
4932 GameVelX, GameVelY-2, SHELL_SHELL);
4933 end;
4934 end;
4936 if not f then Exit;
4938 if (FAngle = 0) or (FAngle = 180) then SetAction(A_ATTACK)
4939 else if (FAngle = ANGLE_LEFTDOWN) or (FAngle = ANGLE_RIGHTDOWN) then SetAction(A_ATTACKDOWN)
4940 else if (FAngle = ANGLE_LEFTUP) or (FAngle = ANGLE_RIGHTUP) then SetAction(A_ATTACKUP);
4941 end;
4943 procedure TPlayer.DoLerp(Level: Integer = 2);
4944 begin
4945 if FObj.X <> FXTo then FObj.X := Lerp(FObj.X, FXTo, Level);
4946 if FObj.Y <> FYTo then FObj.Y := Lerp(FObj.Y, FYTo, Level);
4947 end;
4949 procedure TPlayer.SetLerp(XTo, YTo: Integer);
4950 var
4951 AX, AY: Integer;
4952 begin
4953 if NetInterpLevel < 1 then
4954 begin
4955 FObj.X := XTo;
4956 FObj.Y := YTo;
4957 end
4958 else
4959 begin
4960 FXTo := XTo;
4961 FYTo := YTo;
4963 AX := Abs(FXTo - FObj.X);
4964 AY := Abs(FYTo - FObj.Y);
4965 if (AX > 32) or (AX <= NetInterpLevel) then
4966 FObj.X := FXTo;
4967 if (AY > 32) or (AY <= NetInterpLevel) then
4968 FObj.Y := FYTo;
4969 end;
4970 end;
4972 function TPlayer.FullInLift(XInc, YInc: Integer): Integer;
4973 begin
4974 if g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc,
4975 PLAYER_RECT.Width, PLAYER_RECT.Height-8,
4976 PANEL_LIFTUP, False) then Result := -1
4977 else
4978 if g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc,
4979 PLAYER_RECT.Width, PLAYER_RECT.Height-8,
4980 PANEL_LIFTDOWN, False) then Result := 1
4981 else Result := 0;
4982 end;
4984 function TPlayer.GetFlag(Flag: Byte): Boolean;
4985 var
4986 s, ts: String;
4987 evtype: Byte;
4988 begin
4989 Result := False;
4991 if Flag = FLAG_NONE then
4992 Exit;
4994 if not g_Game_IsServer then Exit;
4996 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
4997 if (Flag = FTeam) and
4998 (gFlags[Flag].State = FLAG_STATE_NORMAL) and
4999 (FFlag <> FLAG_NONE) then
5000 begin
5001 if FFlag = FLAG_RED then
5002 s := _lc[I_PLAYER_FLAG_RED]
5003 else
5004 s := _lc[I_PLAYER_FLAG_BLUE];
5006 evtype := FLAG_STATE_SCORED;
5008 ts := Format('%.4d', [gFlags[FFlag].CaptureTime]);
5009 Insert('.', ts, Length(ts) + 1 - 3);
5010 g_Console_Add(Format(_lc[I_PLAYER_FLAG_CAPTURE], [FName, s, ts]), True);
5012 g_Map_ResetFlag(FFlag);
5013 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_CAPTURE], [AnsiUpperCase(s)]), 144);
5015 gTeamStat[FTeam].Goals := gTeamStat[FTeam].Goals + 1;
5017 Result := True;
5018 if g_Game_IsNet then
5019 begin
5020 MH_SEND_FlagEvent(evtype, FFlag, FUID, False);
5021 MH_SEND_GameStats;
5022 end;
5024 gFlags[FFlag].CaptureTime := 0;
5025 SetFlag(FLAG_NONE);
5026 Exit;
5027 end;
5029 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5030 if (Flag = FTeam) and
5031 (gFlags[Flag].State = FLAG_STATE_DROPPED) then
5032 begin
5033 if Flag = FLAG_RED then
5034 s := _lc[I_PLAYER_FLAG_RED]
5035 else
5036 s := _lc[I_PLAYER_FLAG_BLUE];
5038 evtype := FLAG_STATE_RETURNED;
5039 gFlags[Flag].CaptureTime := 0;
5041 g_Console_Add(Format(_lc[I_PLAYER_FLAG_RETURN], [FName, s]), True);
5043 g_Map_ResetFlag(Flag);
5044 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_RETURN], [AnsiUpperCase(s)]), 144);
5046 Result := True;
5047 if g_Game_IsNet then
5048 begin
5049 MH_SEND_FlagEvent(evtype, Flag, FUID, False);
5050 MH_SEND_GameStats;
5051 end;
5052 Exit;
5053 end;
5055 // Ïîäîáðàë ÷óæîé ôëàã:
5056 if (Flag <> FTeam) and (FTime[T_FLAGCAP] <= gTime) then
5057 begin
5058 SetFlag(Flag);
5060 if Flag = FLAG_RED then
5061 s := _lc[I_PLAYER_FLAG_RED]
5062 else
5063 s := _lc[I_PLAYER_FLAG_BLUE];
5065 evtype := FLAG_STATE_CAPTURED;
5067 g_Console_Add(Format(_lc[I_PLAYER_FLAG_GET], [FName, s]), True);
5069 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_GET], [AnsiUpperCase(s)]), 144);
5071 gFlags[Flag].State := FLAG_STATE_CAPTURED;
5073 Result := True;
5074 if g_Game_IsNet then
5075 begin
5076 MH_SEND_FlagEvent(evtype, Flag, FUID, False);
5077 MH_SEND_GameStats;
5078 end;
5079 end;
5080 end;
5082 procedure TPlayer.SetFlag(Flag: Byte);
5083 begin
5084 FFlag := Flag;
5085 if FModel <> nil then
5086 FModel.SetFlag(FFlag);
5087 end;
5089 function TPlayer.DropFlag(): Boolean;
5090 var
5091 s: String;
5092 begin
5093 Result := False;
5094 if (not g_Game_IsServer) or (FFlag = FLAG_NONE) then
5095 Exit;
5096 FTime[T_FLAGCAP] := gTime + 2000;
5097 with gFlags[FFlag] do
5098 begin
5099 Obj.X := FObj.X;
5100 Obj.Y := FObj.Y;
5101 Direction := FDirection;
5102 State := FLAG_STATE_DROPPED;
5103 Count := FLAG_TIME;
5104 g_Obj_Push(@Obj, (FObj.Vel.X div 2)-2+Random(5),
5105 (FObj.Vel.Y div 2)-2+Random(5));
5107 if FFlag = FLAG_RED then
5108 s := _lc[I_PLAYER_FLAG_RED]
5109 else
5110 s := _lc[I_PLAYER_FLAG_BLUE];
5112 g_Console_Add(Format(_lc[I_PLAYER_FLAG_DROP], [FName, s]), True);
5113 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_DROP], [AnsiUpperCase(s)]), 144);
5115 if g_Game_IsNet then
5116 MH_SEND_FlagEvent(FLAG_STATE_DROPPED, Flag, FUID, False);
5117 end;
5118 SetFlag(FLAG_NONE);
5119 Result := True;
5120 end;
5122 procedure TPlayer.GetSecret();
5123 begin
5124 Inc(FSecrets);
5125 end;
5127 procedure TPlayer.PressKey(Key: Byte; Time: Word = 1);
5128 begin
5129 Assert(Key <= High(FKeys));
5131 FKeys[Key].Pressed := True;
5132 FKeys[Key].Time := Time;
5133 end;
5135 function TPlayer.IsKeyPressed(K: Byte): Boolean;
5136 begin
5137 Result := FKeys[K].Pressed;
5138 end;
5140 procedure TPlayer.ReleaseKeys();
5141 var
5142 a: Integer;
5143 begin
5144 for a := Low(FKeys) to High(FKeys) do
5145 begin
5146 FKeys[a].Pressed := False;
5147 FKeys[a].Time := 0;
5148 end;
5149 end;
5151 procedure TPlayer.OnDamage(Angle: SmallInt);
5152 begin
5153 end;
5155 function TPlayer.firediry(): Integer;
5156 begin
5157 if FKeys[KEY_UP].Pressed then Result := -42
5158 else if FKeys[KEY_DOWN].Pressed then Result := 19
5159 else Result := 0;
5160 end;
5162 procedure TPlayer.RememberState();
5163 var
5164 i: Integer;
5165 begin
5166 FSavedState.Health := FHealth;
5167 FSavedState.Armor := FArmor;
5168 FSavedState.Air := FAir;
5169 FSavedState.JetFuel := FJetFuel;
5170 FSavedState.CurrWeap := FCurrWeap;
5172 for i := 0 to 3 do
5173 FSavedState.Ammo[i] := FAmmo[i];
5174 for i := 0 to 3 do
5175 FSavedState.MaxAmmo[i] := FMaxAmmo[i];
5177 FSavedState.Rulez := FRulez;
5178 FSavedState.WaitRecall := True;
5179 end;
5181 procedure TPlayer.RecallState();
5182 var
5183 i: Integer;
5184 begin
5185 if not FSavedState.WaitRecall then Exit;
5187 FHealth := FSavedState.Health;
5188 FArmor := FSavedState.Armor;
5189 FAir := FSavedState.Air;
5190 FJetFuel := FSavedState.JetFuel;
5191 FCurrWeap := FSavedState.CurrWeap;
5193 for i := 0 to 3 do
5194 FAmmo[i] := FSavedState.Ammo[i];
5195 for i := 0 to 3 do
5196 FMaxAmmo[i] := FSavedState.MaxAmmo[i];
5198 FRulez := FSavedState.Rulez;
5199 FSavedState.WaitRecall := False;
5201 if gGameSettings.GameType = GT_SERVER then
5202 MH_SEND_PlayerStats(FUID);
5203 end;
5205 procedure TPlayer.SaveState(var Mem: TBinMemoryWriter);
5206 var
5207 i: Integer;
5208 sig: DWORD;
5209 str: String;
5210 b: Byte;
5211 begin
5212 if FIamBot then
5213 i := 512
5214 else
5215 i := 256;
5217 Mem := TBinMemoryWriter.Create(i);
5219 // Ñèãíàòóðà èãðîêà:
5220 sig := PLAYER_SIGNATURE; // 'PLYR'
5221 Mem.WriteDWORD(sig);
5222 // Áîò èëè ÷åëîâåê:
5223 Mem.WriteBoolean(FIamBot);
5224 // UID èãðîêà:
5225 Mem.WriteWord(FUID);
5226 // Èìÿ èãðîêà:
5227 Mem.WriteString(FName, 32);
5228 // Êîìàíäà:
5229 Mem.WriteByte(FTeam);
5230 // Æèâ ëè:
5231 Mem.WriteBoolean(FLive);
5232 // Èçðàñõîäîâàë ëè âñå æèçíè:
5233 Mem.WriteBoolean(FNoRespawn);
5234 // Íàïðàâëåíèå:
5235 if FDirection = D_LEFT then
5236 b := 1
5237 else // D_RIGHT
5238 b := 2;
5239 Mem.WriteByte(b);
5240 // Çäîðîâüå:
5241 Mem.WriteInt(FHealth);
5242 // Æèçíè:
5243 Mem.WriteByte(FLives);
5244 // Áðîíÿ:
5245 Mem.WriteInt(FArmor);
5246 // Çàïàñ âîçäóõà:
5247 Mem.WriteInt(FAir);
5248 // Çàïàñ ãîðþ÷åãî:
5249 Mem.WriteInt(FJetFuel);
5250 // Áîëü:
5251 Mem.WriteInt(FPain);
5252 // Óáèë:
5253 Mem.WriteInt(FKills);
5254 // Óáèë ìîíñòðîâ:
5255 Mem.WriteInt(FMonsterKills);
5256 // Ôðàãîâ:
5257 Mem.WriteInt(FFrags);
5258 // Ôðàãîâ ïîäðÿä:
5259 Mem.WriteByte(FFragCombo);
5260 // Âðåìÿ ïîñëåäíåãî ôðàãà:
5261 Mem.WriteDWORD(FLastFrag);
5262 // Ñìåðòåé:
5263 Mem.WriteInt(FDeath);
5264 // Êàêîé ôëàã íåñåò:
5265 Mem.WriteByte(FFlag);
5266 // Íàøåë ñåêðåòîâ:
5267 Mem.WriteInt(FSecrets);
5268 // Òåêóùåå îðóæèå:
5269 Mem.WriteByte(FCurrWeap);
5270 // Âðåìÿ çàðÿäêè BFG:
5271 Mem.WriteSmallInt(FBFGFireCounter);
5272 // Áóôåð óðîíà:
5273 Mem.WriteInt(FDamageBuffer);
5274 // Ïîñëåäíèé óäàðèâøèé:
5275 Mem.WriteWord(FLastSpawnerUID);
5276 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
5277 Mem.WriteByte(FLastHit);
5278 // Îáúåêò èãðîêà:
5279 Obj_SaveState(@FObj, Mem);
5280 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
5281 for i := A_BULLETS to A_CELLS do
5282 Mem.WriteWord(FAmmo[i]);
5283 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
5284 for i := A_BULLETS to A_CELLS do
5285 Mem.WriteWord(FMaxAmmo[i]);
5286 // Íàëè÷èå îðóæèÿ:
5287 for i := WEAPON_KASTET to WEAPON_SUPERPULEMET do
5288 Mem.WriteBoolean(FWeapon[i]);
5289 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
5290 for i := WEAPON_KASTET to WEAPON_SUPERPULEMET do
5291 Mem.WriteWord(FReloading[i]);
5292 // Íàëè÷èå ðþêçàêà:
5293 if R_ITEM_BACKPACK in FRulez then
5294 b := 1
5295 else
5296 b := 0;
5297 Mem.WriteByte(b);
5298 // Íàëè÷èå êðàñíîãî êëþ÷à:
5299 if R_KEY_RED in FRulez then
5300 b := 1
5301 else
5302 b := 0;
5303 Mem.WriteByte(b);
5304 // Íàëè÷èå çåëåíîãî êëþ÷à:
5305 if R_KEY_GREEN in FRulez then
5306 b := 1
5307 else
5308 b := 0;
5309 Mem.WriteByte(b);
5310 // Íàëè÷èå ñèíåãî êëþ÷à:
5311 if R_KEY_BLUE in FRulez then
5312 b := 1
5313 else
5314 b := 0;
5315 Mem.WriteByte(b);
5316 // Íàëè÷èå áåðñåðêà:
5317 if R_BERSERK in FRulez then
5318 b := 1
5319 else
5320 b := 0;
5321 Mem.WriteByte(b);
5322 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
5323 for i := MR_SUIT to MR_MAX do
5324 Mem.WriteDWORD(FMegaRulez[i]);
5325 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
5326 for i := T_RESPAWN to T_FLAGCAP do
5327 Mem.WriteDWORD(FTime[i]);
5328 // Íàçâàíèå ìîäåëè:
5329 str := FModel.Name;
5330 Mem.WriteString(str);
5331 // Öâåò ìîäåëè:
5332 b := FColor.R;
5333 Mem.WriteByte(b);
5334 b := FColor.G;
5335 Mem.WriteByte(b);
5336 b := FColor.B;
5337 Mem.WriteByte(b);
5338 end;
5340 procedure TPlayer.LoadState(var Mem: TBinMemoryReader);
5341 var
5342 i: Integer;
5343 sig: DWORD;
5344 str: String;
5345 b: Byte;
5346 begin
5347 if Mem = nil then
5348 Exit;
5350 // Ñèãíàòóðà èãðîêà:
5351 Mem.ReadDWORD(sig);
5352 if sig <> PLAYER_SIGNATURE then // 'PLYR'
5353 begin
5354 raise EBinSizeError.Create('TPlayer.LoadState: Wrong Player Signature');
5355 end;
5356 // Áîò èëè ÷åëîâåê:
5357 Mem.ReadBoolean(FIamBot);
5358 // UID èãðîêà:
5359 Mem.ReadWord(FUID);
5360 // Èìÿ èãðîêà:
5361 Mem.ReadString(str);
5362 if (Self <> gPlayer1) and (Self <> gPlayer2) then
5363 FName := str;
5364 // Êîìàíäà:
5365 Mem.ReadByte(FTeam);
5366 // Æèâ ëè:
5367 Mem.ReadBoolean(FLive);
5368 // Èçðàñõîäîâàë ëè âñå æèçíè:
5369 Mem.ReadBoolean(FNoRespawn);
5370 // Íàïðàâëåíèå:
5371 Mem.ReadByte(b);
5372 if b = 1 then
5373 FDirection := D_LEFT
5374 else // b = 2
5375 FDirection := D_RIGHT;
5376 // Çäîðîâüå:
5377 Mem.ReadInt(FHealth);
5378 // Æèçíè:
5379 Mem.ReadByte(FLives);
5380 // Áðîíÿ:
5381 Mem.ReadInt(FArmor);
5382 // Çàïàñ âîçäóõà:
5383 Mem.ReadInt(FAir);
5384 // Çàïàñ ãîðþ÷åãî:
5385 Mem.ReadInt(FJetFuel);
5386 // Áîëü:
5387 Mem.ReadInt(FPain);
5388 // Óáèë:
5389 Mem.ReadInt(FKills);
5390 // Óáèë ìîíñòðîâ:
5391 Mem.ReadInt(FMonsterKills);
5392 // Ôðàãîâ:
5393 Mem.ReadInt(FFrags);
5394 // Ôðàãîâ ïîäðÿä:
5395 Mem.ReadByte(FFragCombo);
5396 // Âðåìÿ ïîñëåäíåãî ôðàãà:
5397 Mem.ReadDWORD(FLastFrag);
5398 // Ñìåðòåé:
5399 Mem.ReadInt(FDeath);
5400 // Êàêîé ôëàã íåñåò:
5401 Mem.ReadByte(FFlag);
5402 // Íàøåë ñåêðåòîâ:
5403 Mem.ReadInt(FSecrets);
5404 // Òåêóùåå îðóæèå:
5405 Mem.ReadByte(FCurrWeap);
5406 // Âðåìÿ çàðÿäêè BFG:
5407 Mem.ReadSmallInt(FBFGFireCounter);
5408 // Áóôåð óðîíà:
5409 Mem.ReadInt(FDamageBuffer);
5410 // Ïîñëåäíèé óäàðèâøèé:
5411 Mem.ReadWord(FLastSpawnerUID);
5412 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
5413 Mem.ReadByte(FLastHit);
5414 // Îáúåêò èãðîêà:
5415 Obj_LoadState(@FObj, Mem);
5416 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
5417 for i := A_BULLETS to A_CELLS do
5418 Mem.ReadWord(FAmmo[i]);
5419 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
5420 for i := A_BULLETS to A_CELLS do
5421 Mem.ReadWord(FMaxAmmo[i]);
5422 // Íàëè÷èå îðóæèÿ:
5423 for i := WEAPON_KASTET to WEAPON_SUPERPULEMET do
5424 Mem.ReadBoolean(FWeapon[i]);
5425 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
5426 for i := WEAPON_KASTET to WEAPON_SUPERPULEMET do
5427 Mem.ReadWord(FReloading[i]);
5428 // Íàëè÷èå ðþêçàêà:
5429 Mem.ReadByte(b);
5430 if b = 1 then
5431 Include(FRulez, R_ITEM_BACKPACK);
5432 // Íàëè÷èå êðàñíîãî êëþ÷à:
5433 Mem.ReadByte(b);
5434 if b = 1 then
5435 Include(FRulez, R_KEY_RED);
5436 // Íàëè÷èå çåëåíîãî êëþ÷à:
5437 Mem.ReadByte(b);
5438 if b = 1 then
5439 Include(FRulez, R_KEY_GREEN);
5440 // Íàëè÷èå ñèíåãî êëþ÷à:
5441 Mem.ReadByte(b);
5442 if b = 1 then
5443 Include(FRulez, R_KEY_BLUE);
5444 // Íàëè÷èå áåðñåðêà:
5445 Mem.ReadByte(b);
5446 if b = 1 then
5447 Include(FRulez, R_BERSERK);
5448 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
5449 for i := MR_SUIT to MR_MAX do
5450 Mem.ReadDWORD(FMegaRulez[i]);
5451 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
5452 for i := T_RESPAWN to T_FLAGCAP do
5453 Mem.ReadDWORD(FTime[i]);
5454 // Íàçâàíèå ìîäåëè:
5455 Mem.ReadString(str);
5456 // Öâåò ìîäåëè:
5457 Mem.ReadByte(FColor.R);
5458 Mem.ReadByte(FColor.G);
5459 Mem.ReadByte(FColor.B);
5460 if Self = gPlayer1 then
5461 begin
5462 str := gPlayer1Settings.Model;
5463 FColor := gPlayer1Settings.Color;
5464 end;
5465 if Self = gPlayer2 then
5466 begin
5467 str := gPlayer2Settings.Model;
5468 FColor := gPlayer2Settings.Color;
5469 end;
5470 // Îáíîâëÿåì ìîäåëü èãðîêà:
5471 SetModel(str);
5472 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
5473 FModel.Color := TEAMCOLOR[FTeam]
5474 else
5475 FModel.Color := FColor;
5476 end;
5478 procedure TPlayer.AllRulez(Health: Boolean);
5479 var
5480 a: Integer;
5481 begin
5482 if Health then
5483 begin
5484 FHealth := PLAYER_HP_LIMIT;
5485 FArmor := PLAYER_AP_LIMIT;
5486 Exit;
5487 end;
5489 for a := WEAPON_KASTET to WEAPON_SUPERPULEMET do FWeapon[a] := True;
5490 for a := A_BULLETS to A_CELLS do FAmmo[a] := 30000;
5491 FRulez := FRulez+[R_KEY_RED, R_KEY_GREEN, R_KEY_BLUE];
5492 end;
5494 procedure TPlayer.RestoreHealthArmor();
5495 begin
5496 FHealth := PLAYER_HP_LIMIT;
5497 FArmor := PLAYER_AP_LIMIT;
5498 end;
5500 procedure TPlayer.FragCombo();
5501 var
5502 Param: Integer;
5503 begin
5504 if (gGameSettings.GameMode in [GM_COOP, GM_SINGLE]) or g_Game_IsClient then
5505 Exit;
5506 if gTime - FLastFrag < FRAG_COMBO_TIME then
5507 begin
5508 if FFragCombo < 5 then
5509 Inc(FFragCombo);
5510 Param := FUID or (FFragCombo shl 16);
5511 if (FComboEvnt >= Low(gDelayedEvents)) and
5512 (FComboEvnt <= High(gDelayedEvents)) and
5513 gDelayedEvents[FComboEvnt].Pending and
5514 (gDelayedEvents[FComboEvnt].DEType = DE_KILLCOMBO) and
5515 (gDelayedEvents[FComboEvnt].DENum and $FFFF = FUID) then
5516 begin
5517 gDelayedEvents[FComboEvnt].Time := gTime + 500;
5518 gDelayedEvents[FComboEvnt].DENum := Param;
5519 end
5520 else
5521 FComboEvnt := g_Game_DelayEvent(DE_KILLCOMBO, 500, Param);
5522 end
5523 else
5524 FFragCombo := 1;
5526 FLastFrag := gTime;
5527 end;
5529 procedure TPlayer.GiveItem(ItemType: Byte);
5530 begin
5531 case ItemType of
5532 ITEM_SUIT:
5533 if FMegaRulez[MR_SUIT] < gTime+PLAYER_SUIT_TIME then
5534 begin
5535 FMegaRulez[MR_SUIT] := gTime+PLAYER_SUIT_TIME;
5536 end;
5538 ITEM_OXYGEN:
5539 if FAir < AIR_MAX then
5540 begin
5541 FAir := AIR_MAX;
5542 end;
5544 ITEM_MEDKIT_BLACK:
5545 begin
5546 if not (R_BERSERK in FRulez) then
5547 begin
5548 Include(FRulez, R_BERSERK);
5549 if FBFGFireCounter < 1 then
5550 begin
5551 FCurrWeap := WEAPON_KASTET;
5552 FModel.SetWeapon(WEAPON_KASTET);
5553 end;
5554 if gFlash <> 0 then
5555 Inc(FPain, 100);
5556 FBerserk := gTime+30000;
5557 end;
5558 if FHealth < PLAYER_HP_SOFT then
5559 begin
5560 FHealth := PLAYER_HP_SOFT;
5561 FBerserk := gTime+30000;
5562 end;
5563 end;
5565 ITEM_INVUL:
5566 if FMegaRulez[MR_INVUL] < gTime+PLAYER_INVUL_TIME then
5567 begin
5568 FMegaRulez[MR_INVUL] := gTime+PLAYER_INVUL_TIME;
5569 end;
5571 ITEM_INVIS:
5572 if FMegaRulez[MR_INVIS] < gTime+PLAYER_INVIS_TIME then
5573 begin
5574 FMegaRulez[MR_INVIS] := gTime+PLAYER_INVIS_TIME;
5575 end;
5577 ITEM_JETPACK:
5578 if FJetFuel < JET_MAX then
5579 begin
5580 FJetFuel := JET_MAX;
5581 end;
5583 else
5584 Exit;
5585 end;
5586 if g_Game_IsNet and g_Game_IsServer then
5587 MH_SEND_PlayerStats(FUID);
5588 end;
5590 procedure TPlayer.FlySmoke(Times: DWORD = 1);
5591 var
5592 id, i: DWORD;
5593 Anim: TAnimation;
5594 begin
5595 if (Random(5) = 1) and (Times = 1) then
5596 Exit;
5598 if BodyInLiquid(0, 0) then
5599 begin
5600 g_GFX_Bubbles(Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2)+Random(3)-1,
5601 Obj.Y+Obj.Rect.Height+8, 1, 8, 4);
5602 if Random(2) = 0 then
5603 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj.X, FObj.Y)
5604 else
5605 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj.X, FObj.Y);
5606 Exit;
5607 end;
5609 if g_Frames_Get(id, 'FRAMES_SMOKE') then
5610 begin
5611 for i := 1 to Times do
5612 begin
5613 Anim := TAnimation.Create(id, False, 3);
5614 Anim.Alpha := 150;
5615 g_GFX_OnceAnim(Obj.X+Obj.Rect.X+Random(Obj.Rect.Width+Times*2)-(Anim.Width div 2),
5616 Obj.Y+Obj.Rect.Height-4+Random(8+Times*2), Anim, ONCEANIM_SMOKE);
5617 Anim.Free();
5618 end;
5619 end;
5620 end;
5622 procedure TPlayer.PauseSounds(Enable: Boolean);
5623 begin
5624 FSawSound.Pause(Enable);
5625 FSawSoundIdle.Pause(Enable);
5626 FSawSoundHit.Pause(Enable);
5627 FSawSoundSelect.Pause(Enable);
5628 end;
5630 { T C o r p s e : }
5632 constructor TCorpse.Create(X, Y: Integer; ModelName: String; aMess: Boolean);
5633 begin
5634 g_Obj_Init(@FObj);
5635 FObj.X := X;
5636 FObj.Y := Y;
5637 FObj.Rect := PLAYER_CORPSERECT;
5638 FModelName := ModelName;
5639 FMess := aMess;
5641 if FMess then
5642 begin
5643 FState := CORPSE_STATE_MESS;
5644 g_PlayerModel_GetAnim(ModelName, A_DIE2, FAnimation, FAnimationMask);
5645 end
5646 else
5647 begin
5648 FState := CORPSE_STATE_NORMAL;
5649 g_PlayerModel_GetAnim(ModelName, A_DIE1, FAnimation, FAnimationMask);
5650 end;
5651 end;
5653 destructor TCorpse.Destroy();
5654 begin
5655 FAnimation.Free();
5657 inherited;
5658 end;
5660 procedure TCorpse.Damage(Value: Word; vx, vy: Integer);
5661 var
5662 pm: TPlayerModel;
5663 begin
5664 if FState = CORPSE_STATE_REMOVEME then
5665 Exit;
5667 FDamage := FDamage + Value;
5669 if FDamage > 150 then
5670 begin
5671 if FAnimation <> nil then
5672 begin
5673 FAnimation.Free();
5674 FAnimation := nil;
5676 FState := CORPSE_STATE_REMOVEME;
5678 g_Player_CreateGibs(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
5679 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
5680 FModelName, FColor);
5681 // Çâóê ìÿñà îò òðóïà:
5682 pm := g_PlayerModel_Get(FModelName);
5683 pm.PlaySound(MODELSOUND_DIE, 5, FObj.X, FObj.Y);
5684 pm.Free;
5685 end;
5686 end
5687 else
5688 begin
5689 FObj.Vel.X := FObj.Vel.X + vx;
5690 FObj.Vel.Y := FObj.Vel.Y + vy;
5691 g_GFX_Blood(FObj.X+PLAYER_CORPSERECT.X+(PLAYER_CORPSERECT.Width div 2),
5692 FObj.Y+PLAYER_CORPSERECT.Y+(PLAYER_CORPSERECT.Height div 2),
5693 Value, vx, vy, 16, (PLAYER_CORPSERECT.Height*2) div 3,
5694 150, 0, 0);
5695 end;
5696 end;
5698 procedure TCorpse.Draw();
5699 begin
5700 if FState = CORPSE_STATE_REMOVEME then
5701 Exit;
5703 if FAnimation <> nil then
5704 FAnimation.Draw(FObj.X, FObj.Y, M_NONE);
5706 if FAnimationMask <> nil then
5707 begin
5708 e_Colors := FColor;
5709 FAnimationMask.Draw(FObj.X, FObj.Y, M_NONE);
5710 e_Colors.R := 255;
5711 e_Colors.G := 255;
5712 e_Colors.B := 255;
5713 end;
5714 end;
5716 procedure TCorpse.Update();
5717 var
5718 st: Word;
5719 begin
5720 if FState = CORPSE_STATE_REMOVEME then
5721 Exit;
5723 if gTime mod (GAME_TICK*2) <> 0 then
5724 begin
5725 g_Obj_Move(@FObj, True, True, True);
5727 Exit;
5728 end;
5730 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
5731 FObj.Vel.X := z_dec(FObj.Vel.X, 1);
5733 st := g_Obj_Move(@FObj, True, True, True);
5735 if WordBool(st and MOVE_FALLOUT) then
5736 begin
5737 FState := CORPSE_STATE_REMOVEME;
5738 Exit;
5739 end;
5741 if FAnimation <> nil then
5742 FAnimation.Update();
5743 if FAnimationMask <> nil then
5744 FAnimationMask.Update();
5745 end;
5747 procedure TCorpse.SaveState(var Mem: TBinMemoryWriter);
5748 var
5749 sig: DWORD;
5750 anim: Boolean;
5751 begin
5752 if Mem = nil then
5753 Exit;
5755 // Ñèãíàòóðà òðóïà:
5756 sig := CORPSE_SIGNATURE; // 'CORP'
5757 Mem.WriteDWORD(sig);
5758 // Ñîñòîÿíèå:
5759 Mem.WriteByte(FState);
5760 // Íàêîïëåííûé óðîí:
5761 Mem.WriteByte(FDamage);
5762 // Öâåò:
5763 Mem.WriteByte(FColor.R);
5764 Mem.WriteByte(FColor.G);
5765 Mem.WriteByte(FColor.B);
5766 // Îáúåêò òðóïà:
5767 Obj_SaveState(@FObj, Mem);
5768 // Åñòü ëè àíèìàöèÿ:
5769 anim := FAnimation <> nil;
5770 Mem.WriteBoolean(anim);
5771 // Åñëè åñòü - ñîõðàíÿåì:
5772 if anim then
5773 FAnimation.SaveState(Mem);
5774 // Åñòü ëè ìàñêà àíèìàöèè:
5775 anim := FAnimationMask <> nil;
5776 Mem.WriteBoolean(anim);
5777 // Åñëè åñòü - ñîõðàíÿåì:
5778 if anim then
5779 FAnimationMask.SaveState(Mem);
5780 end;
5782 procedure TCorpse.LoadState(var Mem: TBinMemoryReader);
5783 var
5784 sig: DWORD;
5785 anim: Boolean;
5786 begin
5787 if Mem = nil then
5788 Exit;
5790 // Ñèãíàòóðà òðóïà:
5791 Mem.ReadDWORD(sig);
5792 if sig <> CORPSE_SIGNATURE then // 'CORP'
5793 begin
5794 raise EBinSizeError.Create('TCorpse.LoadState: Wrong Corpse Signature');
5795 end;
5796 // Ñîñòîÿíèå:
5797 Mem.ReadByte(FState);
5798 // Íàêîïëåííûé óðîí:
5799 Mem.ReadByte(FDamage);
5800 // Öâåò:
5801 Mem.ReadByte(FColor.R);
5802 Mem.ReadByte(FColor.G);
5803 Mem.ReadByte(FColor.B);
5804 // Îáúåêò òðóïà:
5805 Obj_LoadState(@FObj, Mem);
5806 // Åñòü ëè àíèìàöèÿ:
5807 Mem.ReadBoolean(anim);
5808 // Åñëè åñòü - çàãðóæàåì:
5809 if anim then
5810 begin
5811 Assert(FAnimation <> nil, 'TCorpse.LoadState: no FAnimation');
5812 FAnimation.LoadState(Mem);
5813 end;
5814 // Åñòü ëè ìàñêà àíèìàöèè:
5815 Mem.ReadBoolean(anim);
5816 // Åñëè åñòü - çàãðóæàåì:
5817 if anim then
5818 begin
5819 Assert(FAnimationMask <> nil, 'TCorpse.LoadState: no FAnimationMask');
5820 FAnimationMask.LoadState(Mem);
5821 end;
5822 end;
5824 { T B o t : }
5826 constructor TBot.Create();
5827 var
5828 a: Integer;
5829 begin
5830 inherited Create();
5832 FPhysics := True;
5833 FSpectator := False;
5834 FGhost := False;
5836 FIamBot := True;
5838 Inc(gNumBots);
5840 for a := WEAPON_KASTET to WEAPON_SUPERPULEMET do
5841 begin
5842 FDifficult.WeaponPrior[a] := WEAPON_PRIOR1[a];
5843 FDifficult.CloseWeaponPrior[a] := WEAPON_PRIOR2[a];
5844 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
5845 end;
5846 end;
5848 destructor TBot.Destroy();
5849 begin
5850 Dec(gNumBots);
5851 inherited Destroy();
5852 end;
5854 procedure TBot.Draw();
5855 begin
5856 inherited Draw();
5858 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
5859 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
5860 end;
5862 procedure TBot.Respawn(Silent: Boolean; Force: Boolean = False);
5863 begin
5864 inherited Respawn(Silent, Force);
5866 FAIFlags := nil;
5867 FSelectedWeapon := FCurrWeap;
5868 FTargetUID := 0;
5869 end;
5871 procedure TBot.UpdateCombat();
5872 type
5873 TTarget = record
5874 UID: Word;
5875 X, Y: Integer;
5876 Rect: TRectWH;
5877 cX, cY: Integer;
5878 Dist: Word;
5879 Line: Boolean;
5880 Visible: Boolean;
5881 IsPlayer: Boolean;
5882 end;
5884 TTargetRecord = array of TTarget;
5886 function Compare(a, b: TTarget): Integer;
5887 begin
5888 if a.Line and not b.Line then // A íà ëèíèè îãíÿ
5889 Result := -1
5890 else
5891 if not a.Line and b.Line then // B íà ëèíèè îãíÿ
5892 Result := 1
5893 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
5894 if (a.Line and b.Line) or ((not a.Line) and (not b.Line)) then
5895 begin
5896 if a.Dist > b.Dist then // B áëèæå
5897 Result := 1
5898 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
5899 Result := -1;
5900 end
5901 else // Ñòðàííî -> A
5902 Result := -1;
5903 end;
5905 var
5906 a, x1, y1, x2, y2: Integer;
5907 targets: TTargetRecord;
5908 ammo: Word;
5909 Target, BestTarget: TTarget;
5910 firew, fireh: Integer;
5911 angle: SmallInt;
5912 mon: TMonster;
5913 pla: TPlayer;
5914 vsPlayer, vsMonster, ok: Boolean;
5915 begin
5916 vsPlayer := LongBool(gGameSettings.Options and GAME_OPTION_BOTVSPLAYER);
5917 vsMonster := LongBool(gGameSettings.Options and GAME_OPTION_BOTVSMONSTER);
5919 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
5920 if FCurrWeap <> FSelectedWeapon then
5921 NextWeapon();
5923 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
5924 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap = FSelectedWeapon) then
5925 begin
5926 RemoveAIFlag('NEEDFIRE');
5928 case FCurrWeap of
5929 WEAPON_PLASMA, WEAPON_SUPERPULEMET, WEAPON_CHAINGUN: PressKey(KEY_FIRE, 20);
5930 WEAPON_SAW, WEAPON_KASTET, WEAPON_MEGAKASTET: PressKey(KEY_FIRE, 40);
5931 else PressKey(KEY_FIRE);
5932 end;
5933 end;
5935 // Êîîðäèíàòû ñòâîëà:
5936 x1 := FObj.X + WEAPONPOINT[FDirection].X;
5937 y1 := FObj.Y + WEAPONPOINT[FDirection].Y;
5939 Target.UID := FTargetUID;
5941 ok := False;
5942 if Target.UID <> 0 then
5943 begin // Öåëü åñòü - íàñòðàèâàåì
5944 if (g_GetUIDType(Target.UID) = UID_PLAYER) and
5945 vsPlayer then
5946 begin // Èãðîê
5947 with g_Player_Get(Target.UID) do
5948 begin
5949 if (@FObj) <> nil then
5950 begin
5951 Target.X := FObj.X;
5952 Target.Y := FObj.Y;
5953 end;
5954 end;
5956 Target.cX := Target.X + PLAYER_RECT_CX;
5957 Target.cY := Target.Y + PLAYER_RECT_CY;
5958 Target.Rect := PLAYER_RECT;
5959 Target.Visible := g_TraceVector(x1, y1, Target.cX, Target.cY);
5960 Target.Line := (y1+4 < Target.Y+PLAYER_RECT.Y+PLAYER_RECT.Height) and
5961 (y1-4 > Target.Y+PLAYER_RECT.Y);
5962 Target.IsPlayer := True;
5963 ok := True;
5964 end
5965 else
5966 if (g_GetUIDType(Target.UID) = UID_MONSTER) and
5967 vsMonster then
5968 begin // Ìîíñòð
5969 mon := g_Monsters_Get(Target.UID);
5970 if mon <> nil then
5971 begin
5972 Target.X := mon.Obj.X;
5973 Target.Y := mon.Obj.Y;
5975 Target.cX := Target.X + mon.Obj.Rect.X + (mon.Obj.Rect.Width div 2);
5976 Target.cY := Target.Y + mon.Obj.Rect.Y + (mon.Obj.Rect.Height div 2);
5977 Target.Rect := mon.Obj.Rect;
5978 Target.Visible := g_TraceVector(x1, y1, Target.cX, Target.cY);
5979 Target.Line := (y1+4 < Target.Y + mon.Obj.Rect.Y + mon.Obj.Rect.Height) and
5980 (y1-4 > Target.Y + mon.Obj.Rect.Y);
5981 Target.IsPlayer := False;
5982 ok := True;
5983 end;
5984 end;
5985 end;
5987 if not ok then
5988 begin // Öåëè íåò - îáíóëÿåì
5989 Target.X := 0;
5990 Target.Y := 0;
5991 Target.cX := 0;
5992 Target.cY := 0;
5993 Target.Visible := False;
5994 Target.Line := False;
5995 Target.IsPlayer := False;
5996 end;
5998 targets := nil;
6000 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6001 if (not Target.Line) or (not Target.Visible) then
6002 begin
6003 // Èãðîêè:
6004 if vsPlayer then
6005 for a := 0 to High(gPlayers) do
6006 if (gPlayers[a] <> nil) and (gPlayers[a].Live) and
6007 (gPlayers[a].FUID <> FUID) and
6008 (not SameTeam(FUID, gPlayers[a].FUID)) and
6009 (not gPlayers[a].NoTarget) and
6010 (gPlayers[a].FMegaRulez[MR_INVIS] < gTime) then
6011 begin
6012 if not TargetOnScreen(gPlayers[a].FObj.X + PLAYER_RECT.X,
6013 gPlayers[a].FObj.Y + PLAYER_RECT.Y) then
6014 Continue;
6016 x2 := gPlayers[a].FObj.X + PLAYER_RECT_CX;
6017 y2 := gPlayers[a].FObj.Y + PLAYER_RECT_CY;
6019 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6020 if g_TraceVector(x1, y1, x2, y2) then
6021 begin
6022 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6023 SetLength(targets, Length(targets)+1);
6024 with targets[High(targets)] do
6025 begin
6026 UID := gPlayers[a].FUID;
6027 X := gPlayers[a].FObj.X;
6028 Y := gPlayers[a].FObj.Y;
6029 cX := x2;
6030 cY := y2;
6031 Rect := PLAYER_RECT;
6032 Dist := g_PatchLength(x1, y1, x2, y2);
6033 Line := (y1+4 < Target.Y+PLAYER_RECT.Y+PLAYER_RECT.Height) and
6034 (y1-4 > Target.Y+PLAYER_RECT.Y);
6035 Visible := True;
6036 IsPlayer := True;
6037 end;
6038 end;
6039 end;
6041 // Ìîíñòðû:
6042 if vsMonster and (gMonsters <> nil) then
6043 for a := 0 to High(gMonsters) do
6044 if (gMonsters[a] <> nil) and (gMonsters[a].Live) and
6045 (gMonsters[a].MonsterType <> MONSTER_BARREL) then
6046 begin
6047 mon := gMonsters[a];
6049 if not TargetOnScreen(mon.Obj.X + mon.Obj.Rect.X,
6050 mon.Obj.Y + mon.Obj.Rect.Y) then
6051 Continue;
6053 x2 := mon.Obj.X + mon.Obj.Rect.X + (mon.Obj.Rect.Width div 2);
6054 y2 := mon.Obj.Y + mon.Obj.Rect.Y + (mon.Obj.Rect.Height div 2);
6056 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6057 if g_TraceVector(x1, y1, x2, y2) then
6058 begin
6059 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6060 SetLength(targets, Length(targets)+1);
6061 with targets[High(targets)] do
6062 begin
6063 UID := mon.UID;
6064 X := mon.Obj.X;
6065 Y := mon.Obj.Y;
6066 cX := x2;
6067 cY := y2;
6068 Rect := mon.Obj.Rect;
6069 Dist := g_PatchLength(x1, y1, x2, y2);
6070 Line := (y1+4 < Target.Y + mon.Obj.Rect.Y + mon.Obj.Rect.Height) and
6071 (y1-4 > Target.Y + mon.Obj.Rect.Y);
6072 Visible := True;
6073 IsPlayer := False;
6074 end;
6075 end;
6076 end;
6077 end;
6079 // Åñëè åñòü âîçìîæíûå öåëè:
6080 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6081 if targets <> nil then
6082 begin
6083 // Âûáèðàåì íàèëó÷øóþ öåëü:
6084 BestTarget := targets[0];
6085 if Length(targets) > 1 then
6086 for a := 1 to High(targets) do
6087 if Compare(BestTarget, targets[a]) = 1 then
6088 BestTarget := targets[a];
6090 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6091 if ((not Target.Visible) and BestTarget.Visible and (Target.UID <> BestTarget.UID)) or
6092 ((not Target.Line) and BestTarget.Line and BestTarget.Visible) then
6093 begin
6094 Target := BestTarget;
6096 if (Healthy() = 3) or ((Healthy() = 2)) then
6097 begin // Åñëè çäîðîâû - äîãîíÿåì
6098 if ((RunDirection() = D_LEFT) and (Target.X > FObj.X)) then
6099 SetAIFlag('GORIGHT', '1');
6100 if ((RunDirection() = D_RIGHT) and (Target.X < FObj.X)) then
6101 SetAIFlag('GOLEFT', '1');
6102 end
6103 else
6104 begin // Åñëè ïîáèòû - óáåãàåì
6105 if ((RunDirection() = D_LEFT) and (Target.X < FObj.X)) then
6106 SetAIFlag('GORIGHT', '1');
6107 if ((RunDirection() = D_RIGHT) and (Target.X > FObj.X)) then
6108 SetAIFlag('GOLEFT', '1');
6109 end;
6111 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6112 SelectWeapon(Abs(x1-Target.cX));
6113 end;
6114 end;
6116 // Åñëè åñòü öåëü:
6117 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6118 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6119 if Target.UID <> 0 then
6120 begin
6121 if not TargetOnScreen(Target.X + Target.Rect.X,
6122 Target.Y + Target.Rect.Y) then
6123 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6124 if (Healthy() = 3) or ((Healthy() = 2)) then
6125 begin // Åñëè çäîðîâû - äîãîíÿåì
6126 if ((RunDirection() = D_LEFT) and (Target.X > FObj.X)) then
6127 SetAIFlag('GORIGHT', '1');
6128 if ((RunDirection() = D_RIGHT) and (Target.X < FObj.X)) then
6129 SetAIFlag('GOLEFT', '1');
6130 end
6131 else
6132 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6133 Target.UID := 0;
6134 if ((RunDirection() = D_LEFT) and (Target.X < FObj.X)) then
6135 SetAIFlag('GORIGHT', '1');
6136 if ((RunDirection() = D_RIGHT) and (Target.X > FObj.X)) then
6137 SetAIFlag('GOLEFT', '1');
6138 end;
6139 end
6140 else
6141 begin // Öåëü ïîêà íà "ýêðàíå"
6142 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
6143 if g_TraceVector(x1, y1, Target.cX, Target.cY) then
6144 FLastVisible := gTime;
6145 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
6146 if (Abs(FObj.Y-Target.Y) <= 128) then
6147 begin
6148 if ((RunDirection() = D_LEFT) and (Target.X > FObj.X)) then
6149 SetAIFlag('GORIGHT', '1');
6150 if ((RunDirection() = D_RIGHT) and (Target.X < FObj.X)) then
6151 SetAIFlag('GOLEFT', '1');
6152 end;
6153 end;
6155 // Âûáèðàåì óãîë ââåðõ:
6156 if FDirection = D_LEFT then
6157 angle := ANGLE_LEFTUP
6158 else
6159 angle := ANGLE_RIGHTUP;
6161 firew := Trunc(Cos(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
6162 fireh := Trunc(Sin(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
6164 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6165 if g_CollideLine(x1, y1, x1+firew, y1+fireh,
6166 Target.X+Target.Rect.X+GetInterval(FDifficult.DiagPrecision, 128), //96
6167 Target.Y+Target.Rect.Y+GetInterval(FDifficult.DiagPrecision, 128),
6168 Target.Rect.Width, Target.Rect.Height) and
6169 g_TraceVector(x1, y1, Target.cX, Target.cY) then
6170 begin // òî íóæíî ñòðåëÿòü ââåðõ
6171 SetAIFlag('NEEDFIRE', '1');
6172 SetAIFlag('NEEDSEEUP', '1');
6173 end;
6175 // Âûáèðàåì óãîë âíèç:
6176 if FDirection = D_LEFT then
6177 angle := ANGLE_LEFTDOWN
6178 else
6179 angle := ANGLE_RIGHTDOWN;
6181 firew := Trunc(Cos(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
6182 fireh := Trunc(Sin(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
6184 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6185 if g_CollideLine(x1, y1, x1+firew, y1+fireh,
6186 Target.X+Target.Rect.X+GetInterval(FDifficult.DiagPrecision, 128),
6187 Target.Y+Target.Rect.Y+GetInterval(FDifficult.DiagPrecision, 128),
6188 Target.Rect.Width, Target.Rect.Height) and
6189 g_TraceVector(x1, y1, Target.cX, Target.cY) then
6190 begin // òî íóæíî ñòðåëÿòü âíèç
6191 SetAIFlag('NEEDFIRE', '1');
6192 SetAIFlag('NEEDSEEDOWN', '1');
6193 end;
6195 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
6196 if Target.Visible and
6197 (y1+4 < Target.Y+Target.Rect.Y+Target.Rect.Height) and
6198 (y1-4 > Target.Y+Target.Rect.Y) then
6199 begin
6200 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
6201 if ((FDirection = D_LEFT) and (Target.X < FObj.X)) or
6202 ((FDirection = D_RIGHT) and (Target.X > FObj.X)) then
6203 begin // òî íóæíî ñòðåëÿòü âïåðåä
6204 SetAIFlag('NEEDFIRE', '1');
6205 SetAIFlag('NEEDSEEDOWN', '');
6206 SetAIFlag('NEEDSEEUP', '');
6207 end;
6208 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
6209 if Abs(FObj.X-Target.X) < Trunc(gPlayerScreenSize.X*0.75) then
6210 if GetRnd(FDifficult.CloseJump) then
6211 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
6212 if Abs(FObj.X-Target.X) < 128 then
6213 a := 4
6214 else
6215 a := 30;
6216 if Random(a) = 0 then
6217 SetAIFlag('NEEDJUMP', '1');
6218 end;
6219 end;
6221 // Åñëè öåëü âñå åùå åñòü:
6222 if Target.UID <> 0 then
6223 if gTime-FLastVisible > 2000 then // Åñëè âèäåëè äàâíî
6224 Target.UID := 0 // òî çàáûòü öåëü
6225 else // Åñëè âèäåëè íåäàâíî
6226 begin // íî öåëü óáèëè
6227 if Target.IsPlayer then
6228 begin // Öåëü - èãðîê
6229 pla := g_Player_Get(Target.UID);
6230 if (pla = nil) or (not pla.Live) or pla.NoTarget or
6231 (pla.FMegaRulez[MR_INVIS] >= gTime) then
6232 Target.UID := 0; // òî çàáûòü öåëü
6233 end
6234 else
6235 begin // Öåëü - ìîíñòð
6236 mon := g_Monsters_Get(Target.UID);
6237 if (mon = nil) or (not mon.Live) then
6238 Target.UID := 0; // òî çàáûòü öåëü
6239 end;
6240 end;
6241 end; // if Target.UID <> 0
6243 FTargetUID := Target.UID;
6245 // Åñëè âîçìîæíûõ öåëåé íåò:
6246 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
6247 if targets = nil then
6248 if GetAIFlag('ATTACKLEFT') <> '' then
6249 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
6250 RemoveAIFlag('ATTACKLEFT');
6252 SetAIFlag('NEEDJUMP', '1');
6254 if RunDirection() = D_RIGHT then
6255 begin // Èäåì íå â òó ñòîðîíó
6256 if (Healthy() > 1) and GetRnd(FDifficult.InvisFire) then
6257 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
6258 SetAIFlag('NEEDFIRE', '1');
6259 SetAIFlag('GOLEFT', '1');
6260 end;
6261 end
6262 else
6263 begin // Èäåì â íóæíóþ ñòîðîíó
6264 if GetRnd(FDifficult.InvisFire) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6265 SetAIFlag('NEEDFIRE', '1');
6266 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6267 SetAIFlag('GORIGHT', '1');
6268 end;
6269 end
6270 else
6271 if GetAIFlag('ATTACKRIGHT') <> '' then
6272 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
6273 RemoveAIFlag('ATTACKRIGHT');
6275 SetAIFlag('NEEDJUMP', '1');
6277 if RunDirection() = D_LEFT then
6278 begin // Èäåì íå â òó ñòîðîíó
6279 if (Healthy() > 1) and GetRnd(FDifficult.InvisFire) then
6280 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
6281 SetAIFlag('NEEDFIRE', '1');
6282 SetAIFlag('GORIGHT', '1');
6283 end;
6284 end
6285 else
6286 begin
6287 if GetRnd(FDifficult.InvisFire) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6288 SetAIFlag('NEEDFIRE', '1');
6289 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6290 SetAIFlag('GOLEFT', '1');
6291 end;
6292 end;
6294 // Åñëè åñòü âîçìîæíûå öåëè:
6295 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
6296 if (targets <> nil) and (GetAIFlag('NEEDFIRE') <> '') then
6297 for a := 0 to High(targets) do
6298 begin
6299 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
6300 if GetRnd(FDifficult.DiagFire) then
6301 begin
6302 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
6303 if FDirection = D_LEFT then
6304 angle := ANGLE_LEFTUP
6305 else
6306 angle := ANGLE_RIGHTUP;
6308 firew := Trunc(Cos(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
6309 fireh := Trunc(Sin(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
6311 if g_CollideLine(x1, y1, x1+firew, y1+fireh,
6312 targets[a].X+targets[a].Rect.X+GetInterval(FDifficult.DiagPrecision, 128),
6313 targets[a].Y+targets[a].Rect.Y+GetInterval(FDifficult.DiagPrecision, 128),
6314 targets[a].Rect.Width, targets[a].Rect.Height) and
6315 g_TraceVector(x1, y1, targets[a].cX, targets[a].cY) then
6316 begin
6317 SetAIFlag('NEEDFIRE', '1');
6318 SetAIFlag('NEEDSEEUP', '1');
6319 end;
6321 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
6322 if FDirection = D_LEFT then
6323 angle := ANGLE_LEFTDOWN
6324 else
6325 angle := ANGLE_RIGHTDOWN;
6327 firew := Trunc(Cos(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
6328 fireh := Trunc(Sin(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
6330 if g_CollideLine(x1, y1, x1+firew, y1+fireh,
6331 targets[a].X+targets[a].Rect.X+GetInterval(FDifficult.DiagPrecision, 128),
6332 targets[a].Y+targets[a].Rect.Y+GetInterval(FDifficult.DiagPrecision, 128),
6333 targets[a].Rect.Width, targets[a].Rect.Height) and
6334 g_TraceVector(x1, y1, targets[a].cX, targets[a].cY) then
6335 begin
6336 SetAIFlag('NEEDFIRE', '1');
6337 SetAIFlag('NEEDSEEDOWN', '1');
6338 end;
6339 end;
6341 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
6342 if targets[a].Line and targets[a].Visible and
6343 (((FDirection = D_LEFT) and (targets[a].X < FObj.X)) or
6344 ((FDirection = D_RIGHT) and (targets[a].X > FObj.X))) then
6345 begin
6346 SetAIFlag('NEEDFIRE', '1');
6347 Break;
6348 end;
6349 end;
6351 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
6352 if g_Weapon_Danger(FUID, FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y,
6353 PLAYER_RECT.Width, PLAYER_RECT.Height,
6354 40+GetInterval(FDifficult.Cover, 40)) then
6355 SetAIFlag('NEEDJUMP', '1');
6357 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
6358 ammo := GetAmmoByWeapon(FCurrWeap);
6359 if ((FCurrWeap = WEAPON_SHOTGUN2) and (ammo < 2)) or
6360 ((FCurrWeap = WEAPON_BFG) and (ammo < 40)) or
6361 (ammo = 0) then
6362 SetAIFlag('SELECTWEAPON', '1');
6364 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
6365 if GetAIFlag('SELECTWEAPON') = '1' then
6366 begin
6367 SelectWeapon(-1);
6368 RemoveAIFlag('SELECTWEAPON');
6369 end;
6370 end;
6372 procedure TBot.Update();
6373 var
6374 EnableAI: Boolean;
6375 begin
6376 if not FLive then
6377 begin // Respawn
6378 ReleaseKeys();
6379 PressKey(KEY_UP);
6380 end
6381 else
6382 begin
6383 EnableAI := True;
6385 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
6386 if (g_debug_BotAIOff = 1) and (Team = TEAM_RED) then
6387 EnableAI := False;
6388 if (g_debug_BotAIOff = 2) and (Team = TEAM_BLUE) then
6389 EnableAI := False;
6390 if g_debug_BotAIOff = 3 then
6391 EnableAI := False;
6393 if EnableAI then
6394 begin
6395 UpdateMove();
6396 UpdateCombat();
6397 end;
6398 end;
6400 inherited Update();
6401 end;
6403 procedure TBot.ReleaseKey(Key: Byte);
6404 begin
6405 with FKeys[Key] do
6406 begin
6407 Pressed := False;
6408 Time := 0;
6409 end;
6410 end;
6412 function TBot.KeyPressed(Key: Word): Boolean;
6413 begin
6414 Result := FKeys[Key].Pressed;
6415 end;
6417 function TBot.GetAIFlag(fName: String20): String20;
6418 var
6419 a: Integer;
6420 begin
6421 Result := '';
6423 fName := LowerCase(fName);
6425 if FAIFlags <> nil then
6426 for a := 0 to High(FAIFlags) do
6427 if LowerCase(FAIFlags[a].Name) = fName then
6428 begin
6429 Result := FAIFlags[a].Value;
6430 Break;
6431 end;
6432 end;
6434 procedure TBot.RemoveAIFlag(fName: String20);
6435 var
6436 a, b: Integer;
6437 begin
6438 if FAIFlags = nil then Exit;
6440 fName := LowerCase(fName);
6442 for a := 0 to High(FAIFlags) do
6443 if LowerCase(FAIFlags[a].Name) = fName then
6444 begin
6445 if a <> High(FAIFlags) then
6446 for b := a to High(FAIFlags)-1 do
6447 FAIFlags[b] := FAIFlags[b+1];
6449 SetLength(FAIFlags, Length(FAIFlags)-1);
6450 Break;
6451 end;
6452 end;
6454 procedure TBot.SetAIFlag(fName, fValue: String20);
6455 var
6456 a: Integer;
6457 ok: Boolean;
6458 begin
6459 a := 0;
6460 ok := False;
6462 fName := LowerCase(fName);
6464 if FAIFlags <> nil then
6465 for a := 0 to High(FAIFlags) do
6466 if LowerCase(FAIFlags[a].Name) = fName then
6467 begin
6468 ok := True;
6469 Break;
6470 end;
6472 if ok then FAIFlags[a].Value := fValue
6473 else
6474 begin
6475 SetLength(FAIFlags, Length(FAIFlags)+1);
6476 with FAIFlags[High(FAIFlags)] do
6477 begin
6478 Name := fName;
6479 Value := fValue;
6480 end;
6481 end;
6482 end;
6484 procedure TBot.UpdateMove;
6486 procedure GoLeft(Time: Word = 1);
6487 begin
6488 ReleaseKey(KEY_LEFT);
6489 ReleaseKey(KEY_RIGHT);
6490 PressKey(KEY_LEFT, Time);
6491 SetDirection(D_LEFT);
6492 end;
6494 procedure GoRight(Time: Word = 1);
6495 begin
6496 ReleaseKey(KEY_LEFT);
6497 ReleaseKey(KEY_RIGHT);
6498 PressKey(KEY_RIGHT, Time);
6499 SetDirection(D_RIGHT);
6500 end;
6502 function Rnd(a: Word): Boolean;
6503 begin
6504 Result := Random(a) = 0;
6505 end;
6507 procedure Turn(Time: Word = 1200);
6508 begin
6509 if RunDirection() = D_LEFT then GoRight(Time) else GoLeft(Time);
6510 end;
6512 procedure Stop();
6513 begin
6514 ReleaseKey(KEY_LEFT);
6515 ReleaseKey(KEY_RIGHT);
6516 end;
6518 function CanRunLeft(): Boolean;
6519 begin
6520 Result := not CollideLevel(-1, 0);
6521 end;
6523 function CanRunRight(): Boolean;
6524 begin
6525 Result := not CollideLevel(1, 0);
6526 end;
6528 function CanRun(): Boolean;
6529 begin
6530 if RunDirection() = D_LEFT then Result := CanRunLeft() else Result := CanRunRight();
6531 end;
6533 procedure Jump(Time: Word = 30);
6534 begin
6535 PressKey(KEY_JUMP, Time);
6536 end;
6538 function NearHole(): Boolean;
6539 var
6540 x, sx: Integer;
6541 begin
6542 { TODO 5 : Ëåñòíèöû }
6543 sx := IfThen(RunDirection() = D_LEFT, -1, 1);
6544 for x := 1 to PLAYER_RECT.Width do
6545 if (not StayOnStep(x*sx, 0)) and
6546 (not CollideLevel(x*sx, PLAYER_RECT.Height)) and
6547 (not CollideLevel(x*sx, PLAYER_RECT.Height*2)) then
6548 begin
6549 Result := True;
6550 Exit;
6551 end;
6553 Result := False;
6554 end;
6556 function BorderHole(): Boolean;
6557 var
6558 x, sx, xx: Integer;
6559 begin
6560 { TODO 5 : Ëåñòíèöû }
6561 sx := IfThen(RunDirection() = D_LEFT, -1, 1);
6562 for x := 1 to PLAYER_RECT.Width do
6563 if (not StayOnStep(x*sx, 0)) and
6564 (not CollideLevel(x*sx, PLAYER_RECT.Height)) and
6565 (not CollideLevel(x*sx, PLAYER_RECT.Height*2)) then
6566 begin
6567 for xx := x to x+32 do
6568 if CollideLevel(xx*sx, PLAYER_RECT.Height) then
6569 begin
6570 Result := True;
6571 Exit;
6572 end;
6573 end;
6575 Result := False;
6576 end;
6578 function NearDeepHole(): Boolean;
6579 var
6580 x, sx, y: Integer;
6581 begin
6582 Result := False;
6584 sx := IfThen(RunDirection() = D_LEFT, -1, 1);
6585 y := 3;
6587 for x := 1 to PLAYER_RECT.Width do
6588 if (not StayOnStep(x*sx, 0)) and
6589 (not CollideLevel(x*sx, PLAYER_RECT.Height)) and
6590 (not CollideLevel(x*sx, PLAYER_RECT.Height*2)) then
6591 begin
6592 while FObj.Y+y*PLAYER_RECT.Height < gMapInfo.Height do
6593 begin
6594 if CollideLevel(x*sx, PLAYER_RECT.Height*y) then Exit;
6595 y := y+1;
6596 end;
6598 Result := True;
6599 end else Result := False;
6600 end;
6602 function OverDeepHole(): Boolean;
6603 var
6604 y: Integer;
6605 begin
6606 Result := False;
6608 y := 1;
6609 while FObj.Y+y*PLAYER_RECT.Height < gMapInfo.Height do
6610 begin
6611 if CollideLevel(0, PLAYER_RECT.Height*y) then Exit;
6612 y := y+1;
6613 end;
6615 Result := True;
6616 end;
6618 function OnGround(): Boolean;
6619 begin
6620 Result := StayOnStep(0, 0) or CollideLevel(0, 1);
6621 end;
6623 function OnLadder(): Boolean;
6624 begin
6625 Result := FullInStep(0, 0);
6626 end;
6628 function BelowLadder(): Boolean;
6629 begin
6630 Result := (FullInStep(IfThen(RunDirection() = D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -PLAYER_RECT.Height) and
6631 not CollideLevel(IfThen(RunDirection() = D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -PLAYER_RECT.Height)) or
6632 (FullInStep(IfThen(RunDirection() = D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -BOT_MAXJUMP) and
6633 not CollideLevel(IfThen(RunDirection() = D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -BOT_MAXJUMP));
6634 end;
6636 function BelowLiftUp(): Boolean;
6637 begin
6638 Result := ((FullInLift(IfThen(RunDirection() = D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -PLAYER_RECT.Height) = -1) and
6639 not CollideLevel(IfThen(RunDirection() = D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -PLAYER_RECT.Height)) or
6640 ((FullInLift(IfThen(RunDirection() = D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -BOT_MAXJUMP) = -1) and
6641 not CollideLevel(IfThen(RunDirection() = D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -BOT_MAXJUMP));
6642 end;
6644 function OnTopLift(): Boolean;
6645 begin
6646 Result := (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
6647 end;
6649 function CanJumpOver(): Boolean;
6650 var
6651 sx, y: Integer;
6652 begin
6653 sx := IfThen(RunDirection() = D_LEFT, -1, 1);
6655 Result := False;
6657 if not CollideLevel(sx, 0) then Exit;
6659 for y := 1 to BOT_MAXJUMP do
6660 if CollideLevel(0, -y) then Exit else
6661 if not CollideLevel(sx, -y) then
6662 begin
6663 Result := True;
6664 Exit;
6665 end;
6666 end;
6668 function CanJumpUp(Dist: ShortInt): Boolean;
6669 var
6670 y, yy: Integer;
6671 c: Boolean;
6672 begin
6673 Result := False;
6675 if CollideLevel(Dist, 0) then Exit;
6677 c := False;
6678 for y := 0 to BOT_MAXJUMP do
6679 if CollideLevel(Dist, -y) then
6680 begin
6681 c := True;
6682 Break;
6683 end;
6685 if not c then Exit;
6687 c := False;
6688 for yy := y+1 to BOT_MAXJUMP do
6689 if not CollideLevel(Dist, -yy) then
6690 begin
6691 c := True;
6692 Break;
6693 end;
6695 if not c then Exit;
6697 c := False;
6698 for y := 0 to BOT_MAXJUMP do
6699 if CollideLevel(0, -y) then
6700 begin
6701 c := True;
6702 Break;
6703 end;
6705 if c then Exit;
6707 if y < yy then Exit;
6709 Result := True;
6710 end;
6712 function IsSafeTrigger(): Boolean;
6713 var
6714 a: Integer;
6715 begin
6716 Result := True;
6717 if gTriggers = nil then
6718 Exit;
6719 for a := 0 to High(gTriggers) do
6720 if Collide(gTriggers[a].X,
6721 gTriggers[a].Y,
6722 gTriggers[a].Width,
6723 gTriggers[a].Height) and
6724 (gTriggers[a].TriggerType in [TRIGGER_EXIT, TRIGGER_CLOSEDOOR,
6725 TRIGGER_CLOSETRAP, TRIGGER_TRAP,
6726 TRIGGER_PRESS, TRIGGER_ON, TRIGGER_OFF,
6727 TRIGGER_ONOFF, TRIGGER_SPAWNMONSTER,
6728 TRIGGER_DAMAGE, TRIGGER_SHOT]) then
6729 Result := False;
6730 end;
6732 begin
6733 // Âîçìîæíî, íàæèìàåì êíîïêó:
6734 if Rnd(16) and IsSafeTrigger() then
6735 PressKey(KEY_OPEN);
6737 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
6738 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
6739 begin
6740 ReleaseKey(KEY_LEFT);
6741 ReleaseKey(KEY_RIGHT);
6742 Jump();
6743 end;
6745 // Èäåì âëåâî, åñëè íàäî áûëî:
6746 if GetAIFlag('GOLEFT') <> '' then
6747 begin
6748 RemoveAIFlag('GOLEFT');
6749 if CanRunLeft() then
6750 GoLeft(360);
6751 end;
6753 // Èäåì âïðàâî, åñëè íàäî áûëî:
6754 if GetAIFlag('GORIGHT') <> '' then
6755 begin
6756 RemoveAIFlag('GORIGHT');
6757 if CanRunRight() then
6758 GoRight(360);
6759 end;
6761 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
6762 if FObj.X < -32 then
6763 GoRight(360)
6764 else
6765 if FObj.X+32 > gMapInfo.Width then
6766 GoLeft(360);
6768 // Ïðûãàåì, åñëè íàäî áûëî:
6769 if GetAIFlag('NEEDJUMP') <> '' then
6770 begin
6771 Jump(0);
6772 RemoveAIFlag('NEEDJUMP');
6773 end;
6775 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
6776 if GetAIFlag('NEEDSEEUP') <> '' then
6777 begin
6778 ReleaseKey(KEY_UP);
6779 ReleaseKey(KEY_DOWN);
6780 PressKey(KEY_UP, 20);
6781 RemoveAIFlag('NEEDSEEUP');
6782 end;
6784 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
6785 if GetAIFlag('NEEDSEEDOWN') <> '' then
6786 begin
6787 ReleaseKey(KEY_UP);
6788 ReleaseKey(KEY_DOWN);
6789 PressKey(KEY_DOWN, 20);
6790 RemoveAIFlag('NEEDSEEDOWN');
6791 end;
6793 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
6794 if GetAIFlag('GOINHOLE') <> '' then
6795 if not OnGround() then
6796 begin
6797 ReleaseKey(KEY_LEFT);
6798 ReleaseKey(KEY_RIGHT);
6799 RemoveAIFlag('GOINHOLE');
6800 SetAIFlag('FALLINHOLE', '1');
6801 end;
6803 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
6804 if GetAIFlag('FALLINHOLE') <> '' then
6805 if OnGround() then
6806 RemoveAIFlag('FALLINHOLE');
6808 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
6809 if not (KeyPressed(KEY_LEFT) or KeyPressed(KEY_RIGHT)) then
6810 if GetAIFlag('FALLINHOLE') = '' then
6811 if (not OnLadder()) or (FObj.Vel.Y >= 0) or (OnTopLift()) then
6812 if Rnd(2) then
6813 GoLeft(360)
6814 else
6815 GoRight(360);
6817 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
6818 if OnGround() and
6819 CanJumpUp(IfThen(RunDirection() = D_LEFT, -1, 1)*32) and
6820 Rnd(8) then
6821 Jump();
6823 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
6824 if OnGround() and NearHole() then
6825 if NearDeepHole() then // Åñëè ýòî áåçäíà
6826 case Random(6) of
6827 0..3: Turn(); // Áåæèì îáðàòíî
6828 4: Jump(); // Ïðûãàåì
6829 5: begin // Ïðûãàåì îáðàòíî
6830 Turn();
6831 Jump();
6832 end;
6833 end
6834 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
6835 if GetAIFlag('GOINHOLE') = '' then
6836 case Random(6) of
6837 0: Turn(); // Íå íóæíî òóäà
6838 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
6839 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
6840 if BorderHole() then
6841 SetAIFlag('GOINHOLE', '1');
6842 end;
6844 // Åñëè íà çåìëå, íî íåêóäà èäòè:
6845 if (not CanRun()) and OnGround() then
6846 begin
6847 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
6848 if CanJumpOver() or OnLadder() then
6849 Jump()
6850 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
6851 if Random(2) = 0 then
6852 begin
6853 if IsSafeTrigger() then
6854 PressKey(KEY_OPEN);
6855 end else
6856 Turn();
6857 end;
6859 // Îñòàëîñü ìàëî âîçäóõà:
6860 if FAir < 36 * 2 then
6861 Jump(20);
6863 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
6864 if (FMegaRulez[MR_SUIT] < gTime) and ((FLastHit = HIT_ACID) or (Healthy() <= 1)) then
6865 if BodyInAcid(0, 0) then
6866 Jump();
6867 end;
6869 function TBot.FullInStep(XInc, YInc: Integer): Boolean;
6870 begin
6871 Result := g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc,
6872 PLAYER_RECT.Width, PLAYER_RECT.Height, PANEL_STEP, False);
6873 end;
6875 {function TBot.NeedItem(Item: Byte): Byte;
6876 begin
6877 Result := 4;
6878 end;}
6880 procedure TBot.SelectWeapon(Dist: Integer);
6881 var
6882 a: Integer;
6884 function HaveAmmo(weapon: Byte): Boolean;
6885 begin
6886 case weapon of
6887 WEAPON_PISTOL: Result := FAmmo[A_BULLETS] >= 1;
6888 WEAPON_SHOTGUN1: Result := FAmmo[A_SHELLS] >= 1;
6889 WEAPON_SHOTGUN2: Result := FAmmo[A_SHELLS] >= 2;
6890 WEAPON_CHAINGUN: Result := FAmmo[A_BULLETS] >= 10;
6891 WEAPON_ROCKETLAUNCHER: Result := FAmmo[A_ROCKETS] >= 1;
6892 WEAPON_PLASMA: Result := FAmmo[A_CELLS] >= 10;
6893 WEAPON_BFG: Result := FAmmo[A_CELLS] >= 40;
6894 WEAPON_SUPERPULEMET: Result := FAmmo[A_SHELLS] >= 1;
6895 else Result := True;
6896 end;
6897 end;
6899 begin
6900 if Dist = -1 then Dist := BOT_LONGDIST;
6902 if Dist > BOT_LONGDIST then
6903 begin // Äàëüíèé áîé
6904 for a := 0 to 9 do
6905 if FWeapon[FDifficult.WeaponPrior[a]] and HaveAmmo(FDifficult.WeaponPrior[a]) then
6906 begin
6907 FSelectedWeapon := FDifficult.WeaponPrior[a];
6908 Break;
6909 end;
6910 end
6911 else //if Dist > BOT_UNSAFEDIST then
6912 begin // Áëèæíèé áîé
6913 for a := 0 to 9 do
6914 if FWeapon[FDifficult.CloseWeaponPrior[a]] and HaveAmmo(FDifficult.CloseWeaponPrior[a]) then
6915 begin
6916 FSelectedWeapon := FDifficult.CloseWeaponPrior[a];
6917 Break;
6918 end;
6919 end;
6920 { else
6921 begin
6922 for a := 0 to 9 do
6923 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
6924 begin
6925 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
6926 Break;
6927 end;
6928 end;}
6929 end;
6931 function TBot.PickItem(ItemType: Byte; force: Boolean; var remove: Boolean): Boolean;
6932 begin
6933 Result := inherited PickItem(ItemType, force, remove);
6935 if Result then SetAIFlag('SELECTWEAPON', '1');
6936 end;
6938 function TBot.Heal(value: Word; Soft: Boolean): Boolean;
6939 begin
6940 Result := inherited Heal(value, Soft);
6941 end;
6943 function TBot.Healthy(): Byte;
6944 begin
6945 if FMegaRulez[MR_INVUL] >= gTime then Result := 3
6946 else if (FHealth > 80) or ((FHealth > 50) and (FArmor > 20)) then Result := 3
6947 else if (FHealth > 50) then Result := 2
6948 else if (FHealth > 20) then Result := 1
6949 else Result := 0;
6950 end;
6952 function TBot.TargetOnScreen(TX, TY: Integer): Boolean;
6953 begin
6954 Result := (Abs(FObj.X-TX) <= Trunc(gPlayerScreenSize.X*0.6)) and
6955 (Abs(FObj.Y-TY) <= Trunc(gPlayerScreenSize.Y*0.6));
6956 end;
6958 procedure TBot.OnDamage(Angle: SmallInt);
6959 var
6960 pla: TPlayer;
6961 mon: TMonster;
6962 ok: Boolean;
6963 begin
6964 inherited;
6966 if (Angle = 0) or (Angle = 180) then
6967 begin
6968 ok := False;
6969 if (g_GetUIDType(FLastSpawnerUID) = UID_PLAYER) and
6970 LongBool(gGameSettings.Options and GAME_OPTION_BOTVSPLAYER) then
6971 begin // Èãðîê
6972 pla := g_Player_Get(FLastSpawnerUID);
6973 ok := not TargetOnScreen(pla.FObj.X + PLAYER_RECT.X,
6974 pla.FObj.Y + PLAYER_RECT.Y);
6975 end
6976 else
6977 if (g_GetUIDType(FLastSpawnerUID) = UID_MONSTER) and
6978 LongBool(gGameSettings.Options and GAME_OPTION_BOTVSMONSTER) then
6979 begin // Ìîíñòð
6980 mon := g_Monsters_Get(FLastSpawnerUID);
6981 ok := not TargetOnScreen(mon.Obj.X + mon.Obj.Rect.X,
6982 mon.Obj.Y + mon.Obj.Rect.Y);
6983 end;
6985 if ok then
6986 if Angle = 0 then
6987 SetAIFlag('ATTACKLEFT', '1')
6988 else
6989 SetAIFlag('ATTACKRIGHT', '1');
6990 end;
6991 end;
6993 function TBot.RunDirection(): TDirection;
6994 begin
6995 if Abs(Vel.X) >= 1 then
6996 begin
6997 if Vel.X > 0 then Result := D_RIGHT else Result := D_LEFT;
6998 end else
6999 Result := FDirection;
7000 end;
7002 function TBot.GetRnd(a: Byte): Boolean;
7003 begin
7004 if a = 0 then Result := False
7005 else if a = 255 then Result := True
7006 else Result := Random(256) > 255-a;
7007 end;
7009 function TBot.GetInterval(a: Byte; radius: SmallInt): SmallInt;
7010 begin
7011 Result := Round((255-a)/255*radius*(Random(2)-1));
7012 end;
7014 procedure TBot.SaveState(var Mem: TBinMemoryWriter);
7015 var
7016 i: Integer;
7017 dw: DWORD;
7018 p: Pointer;
7019 begin
7020 inherited SaveState(Mem);
7022 // Âûáðàííîå îðóæèå:
7023 Mem.WriteByte(FSelectedWeapon);
7024 // UID öåëè:
7025 Mem.WriteWord(FTargetUID);
7026 // Âðåìÿ ïîòåðè öåëè:
7027 Mem.WriteDWORD(FLastVisible);
7028 // Êîëè÷åñòâî ôëàãîâ ÈÈ:
7029 dw := Length(FAIFlags);
7030 Mem.WriteDWORD(dw);
7031 // Ôëàãè ÈÈ:
7032 for i := 0 to Integer(dw)-1 do
7033 begin
7034 Mem.WriteString(FAIFlags[i].Name, 20);
7035 Mem.WriteString(FAIFlags[i].Value, 20);
7036 end;
7037 // Íàñòðîéêè ñëîæíîñòè:
7038 p := @FDifficult;
7039 Mem.WriteMemory(p, SizeOf(TDifficult));
7040 end;
7042 procedure TBot.LoadState(var Mem: TBinMemoryReader);
7043 var
7044 i: Integer;
7045 dw: DWORD;
7046 p: Pointer;
7047 begin
7048 inherited LoadState(Mem);
7050 // Âûáðàííîå îðóæèå:
7051 Mem.ReadByte(FSelectedWeapon);
7052 // UID öåëè:
7053 Mem.ReadWord(FTargetUID);
7054 // Âðåìÿ ïîòåðè öåëè:
7055 Mem.ReadDWORD(FLastVisible);
7056 // Êîëè÷åñòâî ôëàãîâ ÈÈ:
7057 Mem.ReadDWORD(dw);
7058 SetLength(FAIFlags, dw);
7059 // Ôëàãè ÈÈ:
7060 for i := 0 to Integer(dw)-1 do
7061 begin
7062 Mem.ReadString(FAIFlags[i].Name);
7063 Mem.ReadString(FAIFlags[i].Value);
7064 end;
7065 // Íàñòðîéêè ñëîæíîñòè:
7066 Mem.ReadMemory(p, dw);
7067 if dw <> SizeOf(TDifficult) then
7068 begin
7069 raise EBinSizeError.Create('TBot.LoadState: Wrong FDifficult Size');
7070 end;
7071 FDifficult := TDifficult(p^);
7072 end;
7074 end.