DEADSOFTWARE

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