DEADSOFTWARE

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