DEADSOFTWARE

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