DEADSOFTWARE

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