DEADSOFTWARE

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