DEADSOFTWARE

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