DEADSOFTWARE

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