DEADSOFTWARE

1945f94f26be4d2c1a69de7416209db816648a5f
[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
2002 i: Integer;
2003 begin
2004 for i := WP_FIRST to WP_LAST + 1 do
2005 begin
2006 if (Prefs[i] > WP_LAST + 1) then
2007 FWeapPreferences[i] := 0
2008 else
2009 FWeapPreferences[i] := Prefs[i];
2010 end;
2011 end;
2013 procedure TPlayer.SetWeaponPref(Weapon, Pref: Byte);
2014 begin
2015 if (Weapon > WP_LAST + 1) then
2016 exit
2017 else if (Pref <= WP_LAST + 1) and (Weapon <= WP_LAST + 1) then
2018 FWeapPreferences[Weapon] := Pref
2019 else if (Weapon <= WP_LAST + 1) and (Pref > WP_LAST + 1) then
2020 FWeapPreferences[Weapon] := 0;
2021 end;
2023 function TPlayer.GetWeaponPref(Weapon: Byte) : Byte;
2024 begin
2025 if (Weapon > WP_LAST + 1) then
2026 result := 0
2027 else if (FWeapPreferences[Weapon] > WP_LAST + 1) then
2028 result := 0
2029 else
2030 result := FWeapPreferences[Weapon];
2031 end;
2033 function TPlayer.GetMorePrefered() : Byte;
2034 var
2035 testedWeap, i: Byte;
2036 begin
2037 testedWeap := FCurrWeap;
2038 for i := WP_FIRST to WP_LAST do
2039 if FWeapon[i] and (FWeapPreferences[i] > FWeapPreferences[testedWeap]) then
2040 testedWeap := i;
2041 if (R_BERSERK in FRulez) and (FWeapPreferences[WP_LAST + 1] > FWeapPreferences[testedWeap]) then
2042 testedWeap := WEAPON_KASTET;
2043 result := testedWeap;
2044 end;
2046 function TPlayer.maySwitch(Weapon: Byte) : Boolean;
2047 begin
2048 result := true;
2049 if (Weapon = WEAPON_KASTET) and (FSkipFist <> 0) then
2050 begin
2051 if (FSkipFist = 1) and (not (R_BERSERK in FRulez)) then
2052 result := false;
2053 end
2054 else if (FSwitchToEmpty = 0) and (not hasAmmoForShooting(Weapon)) then
2055 result := false;
2056 end;
2058 procedure TPlayer.SwitchTeam;
2059 begin
2060 if g_Game_IsClient then
2061 Exit;
2062 if not (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then Exit;
2064 if gGameOn and FAlive then
2065 Kill(K_SIMPLEKILL, FUID, HIT_SELF);
2067 if FTeam = TEAM_RED then
2068 begin
2069 ChangeTeam(TEAM_BLUE);
2070 g_Console_Add(Format(_lc[I_PLAYER_CHTEAM_BLUE], [FName]), True);
2071 if g_Game_IsNet then
2072 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM, TEAM_BLUE, FName);
2073 end
2074 else
2075 begin
2076 ChangeTeam(TEAM_RED);
2077 g_Console_Add(Format(_lc[I_PLAYER_CHTEAM_RED], [FName]), True);
2078 if g_Game_IsNet then
2079 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM, TEAM_RED, FName);
2080 end;
2081 FPreferredTeam := FTeam;
2082 end;
2084 procedure TPlayer.ChangeTeam(Team: Byte);
2085 var
2086 OldTeam: Byte;
2087 begin
2088 OldTeam := FTeam;
2089 FTeam := Team;
2090 case Team of
2091 TEAM_RED, TEAM_BLUE:
2092 FModel.Color := TEAMCOLOR[Team];
2093 else
2094 FModel.Color := FColor;
2095 end;
2096 if (FTeam <> OldTeam) and g_Game_IsNet and g_Game_IsServer then
2097 MH_SEND_PlayerStats(FUID);
2098 end;
2101 procedure TPlayer.CollideItem();
2102 var
2103 i: Integer;
2104 r: Boolean;
2105 begin
2106 if gItems = nil then Exit;
2107 if not FAlive then Exit;
2109 for i := 0 to High(gItems) do
2110 with gItems[i] do
2111 begin
2112 if (ItemType <> ITEM_NONE) and alive then
2113 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
2114 PLAYER_RECT.Height, @Obj) then
2115 begin
2116 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
2118 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
2119 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
2120 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
2121 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
2122 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
2124 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
2125 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
2126 (gGameSettings.GameType = GT_SINGLE) and
2127 (g_Player_GetCount() > 1)) then
2128 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
2129 end;
2130 end;
2131 end;
2134 function TPlayer.CollideLevel(XInc, YInc: Integer): Boolean;
2135 begin
2136 Result := g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc,
2137 PLAYER_RECT.Width, PLAYER_RECT.Height, PANEL_WALL,
2138 False);
2139 end;
2141 constructor TPlayer.Create();
2142 begin
2143 viewPortX := 0;
2144 viewPortY := 0;
2145 viewPortW := 0;
2146 viewPortH := 0;
2147 mEDamageType := HIT_SOME;
2149 FIamBot := False;
2150 FDummy := False;
2151 FSpawned := False;
2153 FSawSound := TPlayableSound.Create();
2154 FSawSoundIdle := TPlayableSound.Create();
2155 FSawSoundHit := TPlayableSound.Create();
2156 FSawSoundSelect := TPlayableSound.Create();
2157 FFlameSoundOn := TPlayableSound.Create();
2158 FFlameSoundOff := TPlayableSound.Create();
2159 FFlameSoundWork := TPlayableSound.Create();
2160 FJetSoundFly := TPlayableSound.Create();
2161 FJetSoundOn := TPlayableSound.Create();
2162 FJetSoundOff := TPlayableSound.Create();
2164 FSawSound.SetByName('SOUND_WEAPON_FIRESAW');
2165 FSawSoundIdle.SetByName('SOUND_WEAPON_IDLESAW');
2166 FSawSoundHit.SetByName('SOUND_WEAPON_HITSAW');
2167 FSawSoundSelect.SetByName('SOUND_WEAPON_SELECTSAW');
2168 FFlameSoundOn.SetByName('SOUND_WEAPON_FLAMEON');
2169 FFlameSoundOff.SetByName('SOUND_WEAPON_FLAMEOFF');
2170 FFlameSoundWork.SetByName('SOUND_WEAPON_FLAMEWORK');
2171 FJetSoundFly.SetByName('SOUND_PLAYER_JETFLY');
2172 FJetSoundOn.SetByName('SOUND_PLAYER_JETON');
2173 FJetSoundOff.SetByName('SOUND_PLAYER_JETOFF');
2175 FSpectatePlayer := -1;
2176 FClientID := -1;
2177 FPing := 0;
2178 FLoss := 0;
2179 FSavedStateNum := -1;
2180 FShellTimer := -1;
2181 FFireTime := 0;
2182 FFirePainTime := 0;
2183 FFireAttacker := 0;
2184 FHandicap := 100;
2185 FCorpse := -1;
2187 FActualModelName := 'doomer';
2189 g_Obj_Init(@FObj);
2190 FObj.Rect := PLAYER_RECT;
2192 FBFGFireCounter := -1;
2193 FJustTeleported := False;
2194 FNetTime := 0;
2196 FWaitForFirstSpawn := false;
2198 resetWeaponQueue();
2199 end;
2201 procedure TPlayer.positionChanged (); inline;
2202 begin
2203 end;
2205 procedure TPlayer.doDamage (v: Integer);
2206 begin
2207 if (v <= 0) then exit;
2208 if (v > 32767) then v := 32767;
2209 Damage(v, 0, 0, 0, mEDamageType);
2210 end;
2212 procedure TPlayer.Damage(value: Word; SpawnerUID: Word; vx, vy: Integer; t: Byte);
2213 var
2214 c: Word;
2215 begin
2216 if (not g_Game_IsClient) and (not FAlive) then
2217 Exit;
2219 FLastHit := t;
2221 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2222 if ((t = HIT_TRAP) or (t = HIT_SELF)) and (not FGodMode) then
2223 begin
2224 if not g_Game_IsClient then
2225 begin
2226 FArmor := 0;
2227 if t = HIT_TRAP then
2228 begin
2229 // Ëîâóøêà óáèâàåò ñðàçó:
2230 FHealth := -100;
2231 Kill(K_EXTRAHARDKILL, SpawnerUID, t);
2232 end;
2233 if t = HIT_SELF then
2234 begin
2235 // Ñàìîóáèéñòâî:
2236 FHealth := 0;
2237 Kill(K_SIMPLEKILL, SpawnerUID, t);
2238 end;
2239 end;
2240 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2241 FMegaRulez[MR_SUIT] := 0;
2242 FMegaRulez[MR_INVUL] := 0;
2243 FMegaRulez[MR_INVIS] := 0;
2244 FSpawnInvul := 0;
2245 FBerserk := 0;
2246 end;
2248 // Íî îò îñòàëüíîãî ñïàñàåò:
2249 if FMegaRulez[MR_INVUL] >= gTime then
2250 Exit;
2252 // ×èò-êîä "ÃÎÐÅÖ":
2253 if FGodMode then
2254 Exit;
2256 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2257 if LongBool(gGameSettings.Options and GAME_OPTION_TEAMDAMAGE) or
2258 (SpawnerUID = FUID) or
2259 (not SameTeam(FUID, SpawnerUID)) then
2260 begin
2261 FLastSpawnerUID := SpawnerUID;
2263 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2264 if gBloodCount > 0 then
2265 begin
2266 c := Min(value, 200)*gBloodCount + Random(Min(value, 200) div 2);
2267 if value div 4 <= c then
2268 c := c - (value div 4)
2269 else
2270 c := 0;
2272 if (t = HIT_SOME) and (vx = 0) and (vy = 0) then
2273 MakeBloodSimple(c)
2274 else
2275 case t of
2276 HIT_TRAP, HIT_ACID, HIT_FLAME, HIT_SELF: MakeBloodSimple(c);
2277 HIT_BFG, HIT_ROCKET, HIT_SOME: MakeBloodVector(c, vx, vy);
2278 end;
2280 if t = HIT_WATER then
2281 g_GFX_Bubbles(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2),
2282 FObj.Y+PLAYER_RECT.Y-4, value div 2, 8, 4);
2283 end;
2285 // Áóôåð óðîíà:
2286 if FAlive then
2287 Inc(FDamageBuffer, value);
2289 // Âñïûøêà áîëè:
2290 if gFlash <> 0 then
2291 FPain := FPain + value;
2292 end;
2294 if g_Game_IsServer and g_Game_IsNet then
2295 begin
2296 MH_SEND_PlayerDamage(FUID, t, SpawnerUID, value, vx, vy);
2297 MH_SEND_PlayerStats(FUID);
2298 MH_SEND_PlayerPos(False, FUID);
2299 end;
2300 end;
2302 function TPlayer.Heal(value: Word; Soft: Boolean): Boolean;
2303 begin
2304 Result := False;
2305 if g_Game_IsClient then
2306 Exit;
2307 if not FAlive then
2308 Exit;
2310 if Soft and (FHealth < PLAYER_HP_SOFT) then
2311 begin
2312 IncMax(FHealth, value, PLAYER_HP_SOFT);
2313 Result := True;
2314 end;
2315 if (not Soft) and (FHealth < PLAYER_HP_LIMIT) then
2316 begin
2317 IncMax(FHealth, value, PLAYER_HP_LIMIT);
2318 Result := True;
2319 end;
2321 if Result and g_Game_IsServer and g_Game_IsNet then
2322 MH_SEND_PlayerStats(FUID);
2323 end;
2325 destructor TPlayer.Destroy();
2326 begin
2327 if (gPlayer1 <> nil) and (gPlayer1.FUID = FUID) then
2328 gPlayer1 := nil;
2329 if (gPlayer2 <> nil) and (gPlayer2.FUID = FUID) then
2330 gPlayer2 := nil;
2332 FSawSound.Free();
2333 FSawSoundIdle.Free();
2334 FSawSoundHit.Free();
2335 FSawSoundSelect.Free();
2336 FFlameSoundOn.Free();
2337 FFlameSoundOff.Free();
2338 FFlameSoundWork.Free();
2339 FJetSoundFly.Free();
2340 FJetSoundOn.Free();
2341 FJetSoundOff.Free();
2342 FModel.Free();
2343 if FPunchAnim <> nil then
2344 FPunchAnim.Free();
2346 inherited;
2347 end;
2349 procedure TPlayer.DrawIndicator(Color: TRGB);
2350 var
2351 indX, indY, fX, fY, fSlope: Integer;
2352 indW, indH: Word;
2353 indA: Single;
2354 a: TDFPoint;
2355 nW, nH: Byte;
2356 ID: DWORD;
2357 c: TRGB;
2358 begin
2359 if FAlive then
2360 begin
2361 FObj.lerp(gLerpFactor, fX, fY);
2362 fSlope := nlerp(FSlopeOld, FObj.slopeUpLeft, gLerpFactor);
2364 case gPlayerIndicatorStyle of
2365 0:
2366 begin
2367 if g_Texture_Get('TEXTURE_PLAYER_INDICATOR', ID) then
2368 begin
2369 e_GetTextureSize(ID, @indW, @indH);
2370 a.X := indW div 2;
2371 a.Y := indH div 2;
2373 if (FObj.X + FObj.Rect.X) < 0 then
2374 begin
2375 indA := 90;
2376 indX := fX + FObj.Rect.X + FObj.Rect.Width;
2377 indY := fY + FObj.Rect.Y + (FObj.Rect.Height - indW) div 2;
2378 end
2380 else if (FObj.X + FObj.Rect.X + FObj.Rect.Width) > Max(gMapInfo.Width, gPlayerScreenSize.X) then
2381 begin
2382 indA := 270;
2383 indX := fX + FObj.Rect.X - indH;
2384 indY := fY + FObj.Rect.Y + (FObj.Rect.Height - indW) div 2;
2385 end
2387 else if (FObj.Y - indH) < 0 then
2388 begin
2389 indA := 180;
2390 indX := fX + FObj.Rect.X + (FObj.Rect.Width - indW) div 2;
2391 indY := fY + FObj.Rect.Y + FObj.Rect.Height;
2392 end
2394 else
2395 begin
2396 indA := 0;
2397 indX := fX + FObj.Rect.X + (FObj.Rect.Width - indW) div 2;
2398 indY := fY - indH;
2399 end;
2401 indY := indY + fSlope;
2402 indX := EnsureRange(indX, 0, Max(gMapInfo.Width, gPlayerScreenSize.X) - indW);
2403 indY := EnsureRange(indY, 0, Max(gMapInfo.Height, gPlayerScreenSize.Y) - indH);
2405 c := e_Colors;
2406 e_Colors := Color;
2407 e_DrawAdv(ID, indX, indY, 0, True, False, indA, @a);
2408 e_Colors := c;
2409 end;
2410 end;
2412 1:
2413 begin
2414 e_TextureFontGetSize(gStdFont, nW, nH);
2415 indX := fX + FObj.Rect.X + (FObj.Rect.Width - Length(FName) * nW) div 2;
2416 indY := fY - nH + fSlope;
2417 e_TextureFontPrintEx(indX, indY, FName, gStdFont, Color.R, Color.G, Color.B, 1.0, True);
2418 end;
2419 end;
2420 end;
2421 end;
2423 procedure TPlayer.DrawBubble();
2424 var
2425 bubX, bubY, fX, fY: Integer;
2426 ID: LongWord;
2427 Rb, Gb, Bb,
2428 Rw, Gw, Bw: SmallInt;
2429 Dot: Byte;
2430 CObj: TObj;
2431 begin
2432 CObj := getCameraObj();
2433 CObj.lerp(gLerpFactor, fX, fY);
2434 // NB: _F_Obj.Rect is used to keep the bubble higher; this is not a mistake
2435 bubX := fX+FObj.Rect.X + IfThen(FDirection = TDirection.D_LEFT, -4, 18);
2436 bubY := fY+FObj.Rect.Y - 18;
2437 Rb := 64;
2438 Gb := 64;
2439 Bb := 64;
2440 Rw := 240;
2441 Gw := 240;
2442 Bw := 240;
2443 case gChatBubble of
2444 1: // simple textual non-bubble
2445 begin
2446 bubX := fX+FObj.Rect.X - 11;
2447 bubY := fY+FObj.Rect.Y - 17;
2448 e_TextureFontPrint(bubX, bubY, '[...]', gStdFont);
2449 Exit;
2450 end;
2451 2: // advanced pixel-perfect bubble
2452 begin
2453 if FTeam = TEAM_RED then
2454 Rb := 255
2455 else
2456 if FTeam = TEAM_BLUE then
2457 Bb := 255;
2458 end;
2459 3: // colored bubble
2460 begin
2461 Rb := FModel.Color.R;
2462 Gb := FModel.Color.G;
2463 Bb := FModel.Color.B;
2464 Rw := Min(Rb * 2 + 64, 255);
2465 Gw := Min(Gb * 2 + 64, 255);
2466 Bw := Min(Bb * 2 + 64, 255);
2467 if (Abs(Rw - Rb) < 32)
2468 or (Abs(Gw - Gb) < 32)
2469 or (Abs(Bw - Bb) < 32) then
2470 begin
2471 Rb := Max(Rw div 2 - 16, 0);
2472 Gb := Max(Gw div 2 - 16, 0);
2473 Bb := Max(Bw div 2 - 16, 0);
2474 end;
2475 end;
2476 4: // custom textured bubble
2477 begin
2478 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID) then
2479 if FDirection = TDirection.D_RIGHT then
2480 e_Draw(ID, bubX - 6, bubY - 7, 0, True, False)
2481 else
2482 e_Draw(ID, bubX - 6, bubY - 7, 0, True, False, TMirrorType.Horizontal);
2483 Exit;
2484 end;
2485 end;
2487 // Outer borders
2488 e_DrawQuad(bubX + 1, bubY , bubX + 18, bubY + 13, Rb, Gb, Bb);
2489 e_DrawQuad(bubX , bubY + 1, bubX + 19, bubY + 12, Rb, Gb, Bb);
2490 // Inner box
2491 e_DrawFillQuad(bubX + 1, bubY + 1, bubX + 18, bubY + 12, Rw, Gw, Bw, 0);
2493 // Tail
2494 Dot := IfThen(FDirection = TDirection.D_LEFT, 14, 5);
2495 e_DrawLine(1, bubX + Dot, bubY + 14, bubX + Dot, bubY + 16, Rb, Gb, Bb);
2496 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);
2497 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);
2498 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);
2499 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);
2501 // Dots
2502 Dot := 6;
2503 e_DrawFillQuad(bubX + Dot, bubY + 8, bubX + Dot + 1, bubY + 9, Rb, Gb, Bb, 0);
2504 e_DrawFillQuad(bubX + Dot + 3, bubY + 8, bubX + Dot + 4, bubY + 9, Rb, Gb, Bb, 0);
2505 e_DrawFillQuad(bubX + Dot + 6, bubY + 8, bubX + Dot + 7, bubY + 9, Rb, Gb, Bb, 0);
2506 end;
2508 procedure TPlayer.Draw();
2509 var
2510 ID: DWORD;
2511 w, h: Word;
2512 dr: Boolean;
2513 Mirror: TMirrorType;
2514 fX, fY, fSlope: Integer;
2515 begin
2516 FObj.lerp(gLerpFactor, fX, fY);
2517 fSlope := nlerp(FSlopeOld, FObj.slopeUpLeft, gLerpFactor);
2519 if FAlive then
2520 begin
2521 if Direction = TDirection.D_RIGHT then
2522 Mirror := TMirrorType.None
2523 else
2524 Mirror := TMirrorType.Horizontal;
2526 if FPunchAnim <> nil then
2527 begin
2528 FPunchAnim.Draw(fX+IfThen(Direction = TDirection.D_LEFT, 15-FObj.Rect.X, FObj.Rect.X-15),
2529 fY+fSlope+FObj.Rect.Y-11, Mirror);
2530 if FPunchAnim.played then
2531 begin
2532 FPunchAnim.Free;
2533 FPunchAnim := nil;
2534 end;
2535 end;
2537 if (FMegaRulez[MR_INVUL] > gTime) and ((gPlayerDrawn <> Self) or (FSpawnInvul >= gTime)) then
2538 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID) then
2539 begin
2540 e_GetTextureSize(ID, @w, @h);
2541 if FDirection = TDirection.D_LEFT then
2542 e_Draw(ID, fX+FObj.Rect.X+(FObj.Rect.Width div 2)-(w div 2)+4,
2543 fY+FObj.Rect.Y+(FObj.Rect.Height div 2)-(h div 2)-7+fSlope, 0, True, False)
2544 else
2545 e_Draw(ID, fX+FObj.Rect.X+(FObj.Rect.Width div 2)-(w div 2)-2,
2546 fY+FObj.Rect.Y+(FObj.Rect.Height div 2)-(h div 2)-7+fSlope, 0, True, False);
2547 end;
2549 if FMegaRulez[MR_INVIS] > gTime then
2550 begin
2551 if (gPlayerDrawn <> nil) and ((Self = gPlayerDrawn) or
2552 ((FTeam = gPlayerDrawn.Team) and (gGameSettings.GameMode <> GM_DM))) then
2553 begin
2554 if (FMegaRulez[MR_INVIS] - gTime) <= 2100 then
2555 dr := not Odd((FMegaRulez[MR_INVIS] - gTime) div 300)
2556 else
2557 dr := True;
2558 if dr then
2559 FModel.Draw(fX, fY+fSlope, 200)
2560 else
2561 FModel.Draw(fX, fY+fSlope);
2562 end
2563 else
2564 FModel.Draw(fX, fY+fSlope, 254);
2565 end
2566 else
2567 FModel.Draw(fX, fY+fSlope);
2568 end;
2570 if g_debug_Frames then
2571 begin
2572 e_DrawQuad(FObj.X+FObj.Rect.X,
2573 FObj.Y+FObj.Rect.Y,
2574 FObj.X+FObj.Rect.X+FObj.Rect.Width-1,
2575 FObj.Y+FObj.Rect.Y+FObj.Rect.Height-1,
2576 0, 255, 0);
2577 end;
2579 if (gChatBubble > 0) and (FKeys[KEY_CHAT].Pressed) and not FGhost then
2580 if (FMegaRulez[MR_INVIS] <= gTime) or ((gPlayerDrawn <> nil) and ((Self = gPlayerDrawn) or
2581 ((FTeam = gPlayerDrawn.Team) and (gGameSettings.GameMode <> GM_DM)))) then
2582 DrawBubble();
2583 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2584 if gAimLine and alive and
2585 ((Self = gPlayer1) or (Self = gPlayer2)) then
2586 DrawAim();
2587 end;
2590 procedure TPlayer.DrawAim();
2591 procedure drawCast (sz: Integer; ax0, ay0, ax1, ay1: Integer);
2592 var
2593 ex, ey: Integer;
2594 begin
2596 {$IFDEF ENABLE_HOLMES}
2597 if isValidViewPort and (self = gPlayer1) then
2598 begin
2599 g_Holmes_plrLaser(ax0, ay0, ax1, ay1);
2600 end;
2601 {$ENDIF}
2603 e_DrawLine(sz, ax0, ay0, ax1, ay1, 255, 0, 0, 96);
2604 if (g_Map_traceToNearestWall(ax0, ay0, ax1, ay1, @ex, @ey) <> nil) then
2605 begin
2606 e_DrawLine(sz, ax0, ay0, ex, ey, 0, 255, 0, 96);
2607 end
2608 else
2609 begin
2610 e_DrawLine(sz, ax0, ay0, ex, ey, 0, 0, 255, 96);
2611 end;
2612 end;
2614 var
2615 wx, wy, xx, yy: Integer;
2616 angle: SmallInt;
2617 sz, len: Word;
2618 begin
2619 wx := FObj.X + WEAPONPOINT[FDirection].X + IfThen(FDirection = TDirection.D_LEFT, 7, -7);
2620 wy := FObj.Y + WEAPONPOINT[FDirection].Y;
2621 angle := FAngle;
2622 len := 1024;
2623 sz := 2;
2624 case FCurrWeap of
2625 0: begin // Punch
2626 len := 12;
2627 sz := 4;
2628 end;
2629 1: begin // Chainsaw
2630 len := 24;
2631 sz := 6;
2632 end;
2633 2: begin // Pistol
2634 len := 1024;
2635 sz := 2;
2636 if angle = ANGLE_RIGHTUP then Dec(angle, 2);
2637 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2638 if angle = ANGLE_LEFTUP then Inc(angle, 2);
2639 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2640 end;
2641 3: begin // Shotgun
2642 len := 1024;
2643 sz := 3;
2644 if angle = ANGLE_RIGHTUP then Dec(angle, 2);
2645 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2646 if angle = ANGLE_LEFTUP then Inc(angle, 2);
2647 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2648 end;
2649 4: begin // Double Shotgun
2650 len := 1024;
2651 sz := 4;
2652 if angle = ANGLE_RIGHTUP then Dec(angle, 2);
2653 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2654 if angle = ANGLE_LEFTUP then Inc(angle, 2);
2655 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2656 end;
2657 5: begin // Chaingun
2658 len := 1024;
2659 sz := 3;
2660 if angle = ANGLE_RIGHTUP then Dec(angle, 2);
2661 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2662 if angle = ANGLE_LEFTUP then Inc(angle, 2);
2663 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2664 end;
2665 6: begin // Rocket Launcher
2666 len := 1024;
2667 sz := 7;
2668 if angle = ANGLE_RIGHTUP then Inc(angle, 2);
2669 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2670 if angle = ANGLE_LEFTUP then Dec(angle, 2);
2671 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2672 end;
2673 7: begin // Plasmagun
2674 len := 1024;
2675 sz := 5;
2676 if angle = ANGLE_RIGHTUP then Inc(angle);
2677 if angle = ANGLE_RIGHTDOWN then Inc(angle, 3);
2678 if angle = ANGLE_LEFTUP then Dec(angle);
2679 if angle = ANGLE_LEFTDOWN then Dec(angle, 3);
2680 end;
2681 8: begin // BFG
2682 len := 1024;
2683 sz := 12;
2684 if angle = ANGLE_RIGHTUP then Inc(angle, 1);
2685 if angle = ANGLE_RIGHTDOWN then Inc(angle, 2);
2686 if angle = ANGLE_LEFTUP then Dec(angle, 1);
2687 if angle = ANGLE_LEFTDOWN then Dec(angle, 2);
2688 end;
2689 9: begin // Super Chaingun
2690 len := 1024;
2691 sz := 4;
2692 if angle = ANGLE_RIGHTUP then Dec(angle, 2);
2693 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2694 if angle = ANGLE_LEFTUP then Inc(angle, 2);
2695 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2696 end;
2697 end;
2698 xx := Trunc(Cos(-DegToRad(angle)) * len) + wx;
2699 yy := Trunc(Sin(-DegToRad(angle)) * len) + wy;
2700 {$IF DEFINED(D2F_DEBUG)}
2701 drawCast(sz, wx, wy, xx, yy);
2702 {$ELSE}
2703 e_DrawLine(sz, wx, wy, xx, yy, 255, 0, 0, 96);
2704 {$ENDIF}
2705 end;
2707 procedure TPlayer.DrawGUI();
2708 var
2709 ID: DWORD;
2710 X, Y, SY, a, p, m: Integer;
2711 tw, th: Word;
2712 cw, ch: Byte;
2713 s: string;
2714 stat: TPlayerStatArray;
2715 begin
2716 X := gPlayerScreenSize.X;
2717 SY := gPlayerScreenSize.Y;
2718 Y := 0;
2720 if gShowGoals and (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
2721 begin
2722 if gGameSettings.GameMode = GM_CTF then
2723 a := 32 + 8
2724 else
2725 a := 0;
2726 if gGameSettings.GameMode = GM_CTF then
2727 begin
2728 s := 'TEXTURE_PLAYER_REDFLAG';
2729 if gFlags[FLAG_RED].State = FLAG_STATE_CAPTURED then
2730 s := 'TEXTURE_PLAYER_REDFLAG_S';
2731 if gFlags[FLAG_RED].State = FLAG_STATE_DROPPED then
2732 s := 'TEXTURE_PLAYER_REDFLAG_D';
2733 if g_Texture_Get(s, ID) then
2734 e_Draw(ID, X-16-32, 240-72-4, 0, True, False);
2735 end;
2737 s := IntToStr(gTeamStat[TEAM_RED].Goals);
2738 e_CharFont_GetSize(gMenuFont, s, tw, th);
2739 e_CharFont_PrintEx(gMenuFont, X-16-a-tw, 240-72-4, s, TEAMCOLOR[TEAM_RED]);
2741 if gGameSettings.GameMode = GM_CTF then
2742 begin
2743 s := 'TEXTURE_PLAYER_BLUEFLAG';
2744 if gFlags[FLAG_BLUE].State = FLAG_STATE_CAPTURED then
2745 s := 'TEXTURE_PLAYER_BLUEFLAG_S';
2746 if gFlags[FLAG_BLUE].State = FLAG_STATE_DROPPED then
2747 s := 'TEXTURE_PLAYER_BLUEFLAG_D';
2748 if g_Texture_Get(s, ID) then
2749 e_Draw(ID, X-16-32, 240-32-4, 0, True, False);
2750 end;
2752 s := IntToStr(gTeamStat[TEAM_BLUE].Goals);
2753 e_CharFont_GetSize(gMenuFont, s, tw, th);
2754 e_CharFont_PrintEx(gMenuFont, X-16-a-tw, 240-32-4, s, TEAMCOLOR[TEAM_BLUE]);
2755 end;
2757 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID) then
2758 e_DrawFill(ID, X, 0, 1, (gPlayerScreenSize.Y div 256)+IfThen(gPlayerScreenSize.Y mod 256 > 0, 1, 0),
2759 0, False, False);
2761 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID) then
2762 e_Draw(ID, X+2, Y, 0, True, False);
2764 if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
2765 begin
2766 if gShowStat then
2767 begin
2768 s := IntToStr(Frags);
2769 e_CharFont_GetSize(gMenuFont, s, tw, th);
2770 e_CharFont_PrintEx(gMenuFont, X-16-tw, Y, s, _RGB(255, 0, 0));
2772 s := '';
2773 p := 1;
2774 m := 0;
2775 stat := g_Player_GetStats();
2776 if stat <> nil then
2777 begin
2778 p := 1;
2780 for a := 0 to High(stat) do
2781 if stat[a].Name <> Name then
2782 begin
2783 if stat[a].Frags > m then m := stat[a].Frags;
2784 if stat[a].Frags > Frags then p := p+1;
2785 end;
2786 end;
2788 s := IntToStr(p)+' / '+IntToStr(Length(stat))+' ';
2789 if Frags >= m then s := s+'+' else s := s+'-';
2790 s := s+IntToStr(Abs(Frags-m));
2792 e_CharFont_GetSize(gMenuSmallFont, s, tw, th);
2793 e_CharFont_PrintEx(gMenuSmallFont, X-16-tw, Y+32, s, _RGB(255, 0, 0));
2794 end;
2796 if gLMSRespawn > LMS_RESPAWN_NONE then
2797 begin
2798 s := _lc[I_GAME_WARMUP];
2799 e_CharFont_GetSize(gMenuFont, s, tw, th);
2800 s := s + ': ' + IntToStr((gLMSRespawnTime - gTime) div 1000);
2801 e_CharFont_PrintEx(gMenuFont, X-64-tw, SY-32, s, _RGB(0, 255, 0));
2802 end
2803 else if gShowLives and (gGameSettings.MaxLives > 0) then
2804 begin
2805 s := IntToStr(Lives);
2806 e_CharFont_GetSize(gMenuFont, s, tw, th);
2807 e_CharFont_PrintEx(gMenuFont, X-16-tw, SY-32, s, _RGB(0, 255, 0));
2808 end;
2809 end;
2811 e_CharFont_GetSize(gMenuSmallFont, FName, tw, th);
2812 e_CharFont_PrintEx(gMenuSmallFont, X+98-(tw div 2), Y+8, FName, _RGB(255, 0, 0));
2814 if R_BERSERK in FRulez then
2815 e_Draw(gItemsTexturesID[ITEM_MEDKIT_BLACK], X+37, Y+45, 0, True, False)
2816 else
2817 e_Draw(gItemsTexturesID[ITEM_MEDKIT_LARGE], X+37, Y+45, 0, True, False);
2819 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID) then
2820 e_Draw(ID, X+36, Y+77, 0, True, False);
2822 s := IntToStr(IfThen(FHealth > 0, FHealth, 0));
2823 e_CharFont_GetSize(gMenuFont, s, tw, th);
2824 e_CharFont_PrintEx(gMenuFont, X+178-tw, Y+40, s, _RGB(255, 0, 0));
2826 s := IntToStr(FArmor);
2827 e_CharFont_GetSize(gMenuFont, s, tw, th);
2828 e_CharFont_PrintEx(gMenuFont, X+178-tw, Y+68, s, _RGB(255, 0, 0));
2830 s := IntToStr(GetAmmoByWeapon(FCurrWeap));
2832 case FCurrWeap of
2833 WEAPON_KASTET:
2834 begin
2835 s := '--';
2836 ID := gItemsTexturesID[ITEM_WEAPON_KASTET];
2837 end;
2838 WEAPON_SAW:
2839 begin
2840 s := '--';
2841 ID := gItemsTexturesID[ITEM_WEAPON_SAW];
2842 end;
2843 WEAPON_PISTOL: ID := gItemsTexturesID[ITEM_WEAPON_PISTOL];
2844 WEAPON_CHAINGUN: ID := gItemsTexturesID[ITEM_WEAPON_CHAINGUN];
2845 WEAPON_SHOTGUN1: ID := gItemsTexturesID[ITEM_WEAPON_SHOTGUN1];
2846 WEAPON_SHOTGUN2: ID := gItemsTexturesID[ITEM_WEAPON_SHOTGUN2];
2847 WEAPON_SUPERPULEMET: ID := gItemsTexturesID[ITEM_WEAPON_SUPERPULEMET];
2848 WEAPON_ROCKETLAUNCHER: ID := gItemsTexturesID[ITEM_WEAPON_ROCKETLAUNCHER];
2849 WEAPON_PLASMA: ID := gItemsTexturesID[ITEM_WEAPON_PLASMA];
2850 WEAPON_BFG: ID := gItemsTexturesID[ITEM_WEAPON_BFG];
2851 WEAPON_FLAMETHROWER: ID := gItemsTexturesID[ITEM_WEAPON_FLAMETHROWER];
2852 end;
2854 e_CharFont_GetSize(gMenuFont, s, tw, th);
2855 e_CharFont_PrintEx(gMenuFont, X+178-tw, Y+158, s, _RGB(255, 0, 0));
2856 e_Draw(ID, X+20, Y+160, 0, True, False);
2858 if R_KEY_RED in FRulez then
2859 e_Draw(gItemsTexturesID[ITEM_KEY_RED], X+78, Y+214, 0, True, False);
2861 if R_KEY_GREEN in FRulez then
2862 e_Draw(gItemsTexturesID[ITEM_KEY_GREEN], X+95, Y+214, 0, True, False);
2864 if R_KEY_BLUE in FRulez then
2865 e_Draw(gItemsTexturesID[ITEM_KEY_BLUE], X+112, Y+214, 0, True, False);
2867 if FJetFuel > 0 then
2868 begin
2869 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID) then
2870 e_Draw(ID, X+2, Y+116, 0, True, False);
2871 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID) then
2872 e_Draw(ID, X+2, Y+126, 0, True, False);
2873 e_DrawLine(4, X+16, Y+122, X+16+Trunc(168*IfThen(FAir > 0, FAir, 0)/AIR_MAX), Y+122, 0, 0, 196);
2874 e_DrawLine(4, X+16, Y+132, X+16+Trunc(168*FJetFuel/JET_MAX), Y+132, 208, 0, 0);
2875 end
2876 else
2877 begin
2878 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID) then
2879 e_Draw(ID, X+2, Y+124, 0, True, False);
2880 e_DrawLine(4, X+16, Y+130, X+16+Trunc(168*IfThen(FAir > 0, FAir, 0)/AIR_MAX), Y+130, 0, 0, 196);
2881 end;
2883 if gShowPing and g_Game_IsClient then
2884 begin
2885 s := _lc[I_GAME_PING_HUD] + IntToStr(NetPeer.lastRoundTripTime) + _lc[I_NET_SLIST_PING_MS];
2886 e_TextureFontPrint(X + 4, Y + 242, s, gStdFont);
2887 Y := Y + 16;
2888 end;
2890 if FSpectator then
2891 begin
2892 e_TextureFontPrint(X + 4, Y + 242, _lc[I_PLAYER_SPECT], gStdFont);
2893 e_TextureFontPrint(X + 4, Y + 258, _lc[I_PLAYER_SPECT2], gStdFont);
2894 e_TextureFontPrint(X + 4, Y + 274, _lc[I_PLAYER_SPECT1], gStdFont);
2895 if FNoRespawn then
2896 begin
2897 e_TextureFontGetSize(gStdFont, cw, ch);
2898 s := _lc[I_PLAYER_SPECT4];
2899 e_TextureFontPrintEx(gScreenWidth div 2 - cw*(Length(s) div 2),
2900 gScreenHeight-4-ch, s, gStdFont, 255, 255, 255, 1, True);
2901 e_TextureFontPrint(X + 4, Y + 290, _lc[I_PLAYER_SPECT1S], gStdFont);
2902 end;
2904 end;
2905 end;
2907 procedure TPlayer.DrawRulez();
2908 var
2909 dr: Boolean;
2910 begin
2911 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2912 if (FMegaRulez[MR_INVUL] >= gTime) and (FSpawnInvul < gTime) then
2913 begin
2914 if (FMegaRulez[MR_INVUL]-gTime) <= 2100 then
2915 dr := not Odd((FMegaRulez[MR_INVUL]-gTime) div 300)
2916 else
2917 dr := True;
2919 if dr then
2920 e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1,
2921 191, 191, 191, 0, TBlending.Invert);
2922 end;
2924 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2925 if FMegaRulez[MR_SUIT] >= gTime then
2926 begin
2927 if (FMegaRulez[MR_SUIT]-gTime) <= 2100 then
2928 dr := not Odd((FMegaRulez[MR_SUIT]-gTime) div 300)
2929 else
2930 dr := True;
2932 if dr then
2933 e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1,
2934 0, 96, 0, 200, TBlending.None);
2935 end;
2937 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2938 if (FBerserk >= 0) and (LongWord(FBerserk) >= gTime) and (gFlash = 2) then
2939 begin
2940 e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1,
2941 255, 0, 0, 200, TBlending.None);
2942 end;
2943 end;
2945 procedure TPlayer.DrawPain();
2946 var
2947 a, h: Integer;
2948 begin
2949 if FPain = 0 then Exit;
2951 a := FPain;
2953 if a < 15 then h := 0
2954 else if a < 35 then h := 1
2955 else if a < 55 then h := 2
2956 else if a < 75 then h := 3
2957 else if a < 95 then h := 4
2958 else h := 5;
2960 //if a > 255 then a := 255;
2962 e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255, 0, 0, 255-h*50);
2963 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2964 end;
2966 procedure TPlayer.DrawPickup();
2967 var
2968 a, h: Integer;
2969 begin
2970 if FPickup = 0 then Exit;
2972 a := FPickup;
2974 if a < 15 then h := 1
2975 else if a < 35 then h := 2
2976 else if a < 55 then h := 3
2977 else if a < 75 then h := 4
2978 else h := 5;
2980 e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 150, 200, 150, 255-h*50);
2981 end;
2983 procedure TPlayer.DoPunch();
2984 var
2985 id: DWORD;
2986 st: String;
2987 begin
2988 if FPunchAnim <> nil then begin
2989 FPunchAnim.reset();
2990 FPunchAnim.Free;
2991 FPunchAnim := nil;
2992 end;
2993 st := 'FRAMES_PUNCH';
2994 if R_BERSERK in FRulez then
2995 st := st + '_BERSERK';
2996 if FKeys[KEY_UP].Pressed then
2997 st := st + '_UP'
2998 else if FKeys[KEY_DOWN].Pressed then
2999 st := st + '_DN';
3000 g_Frames_Get(id, st);
3001 FPunchAnim := TAnimation.Create(id, False, 1);
3002 end;
3004 procedure TPlayer.Fire();
3005 var
3006 f, DidFire: Boolean;
3007 wx, wy, xd, yd: Integer;
3008 locobj: TObj;
3009 begin
3010 if g_Game_IsClient then Exit;
3011 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
3012 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
3014 if FSpectator then
3015 begin
3016 Respawn(False);
3017 Exit;
3018 end;
3020 if FReloading[FCurrWeap] <> 0 then Exit;
3022 DidFire := False;
3024 f := False;
3025 wx := FObj.X+WEAPONPOINT[FDirection].X;
3026 wy := FObj.Y+WEAPONPOINT[FDirection].Y;
3027 xd := wx+IfThen(FDirection = TDirection.D_LEFT, -30, 30);
3028 yd := wy+firediry();
3030 case FCurrWeap of
3031 WEAPON_KASTET:
3032 begin
3033 DoPunch();
3034 if R_BERSERK in FRulez then
3035 begin
3036 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
3037 locobj.X := FObj.X+FObj.Rect.X;
3038 locobj.Y := FObj.Y+FObj.Rect.Y;
3039 locobj.rect.X := 0;
3040 locobj.rect.Y := 0;
3041 locobj.rect.Width := 39;
3042 locobj.rect.Height := 52;
3043 locobj.Vel.X := (xd-wx) div 2;
3044 locobj.Vel.Y := (yd-wy) div 2;
3045 locobj.Accel.X := xd-wx;
3046 locobj.Accel.y := yd-wy;
3048 if g_Weapon_Hit(@locobj, 50, FUID, HIT_SOME) <> 0 then
3049 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj.X, FObj.Y)
3050 else
3051 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj.X, FObj.Y);
3053 if (gFlash = 1) and (FPain < 50) then FPain := min(FPain + 25, 50);
3054 end
3055 else
3056 begin
3057 g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 3, FUID);
3058 end;
3060 DidFire := True;
3061 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3062 end;
3064 WEAPON_SAW:
3065 begin
3066 if g_Weapon_chainsaw(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y,
3067 IfThen(gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF], 9, 3), FUID) <> 0 then
3068 begin
3069 FSawSoundSelect.Stop();
3070 FSawSound.Stop();
3071 FSawSoundHit.PlayAt(FObj.X, FObj.Y);
3072 end
3073 else if not FSawSoundHit.IsPlaying() then
3074 begin
3075 FSawSoundSelect.Stop();
3076 FSawSound.PlayAt(FObj.X, FObj.Y);
3077 end;
3079 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3080 DidFire := True;
3081 f := True;
3082 end;
3084 WEAPON_PISTOL:
3085 if FAmmo[A_BULLETS] > 0 then
3086 begin
3087 g_Weapon_pistol(wx, wy, xd, yd, FUID);
3088 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3089 Dec(FAmmo[A_BULLETS]);
3090 FFireAngle := FAngle;
3091 f := True;
3092 DidFire := True;
3093 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
3094 GameVelX, GameVelY-2, SHELL_BULLET);
3095 end;
3097 WEAPON_SHOTGUN1:
3098 if FAmmo[A_SHELLS] > 0 then
3099 begin
3100 g_Weapon_shotgun(wx, wy, xd, yd, FUID);
3101 if not gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx, wy);
3102 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3103 Dec(FAmmo[A_SHELLS]);
3104 FFireAngle := FAngle;
3105 f := True;
3106 DidFire := True;
3107 FShellTimer := 10;
3108 FShellType := SHELL_SHELL;
3109 end;
3111 WEAPON_SHOTGUN2:
3112 if FAmmo[A_SHELLS] >= 2 then
3113 begin
3114 g_Weapon_dshotgun(wx, wy, xd, yd, FUID);
3115 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3116 Dec(FAmmo[A_SHELLS], 2);
3117 FFireAngle := FAngle;
3118 f := True;
3119 DidFire := True;
3120 FShellTimer := 13;
3121 FShellType := SHELL_DBLSHELL;
3122 end;
3124 WEAPON_CHAINGUN:
3125 if FAmmo[A_BULLETS] > 0 then
3126 begin
3127 g_Weapon_mgun(wx, wy, xd, yd, FUID);
3128 if not gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx, wy);
3129 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3130 Dec(FAmmo[A_BULLETS]);
3131 FFireAngle := FAngle;
3132 f := True;
3133 DidFire := True;
3134 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
3135 GameVelX, GameVelY-2, SHELL_BULLET);
3136 end;
3138 WEAPON_ROCKETLAUNCHER:
3139 if FAmmo[A_ROCKETS] > 0 then
3140 begin
3141 g_Weapon_rocket(wx, wy, xd, yd, FUID);
3142 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3143 Dec(FAmmo[A_ROCKETS]);
3144 FFireAngle := FAngle;
3145 f := True;
3146 DidFire := True;
3147 end;
3149 WEAPON_PLASMA:
3150 if FAmmo[A_CELLS] > 0 then
3151 begin
3152 g_Weapon_plasma(wx, wy, xd, yd, FUID);
3153 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3154 Dec(FAmmo[A_CELLS]);
3155 FFireAngle := FAngle;
3156 f := True;
3157 DidFire := True;
3158 end;
3160 WEAPON_BFG:
3161 if (FAmmo[A_CELLS] >= 40) and (FBFGFireCounter = -1) then
3162 begin
3163 FBFGFireCounter := 17;
3164 if not FNoReload then
3165 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj.X, FObj.Y);
3166 Dec(FAmmo[A_CELLS], 40);
3167 DidFire := True;
3168 end;
3170 WEAPON_SUPERPULEMET:
3171 if FAmmo[A_SHELLS] > 0 then
3172 begin
3173 g_Weapon_shotgun(wx, wy, xd, yd, FUID);
3174 if not gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx, wy);
3175 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3176 Dec(FAmmo[A_SHELLS]);
3177 FFireAngle := FAngle;
3178 f := True;
3179 DidFire := True;
3180 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
3181 GameVelX, GameVelY-2, SHELL_SHELL);
3182 end;
3184 WEAPON_FLAMETHROWER:
3185 if FAmmo[A_FUEL] > 0 then
3186 begin
3187 g_Weapon_flame(wx, wy, xd, yd, FUID);
3188 FlamerOn;
3189 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3190 Dec(FAmmo[A_FUEL]);
3191 FFireAngle := FAngle;
3192 f := True;
3193 DidFire := True;
3194 end
3195 else
3196 begin
3197 FlamerOff;
3198 if g_Game_IsNet and g_Game_IsServer then MH_SEND_PlayerStats(FUID);
3199 end;
3200 end;
3202 if g_Game_IsNet then
3203 begin
3204 if DidFire then
3205 begin
3206 if FCurrWeap <> WEAPON_BFG then
3207 MH_SEND_PlayerFire(FUID, FCurrWeap, wx, wy, xd, yd, LastShotID)
3208 else
3209 if not FNoReload then
3210 MH_SEND_Sound(FObj.X, FObj.Y, 'SOUND_WEAPON_STARTFIREBFG');
3211 end;
3213 MH_SEND_PlayerStats(FUID);
3214 end;
3216 if not f then Exit;
3218 if (FAngle = 0) or (FAngle = 180) then SetAction(A_ATTACK)
3219 else if (FAngle = ANGLE_LEFTDOWN) or (FAngle = ANGLE_RIGHTDOWN) then SetAction(A_ATTACKDOWN)
3220 else if (FAngle = ANGLE_LEFTUP) or (FAngle = ANGLE_RIGHTUP) then SetAction(A_ATTACKUP);
3221 end;
3223 function TPlayer.GetAmmoByWeapon(Weapon: Byte): Word;
3224 begin
3225 case Weapon of
3226 WEAPON_PISTOL, WEAPON_CHAINGUN: Result := FAmmo[A_BULLETS];
3227 WEAPON_SHOTGUN1, WEAPON_SHOTGUN2, WEAPON_SUPERPULEMET: Result := FAmmo[A_SHELLS];
3228 WEAPON_ROCKETLAUNCHER: Result := FAmmo[A_ROCKETS];
3229 WEAPON_PLASMA, WEAPON_BFG: Result := FAmmo[A_CELLS];
3230 WEAPON_FLAMETHROWER: Result := FAmmo[A_FUEL];
3231 else Result := 0;
3232 end;
3233 end;
3235 function TPlayer.HeadInLiquid(XInc, YInc: Integer): Boolean;
3236 begin
3237 Result := g_Map_CollidePanel(FObj.X+PLAYER_HEADRECT.X+XInc, FObj.Y+PLAYER_HEADRECT.Y+YInc,
3238 PLAYER_HEADRECT.Width, PLAYER_HEADRECT.Height,
3239 PANEL_WATER or PANEL_ACID1 or PANEL_ACID2, True);
3240 end;
3242 procedure TPlayer.FlamerOn;
3243 begin
3244 FFlameSoundOff.Stop();
3245 FFlameSoundOff.SetPosition(0);
3246 if FFlaming then
3247 begin
3248 if (not FFlameSoundOn.IsPlaying()) and (not FFlameSoundWork.IsPlaying()) then
3249 FFlameSoundWork.PlayAt(FObj.X, FObj.Y);
3250 end
3251 else
3252 begin
3253 FFlameSoundOn.PlayAt(FObj.X, FObj.Y);
3254 FFlaming := True;
3255 end;
3256 end;
3258 procedure TPlayer.FlamerOff;
3259 begin
3260 if FFlaming then
3261 begin
3262 FFlameSoundOn.Stop();
3263 FFlameSoundOn.SetPosition(0);
3264 FFlameSoundWork.Stop();
3265 FFlameSoundWork.SetPosition(0);
3266 FFlameSoundOff.PlayAt(FObj.X, FObj.Y);
3267 FFlaming := False;
3268 end;
3269 end;
3271 procedure TPlayer.JetpackOn;
3272 begin
3273 FJetSoundFly.Stop;
3274 FJetSoundOff.Stop;
3275 FJetSoundOn.SetPosition(0);
3276 FJetSoundOn.PlayAt(FObj.X, FObj.Y);
3277 FlySmoke(8);
3278 end;
3280 procedure TPlayer.JetpackOff;
3281 begin
3282 FJetSoundFly.Stop;
3283 FJetSoundOn.Stop;
3284 FJetSoundOff.SetPosition(0);
3285 FJetSoundOff.PlayAt(FObj.X, FObj.Y);
3286 end;
3288 procedure TPlayer.CatchFire(Attacker: Word; Timeout: Integer = PLAYER_BURN_TIME);
3289 begin
3290 if Timeout <= 0 then
3291 exit;
3292 if (FMegaRulez[MR_SUIT] > gTime) or (FMegaRulez[MR_INVUL] > gTime) then
3293 exit; // Íå çàãîðàåìñÿ êîãäà åñòü çàùèòà
3294 if g_Obj_CollidePanel(@FObj, 0, 0, PANEL_WATER or PANEL_ACID1 or PANEL_ACID2) then
3295 exit; // Íå ïîäãîðàåì â âîäå íà âñÿêèé ñëó÷àé
3296 if FFireTime <= 0 then
3297 g_Sound_PlayExAt('SOUND_IGNITE', FObj.X, FObj.Y);
3298 FFireTime := Timeout;
3299 FFireAttacker := Attacker;
3300 if g_Game_IsNet and g_Game_IsServer then
3301 MH_SEND_PlayerStats(FUID);
3302 end;
3304 procedure TPlayer.Jump();
3305 begin
3306 if gFly or FJetpack then
3307 begin
3308 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
3309 if FObj.Vel.Y > -VEL_FLY then
3310 FObj.Vel.Y := FObj.Vel.Y - 3;
3311 if FJetpack then
3312 begin
3313 if FJetFuel > 0 then
3314 Dec(FJetFuel);
3315 if (FJetFuel < 1) and g_Game_IsServer then
3316 begin
3317 FJetpack := False;
3318 JetpackOff;
3319 if g_Game_IsNet then
3320 MH_SEND_PlayerStats(FUID);
3321 end;
3322 end;
3323 Exit;
3324 end;
3326 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
3327 if FGhost then
3328 FCanJetpack := False;
3330 // Ïðûãàåì èëè âñïëûâàåì:
3331 if (CollideLevel(0, 1) or
3332 g_Map_CollidePanel(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y+36, PLAYER_RECT.Width,
3333 PLAYER_RECT.Height-33, PANEL_STEP, False)
3334 ) and (FObj.Accel.Y = 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
3335 begin
3336 FObj.Vel.Y := -VEL_JUMP;
3337 FCanJetpack := False;
3338 end
3339 else
3340 begin
3341 if BodyInLiquid(0, 0) then
3342 FObj.Vel.Y := -VEL_SW
3343 else if (FJetFuel > 0) and FCanJetpack and
3344 g_Game_IsServer and (not g_Obj_CollideLiquid(@FObj, 0, 0)) then
3345 begin
3346 FJetpack := True;
3347 JetpackOn;
3348 if g_Game_IsNet then
3349 MH_SEND_PlayerStats(FUID);
3350 end;
3351 end;
3352 end;
3354 procedure TPlayer.Kill(KillType: Byte; SpawnerUID: Word; t: Byte);
3355 var
3356 a, i, k, ab, ar: Byte;
3357 s: String;
3358 mon: TMonster;
3359 plr: TPlayer;
3360 srv, netsrv: Boolean;
3361 DoFrags: Boolean;
3362 OldLR: Byte;
3363 KP: TPlayer;
3364 it: PItem;
3366 procedure PushItem(t: Byte);
3367 var
3368 id: DWORD;
3369 begin
3370 id := g_Items_Create(FObj.X, FObj.Y, t, True, False);
3371 it := g_Items_ByIdx(id);
3372 if KillType = K_EXTRAHARDKILL then // -7..+7; -8..0
3373 begin
3374 g_Obj_Push(@it.Obj, (FObj.Vel.X div 2)-7+Random(15),
3375 (FObj.Vel.Y div 2)-Random(9));
3376 it.positionChanged(); // this updates spatial accelerators
3377 end
3378 else
3379 begin
3380 if KillType = K_HARDKILL then // -5..+5; -5..0
3381 begin
3382 g_Obj_Push(@it.Obj, (FObj.Vel.X div 2)-5+Random(11),
3383 (FObj.Vel.Y div 2)-Random(6));
3384 end
3385 else // -3..+3; -3..0
3386 begin
3387 g_Obj_Push(@it.Obj, (FObj.Vel.X div 2)-3+Random(7),
3388 (FObj.Vel.Y div 2)-Random(4));
3389 end;
3390 it.positionChanged(); // this updates spatial accelerators
3391 end;
3393 if g_Game_IsNet and g_Game_IsServer then
3394 MH_SEND_ItemSpawn(True, id);
3395 end;
3397 begin
3398 DoFrags := (gGameSettings.MaxLives = 0) or (gGameSettings.GameMode = GM_COOP);
3399 Srv := g_Game_IsServer;
3400 Netsrv := g_Game_IsServer and g_Game_IsNet;
3401 if Srv then FDeath := FDeath + 1;
3402 if FAlive then
3403 begin
3404 if FGhost then
3405 FGhost := False;
3406 if not FPhysics then
3407 FPhysics := True;
3408 FAlive := False;
3409 end;
3410 FShellTimer := -1;
3412 if (gGameSettings.MaxLives > 0) and Srv and (gLMSRespawn = LMS_RESPAWN_NONE) then
3413 begin
3414 if FLives > 0 then FLives := FLives - 1;
3415 if FLives = 0 then FNoRespawn := True;
3416 end;
3418 // Íîìåð òèïà ñìåðòè:
3419 a := 1;
3420 case KillType of
3421 K_SIMPLEKILL: a := 1;
3422 K_HARDKILL: a := 2;
3423 K_EXTRAHARDKILL: a := 3;
3424 K_FALLKILL: a := 4;
3425 end;
3427 // Çâóê ñìåðòè:
3428 if not FModel.PlaySound(MODELSOUND_DIE, a, FObj.X, FObj.Y) then
3429 for i := 1 to 3 do
3430 if FModel.PlaySound(MODELSOUND_DIE, i, FObj.X, FObj.Y) then
3431 Break;
3433 // Âðåìÿ ðåñïàóíà:
3434 if Srv then
3435 case KillType of
3436 K_SIMPLEKILL:
3437 FTime[T_RESPAWN] := gTime + TIME_RESPAWN1;
3438 K_HARDKILL:
3439 FTime[T_RESPAWN] := gTime + TIME_RESPAWN2;
3440 K_EXTRAHARDKILL, K_FALLKILL:
3441 FTime[T_RESPAWN] := gTime + TIME_RESPAWN3;
3442 end;
3444 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3445 case KillType of
3446 K_SIMPLEKILL:
3447 SetAction(A_DIE1);
3448 K_HARDKILL, K_EXTRAHARDKILL:
3449 SetAction(A_DIE2);
3450 end;
3452 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3453 if (KillType <> K_FALLKILL) and (Srv) then
3454 g_Monsters_killedp();
3456 if SpawnerUID = FUID then
3457 begin // Ñàìîóáèëñÿ
3458 if Srv then
3459 begin
3460 if gGameSettings.GameMode = GM_TDM then
3461 Dec(gTeamStat[FTeam].Goals);
3462 if DoFrags or (gGameSettings.GameMode = GM_TDM) then
3463 begin
3464 Dec(FFrags);
3465 FLastFrag := 0;
3466 end;
3467 end;
3468 g_Console_Add(Format(_lc[I_PLAYER_KILL_SELF], [FName]), True);
3469 end
3470 else
3471 if g_GetUIDType(SpawnerUID) = UID_PLAYER then
3472 begin // Óáèò äðóãèì èãðîêîì
3473 KP := g_Player_Get(SpawnerUID);
3474 if (KP <> nil) and Srv then
3475 begin
3476 if (DoFrags or (gGameSettings.GameMode = GM_TDM)) then
3477 if SameTeam(FUID, SpawnerUID) then
3478 begin
3479 Dec(KP.FFrags);
3480 KP.FLastFrag := 0;
3481 end else
3482 begin
3483 Inc(KP.FFrags);
3484 KP.FragCombo();
3485 end;
3487 if (gGameSettings.GameMode = GM_TDM) and DoFrags then
3488 Inc(gTeamStat[KP.Team].Goals,
3489 IfThen(SameTeam(FUID, SpawnerUID), -1, 1));
3491 if netsrv then MH_SEND_PlayerStats(SpawnerUID);
3492 end;
3494 plr := g_Player_Get(SpawnerUID);
3495 if plr = nil then
3496 s := '?'
3497 else
3498 s := plr.FName;
3500 case KillType of
3501 K_HARDKILL:
3502 g_Console_Add(Format(_lc[I_PLAYER_KILL_EXTRAHARD_2],
3503 [FName, s]),
3504 gShowKillMsg);
3505 K_EXTRAHARDKILL:
3506 g_Console_Add(Format(_lc[I_PLAYER_KILL_EXTRAHARD_1],
3507 [FName, s]),
3508 gShowKillMsg);
3509 else
3510 g_Console_Add(Format(_lc[I_PLAYER_KILL],
3511 [FName, s]),
3512 gShowKillMsg);
3513 end;
3514 end
3515 else if g_GetUIDType(SpawnerUID) = UID_MONSTER then
3516 begin // Óáèò ìîíñòðîì
3517 mon := g_Monsters_ByUID(SpawnerUID);
3518 if mon = nil then
3519 s := '?'
3520 else
3521 s := g_Mons_GetKilledByTypeId(mon.MonsterType);
3523 case KillType of
3524 K_HARDKILL:
3525 g_Console_Add(Format(_lc[I_PLAYER_KILL_EXTRAHARD_2],
3526 [FName, s]),
3527 gShowKillMsg);
3528 K_EXTRAHARDKILL:
3529 g_Console_Add(Format(_lc[I_PLAYER_KILL_EXTRAHARD_1],
3530 [FName, s]),
3531 gShowKillMsg);
3532 else
3533 g_Console_Add(Format(_lc[I_PLAYER_KILL],
3534 [FName, s]),
3535 gShowKillMsg);
3536 end;
3537 end
3538 else // Îñîáûå òèïû ñìåðòè
3539 case t of
3540 HIT_DISCON: ;
3541 HIT_SELF: g_Console_Add(Format(_lc[I_PLAYER_KILL_SELF], [FName]), True);
3542 HIT_FALL: g_Console_Add(Format(_lc[I_PLAYER_KILL_FALL], [FName]), True);
3543 HIT_WATER: g_Console_Add(Format(_lc[I_PLAYER_KILL_WATER], [FName]), True);
3544 HIT_ACID: g_Console_Add(Format(_lc[I_PLAYER_KILL_ACID], [FName]), True);
3545 HIT_TRAP: g_Console_Add(Format(_lc[I_PLAYER_KILL_TRAP], [FName]), True);
3546 else g_Console_Add(Format(_lc[I_PLAYER_DIED], [FName]), True);
3547 end;
3549 if Srv then
3550 begin
3551 // Âûáðîñ îðóæèÿ:
3552 for a := WP_FIRST to WP_LAST do
3553 if FWeapon[a] then
3554 begin
3555 case a of
3556 WEAPON_SAW: i := ITEM_WEAPON_SAW;
3557 WEAPON_SHOTGUN1: i := ITEM_WEAPON_SHOTGUN1;
3558 WEAPON_SHOTGUN2: i := ITEM_WEAPON_SHOTGUN2;
3559 WEAPON_CHAINGUN: i := ITEM_WEAPON_CHAINGUN;
3560 WEAPON_ROCKETLAUNCHER: i := ITEM_WEAPON_ROCKETLAUNCHER;
3561 WEAPON_PLASMA: i := ITEM_WEAPON_PLASMA;
3562 WEAPON_BFG: i := ITEM_WEAPON_BFG;
3563 WEAPON_SUPERPULEMET: i := ITEM_WEAPON_SUPERPULEMET;
3564 WEAPON_FLAMETHROWER: i := ITEM_WEAPON_FLAMETHROWER;
3565 else i := 0;
3566 end;
3568 if i <> 0 then
3569 PushItem(i);
3570 end;
3572 // Âûáðîñ ðþêçàêà:
3573 if R_ITEM_BACKPACK in FRulez then
3574 PushItem(ITEM_AMMO_BACKPACK);
3576 // Âûáðîñ ðàêåòíîãî ðàíöà:
3577 if FJetFuel > 0 then
3578 PushItem(ITEM_JETPACK);
3580 // Âûáðîñ êëþ÷åé:
3581 if (not (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF])) or
3582 (not LongBool(gGameSettings.Options and GAME_OPTION_DMKEYS)) then
3583 begin
3584 if R_KEY_RED in FRulez then
3585 PushItem(ITEM_KEY_RED);
3587 if R_KEY_GREEN in FRulez then
3588 PushItem(ITEM_KEY_GREEN);
3590 if R_KEY_BLUE in FRulez then
3591 PushItem(ITEM_KEY_BLUE);
3592 end;
3594 // Âûáðîñ ôëàãà:
3595 DropFlag(KillType = K_FALLKILL);
3596 end;
3598 FCorpse := g_Player_CreateCorpse(Self);
3600 if Srv and (gGameSettings.MaxLives > 0) and FNoRespawn and
3601 (gLMSRespawn = LMS_RESPAWN_NONE) then
3602 begin
3603 a := 0;
3604 k := 0;
3605 ar := 0;
3606 ab := 0;
3607 for i := Low(gPlayers) to High(gPlayers) do
3608 begin
3609 if gPlayers[i] = nil then continue;
3610 if (not gPlayers[i].FNoRespawn) and (not gPlayers[i].FSpectator) then
3611 begin
3612 Inc(a);
3613 if gPlayers[i].FTeam = TEAM_RED then Inc(ar)
3614 else if gPlayers[i].FTeam = TEAM_BLUE then Inc(ab);
3615 k := i;
3616 end;
3617 end;
3619 OldLR := gLMSRespawn;
3620 if (gGameSettings.GameMode = GM_COOP) then
3621 begin
3622 if (a = 0) then
3623 begin
3624 // everyone is dead, restart the map
3625 g_Game_Message(_lc[I_MESSAGE_LMS_LOSE], 144);
3626 if Netsrv then
3627 MH_SEND_GameEvent(NET_EV_LMS_LOSE);
3628 gLMSRespawn := LMS_RESPAWN_FINAL;
3629 gLMSRespawnTime := gTime + 5000;
3630 end
3631 else if (a = 1) then
3632 begin
3633 if (gPlayers[k] <> nil) and not (gPlayers[k] is TBot) then
3634 if (gPlayers[k] = gPlayer1) or
3635 (gPlayers[k] = gPlayer2) then
3636 g_Console_Add('*** ' + _lc[I_MESSAGE_LMS_SURVIVOR] + ' ***', True)
3637 else if Netsrv and (gPlayers[k].FClientID >= 0) then
3638 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR, 0, 'N', gPlayers[k].FClientID);
3639 end;
3640 end
3641 else if (gGameSettings.GameMode = GM_TDM) then
3642 begin
3643 if (ab = 0) and (ar <> 0) then
3644 begin
3645 // blu team ded
3646 g_Game_Message(Format(_lc[I_MESSAGE_TLMS_WIN], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 144);
3647 if Netsrv then
3648 MH_SEND_GameEvent(NET_EV_TLMS_WIN, TEAM_RED);
3649 Inc(gTeamStat[TEAM_RED].Goals);
3650 gLMSRespawn := LMS_RESPAWN_FINAL;
3651 gLMSRespawnTime := gTime + 5000;
3652 end
3653 else if (ar = 0) and (ab <> 0) then
3654 begin
3655 // red team ded
3656 g_Game_Message(Format(_lc[I_MESSAGE_TLMS_WIN], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 144);
3657 if Netsrv then
3658 MH_SEND_GameEvent(NET_EV_TLMS_WIN, TEAM_BLUE);
3659 Inc(gTeamStat[TEAM_BLUE].Goals);
3660 gLMSRespawn := LMS_RESPAWN_FINAL;
3661 gLMSRespawnTime := gTime + 5000;
3662 end
3663 else if (ar = 0) and (ab = 0) then
3664 begin
3665 // everyone ded
3666 g_Game_Message(_lc[I_GAME_WIN_DRAW], 144);
3667 if Netsrv then
3668 MH_SEND_GameEvent(NET_EV_LMS_DRAW, 0, FName);
3669 gLMSRespawn := LMS_RESPAWN_FINAL;
3670 gLMSRespawnTime := gTime + 5000;
3671 end;
3672 end
3673 else if (gGameSettings.GameMode = GM_DM) then
3674 begin
3675 if (a = 1) then
3676 begin
3677 if gPlayers[k] <> nil then
3678 with gPlayers[k] do
3679 begin
3680 // survivor is the winner
3681 g_Game_Message(Format(_lc[I_MESSAGE_LMS_WIN], [AnsiUpperCase(FName)]), 144);
3682 if Netsrv then
3683 MH_SEND_GameEvent(NET_EV_LMS_WIN, 0, FName);
3684 Inc(FFrags);
3685 end;
3686 gLMSRespawn := LMS_RESPAWN_FINAL;
3687 gLMSRespawnTime := gTime + 5000;
3688 end
3689 else if (a = 0) then
3690 begin
3691 // everyone is dead, restart the map
3692 g_Game_Message(_lc[I_GAME_WIN_DRAW], 144);
3693 if Netsrv then
3694 MH_SEND_GameEvent(NET_EV_LMS_DRAW, 0, FName);
3695 gLMSRespawn := LMS_RESPAWN_FINAL;
3696 gLMSRespawnTime := gTime + 5000;
3697 end;
3698 end;
3699 if srv and (OldLR = LMS_RESPAWN_NONE) and (gLMSRespawn > LMS_RESPAWN_NONE) then
3700 begin
3701 if NetMode = NET_SERVER then
3702 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, gLMSRespawnTime - gTime)
3703 else
3704 g_Console_Add(Format(_lc[I_MSG_WARMUP_START], [(gLMSRespawnTime - gTime) div 1000]), True);
3705 end;
3706 end;
3708 if Netsrv then
3709 begin
3710 MH_SEND_PlayerStats(FUID);
3711 MH_SEND_PlayerDeath(FUID, KillType, t, SpawnerUID);
3712 if gGameSettings.GameMode = GM_TDM then MH_SEND_GameStats;
3713 end;
3715 if srv and FNoRespawn then Spectate(True);
3716 FWantsInGame := True;
3717 end;
3719 function TPlayer.BodyInLiquid(XInc, YInc: Integer): Boolean;
3720 begin
3721 Result := g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc, PLAYER_RECT.Width,
3722 PLAYER_RECT.Height-20, PANEL_WATER or PANEL_ACID1 or PANEL_ACID2, False);
3723 end;
3725 function TPlayer.BodyInAcid(XInc, YInc: Integer): Boolean;
3726 begin
3727 Result := g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc, PLAYER_RECT.Width,
3728 PLAYER_RECT.Height-20, PANEL_ACID1 or PANEL_ACID2, False);
3729 end;
3731 procedure TPlayer.MakeBloodSimple(Count: Word);
3732 begin
3733 g_GFX_Blood(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)+8,
3734 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2),
3735 Count div 2, 3, -1, 16, (PLAYER_RECT.Height*2 div 3),
3736 FModel.Blood.R, FModel.Blood.G, FModel.Blood.B, FModel.Blood.Kind);
3737 g_GFX_Blood(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-8,
3738 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2),
3739 Count div 2, -3, -1, 16, (PLAYER_RECT.Height*2) div 3,
3740 FModel.Blood.R, FModel.Blood.G, FModel.Blood.B, FModel.Blood.Kind);
3741 end;
3743 procedure TPlayer.MakeBloodVector(Count: Word; VelX, VelY: Integer);
3744 begin
3745 g_GFX_Blood(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2),
3746 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2),
3747 Count, VelX, VelY, 16, (PLAYER_RECT.Height*2) div 3,
3748 FModel.Blood.R, FModel.Blood.G, FModel.Blood.B, FModel.Blood.Kind);
3749 end;
3751 procedure TPlayer.ProcessWeaponAction(Action: Byte);
3752 begin
3753 if g_Game_IsClient then Exit;
3754 case Action of
3755 WP_PREV: PrevWeapon();
3756 WP_NEXT: NextWeapon();
3757 end;
3758 end;
3760 procedure TPlayer.QueueWeaponSwitch(Weapon: Byte);
3761 begin
3762 if g_Game_IsClient then Exit;
3763 if Weapon > High(FWeapon) then Exit;
3764 FNextWeap := FNextWeap or (1 shl Weapon);
3765 end;
3767 procedure TPlayer.resetWeaponQueue ();
3768 begin
3769 FNextWeap := 0;
3770 FNextWeapDelay := 0;
3771 end;
3773 function TPlayer.hasAmmoForWeapon (weapon: Byte): Boolean;
3774 begin
3775 result := false;
3776 case weapon of
3777 WEAPON_KASTET, WEAPON_SAW: result := true;
3778 WEAPON_SHOTGUN1, WEAPON_SHOTGUN2, WEAPON_SUPERPULEMET: result := (FAmmo[A_SHELLS] > 0);
3779 WEAPON_PISTOL, WEAPON_CHAINGUN: result := (FAmmo[A_BULLETS] > 0);
3780 WEAPON_ROCKETLAUNCHER: result := (FAmmo[A_ROCKETS] > 0);
3781 WEAPON_PLASMA, WEAPON_BFG: result := (FAmmo[A_CELLS] > 0);
3782 WEAPON_FLAMETHROWER: result := (FAmmo[A_FUEL] > 0);
3783 else result := (weapon < length(FWeapon));
3784 end;
3785 end;
3787 function TPlayer.hasAmmoForShooting (weapon: Byte): Boolean;
3788 begin
3789 result := false;
3790 case weapon of
3791 WEAPON_KASTET, WEAPON_SAW: result := true;
3792 WEAPON_SHOTGUN1, WEAPON_SUPERPULEMET: result := (FAmmo[A_SHELLS] > 0);
3793 WEAPON_SHOTGUN2: result := (FAmmo[A_SHELLS] > 1);
3794 WEAPON_PISTOL, WEAPON_CHAINGUN: result := (FAmmo[A_BULLETS] > 0);
3795 WEAPON_ROCKETLAUNCHER: result := (FAmmo[A_ROCKETS] > 0);
3796 WEAPON_PLASMA: result := (FAmmo[A_CELLS] > 0);
3797 WEAPON_BFG: result := (FAmmo[A_CELLS] >= 40);
3798 WEAPON_FLAMETHROWER: result := (FAmmo[A_FUEL] > 0);
3799 else result := (weapon < length(FWeapon));
3800 end;
3801 end;
3803 function TPlayer.shouldSwitch (weapon: Byte; hadWeapon: Boolean): Boolean;
3804 begin
3805 result := false;
3806 if (weapon > WP_LAST + 1) then
3807 begin
3808 result := false;
3809 exit;
3810 end;
3811 if (FWeapSwitchMode = 1) and not hadWeapon then
3812 result := true
3813 else if (FWeapSwitchMode = 2) then
3814 result := (FWeapPreferences[weapon] > FWeapPreferences[FCurrWeap]);
3815 end;
3817 // return 255 for "no switch"
3818 function TPlayer.getNextWeaponIndex (): Byte;
3819 var
3820 i: Word;
3821 wantThisWeapon: array[0..64] of Boolean;
3822 wwc: Integer = 0; //HACK!
3823 dir, cwi: Integer;
3824 begin
3825 result := 255; // default result: "no switch"
3826 //e_LogWriteFln('FSWITCHTOEMPTY: %s', [FSwitchToEmpty], TMsgType.Notify);
3827 // had weapon cycling on previous frame? remove that flag
3828 if (FNextWeap and $2000) <> 0 then
3829 begin
3830 FNextWeap := FNextWeap and $1FFF;
3831 FNextWeapDelay := 0;
3832 end;
3833 // cycling has priority
3834 if (FNextWeap and $C000) <> 0 then
3835 begin
3836 if (FNextWeap and $8000) <> 0 then
3837 dir := 1
3838 else
3839 dir := -1;
3840 FNextWeap := FNextWeap or $2000; // we need this
3841 if FNextWeapDelay > 0 then
3842 exit; // cooldown time
3843 cwi := FCurrWeap;
3844 for i := 0 to High(FWeapon) do
3845 begin
3846 cwi := (cwi+length(FWeapon)+dir) mod length(FWeapon);
3847 if FWeapon[cwi] and maySwitch(cwi) then
3848 begin
3849 //e_LogWriteFln(' SWITCH: cur=%d; new=%d %s %s', [FCurrWeap, cwi, FSwitchToEmpty, hasAmmoForWeapon(cwi)], TMsgType.Notify);
3850 result := Byte(cwi);
3851 FNextWeapDelay := WEAPON_DELAY;
3852 exit;
3853 end;
3854 end;
3855 resetWeaponQueue();
3856 exit;
3857 end;
3858 // no cycling
3859 for i := 0 to High(wantThisWeapon) do
3860 wantThisWeapon[i] := false;
3861 for i := 0 to High(FWeapon) do
3862 if (FNextWeap and (1 shl i)) <> 0 then
3863 begin
3864 wantThisWeapon[i] := true;
3865 Inc(wwc);
3866 end;
3868 // exclude currently selected weapon from the set
3869 wantThisWeapon[FCurrWeap] := false;
3870 // slow down alterations a little
3871 if wwc > 1 then
3872 begin
3873 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3874 // more than one weapon requested, assume "alteration" and check alteration delay
3875 if FNextWeapDelay > 0 then
3876 begin
3877 FNextWeap := 0;
3878 exit;
3879 end; // yeah
3880 end;
3881 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3882 // but clear all counters if no weapon should be switched
3883 if wwc < 1 then
3884 begin
3885 resetWeaponQueue();
3886 exit;
3887 end;
3888 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3889 // try weapons in descending order
3890 for i := High(FWeapon) downto 0 do
3891 begin
3892 if wantThisWeapon[i] and FWeapon[i] and ((wwc = 1) or hasAmmoForWeapon(i)) then
3893 begin
3894 // i found her!
3895 result := Byte(i);
3896 resetWeaponQueue();
3897 FNextWeapDelay := WEAPON_DELAY * 2; // anyway, 'cause why not
3898 //e_LogWriteFln('FOUND %s %s %s', [result, FSwitchToEmpty, hasAmmoForWeapon(i)], TMsgType.Notify);
3899 exit;
3900 end;
3901 end;
3902 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3903 resetWeaponQueue();
3904 end;
3906 procedure TPlayer.RealizeCurrentWeapon();
3907 function switchAllowed (): Boolean;
3908 var
3909 i: Byte;
3910 begin
3911 result := false;
3912 if FBFGFireCounter <> -1 then
3913 exit;
3914 if FTime[T_SWITCH] > gTime then
3915 exit;
3916 for i := WP_FIRST to WP_LAST do
3917 if FReloading[i] > 0 then
3918 exit;
3919 result := true;
3920 end;
3922 var
3923 nw: Byte;
3924 begin
3925 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3926 //FNextWeap := FNextWeap and $1FFF;
3927 if FNextWeapDelay > 0 then Dec(FNextWeapDelay); // "alteration delay"
3929 if not switchAllowed then
3930 begin
3931 //HACK for weapon cycling
3932 if (FNextWeap and $E000) <> 0 then FNextWeap := 0;
3933 exit;
3934 end;
3936 nw := getNextWeaponIndex();
3937 //
3938 if nw = 255 then exit; // don't reset anything here
3939 if nw > High(FWeapon) then
3940 begin
3941 // don't forget to reset queue here!
3942 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
3943 resetWeaponQueue();
3944 exit;
3945 end;
3947 if FWeapon[nw] then
3948 begin
3949 FCurrWeap := nw;
3950 FTime[T_SWITCH] := gTime+156;
3951 if FCurrWeap = WEAPON_SAW then FSawSoundSelect.PlayAt(FObj.X, FObj.Y);
3952 FModel.SetWeapon(FCurrWeap);
3953 if g_Game_IsNet then MH_SEND_PlayerStats(FUID);
3954 end;
3955 end;
3957 procedure TPlayer.NextWeapon();
3958 begin
3959 if g_Game_IsClient then Exit;
3960 FNextWeap := $8000;
3961 end;
3963 procedure TPlayer.PrevWeapon();
3964 begin
3965 if g_Game_IsClient then Exit;
3966 FNextWeap := $4000;
3967 end;
3969 procedure TPlayer.SetWeapon(W: Byte);
3970 begin
3971 if FCurrWeap <> W then
3972 if W = WEAPON_SAW then
3973 FSawSoundSelect.PlayAt(FObj.X, FObj.Y);
3975 FCurrWeap := W;
3976 FModel.SetWeapon(CurrWeap);
3977 resetWeaponQueue();
3978 end;
3980 function TPlayer.PickItem(ItemType: Byte; arespawn: Boolean; var remove: Boolean): Boolean;
3982 function allowBerserkSwitching (): Boolean;
3983 begin
3984 if (FBFGFireCounter <> -1) then begin result := false; exit; end;
3985 result := true;
3986 if gBerserkAutoswitch then exit;
3987 if not conIsCheatsEnabled then exit;
3988 result := false;
3989 end;
3991 var
3992 a: Boolean;
3993 switchWeapon: Byte = 255;
3994 hadWeapon: Boolean = False;
3995 begin
3996 Result := False;
3997 if g_Game_IsClient then Exit;
3999 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
4000 a := LongBool(gGameSettings.Options and GAME_OPTION_WEAPONSTAY) and arespawn;
4001 remove := not a;
4002 case ItemType of
4003 ITEM_MEDKIT_SMALL:
4004 if (FHealth < PLAYER_HP_SOFT) or (FFireTime > 0) then
4005 begin
4006 if FHealth < PLAYER_HP_SOFT then IncMax(FHealth, 10, PLAYER_HP_SOFT);
4007 Result := True;
4008 remove := True;
4009 FFireTime := 0;
4010 if gFlash = 2 then Inc(FPickup, 5);
4011 end;
4013 ITEM_MEDKIT_LARGE:
4014 if (FHealth < PLAYER_HP_SOFT) or (FFireTime > 0) then
4015 begin
4016 if FHealth < PLAYER_HP_SOFT then IncMax(FHealth, 25, PLAYER_HP_SOFT);
4017 Result := True;
4018 remove := True;
4019 FFireTime := 0;
4020 if gFlash = 2 then Inc(FPickup, 5);
4021 end;
4023 ITEM_ARMOR_GREEN:
4024 if FArmor < PLAYER_AP_SOFT then
4025 begin
4026 FArmor := PLAYER_AP_SOFT;
4027 Result := True;
4028 remove := True;
4029 if gFlash = 2 then Inc(FPickup, 5);
4030 end;
4032 ITEM_ARMOR_BLUE:
4033 if FArmor < PLAYER_AP_LIMIT then
4034 begin
4035 FArmor := PLAYER_AP_LIMIT;
4036 Result := True;
4037 remove := True;
4038 if gFlash = 2 then Inc(FPickup, 5);
4039 end;
4041 ITEM_SPHERE_BLUE:
4042 if (FHealth < PLAYER_HP_LIMIT) or (FFireTime > 0) then
4043 begin
4044 if FHealth < PLAYER_HP_LIMIT then IncMax(FHealth, 100, PLAYER_HP_LIMIT);
4045 Result := True;
4046 remove := True;
4047 FFireTime := 0;
4048 if gFlash = 2 then Inc(FPickup, 5);
4049 end;
4051 ITEM_SPHERE_WHITE:
4052 if (FHealth < PLAYER_HP_LIMIT) or (FArmor < PLAYER_AP_LIMIT) or (FFireTime > 0) then
4053 begin
4054 if FHealth < PLAYER_HP_LIMIT then
4055 FHealth := PLAYER_HP_LIMIT;
4056 if FArmor < PLAYER_AP_LIMIT then
4057 FArmor := PLAYER_AP_LIMIT;
4058 Result := True;
4059 remove := True;
4060 FFireTime := 0;
4061 if gFlash = 2 then Inc(FPickup, 5);
4062 end;
4064 ITEM_WEAPON_SAW:
4065 if (not FWeapon[WEAPON_SAW]) or ((not arespawn) and (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF])) then
4066 begin
4067 hadWeapon := FWeapon[WEAPON_SAW];
4068 switchWeapon := WEAPON_SAW;
4069 FWeapon[WEAPON_SAW] := True;
4070 Result := True;
4071 if gFlash = 2 then Inc(FPickup, 5);
4072 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
4073 end;
4075 ITEM_WEAPON_SHOTGUN1:
4076 if (FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS]) or not FWeapon[WEAPON_SHOTGUN1] then
4077 begin
4078 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
4079 if a and FWeapon[WEAPON_SHOTGUN1] then Exit;
4080 hadWeapon := FWeapon[WEAPON_SHOTGUN1];
4081 switchWeapon := WEAPON_SHOTGUN1;
4082 IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
4083 FWeapon[WEAPON_SHOTGUN1] := True;
4084 Result := True;
4085 if gFlash = 2 then Inc(FPickup, 5);
4086 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
4087 end;
4089 ITEM_WEAPON_SHOTGUN2:
4090 if (FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS]) or not FWeapon[WEAPON_SHOTGUN2] then
4091 begin
4092 if a and FWeapon[WEAPON_SHOTGUN2] then Exit;
4093 hadWeapon := FWeapon[WEAPON_SHOTGUN2];
4094 switchWeapon := WEAPON_SHOTGUN2;
4095 IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
4096 FWeapon[WEAPON_SHOTGUN2] := True;
4097 Result := True;
4098 if gFlash = 2 then Inc(FPickup, 5);
4099 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
4100 end;
4102 ITEM_WEAPON_CHAINGUN:
4103 if (FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS]) or not FWeapon[WEAPON_CHAINGUN] then
4104 begin
4105 if a and FWeapon[WEAPON_CHAINGUN] then Exit;
4106 hadWeapon := FWeapon[WEAPON_CHAINGUN];
4107 switchWeapon := WEAPON_CHAINGUN;
4108 IncMax(FAmmo[A_BULLETS], 50, FMaxAmmo[A_BULLETS]);
4109 FWeapon[WEAPON_CHAINGUN] := True;
4110 Result := True;
4111 if gFlash = 2 then Inc(FPickup, 5);
4112 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
4113 end;
4115 ITEM_WEAPON_ROCKETLAUNCHER:
4116 if (FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS]) or not FWeapon[WEAPON_ROCKETLAUNCHER] then
4117 begin
4118 if a and FWeapon[WEAPON_ROCKETLAUNCHER] then Exit;
4119 switchWeapon := WEAPON_ROCKETLAUNCHER;
4120 hadWeapon := FWeapon[WEAPON_ROCKETLAUNCHER];
4121 IncMax(FAmmo[A_ROCKETS], 2, FMaxAmmo[A_ROCKETS]);
4122 FWeapon[WEAPON_ROCKETLAUNCHER] := True;
4123 Result := True;
4124 if gFlash = 2 then Inc(FPickup, 5);
4125 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
4126 end;
4128 ITEM_WEAPON_PLASMA:
4129 if (FAmmo[A_CELLS] < FMaxAmmo[A_CELLS]) or not FWeapon[WEAPON_PLASMA] then
4130 begin
4131 if a and FWeapon[WEAPON_PLASMA] then Exit;
4132 switchWeapon := WEAPON_PLASMA;
4133 hadWeapon := FWeapon[WEAPON_PLASMA];
4134 IncMax(FAmmo[A_CELLS], 40, FMaxAmmo[A_CELLS]);
4135 FWeapon[WEAPON_PLASMA] := True;
4136 Result := True;
4137 if gFlash = 2 then Inc(FPickup, 5);
4138 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
4139 end;
4141 ITEM_WEAPON_BFG:
4142 if (FAmmo[A_CELLS] < FMaxAmmo[A_CELLS]) or not FWeapon[WEAPON_BFG] then
4143 begin
4144 if a and FWeapon[WEAPON_BFG] then Exit;
4145 switchWeapon := WEAPON_BFG;
4146 hadWeapon := FWeapon[WEAPON_BFG];
4147 IncMax(FAmmo[A_CELLS], 40, FMaxAmmo[A_CELLS]);
4148 FWeapon[WEAPON_BFG] := True;
4149 Result := True;
4150 if gFlash = 2 then Inc(FPickup, 5);
4151 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
4152 end;
4154 ITEM_WEAPON_SUPERPULEMET:
4155 if (FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS]) or not FWeapon[WEAPON_SUPERPULEMET] then
4156 begin
4157 if a and FWeapon[WEAPON_SUPERPULEMET] then Exit;
4158 switchWeapon := WEAPON_SUPERPULEMET;
4159 hadWeapon := FWeapon[WEAPON_SUPERPULEMET];
4160 IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
4161 FWeapon[WEAPON_SUPERPULEMET] := True;
4162 Result := True;
4163 if gFlash = 2 then Inc(FPickup, 5);
4164 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
4165 end;
4167 ITEM_WEAPON_FLAMETHROWER:
4168 if (FAmmo[A_FUEL] < FMaxAmmo[A_FUEL]) or not FWeapon[WEAPON_FLAMETHROWER] then
4169 begin
4170 if a and FWeapon[WEAPON_FLAMETHROWER] then Exit;
4171 switchWeapon := WEAPON_FLAMETHROWER;
4172 hadWeapon := FWeapon[WEAPON_FLAMETHROWER];
4173 IncMax(FAmmo[A_FUEL], 100, FMaxAmmo[A_FUEL]);
4174 FWeapon[WEAPON_FLAMETHROWER] := True;
4175 Result := True;
4176 if gFlash = 2 then Inc(FPickup, 5);
4177 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
4178 end;
4180 ITEM_AMMO_BULLETS:
4181 if FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS] then
4182 begin
4183 IncMax(FAmmo[A_BULLETS], 10, FMaxAmmo[A_BULLETS]);
4184 Result := True;
4185 remove := True;
4186 if gFlash = 2 then Inc(FPickup, 5);
4187 end;
4189 ITEM_AMMO_BULLETS_BOX:
4190 if FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS] then
4191 begin
4192 IncMax(FAmmo[A_BULLETS], 50, FMaxAmmo[A_BULLETS]);
4193 Result := True;
4194 remove := True;
4195 if gFlash = 2 then Inc(FPickup, 5);
4196 end;
4198 ITEM_AMMO_SHELLS:
4199 if FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS] then
4200 begin
4201 IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
4202 Result := True;
4203 remove := True;
4204 if gFlash = 2 then Inc(FPickup, 5);
4205 end;
4207 ITEM_AMMO_SHELLS_BOX:
4208 if FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS] then
4209 begin
4210 IncMax(FAmmo[A_SHELLS], 25, FMaxAmmo[A_SHELLS]);
4211 Result := True;
4212 remove := True;
4213 if gFlash = 2 then Inc(FPickup, 5);
4214 end;
4216 ITEM_AMMO_ROCKET:
4217 if FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS] then
4218 begin
4219 IncMax(FAmmo[A_ROCKETS], 1, FMaxAmmo[A_ROCKETS]);
4220 Result := True;
4221 remove := True;
4222 if gFlash = 2 then Inc(FPickup, 5);
4223 end;
4225 ITEM_AMMO_ROCKET_BOX:
4226 if FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS] then
4227 begin
4228 IncMax(FAmmo[A_ROCKETS], 5, FMaxAmmo[A_ROCKETS]);
4229 Result := True;
4230 remove := True;
4231 if gFlash = 2 then Inc(FPickup, 5);
4232 end;
4234 ITEM_AMMO_CELL:
4235 if FAmmo[A_CELLS] < FMaxAmmo[A_CELLS] then
4236 begin
4237 IncMax(FAmmo[A_CELLS], 40, FMaxAmmo[A_CELLS]);
4238 Result := True;
4239 remove := True;
4240 if gFlash = 2 then Inc(FPickup, 5);
4241 end;
4243 ITEM_AMMO_CELL_BIG:
4244 if FAmmo[A_CELLS] < FMaxAmmo[A_CELLS] then
4245 begin
4246 IncMax(FAmmo[A_CELLS], 100, FMaxAmmo[A_CELLS]);
4247 Result := True;
4248 remove := True;
4249 if gFlash = 2 then Inc(FPickup, 5);
4250 end;
4252 ITEM_AMMO_FUELCAN:
4253 if FAmmo[A_FUEL] < FMaxAmmo[A_FUEL] then
4254 begin
4255 IncMax(FAmmo[A_FUEL], 100, FMaxAmmo[A_FUEL]);
4256 Result := True;
4257 remove := True;
4258 if gFlash = 2 then Inc(FPickup, 5);
4259 end;
4261 ITEM_AMMO_BACKPACK:
4262 if not(R_ITEM_BACKPACK in FRulez) or
4263 (FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS]) or
4264 (FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS]) or
4265 (FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS]) or
4266 (FAmmo[A_CELLS] < FMaxAmmo[A_CELLS]) or
4267 (FAmmo[A_FUEL] < FMaxAmmo[A_FUEL]) then
4268 begin
4269 FMaxAmmo[A_BULLETS] := AmmoLimits[1, A_BULLETS];
4270 FMaxAmmo[A_SHELLS] := AmmoLimits[1, A_SHELLS];
4271 FMaxAmmo[A_ROCKETS] := AmmoLimits[1, A_ROCKETS];
4272 FMaxAmmo[A_CELLS] := AmmoLimits[1, A_CELLS];
4273 FMaxAmmo[A_FUEL] := AmmoLimits[1, A_FUEL];
4275 if FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS] then
4276 IncMax(FAmmo[A_BULLETS], 10, FMaxAmmo[A_BULLETS]);
4277 if FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS] then
4278 IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
4279 if FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS] then
4280 IncMax(FAmmo[A_ROCKETS], 1, FMaxAmmo[A_ROCKETS]);
4281 if FAmmo[A_CELLS] < FMaxAmmo[A_CELLS] then
4282 IncMax(FAmmo[A_CELLS], 40, FMaxAmmo[A_CELLS]);
4283 if FAmmo[A_FUEL] < FMaxAmmo[A_FUEL] then
4284 IncMax(FAmmo[A_FUEL], 50, FMaxAmmo[A_FUEL]);
4286 FRulez := FRulez + [R_ITEM_BACKPACK];
4287 Result := True;
4288 remove := True;
4289 if gFlash = 2 then Inc(FPickup, 5);
4290 end;
4292 ITEM_KEY_RED:
4293 if not(R_KEY_RED in FRulez) then
4294 begin
4295 Include(FRulez, R_KEY_RED);
4296 Result := True;
4297 remove := (gGameSettings.GameMode <> GM_COOP) and (g_Player_GetCount() < 2);
4298 if gFlash = 2 then Inc(FPickup, 5);
4299 if (not remove) and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETITEM');
4300 end;
4302 ITEM_KEY_GREEN:
4303 if not(R_KEY_GREEN in FRulez) then
4304 begin
4305 Include(FRulez, R_KEY_GREEN);
4306 Result := True;
4307 remove := (gGameSettings.GameMode <> GM_COOP) and (g_Player_GetCount() < 2);
4308 if gFlash = 2 then Inc(FPickup, 5);
4309 if (not remove) and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETITEM');
4310 end;
4312 ITEM_KEY_BLUE:
4313 if not(R_KEY_BLUE in FRulez) then
4314 begin
4315 Include(FRulez, R_KEY_BLUE);
4316 Result := True;
4317 remove := (gGameSettings.GameMode <> GM_COOP) and (g_Player_GetCount() < 2);
4318 if gFlash = 2 then Inc(FPickup, 5);
4319 if (not remove) and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETITEM');
4320 end;
4322 ITEM_SUIT:
4323 if FMegaRulez[MR_SUIT] < gTime+PLAYER_SUIT_TIME then
4324 begin
4325 FMegaRulez[MR_SUIT] := gTime+PLAYER_SUIT_TIME;
4326 Result := True;
4327 remove := True;
4328 FFireTime := 0;
4329 if gFlash = 2 then Inc(FPickup, 5);
4330 end;
4332 ITEM_OXYGEN:
4333 if FAir < AIR_MAX then
4334 begin
4335 FAir := AIR_MAX;
4336 Result := True;
4337 remove := True;
4338 if gFlash = 2 then Inc(FPickup, 5);
4339 end;
4341 ITEM_MEDKIT_BLACK:
4342 begin
4343 if not (R_BERSERK in FRulez) then
4344 begin
4345 Include(FRulez, R_BERSERK);
4346 if (shouldSwitch(WP_LAST + 1, false)) then
4347 QueueWeaponSwitch(WEAPON_KASTET);
4348 if gFlash <> 0 then
4349 begin
4350 Inc(FPain, 100);
4351 if gFlash = 2 then Inc(FPickup, 5);
4352 end;
4353 FBerserk := gTime+30000;
4354 Result := True;
4355 remove := True;
4356 FFireTime := 0;
4357 end;
4358 if (FHealth < PLAYER_HP_SOFT) or (FFireTime > 0) then
4359 begin
4360 if FHealth < PLAYER_HP_SOFT then FHealth := PLAYER_HP_SOFT;
4361 FBerserk := gTime+30000;
4362 Result := True;
4363 remove := True;
4364 FFireTime := 0;
4365 end;
4366 end;
4368 ITEM_INVUL:
4369 if FMegaRulez[MR_INVUL] < gTime+PLAYER_INVUL_TIME then
4370 begin
4371 FMegaRulez[MR_INVUL] := gTime+PLAYER_INVUL_TIME;
4372 FSpawnInvul := 0;
4373 Result := True;
4374 remove := True;
4375 if gFlash = 2 then Inc(FPickup, 5);
4376 end;
4378 ITEM_BOTTLE:
4379 if (FHealth < PLAYER_HP_LIMIT) or (FFireTime > 0) then
4380 begin
4381 if FHealth < PLAYER_HP_LIMIT then IncMax(FHealth, 4, PLAYER_HP_LIMIT);
4382 Result := True;
4383 remove := True;
4384 FFireTime := 0;
4385 if gFlash = 2 then Inc(FPickup, 5);
4386 end;
4388 ITEM_HELMET:
4389 if FArmor < PLAYER_AP_LIMIT then
4390 begin
4391 IncMax(FArmor, 5, PLAYER_AP_LIMIT);
4392 Result := True;
4393 remove := True;
4394 if gFlash = 2 then Inc(FPickup, 5);
4395 end;
4397 ITEM_JETPACK:
4398 if FJetFuel < JET_MAX then
4399 begin
4400 FJetFuel := JET_MAX;
4401 Result := True;
4402 remove := True;
4403 if gFlash = 2 then Inc(FPickup, 5);
4404 end;
4406 ITEM_INVIS:
4407 if FMegaRulez[MR_INVIS] < gTime+PLAYER_INVIS_TIME then
4408 begin
4409 FMegaRulez[MR_INVIS] := gTime+PLAYER_INVIS_TIME;
4410 Result := True;
4411 remove := True;
4412 if gFlash = 2 then Inc(FPickup, 5);
4413 end;
4414 end;
4416 if (shouldSwitch(switchWeapon, hadWeapon)) then
4417 QueueWeaponSwitch(switchWeapon);
4418 end;
4420 procedure TPlayer.Touch();
4421 begin
4422 if not FAlive then
4423 Exit;
4424 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4425 if FIamBot then
4426 begin
4427 // Áðîñèòü ôëàã òîâàðèùó:
4428 if gGameSettings.GameMode = GM_CTF then
4429 DropFlag();
4430 end;
4431 end;
4433 procedure TPlayer.Push(vx, vy: Integer);
4434 begin
4435 if (not FPhysics) and FGhost then
4436 Exit;
4437 FObj.Accel.X := FObj.Accel.X + vx;
4438 FObj.Accel.Y := FObj.Accel.Y + vy;
4439 if g_Game_IsNet and g_Game_IsServer then
4440 MH_SEND_PlayerPos(True, FUID, NET_EVERYONE);
4441 end;
4443 procedure TPlayer.Reset(Force: Boolean);
4444 begin
4445 if Force then
4446 FAlive := False;
4448 FSpawned := False;
4449 FTime[T_RESPAWN] := 0;
4450 FTime[T_FLAGCAP] := 0;
4451 FGodMode := False;
4452 FNoTarget := False;
4453 FNoReload := False;
4454 FFrags := 0;
4455 FLastFrag := 0;
4456 FComboEvnt := -1;
4457 FKills := 0;
4458 FMonsterKills := 0;
4459 FDeath := 0;
4460 FSecrets := 0;
4461 FSpawnInvul := 0;
4462 FCorpse := -1;
4463 FReady := False;
4464 if FNoRespawn then
4465 begin
4466 FSpectator := False;
4467 FGhost := False;
4468 FPhysics := True;
4469 FSpectatePlayer := -1;
4470 FNoRespawn := False;
4471 end;
4472 FLives := gGameSettings.MaxLives;
4474 SetFlag(FLAG_NONE);
4475 end;
4477 procedure TPlayer.SoftReset();
4478 begin
4479 ReleaseKeys();
4481 FDamageBuffer := 0;
4482 FSlopeOld := 0;
4483 FIncCamOld := 0;
4484 FIncCam := 0;
4485 FBFGFireCounter := -1;
4486 FShellTimer := -1;
4487 FPain := 0;
4488 FLastHit := 0;
4489 FLastFrag := 0;
4490 FComboEvnt := -1;
4492 SetFlag(FLAG_NONE);
4493 SetAction(A_STAND, True);
4494 end;
4496 function TPlayer.GetRespawnPoint(): Byte;
4497 var
4498 c: Byte;
4499 begin
4500 Result := 255;
4501 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4503 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4504 if gGameSettings.GameMode in [GM_COOP, GM_SINGLE] then
4505 begin
4506 if Self = gPlayer1 then
4507 begin
4508 // player 1 should try to spawn on the player 1 point
4509 if g_Map_GetPointCount(RESPAWNPOINT_PLAYER1) > 0 then
4510 Exit(RESPAWNPOINT_PLAYER1)
4511 else if g_Map_GetPointCount(RESPAWNPOINT_PLAYER2) > 0 then
4512 Exit(RESPAWNPOINT_PLAYER2);
4513 end
4514 else if Self = gPlayer2 then
4515 begin
4516 // player 2 should try to spawn on the player 2 point
4517 if g_Map_GetPointCount(RESPAWNPOINT_PLAYER2) > 0 then
4518 Exit(RESPAWNPOINT_PLAYER2)
4519 else if g_Map_GetPointCount(RESPAWNPOINT_PLAYER1) > 0 then
4520 Exit(RESPAWNPOINT_PLAYER1);
4521 end
4522 else
4523 begin
4524 // other players randomly pick either the first or the second point
4525 c := IfThen((Random(2) = 0), RESPAWNPOINT_PLAYER1, RESPAWNPOINT_PLAYER2);
4526 if g_Map_GetPointCount(c) > 0 then
4527 Exit(c);
4528 // try the other one
4529 c := IfThen((c = RESPAWNPOINT_PLAYER1), RESPAWNPOINT_PLAYER2, RESPAWNPOINT_PLAYER1);
4530 if g_Map_GetPointCount(c) > 0 then
4531 Exit(c);
4532 end;
4533 end;
4535 // Ìÿñîïîâàë
4536 if gGameSettings.GameMode = GM_DM then
4537 begin
4538 // try DM points first
4539 if g_Map_GetPointCount(RESPAWNPOINT_DM) > 0 then
4540 Exit(RESPAWNPOINT_DM);
4541 end;
4543 // Êîìàíäíûå
4544 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
4545 begin
4546 // try team points first
4547 c := RESPAWNPOINT_DM;
4548 if FTeam = TEAM_RED then
4549 c := RESPAWNPOINT_RED
4550 else if FTeam = TEAM_BLUE then
4551 c := RESPAWNPOINT_BLUE;
4552 if g_Map_GetPointCount(c) > 0 then
4553 Exit(c);
4554 end;
4556 // still haven't found a spawnpoint, try random shit
4557 Result := g_Map_GetRandomPointType();
4558 end;
4560 procedure TPlayer.Respawn(Silent: Boolean; Force: Boolean = False);
4561 var
4562 RespawnPoint: TRespawnPoint;
4563 a, b, c: Byte;
4564 Anim: TAnimation;
4565 ID: DWORD;
4566 begin
4567 FSlopeOld := 0;
4568 FIncCamOld := 0;
4569 FIncCam := 0;
4570 FBFGFireCounter := -1;
4571 FShellTimer := -1;
4572 FPain := 0;
4573 FLastHit := 0;
4574 FSpawnInvul := 0;
4575 FCorpse := -1;
4577 if not g_Game_IsServer then
4578 Exit;
4579 if FDummy then
4580 Exit;
4581 FWantsInGame := True;
4582 FJustTeleported := True;
4583 if Force then
4584 begin
4585 FTime[T_RESPAWN] := 0;
4586 FAlive := False;
4587 end;
4588 FNetTime := 0;
4589 // if server changes MaxLives we gotta be ready
4590 if gGameSettings.MaxLives = 0 then FNoRespawn := False;
4592 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4593 if FTime[T_RESPAWN] > gTime then
4594 Exit;
4596 // Ïðîñðàë âñå æèçíè:
4597 if FNoRespawn then
4598 begin
4599 if not FSpectator then Spectate(True);
4600 FWantsInGame := True;
4601 Exit;
4602 end;
4604 if (gGameSettings.GameType <> GT_SINGLE) and (gGameSettings.GameMode <> GM_COOP) then
4605 begin // "Ñâîÿ èãðà"
4606 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4607 FRulez := FRulez-[R_BERSERK];
4608 end
4609 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4610 begin
4611 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4612 FRulez := FRulez-[R_KEY_RED, R_KEY_GREEN, R_KEY_BLUE, R_BERSERK];
4613 end;
4615 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4616 c := GetRespawnPoint();
4618 ReleaseKeys();
4619 SetFlag(FLAG_NONE);
4621 // Âîñêðåøåíèå áåç îðóæèÿ:
4622 if not FAlive then
4623 begin
4624 FHealth := Round(PLAYER_HP_SOFT * (FHandicap / 100));
4625 FArmor := 0;
4626 FAlive := True;
4627 FAir := AIR_DEF;
4628 FJetFuel := 0;
4630 for a := WP_FIRST to WP_LAST do
4631 begin
4632 FWeapon[a] := False;
4633 FReloading[a] := 0;
4634 end;
4636 FWeapon[WEAPON_PISTOL] := True;
4637 FWeapon[WEAPON_KASTET] := True;
4638 FCurrWeap := WEAPON_PISTOL;
4639 resetWeaponQueue();
4641 FModel.SetWeapon(FCurrWeap);
4643 for b := A_BULLETS to A_HIGH do
4644 FAmmo[b] := 0;
4646 FAmmo[A_BULLETS] := 50;
4648 FMaxAmmo[A_BULLETS] := AmmoLimits[0, A_BULLETS];
4649 FMaxAmmo[A_SHELLS] := AmmoLimits[0, A_SHELLS];
4650 FMaxAmmo[A_ROCKETS] := AmmoLimits[0, A_SHELLS];
4651 FMaxAmmo[A_CELLS] := AmmoLimits[0, A_CELLS];
4652 FMaxAmmo[A_FUEL] := AmmoLimits[0, A_FUEL];
4654 if (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF]) and
4655 LongBool(gGameSettings.Options and GAME_OPTION_DMKEYS) then
4656 FRulez := [R_KEY_RED, R_KEY_GREEN, R_KEY_BLUE]
4657 else
4658 FRulez := [];
4659 end;
4661 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4662 if not g_Map_GetPoint(c, RespawnPoint) then
4663 begin
4664 g_FatalError(_lc[I_GAME_ERROR_GET_SPAWN]);
4665 Exit;
4666 end;
4668 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4669 FObj.X := RespawnPoint.X-PLAYER_RECT.X;
4670 FObj.Y := RespawnPoint.Y-PLAYER_RECT.Y;
4671 FObj.oldX := FObj.X; // don't interpolate after respawn
4672 FObj.oldY := FObj.Y;
4673 FObj.Vel.X := 0;
4674 FObj.Vel.Y := 0;
4675 FObj.Accel.X := 0;
4676 FObj.Accel.Y := 0;
4678 FDirection := RespawnPoint.Direction;
4679 if FDirection = TDirection.D_LEFT then
4680 FAngle := 180
4681 else
4682 FAngle := 0;
4684 SetAction(A_STAND, True);
4685 FModel.Direction := FDirection;
4687 for a := Low(FTime) to High(FTime) do
4688 FTime[a] := 0;
4690 for a := Low(FMegaRulez) to High(FMegaRulez) do
4691 FMegaRulez[a] := 0;
4693 // Respawn invulnerability
4694 if (gGameSettings.GameType <> GT_SINGLE) and (gGameSettings.SpawnInvul > 0) then
4695 begin
4696 FMegaRulez[MR_INVUL] := gTime + gGameSettings.SpawnInvul * 1000;
4697 FSpawnInvul := FMegaRulez[MR_INVUL];
4698 end;
4700 FDamageBuffer := 0;
4701 FJetpack := False;
4702 FCanJetpack := False;
4703 FFlaming := False;
4704 FFireTime := 0;
4705 FFirePainTime := 0;
4706 FFireAttacker := 0;
4708 // Àíèìàöèÿ âîçðîæäåíèÿ:
4709 if (not gLoadGameMode) and (not Silent) then
4710 if g_Frames_Get(ID, 'FRAMES_TELEPORT') then
4711 begin
4712 Anim := TAnimation.Create(ID, False, 3);
4713 g_GFX_OnceAnim(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
4714 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32, Anim);
4715 Anim.Free();
4716 end;
4718 FSpectator := False;
4719 FGhost := False;
4720 FPhysics := True;
4721 FSpectatePlayer := -1;
4722 FSpawned := True;
4724 if (gPlayer1 = nil) and (gSpectLatchPID1 = FUID) then
4725 gPlayer1 := self;
4726 if (gPlayer2 = nil) and (gSpectLatchPID2 = FUID) then
4727 gPlayer2 := self;
4729 if g_Game_IsNet then
4730 begin
4731 MH_SEND_PlayerPos(True, FUID, NET_EVERYONE);
4732 MH_SEND_PlayerStats(FUID, NET_EVERYONE);
4733 if not Silent then
4734 MH_SEND_Effect(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
4735 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32,
4736 0, NET_GFX_TELE);
4737 end;
4738 end;
4740 procedure TPlayer.Spectate(NoMove: Boolean = False);
4741 begin
4742 if FAlive then
4743 Kill(K_EXTRAHARDKILL, FUID, HIT_SOME)
4744 else if (not NoMove) then
4745 begin
4746 GameX := gMapInfo.Width div 2;
4747 GameY := gMapInfo.Height div 2;
4748 end;
4749 FXTo := GameX;
4750 FYTo := GameY;
4752 FAlive := False;
4753 FSpectator := True;
4754 FGhost := True;
4755 FPhysics := False;
4756 FWantsInGame := False;
4757 FSpawned := False;
4758 FCorpse := -1;
4760 if FNoRespawn then
4761 begin
4762 if Self = gPlayer1 then
4763 begin
4764 gSpectLatchPID1 := FUID;
4765 gPlayer1 := nil;
4766 end
4767 else if Self = gPlayer2 then
4768 begin
4769 gSpectLatchPID2 := FUID;
4770 gPlayer2 := nil;
4771 end;
4772 end;
4774 if g_Game_IsNet then
4775 MH_SEND_PlayerStats(FUID);
4776 end;
4778 procedure TPlayer.SwitchNoClip;
4779 begin
4780 if not FAlive then
4781 Exit;
4782 FGhost := not FGhost;
4783 FPhysics := not FGhost;
4784 if FGhost then
4785 begin
4786 FXTo := FObj.X;
4787 FYTo := FObj.Y;
4788 end else
4789 begin
4790 FObj.Accel.X := 0;
4791 FObj.Accel.Y := 0;
4792 end;
4793 end;
4795 procedure TPlayer.Run(Direction: TDirection);
4796 var
4797 a, b: Integer;
4798 begin
4799 if MAX_RUNVEL > 8 then
4800 FlySmoke();
4802 // Áåæèì:
4803 if Direction = TDirection.D_LEFT then
4804 begin
4805 if FObj.Vel.X > -MAX_RUNVEL then
4806 FObj.Vel.X := FObj.Vel.X - (MAX_RUNVEL shr 3);
4807 end
4808 else
4809 if FObj.Vel.X < MAX_RUNVEL then
4810 FObj.Vel.X := FObj.Vel.X + (MAX_RUNVEL shr 3);
4812 // Âîçìîæíî, ïèíàåì êóñêè:
4813 if (FObj.Vel.X <> 0) and (gGibs <> nil) then
4814 begin
4815 b := Abs(FObj.Vel.X);
4816 if b > 1 then b := b * (Random(8 div b) + 1);
4817 for a := 0 to High(gGibs) do
4818 begin
4819 if gGibs[a].alive and
4820 g_Obj_Collide(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y+FObj.Rect.Height-4,
4821 FObj.Rect.Width, 8, @gGibs[a].Obj) and (Random(3) = 0) then
4822 begin
4823 // Ïèíàåì êóñêè
4824 if FObj.Vel.X < 0 then
4825 begin
4826 g_Obj_PushA(@gGibs[a].Obj, b, Random(61)+120) // íàëåâî
4827 end
4828 else
4829 begin
4830 g_Obj_PushA(@gGibs[a].Obj, b, Random(61)); // íàïðàâî
4831 end;
4832 gGibs[a].positionChanged(); // this updates spatial accelerators
4833 end;
4834 end;
4835 end;
4837 SetAction(A_WALK);
4838 end;
4840 procedure TPlayer.SeeDown();
4841 begin
4842 SetAction(A_SEEDOWN);
4844 if FDirection = TDirection.D_LEFT then FAngle := ANGLE_LEFTDOWN else FAngle := ANGLE_RIGHTDOWN;
4846 if FIncCam > -120 then DecMin(FIncCam, 5, -120);
4847 end;
4849 procedure TPlayer.SeeUp();
4850 begin
4851 SetAction(A_SEEUP);
4853 if FDirection = TDirection.D_LEFT then FAngle := ANGLE_LEFTUP else FAngle := ANGLE_RIGHTUP;
4855 if FIncCam < 120 then IncMax(FIncCam, 5, 120);
4856 end;
4858 procedure TPlayer.SetAction(Action: Byte; Force: Boolean = False);
4859 var
4860 Prior: Byte;
4861 begin
4862 case Action of
4863 A_WALK: Prior := 3;
4864 A_DIE1: Prior := 5;
4865 A_DIE2: Prior := 5;
4866 A_ATTACK: Prior := 2;
4867 A_SEEUP: Prior := 1;
4868 A_SEEDOWN: Prior := 1;
4869 A_ATTACKUP: Prior := 2;
4870 A_ATTACKDOWN: Prior := 2;
4871 A_PAIN: Prior := 4;
4872 else Prior := 0;
4873 end;
4875 if (Prior > FActionPrior) or Force then
4876 if not ((Prior = 2) and (FCurrWeap = WEAPON_SAW)) then
4877 begin
4878 FActionPrior := Prior;
4879 FActionAnim := Action;
4880 FActionForce := Force;
4881 FActionChanged := True;
4882 end;
4884 if Action in [A_ATTACK, A_ATTACKUP, A_ATTACKDOWN] then FModel.SetFire(True);
4885 end;
4887 function TPlayer.StayOnStep(XInc, YInc: Integer): Boolean;
4888 begin
4889 Result := not g_Map_CollidePanel(FObj.X+PLAYER_RECT.X, FObj.Y+YInc+PLAYER_RECT.Y+PLAYER_RECT.Height-1,
4890 PLAYER_RECT.Width, 1, PANEL_STEP, False)
4891 and g_Map_CollidePanel(FObj.X+PLAYER_RECT.X, FObj.Y+YInc+PLAYER_RECT.Y+PLAYER_RECT.Height,
4892 PLAYER_RECT.Width, 1, PANEL_STEP, False);
4893 end;
4895 function TPlayer.TeleportTo(X, Y: Integer; silent: Boolean; dir: Byte): Boolean;
4896 var
4897 Anim: TAnimation;
4898 ID: DWORD;
4899 begin
4900 Result := False;
4902 if g_CollideLevel(X, Y, PLAYER_RECT.Width, PLAYER_RECT.Height) then
4903 begin
4904 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj.X, FObj.Y);
4905 if g_Game_IsServer and g_Game_IsNet then
4906 MH_SEND_Sound(FObj.X, FObj.Y, 'SOUND_GAME_NOTELEPORT');
4907 Exit;
4908 end;
4910 FJustTeleported := True;
4912 Anim := nil;
4913 if not silent then
4914 begin
4915 if g_Frames_Get(ID, 'FRAMES_TELEPORT') then
4916 begin
4917 Anim := TAnimation.Create(ID, False, 3);
4918 end;
4920 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj.X, FObj.Y);
4921 g_GFX_OnceAnim(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
4922 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32, Anim);
4923 if g_Game_IsServer and g_Game_IsNet then
4924 MH_SEND_Effect(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
4925 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32, 1,
4926 NET_GFX_TELE);
4927 end;
4929 FObj.X := X-PLAYER_RECT.X;
4930 FObj.Y := Y-PLAYER_RECT.Y;
4931 FObj.oldX := FObj.X; // don't interpolate after respawn
4932 FObj.oldY := FObj.Y;
4933 if FAlive and FGhost then
4934 begin
4935 FXTo := FObj.X;
4936 FYTo := FObj.Y;
4937 end;
4939 if not g_Game_IsNet then
4940 begin
4941 if dir = 1 then
4942 begin
4943 SetDirection(TDirection.D_LEFT);
4944 FAngle := 180;
4945 end
4946 else
4947 if dir = 2 then
4948 begin
4949 SetDirection(TDirection.D_RIGHT);
4950 FAngle := 0;
4951 end
4952 else
4953 if dir = 3 then
4954 begin // îáðàòíîå
4955 if FDirection = TDirection.D_RIGHT then
4956 begin
4957 SetDirection(TDirection.D_LEFT);
4958 FAngle := 180;
4959 end
4960 else
4961 begin
4962 SetDirection(TDirection.D_RIGHT);
4963 FAngle := 0;
4964 end;
4965 end;
4966 end;
4968 if not silent and (Anim <> nil) then
4969 begin
4970 g_GFX_OnceAnim(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
4971 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32, Anim);
4972 Anim.Free();
4974 if g_Game_IsServer and g_Game_IsNet then
4975 MH_SEND_Effect(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
4976 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32, 0,
4977 NET_GFX_TELE);
4978 end;
4980 Result := True;
4981 end;
4983 function nonz(a: Single): Single;
4984 begin
4985 if a <> 0 then
4986 Result := a
4987 else
4988 Result := 1;
4989 end;
4991 function TPlayer.refreshCorpse(): Boolean;
4992 var
4993 i: Integer;
4994 begin
4995 Result := False;
4996 FCorpse := -1;
4997 if FAlive or FSpectator then
4998 Exit;
4999 if (gCorpses = nil) or (Length(gCorpses) = 0) then
5000 Exit;
5001 for i := 0 to High(gCorpses) do
5002 if gCorpses[i] <> nil then
5003 if gCorpses[i].FPlayerUID = FUID then
5004 begin
5005 Result := True;
5006 FCorpse := i;
5007 break;
5008 end;
5009 end;
5011 function TPlayer.getCameraObj(): TObj;
5012 begin
5013 if (not FAlive) and (not FSpectator) and
5014 (FCorpse >= 0) and (FCorpse < Length(gCorpses)) and
5015 (gCorpses[FCorpse] <> nil) and (gCorpses[FCorpse].FPlayerUID = FUID) then
5016 begin
5017 gCorpses[FCorpse].FObj.slopeUpLeft := FObj.slopeUpLeft;
5018 Result := gCorpses[FCorpse].FObj;
5019 end
5020 else
5021 begin
5022 Result := FObj;
5023 end;
5024 end;
5026 procedure TPlayer.PreUpdate();
5027 begin
5028 FSlopeOld := FObj.slopeUpLeft;
5029 FIncCamOld := FIncCam;
5030 FObj.oldX := FObj.X;
5031 FObj.oldY := FObj.Y;
5032 end;
5034 procedure TPlayer.Update();
5035 var
5036 b: Byte;
5037 i, ii, wx, wy, xd, yd, k: Integer;
5038 blockmon, headwater, dospawn: Boolean;
5039 NetServer: Boolean;
5040 AnyServer: Boolean;
5041 SetSpect: Boolean;
5042 begin
5043 NetServer := g_Game_IsNet and g_Game_IsServer;
5044 AnyServer := g_Game_IsServer;
5046 if g_Game_IsClient and (NetInterpLevel > 0) then
5047 DoLerp(NetInterpLevel + 1)
5048 else
5049 if FGhost then
5050 DoLerp(4);
5052 if NetServer then
5053 if (FClientID >= 0) and (NetClients[FClientID].Peer <> nil) then
5054 begin
5055 FPing := NetClients[FClientID].Peer^.lastRoundTripTime;
5056 if NetClients[FClientID].Peer^.packetsSent > 0 then
5057 FLoss := Round(100*NetClients[FClientID].Peer^.packetsLost/NetClients[FClientID].Peer^.packetsSent)
5058 else
5059 FLoss := 0;
5060 end else
5061 begin
5062 FPing := 0;
5063 FLoss := 0;
5064 end;
5066 if FAlive and (FPunchAnim <> nil) then
5067 FPunchAnim.Update();
5069 if FAlive and (gFly or FJetpack) then
5070 FlySmoke();
5072 if FDirection = TDirection.D_LEFT then
5073 FAngle := 180
5074 else
5075 FAngle := 0;
5077 if FAlive and (not FGhost) then
5078 begin
5079 if FKeys[KEY_UP].Pressed then
5080 SeeUp();
5081 if FKeys[KEY_DOWN].Pressed then
5082 SeeDown();
5083 end;
5085 if (not (FKeys[KEY_UP].Pressed or FKeys[KEY_DOWN].Pressed)) and
5086 (FIncCam <> 0) then
5087 begin
5088 i := g_basic.Sign(FIncCam);
5089 FIncCam := Abs(FIncCam);
5090 DecMin(FIncCam, 5, 0);
5091 FIncCam := FIncCam*i;
5092 end;
5094 if gTime mod (GAME_TICK*2) <> 0 then
5095 begin
5096 if (FObj.Vel.X = 0) and FAlive then
5097 begin
5098 if FKeys[KEY_LEFT].Pressed then
5099 Run(TDirection.D_LEFT);
5100 if FKeys[KEY_RIGHT].Pressed then
5101 Run(TDirection.D_RIGHT);
5102 end;
5104 if FPhysics then
5105 begin
5106 g_Obj_Move(@FObj, True, True, True);
5107 positionChanged(); // this updates spatial accelerators
5108 end;
5110 Exit;
5111 end;
5113 FActionChanged := False;
5115 if FAlive then
5116 begin
5117 // Let alive player do some actions
5118 if FKeys[KEY_LEFT].Pressed then Run(TDirection.D_LEFT);
5119 if FKeys[KEY_RIGHT].Pressed then Run(TDirection.D_RIGHT);
5120 if FKeys[KEY_FIRE].Pressed and AnyServer then Fire()
5121 else
5122 begin
5123 if AnyServer then
5124 begin
5125 FlamerOff;
5126 if NetServer then MH_SEND_PlayerStats(FUID);
5127 end;
5128 end;
5129 if FKeys[KEY_OPEN].Pressed and AnyServer then Use();
5130 if FKeys[KEY_JUMP].Pressed then Jump()
5131 else
5132 begin
5133 if AnyServer and FJetpack then
5134 begin
5135 FJetpack := False;
5136 JetpackOff;
5137 if NetServer then MH_SEND_PlayerStats(FUID);
5138 end;
5139 FCanJetpack := True;
5140 end;
5141 end
5142 else // Dead
5143 begin
5144 dospawn := False;
5145 if not FGhost then
5146 for k := Low(FKeys) to KEY_CHAT-1 do
5147 begin
5148 if FKeys[k].Pressed then
5149 begin
5150 dospawn := True;
5151 break;
5152 end;
5153 end;
5154 if dospawn then
5155 begin
5156 if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
5157 Respawn(False)
5158 else // Single
5159 if (FTime[T_RESPAWN] <= gTime) and
5160 gGameOn and (not FAlive) then
5161 begin
5162 if (g_Player_GetCount() > 1) then
5163 Respawn(False)
5164 else
5165 begin
5166 gExit := EXIT_RESTART;
5167 Exit;
5168 end;
5169 end;
5170 end;
5171 // Dead spectator actions
5172 if FGhost then
5173 begin
5174 if FKeys[KEY_OPEN].Pressed and AnyServer then Fire();
5175 if FKeys[KEY_FIRE].Pressed and AnyServer then
5176 begin
5177 if FSpectator then
5178 begin
5179 if (FSpectatePlayer >= High(gPlayers)) then
5180 FSpectatePlayer := -1
5181 else
5182 begin
5183 SetSpect := False;
5184 for I := FSpectatePlayer + 1 to High(gPlayers) do
5185 if gPlayers[I] <> nil then
5186 if gPlayers[I].alive then
5187 if gPlayers[I].UID <> FUID then
5188 begin
5189 FSpectatePlayer := I;
5190 SetSpect := True;
5191 break;
5192 end;
5194 if not SetSpect then FSpectatePlayer := -1;
5195 end;
5197 ReleaseKeys;
5198 end;
5199 end;
5200 end;
5201 end;
5202 // No clipping
5203 if FGhost then
5204 begin
5205 if FKeys[KEY_UP].Pressed or FKeys[KEY_JUMP].Pressed then
5206 begin
5207 FYTo := FObj.Y - 32;
5208 FSpectatePlayer := -1;
5209 end;
5210 if FKeys[KEY_DOWN].Pressed then
5211 begin
5212 FYTo := FObj.Y + 32;
5213 FSpectatePlayer := -1;
5214 end;
5215 if FKeys[KEY_LEFT].Pressed then
5216 begin
5217 FXTo := FObj.X - 32;
5218 FSpectatePlayer := -1;
5219 end;
5220 if FKeys[KEY_RIGHT].Pressed then
5221 begin
5222 FXTo := FObj.X + 32;
5223 FSpectatePlayer := -1;
5224 end;
5226 if (FXTo < -64) then
5227 FXTo := -64
5228 else if (FXTo > gMapInfo.Width + 32) then
5229 FXTo := gMapInfo.Width + 32;
5230 if (FYTo < -72) then
5231 FYTo := -72
5232 else if (FYTo > gMapInfo.Height + 32) then
5233 FYTo := gMapInfo.Height + 32;
5234 end;
5236 if FPhysics then
5237 begin
5238 g_Obj_Move(@FObj, True, True, True);
5239 positionChanged(); // this updates spatial accelerators
5240 end
5241 else
5242 begin
5243 FObj.Vel.X := 0;
5244 FObj.Vel.Y := 0;
5245 if FSpectator then
5246 if (FSpectatePlayer <= High(gPlayers)) and (FSpectatePlayer >= 0) then
5247 if gPlayers[FSpectatePlayer] <> nil then
5248 if gPlayers[FSpectatePlayer].alive then
5249 begin
5250 FXTo := gPlayers[FSpectatePlayer].GameX;
5251 FYTo := gPlayers[FSpectatePlayer].GameY;
5252 end;
5253 end;
5255 blockmon := g_Map_CollidePanel(FObj.X+PLAYER_HEADRECT.X, FObj.Y+PLAYER_HEADRECT.Y,
5256 PLAYER_HEADRECT.Width, PLAYER_HEADRECT.Height,
5257 PANEL_BLOCKMON, True);
5258 headwater := HeadInLiquid(0, 0);
5260 // Ñîïðîòèâëåíèå âîçäóõà:
5261 if (not FAlive) or not (FKeys[KEY_LEFT].Pressed or FKeys[KEY_RIGHT].Pressed) then
5262 if FObj.Vel.X <> 0 then
5263 FObj.Vel.X := z_dec(FObj.Vel.X, 1);
5265 if (FLastHit = HIT_TRAP) and (FPain > 90) then FPain := 90;
5266 DecMin(FPain, 5, 0);
5267 DecMin(FPickup, 1, 0);
5269 if FAlive and (FObj.Y > Integer(gMapInfo.Height)+128) and AnyServer then
5270 begin
5271 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
5272 FMegaRulez[MR_SUIT] := 0;
5273 FMegaRulez[MR_INVUL] := 0;
5274 FMegaRulez[MR_INVIS] := 0;
5275 Kill(K_FALLKILL, 0, HIT_FALL);
5276 end;
5278 i := 9;
5280 if FAlive then
5281 begin
5282 if FCurrWeap = WEAPON_SAW then
5283 if not (FSawSound.IsPlaying() or FSawSoundHit.IsPlaying() or
5284 FSawSoundSelect.IsPlaying()) then
5285 FSawSoundIdle.PlayAt(FObj.X, FObj.Y);
5287 if FJetpack then
5288 if (not FJetSoundFly.IsPlaying()) and (not FJetSoundOn.IsPlaying()) and
5289 (not FJetSoundOff.IsPlaying()) then
5290 begin
5291 FJetSoundFly.SetPosition(0);
5292 FJetSoundFly.PlayAt(FObj.X, FObj.Y);
5293 end;
5295 for b := WP_FIRST to WP_LAST do
5296 if FReloading[b] > 0 then
5297 if FNoReload then
5298 FReloading[b] := 0
5299 else
5300 Dec(FReloading[b]);
5302 if FShellTimer > -1 then
5303 if FShellTimer = 0 then
5304 begin
5305 if FShellType = SHELL_SHELL then
5306 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
5307 GameVelX, GameVelY-2, SHELL_SHELL)
5308 else if FShellType = SHELL_DBLSHELL then
5309 begin
5310 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
5311 GameVelX+1, GameVelY-2, SHELL_SHELL);
5312 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
5313 GameVelX-1, GameVelY-2, SHELL_SHELL);
5314 end;
5315 FShellTimer := -1;
5316 end else Dec(FShellTimer);
5318 if (FBFGFireCounter > -1) then
5319 if FBFGFireCounter = 0 then
5320 begin
5321 if AnyServer then
5322 begin
5323 wx := FObj.X+WEAPONPOINT[FDirection].X;
5324 wy := FObj.Y+WEAPONPOINT[FDirection].Y;
5325 xd := wx+IfThen(FDirection = TDirection.D_LEFT, -30, 30);
5326 yd := wy+firediry();
5327 g_Weapon_bfgshot(wx, wy, xd, yd, FUID);
5328 if NetServer then MH_SEND_PlayerFire(FUID, WEAPON_BFG, wx, wy, xd, yd);
5329 if (FAngle = 0) or (FAngle = 180) then SetAction(A_ATTACK)
5330 else if (FAngle = ANGLE_LEFTDOWN) or (FAngle = ANGLE_RIGHTDOWN) then SetAction(A_ATTACKDOWN)
5331 else if (FAngle = ANGLE_LEFTUP) or (FAngle = ANGLE_RIGHTUP) then SetAction(A_ATTACKUP);
5332 end;
5334 FReloading[WEAPON_BFG] := WEAPON_RELOAD[WEAPON_BFG];
5335 FBFGFireCounter := -1;
5336 end else
5337 if FNoReload then
5338 FBFGFireCounter := 0
5339 else
5340 Dec(FBFGFireCounter);
5342 if (FMegaRulez[MR_SUIT] < gTime) and AnyServer then
5343 begin
5344 b := g_GetAcidHit(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width, PLAYER_RECT.Height);
5346 if (b > 0) and (gTime mod (15*GAME_TICK) = 0) then Damage(b, 0, 0, 0, HIT_ACID);
5347 end;
5349 if (headwater or blockmon) then
5350 begin
5351 Dec(FAir);
5353 if FAir < -9 then
5354 begin
5355 if AnyServer then Damage(10, 0, 0, 0, HIT_WATER);
5356 FAir := 0;
5357 end
5358 else if (FAir mod 31 = 0) and not blockmon then
5359 begin
5360 g_GFX_Bubbles(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2), FObj.Y+PLAYER_RECT.Y-4, 5+Random(6), 8, 4);
5361 if Random(2) = 0 then
5362 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj.X, FObj.Y)
5363 else
5364 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj.X, FObj.Y);
5365 end;
5366 end else if FAir < AIR_DEF then
5367 FAir := AIR_DEF;
5369 if FFireTime > 0 then
5370 begin
5371 if BodyInLiquid(0, 0) then
5372 begin
5373 FFireTime := 0;
5374 FFirePainTime := 0;
5375 end
5376 else if FMegaRulez[MR_SUIT] >= gTime then
5377 begin
5378 if FMegaRulez[MR_SUIT] = gTime then
5379 FFireTime := 1;
5380 FFirePainTime := 0;
5381 end
5382 else
5383 begin
5384 OnFireFlame(1);
5385 if FFirePainTime <= 0 then
5386 begin
5387 if g_Game_IsServer then
5388 Damage(2, FFireAttacker, 0, 0, HIT_FLAME);
5389 FFirePainTime := 12 - FFireTime div 12;
5390 end;
5391 FFirePainTime := FFirePainTime - 1;
5392 FFireTime := FFireTime - 1;
5393 if ((FFireTime mod 33) = 0) and (FMegaRulez[MR_INVUL] < gTime) then
5394 FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
5395 if (FFireTime = 0) and g_Game_IsNet and g_Game_IsServer then
5396 MH_SEND_PlayerStats(FUID);
5397 end;
5398 end;
5400 if FDamageBuffer > 0 then
5401 begin
5402 if FDamageBuffer >= 9 then
5403 begin
5404 SetAction(A_PAIN);
5406 if FDamageBuffer < 30 then i := 9
5407 else if FDamageBuffer < 100 then i := 18
5408 else i := 27;
5409 end;
5411 ii := Round(FDamageBuffer*FHealth / nonz(FArmor*(3/4)+FHealth));
5412 FArmor := FArmor-(FDamageBuffer-ii);
5413 FHealth := FHealth-ii;
5414 if FArmor < 0 then
5415 begin
5416 FHealth := FHealth+FArmor;
5417 FArmor := 0;
5418 end;
5420 if AnyServer then
5421 if FHealth <= 0 then
5422 if FHealth > -30 then Kill(K_SIMPLEKILL, FLastSpawnerUID, FLastHit)
5423 else if FHealth > -50 then Kill(K_HARDKILL, FLastSpawnerUID, FLastHit)
5424 else Kill(K_EXTRAHARDKILL, FLastSpawnerUID, FLastHit);
5426 if FAlive and ((FLastHit <> HIT_FLAME) or (FFireTime <= 0)) then
5427 begin
5428 if FDamageBuffer <= 20 then FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y)
5429 else if FDamageBuffer <= 55 then FModel.PlaySound(MODELSOUND_PAIN, 2, FObj.X, FObj.Y)
5430 else if FDamageBuffer <= 120 then FModel.PlaySound(MODELSOUND_PAIN, 3, FObj.X, FObj.Y)
5431 else FModel.PlaySound(MODELSOUND_PAIN, 4, FObj.X, FObj.Y);
5432 end;
5434 FDamageBuffer := 0;
5435 end;
5437 {CollideItem();}
5438 end; // if FAlive then ...
5440 if (FActionAnim = A_PAIN) and (FModel.Animation <> A_PAIN) then
5441 begin
5442 FModel.ChangeAnimation(FActionAnim, FActionForce);
5443 FModel.GetCurrentAnimation.MinLength := i;
5444 FModel.GetCurrentAnimationMask.MinLength := i;
5445 end else FModel.ChangeAnimation(FActionAnim, FActionForce and (FModel.Animation <> A_STAND));
5447 if (FModel.GetCurrentAnimation.Played or ((not FActionChanged) and (FModel.Animation = A_WALK)))
5448 then SetAction(A_STAND, True);
5450 if not ((FModel.Animation = A_WALK) and (Abs(FObj.Vel.X) < 4) and not FModel.Fire) then FModel.Update;
5452 for b := Low(FKeys) to High(FKeys) do
5453 if FKeys[b].Time = 0 then FKeys[b].Pressed := False else Dec(FKeys[b].Time);
5454 end;
5457 procedure TPlayer.getMapBox (out x, y, w, h: Integer); inline;
5458 begin
5459 x := FObj.X+PLAYER_RECT.X;
5460 y := FObj.Y+PLAYER_RECT.Y;
5461 w := PLAYER_RECT.Width;
5462 h := PLAYER_RECT.Height;
5463 end;
5466 procedure TPlayer.moveBy (dx, dy: Integer); inline;
5467 begin
5468 if (dx <> 0) or (dy <> 0) then
5469 begin
5470 FObj.X += dx;
5471 FObj.Y += dy;
5472 positionChanged();
5473 end;
5474 end;
5477 function TPlayer.Collide(X, Y: Integer; Width, Height: Word): Boolean;
5478 begin
5479 Result := g_Collide(FObj.X+PLAYER_RECT.X,
5480 FObj.Y+PLAYER_RECT.Y,
5481 PLAYER_RECT.Width,
5482 PLAYER_RECT.Height,
5483 X, Y,
5484 Width, Height);
5485 end;
5487 function TPlayer.Collide(Panel: TPanel): Boolean;
5488 begin
5489 Result := g_Collide(FObj.X+PLAYER_RECT.X,
5490 FObj.Y+PLAYER_RECT.Y,
5491 PLAYER_RECT.Width,
5492 PLAYER_RECT.Height,
5493 Panel.X, Panel.Y,
5494 Panel.Width, Panel.Height);
5495 end;
5497 function TPlayer.Collide(X, Y: Integer): Boolean;
5498 begin
5499 X := X-FObj.X-PLAYER_RECT.X;
5500 Y := Y-FObj.Y-PLAYER_RECT.Y;
5501 Result := (x >= 0) and (x <= PLAYER_RECT.Width) and
5502 (y >= 0) and (y <= PLAYER_RECT.Height);
5503 end;
5505 function g_Player_ValidName(Name: string): Boolean;
5506 var
5507 a: Integer;
5508 begin
5509 Result := True;
5511 if gPlayers = nil then Exit;
5513 for a := 0 to High(gPlayers) do
5514 if gPlayers[a] <> nil then
5515 if LowerCase(Name) = LowerCase(gPlayers[a].FName) then
5516 begin
5517 Result := False;
5518 Exit;
5519 end;
5520 end;
5522 procedure TPlayer.SetDirection(Direction: TDirection);
5523 var
5524 d: TDirection;
5525 begin
5526 d := FModel.Direction;
5528 FModel.Direction := Direction;
5529 if d <> Direction then FModel.ChangeAnimation(FModel.Animation, True);
5531 FDirection := Direction;
5532 end;
5534 function TPlayer.GetKeys(): Byte;
5535 begin
5536 Result := 0;
5538 if R_KEY_RED in FRulez then Result := KEY_RED;
5539 if R_KEY_GREEN in FRulez then Result := Result or KEY_GREEN;
5540 if R_KEY_BLUE in FRulez then Result := Result or KEY_BLUE;
5542 if FTeam = TEAM_RED then Result := Result or KEY_REDTEAM;
5543 if FTeam = TEAM_BLUE then Result := Result or KEY_BLUETEAM;
5544 end;
5546 procedure TPlayer.Use();
5547 var
5548 a: Integer;
5549 begin
5550 if FTime[T_USE] > gTime then Exit;
5552 g_Triggers_PressR(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
5553 PLAYER_RECT.Height, FUID, ACTIVATE_PLAYERPRESS);
5555 for a := 0 to High(gPlayers) do
5556 if (gPlayers[a] <> nil) and (gPlayers[a] <> Self) and
5557 gPlayers[a].alive and SameTeam(FUID, gPlayers[a].FUID) and
5558 g_Obj_Collide(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y,
5559 FObj.Rect.Width, FObj.Rect.Height, @gPlayers[a].FObj) then
5560 begin
5561 gPlayers[a].Touch();
5562 if g_Game_IsNet and g_Game_IsServer then
5563 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH, gPlayers[a].FUID);
5564 end;
5566 FTime[T_USE] := gTime+120;
5567 end;
5569 procedure TPlayer.NetFire(Wpn: Byte; X, Y, AX, AY: Integer; WID: Integer = -1);
5570 var
5571 locObj: TObj;
5572 F: Boolean;
5573 WX, WY, XD, YD: Integer;
5574 begin
5575 F := False;
5576 WX := X;
5577 WY := Y;
5578 XD := AX;
5579 YD := AY;
5581 case FCurrWeap of
5582 WEAPON_KASTET:
5583 begin
5584 DoPunch();
5585 if R_BERSERK in FRulez then
5586 begin
5587 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5588 locobj.X := FObj.X+FObj.Rect.X;
5589 locobj.Y := FObj.Y+FObj.Rect.Y;
5590 locobj.rect.X := 0;
5591 locobj.rect.Y := 0;
5592 locobj.rect.Width := 39;
5593 locobj.rect.Height := 52;
5594 locobj.Vel.X := (xd-wx) div 2;
5595 locobj.Vel.Y := (yd-wy) div 2;
5596 locobj.Accel.X := xd-wx;
5597 locobj.Accel.y := yd-wy;
5599 if g_Weapon_Hit(@locobj, 50, FUID, HIT_SOME) <> 0 then
5600 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj.X, FObj.Y)
5601 else
5602 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj.X, FObj.Y);
5604 if gFlash = 1 then
5605 if FPain < 50 then
5606 FPain := min(FPain + 25, 50);
5607 end else
5608 g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 3, FUID);
5609 end;
5611 WEAPON_SAW:
5612 begin
5613 if g_Weapon_chainsaw(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y,
5614 IfThen(gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF], 9, 3), FUID) <> 0 then
5615 begin
5616 FSawSoundSelect.Stop();
5617 FSawSound.Stop();
5618 FSawSoundHit.PlayAt(FObj.X, FObj.Y);
5619 end
5620 else if not FSawSoundHit.IsPlaying() then
5621 begin
5622 FSawSoundSelect.Stop();
5623 FSawSound.PlayAt(FObj.X, FObj.Y);
5624 end;
5625 f := True;
5626 end;
5628 WEAPON_PISTOL:
5629 begin
5630 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX, Gamey);
5631 FFireAngle := FAngle;
5632 f := True;
5633 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
5634 GameVelX, GameVelY-2, SHELL_BULLET);
5635 end;
5637 WEAPON_SHOTGUN1:
5638 begin
5639 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex, Gamey);
5640 FFireAngle := FAngle;
5641 f := True;
5642 FShellTimer := 10;
5643 FShellType := SHELL_SHELL;
5644 end;
5646 WEAPON_SHOTGUN2:
5647 begin
5648 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex, Gamey);
5649 FFireAngle := FAngle;
5650 f := True;
5651 FShellTimer := 13;
5652 FShellType := SHELL_DBLSHELL;
5653 end;
5655 WEAPON_CHAINGUN:
5656 begin
5657 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex, Gamey);
5658 FFireAngle := FAngle;
5659 f := True;
5660 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
5661 GameVelX, GameVelY-2, SHELL_BULLET);
5662 end;
5664 WEAPON_ROCKETLAUNCHER:
5665 begin
5666 g_Weapon_Rocket(wx, wy, xd, yd, FUID, WID);
5667 FFireAngle := FAngle;
5668 f := True;
5669 end;
5671 WEAPON_PLASMA:
5672 begin
5673 g_Weapon_Plasma(wx, wy, xd, yd, FUID, WID);
5674 FFireAngle := FAngle;
5675 f := True;
5676 end;
5678 WEAPON_BFG:
5679 begin
5680 g_Weapon_BFGShot(wx, wy, xd, yd, FUID, WID);
5681 FFireAngle := FAngle;
5682 f := True;
5683 end;
5685 WEAPON_SUPERPULEMET:
5686 begin
5687 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex, Gamey);
5688 FFireAngle := FAngle;
5689 f := True;
5690 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
5691 GameVelX, GameVelY-2, SHELL_SHELL);
5692 end;
5694 WEAPON_FLAMETHROWER:
5695 begin
5696 g_Weapon_flame(wx, wy, xd, yd, FUID, WID);
5697 FlamerOn;
5698 FFireAngle := FAngle;
5699 f := True;
5700 end;
5701 end;
5703 if not f then Exit;
5705 if (FAngle = 0) or (FAngle = 180) then SetAction(A_ATTACK)
5706 else if (FAngle = ANGLE_LEFTDOWN) or (FAngle = ANGLE_RIGHTDOWN) then SetAction(A_ATTACKDOWN)
5707 else if (FAngle = ANGLE_LEFTUP) or (FAngle = ANGLE_RIGHTUP) then SetAction(A_ATTACKUP);
5708 end;
5710 procedure TPlayer.DoLerp(Level: Integer = 2);
5711 begin
5712 if FObj.X <> FXTo then FObj.X := Lerp(FObj.X, FXTo, Level);
5713 if FObj.Y <> FYTo then FObj.Y := Lerp(FObj.Y, FYTo, Level);
5714 end;
5716 procedure TPlayer.SetLerp(XTo, YTo: Integer);
5717 var
5718 AX, AY: Integer;
5719 begin
5720 FXTo := XTo;
5721 FYTo := YTo;
5722 if FJustTeleported or (NetInterpLevel < 1) then
5723 begin
5724 FObj.X := XTo;
5725 FObj.Y := YTo;
5726 if FJustTeleported then
5727 begin
5728 FObj.oldX := FObj.X;
5729 FObj.oldY := FObj.Y;
5730 end;
5731 end
5732 else
5733 begin
5734 AX := Abs(FXTo - FObj.X);
5735 AY := Abs(FYTo - FObj.Y);
5736 if (AX > 32) or (AX <= NetInterpLevel) then
5737 FObj.X := FXTo;
5738 if (AY > 32) or (AY <= NetInterpLevel) then
5739 FObj.Y := FYTo;
5740 end;
5741 end;
5743 function TPlayer.FullInLift(XInc, YInc: Integer): Integer;
5744 begin
5745 if g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc,
5746 PLAYER_RECT.Width, PLAYER_RECT.Height-8,
5747 PANEL_LIFTUP, False) then Result := -1
5748 else
5749 if g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc,
5750 PLAYER_RECT.Width, PLAYER_RECT.Height-8,
5751 PANEL_LIFTDOWN, False) then Result := 1
5752 else Result := 0;
5753 end;
5755 function TPlayer.GetFlag(Flag: Byte): Boolean;
5756 var
5757 s, ts: String;
5758 evtype, a: Byte;
5759 begin
5760 Result := False;
5762 if Flag = FLAG_NONE then
5763 Exit;
5765 if not g_Game_IsServer then Exit;
5767 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5768 if (Flag = FTeam) and
5769 (gFlags[Flag].State = FLAG_STATE_NORMAL) and
5770 (FFlag <> FLAG_NONE) then
5771 begin
5772 if FFlag = FLAG_RED then
5773 s := _lc[I_PLAYER_FLAG_RED]
5774 else
5775 s := _lc[I_PLAYER_FLAG_BLUE];
5777 evtype := FLAG_STATE_SCORED;
5779 ts := Format('%.4d', [gFlags[FFlag].CaptureTime]);
5780 Insert('.', ts, Length(ts) + 1 - 3);
5781 g_Console_Add(Format(_lc[I_PLAYER_FLAG_CAPTURE], [FName, s, ts]), True);
5783 g_Map_ResetFlag(FFlag);
5784 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_CAPTURE], [AnsiUpperCase(s)]), 144);
5786 if ((Self = gPlayer1) or (Self = gPlayer2)
5787 or ((gPlayer1 <> nil) and (gPlayer1.Team = FTeam))
5788 or ((gPlayer2 <> nil) and (gPlayer2.Team = FTeam))) then
5789 a := 0
5790 else
5791 a := 1;
5793 if not sound_cap_flag[a].IsPlaying() then
5794 sound_cap_flag[a].Play();
5796 gTeamStat[FTeam].Goals := gTeamStat[FTeam].Goals + 1;
5798 Result := True;
5799 if g_Game_IsNet then
5800 begin
5801 MH_SEND_FlagEvent(evtype, FFlag, FUID, False);
5802 MH_SEND_GameStats;
5803 end;
5805 gFlags[FFlag].CaptureTime := 0;
5806 SetFlag(FLAG_NONE);
5807 Exit;
5808 end;
5810 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5811 if (Flag = FTeam) and
5812 (gFlags[Flag].State = FLAG_STATE_DROPPED) then
5813 begin
5814 if Flag = FLAG_RED then
5815 s := _lc[I_PLAYER_FLAG_RED]
5816 else
5817 s := _lc[I_PLAYER_FLAG_BLUE];
5819 evtype := FLAG_STATE_RETURNED;
5820 gFlags[Flag].CaptureTime := 0;
5822 g_Console_Add(Format(_lc[I_PLAYER_FLAG_RETURN], [FName, s]), True);
5824 g_Map_ResetFlag(Flag);
5825 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_RETURN], [AnsiUpperCase(s)]), 144);
5827 if ((Self = gPlayer1) or (Self = gPlayer2)
5828 or ((gPlayer1 <> nil) and (gPlayer1.Team = FTeam))
5829 or ((gPlayer2 <> nil) and (gPlayer2.Team = FTeam))) then
5830 a := 0
5831 else
5832 a := 1;
5834 if not sound_ret_flag[a].IsPlaying() then
5835 sound_ret_flag[a].Play();
5837 Result := True;
5838 if g_Game_IsNet then
5839 begin
5840 MH_SEND_FlagEvent(evtype, Flag, FUID, False);
5841 MH_SEND_GameStats;
5842 end;
5843 Exit;
5844 end;
5846 // Ïîäîáðàë ÷óæîé ôëàã:
5847 if (Flag <> FTeam) and (FTime[T_FLAGCAP] <= gTime) then
5848 begin
5849 SetFlag(Flag);
5851 if Flag = FLAG_RED then
5852 s := _lc[I_PLAYER_FLAG_RED]
5853 else
5854 s := _lc[I_PLAYER_FLAG_BLUE];
5856 evtype := FLAG_STATE_CAPTURED;
5858 g_Console_Add(Format(_lc[I_PLAYER_FLAG_GET], [FName, s]), True);
5860 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_GET], [AnsiUpperCase(s)]), 144);
5862 gFlags[Flag].State := FLAG_STATE_CAPTURED;
5864 if ((Self = gPlayer1) or (Self = gPlayer2)
5865 or ((gPlayer1 <> nil) and (gPlayer1.Team = FTeam))
5866 or ((gPlayer2 <> nil) and (gPlayer2.Team = FTeam))) then
5867 a := 0
5868 else
5869 a := 1;
5871 if not sound_get_flag[a].IsPlaying() then
5872 sound_get_flag[a].Play();
5874 Result := True;
5875 if g_Game_IsNet then
5876 begin
5877 MH_SEND_FlagEvent(evtype, Flag, FUID, False);
5878 MH_SEND_GameStats;
5879 end;
5880 end;
5881 end;
5883 procedure TPlayer.SetFlag(Flag: Byte);
5884 begin
5885 FFlag := Flag;
5886 if FModel <> nil then
5887 FModel.SetFlag(FFlag);
5888 end;
5890 function TPlayer.TryDropFlag(): Boolean;
5891 begin
5892 if LongBool(gGameSettings.Options and GAME_OPTION_ALLOWDROPFLAG) then
5893 Result := DropFlag(False, LongBool(gGameSettings.Options and GAME_OPTION_THROWFLAG))
5894 else
5895 Result := False;
5896 end;
5898 function TPlayer.DropFlag(Silent: Boolean = True; DoThrow: Boolean = False): Boolean;
5899 var
5900 s: String;
5901 a: Byte;
5902 xv, yv: Integer;
5903 begin
5904 Result := False;
5905 if (not g_Game_IsServer) or (FFlag = FLAG_NONE) then
5906 Exit;
5907 FTime[T_FLAGCAP] := gTime + 2000;
5908 with gFlags[FFlag] do
5909 begin
5910 Obj.X := FObj.X;
5911 Obj.Y := FObj.Y;
5912 Direction := FDirection;
5913 State := FLAG_STATE_DROPPED;
5914 Count := FLAG_TIME;
5915 if DoThrow then
5916 begin
5917 xv := FObj.Vel.X + IfThen(Direction = TDirection.D_RIGHT, 10, -10);
5918 yv := FObj.Vel.Y - 2;
5919 end
5920 else
5921 begin
5922 xv := (FObj.Vel.X div 2);
5923 yv := (FObj.Vel.Y div 2) - 2;
5924 end;
5925 g_Obj_Push(@Obj, xv, yv);
5927 positionChanged(); // this updates spatial accelerators
5929 if FFlag = FLAG_RED then
5930 s := _lc[I_PLAYER_FLAG_RED]
5931 else
5932 s := _lc[I_PLAYER_FLAG_BLUE];
5934 g_Console_Add(Format(_lc[I_PLAYER_FLAG_DROP], [FName, s]), True);
5935 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_DROP], [AnsiUpperCase(s)]), 144);
5937 if ((Self = gPlayer1) or (Self = gPlayer2)
5938 or ((gPlayer1 <> nil) and (gPlayer1.Team = FTeam))
5939 or ((gPlayer2 <> nil) and (gPlayer2.Team = FTeam))) then
5940 a := 0
5941 else
5942 a := 1;
5944 if (not Silent) and (not sound_lost_flag[a].IsPlaying()) then
5945 sound_lost_flag[a].Play();
5947 if g_Game_IsNet then
5948 MH_SEND_FlagEvent(FLAG_STATE_DROPPED, Flag, FUID, False);
5949 end;
5950 SetFlag(FLAG_NONE);
5951 Result := True;
5952 end;
5954 procedure TPlayer.GetSecret();
5955 begin
5956 if (self = gPlayer1) or (self = gPlayer2) then
5957 begin
5958 g_Console_Add(Format(_lc[I_PLAYER_SECRET], [FName]), True);
5959 g_Sound_PlayEx('SOUND_GAME_SECRET');
5960 end;
5961 Inc(FSecrets);
5962 end;
5964 procedure TPlayer.PressKey(Key: Byte; Time: Word = 1);
5965 begin
5966 Assert(Key <= High(FKeys));
5968 FKeys[Key].Pressed := True;
5969 FKeys[Key].Time := Time;
5970 end;
5972 function TPlayer.IsKeyPressed(K: Byte): Boolean;
5973 begin
5974 Result := FKeys[K].Pressed;
5975 end;
5977 procedure TPlayer.ReleaseKeys();
5978 var
5979 a: Integer;
5980 begin
5981 for a := Low(FKeys) to High(FKeys) do
5982 begin
5983 FKeys[a].Pressed := False;
5984 FKeys[a].Time := 0;
5985 end;
5986 end;
5988 procedure TPlayer.OnDamage(Angle: SmallInt);
5989 begin
5990 end;
5992 function TPlayer.firediry(): Integer;
5993 begin
5994 if FKeys[KEY_UP].Pressed then Result := -42
5995 else if FKeys[KEY_DOWN].Pressed then Result := 19
5996 else Result := 0;
5997 end;
5999 procedure TPlayer.RememberState();
6000 var
6001 i: Integer;
6002 SavedState: TPlayerSavedState;
6003 begin
6004 SavedState.Health := FHealth;
6005 SavedState.Armor := FArmor;
6006 SavedState.Air := FAir;
6007 SavedState.JetFuel := FJetFuel;
6008 SavedState.CurrWeap := FCurrWeap;
6009 SavedState.NextWeap := FNextWeap;
6010 SavedState.NextWeapDelay := FNextWeapDelay;
6011 for i := Low(FWeapon) to High(FWeapon) do
6012 SavedState.Weapon[i] := FWeapon[i];
6013 for i := Low(FAmmo) to High(FAmmo) do
6014 SavedState.Ammo[i] := FAmmo[i];
6015 for i := Low(FMaxAmmo) to High(FMaxAmmo) do
6016 SavedState.MaxAmmo[i] := FMaxAmmo[i];
6017 SavedState.Rulez := FRulez - [R_KEY_RED, R_KEY_GREEN, R_KEY_BLUE];
6019 FSavedStateNum := -1;
6020 for i := Low(SavedStates) to High(SavedStates) do
6021 if not SavedStates[i].Used then
6022 begin
6023 FSavedStateNum := i;
6024 break;
6025 end;
6026 if FSavedStateNum < 0 then
6027 begin
6028 SetLength(SavedStates, Length(SavedStates) + 1);
6029 FSavedStateNum := High(SavedStates);
6030 end;
6032 SavedState.Used := True;
6033 SavedStates[FSavedStateNum] := SavedState;
6034 end;
6036 procedure TPlayer.RecallState();
6037 var
6038 i: Integer;
6039 SavedState: TPlayerSavedState;
6040 begin
6041 if(FSavedStateNum < 0) or (FSavedStateNum > High(SavedStates)) then
6042 Exit;
6044 SavedState := SavedStates[FSavedStateNum];
6045 SavedStates[FSavedStateNum].Used := False;
6046 FSavedStateNum := -1;
6048 FHealth := SavedState.Health;
6049 FArmor := SavedState.Armor;
6050 FAir := SavedState.Air;
6051 FJetFuel := SavedState.JetFuel;
6052 FCurrWeap := SavedState.CurrWeap;
6053 FNextWeap := SavedState.NextWeap;
6054 FNextWeapDelay := SavedState.NextWeapDelay;
6055 for i := Low(FWeapon) to High(FWeapon) do
6056 FWeapon[i] := SavedState.Weapon[i];
6057 for i := Low(FAmmo) to High(FAmmo) do
6058 FAmmo[i] := SavedState.Ammo[i];
6059 for i := Low(FMaxAmmo) to High(FMaxAmmo) do
6060 FMaxAmmo[i] := SavedState.MaxAmmo[i];
6061 FRulez := SavedState.Rulez;
6063 if gGameSettings.GameType = GT_SERVER then
6064 MH_SEND_PlayerStats(FUID);
6065 end;
6067 procedure TPlayer.SaveState (st: TStream);
6068 var
6069 i: Integer;
6070 b: Byte;
6071 begin
6072 // Ñèãíàòóðà èãðîêà
6073 utils.writeSign(st, 'PLYR');
6074 utils.writeInt(st, Byte(PLR_SAVE_VERSION)); // version
6075 // Áîò èëè ÷åëîâåê
6076 utils.writeBool(st, FIamBot);
6077 // UID èãðîêà
6078 utils.writeInt(st, Word(FUID));
6079 // Èìÿ èãðîêà
6080 utils.writeStr(st, FName);
6081 // Êîìàíäà
6082 utils.writeInt(st, Byte(FTeam));
6083 // Æèâ ëè
6084 utils.writeBool(st, FAlive);
6085 // Èçðàñõîäîâàë ëè âñå æèçíè
6086 utils.writeBool(st, FNoRespawn);
6087 // Íàïðàâëåíèå
6088 if FDirection = TDirection.D_LEFT then b := 1 else b := 2; // D_RIGHT
6089 utils.writeInt(st, Byte(b));
6090 // Çäîðîâüå
6091 utils.writeInt(st, LongInt(FHealth));
6092 // Êîýôôèöèåíò èíâàëèäíîñòè
6093 utils.writeInt(st, LongInt(FHandicap));
6094 // Æèçíè
6095 utils.writeInt(st, Byte(FLives));
6096 // Áðîíÿ
6097 utils.writeInt(st, LongInt(FArmor));
6098 // Çàïàñ âîçäóõà
6099 utils.writeInt(st, LongInt(FAir));
6100 // Çàïàñ ãîðþ÷åãî
6101 utils.writeInt(st, LongInt(FJetFuel));
6102 // Áîëü
6103 utils.writeInt(st, LongInt(FPain));
6104 // Óáèë
6105 utils.writeInt(st, LongInt(FKills));
6106 // Óáèë ìîíñòðîâ
6107 utils.writeInt(st, LongInt(FMonsterKills));
6108 // Ôðàãîâ
6109 utils.writeInt(st, LongInt(FFrags));
6110 // Ôðàãîâ ïîäðÿä
6111 utils.writeInt(st, Byte(FFragCombo));
6112 // Âðåìÿ ïîñëåäíåãî ôðàãà
6113 utils.writeInt(st, LongWord(FLastFrag));
6114 // Ñìåðòåé
6115 utils.writeInt(st, LongInt(FDeath));
6116 // Êàêîé ôëàã íåñåò
6117 utils.writeInt(st, Byte(FFlag));
6118 // Íàøåë ñåêðåòîâ
6119 utils.writeInt(st, LongInt(FSecrets));
6120 // Òåêóùåå îðóæèå
6121 utils.writeInt(st, Byte(FCurrWeap));
6122 // Æåëàåìîå îðóæèå
6123 utils.writeInt(st, Word(FNextWeap));
6124 // ...è ïàóçà
6125 utils.writeInt(st, Byte(FNextWeapDelay));
6126 // Âðåìÿ çàðÿäêè BFG
6127 utils.writeInt(st, SmallInt(FBFGFireCounter));
6128 // Áóôåð óðîíà
6129 utils.writeInt(st, LongInt(FDamageBuffer));
6130 // Ïîñëåäíèé óäàðèâøèé
6131 utils.writeInt(st, Word(FLastSpawnerUID));
6132 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6133 utils.writeInt(st, Byte(FLastHit));
6134 // Îáúåêò èãðîêà
6135 Obj_SaveState(st, @FObj);
6136 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6137 for i := A_BULLETS to A_HIGH do utils.writeInt(st, Word(FAmmo[i]));
6138 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6139 for i := A_BULLETS to A_HIGH do utils.writeInt(st, Word(FMaxAmmo[i]));
6140 // Íàëè÷èå îðóæèÿ
6141 for i := WP_FIRST to WP_LAST do utils.writeBool(st, FWeapon[i]);
6142 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6143 for i := WP_FIRST to WP_LAST do utils.writeInt(st, Word(FReloading[i]));
6144 // Íàëè÷èå ðþêçàêà
6145 utils.writeBool(st, (R_ITEM_BACKPACK in FRulez));
6146 // Íàëè÷èå êðàñíîãî êëþ÷à
6147 utils.writeBool(st, (R_KEY_RED in FRulez));
6148 // Íàëè÷èå çåëåíîãî êëþ÷à
6149 utils.writeBool(st, (R_KEY_GREEN in FRulez));
6150 // Íàëè÷èå ñèíåãî êëþ÷à
6151 utils.writeBool(st, (R_KEY_BLUE in FRulez));
6152 // Íàëè÷èå áåðñåðêà
6153 utils.writeBool(st, (R_BERSERK in FRulez));
6154 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6155 for i := MR_SUIT to MR_MAX do utils.writeInt(st, LongWord(FMegaRulez[i]));
6156 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6157 for i := T_RESPAWN to T_FLAGCAP do utils.writeInt(st, LongWord(FTime[i]));
6158 // Íàçâàíèå ìîäåëè
6159 utils.writeStr(st, FModel.Name);
6160 // Öâåò ìîäåëè
6161 utils.writeInt(st, Byte(FColor.R));
6162 utils.writeInt(st, Byte(FColor.G));
6163 utils.writeInt(st, Byte(FColor.B));
6164 end;
6167 procedure TPlayer.LoadState (st: TStream);
6168 var
6169 i: Integer;
6170 str: String;
6171 b: Byte;
6172 begin
6173 assert(st <> nil);
6175 // Ñèãíàòóðà èãðîêà
6176 if not utils.checkSign(st, 'PLYR') then raise XStreamError.Create('invalid player signature');
6177 if (utils.readByte(st) <> PLR_SAVE_VERSION) then raise XStreamError.Create('invalid player version');
6178 // Áîò èëè ÷åëîâåê:
6179 FIamBot := utils.readBool(st);
6180 // UID èãðîêà
6181 FUID := utils.readWord(st);
6182 // Èìÿ èãðîêà
6183 str := utils.readStr(st);
6184 if (self <> gPlayer1) and (self <> gPlayer2) then FName := str;
6185 // Êîìàíäà
6186 FTeam := utils.readByte(st);
6187 // Æèâ ëè
6188 FAlive := utils.readBool(st);
6189 // Èçðàñõîäîâàë ëè âñå æèçíè
6190 FNoRespawn := utils.readBool(st);
6191 // Íàïðàâëåíèå
6192 b := utils.readByte(st);
6193 if b = 1 then FDirection := TDirection.D_LEFT else FDirection := TDirection.D_RIGHT; // b = 2
6194 // Çäîðîâüå
6195 FHealth := utils.readLongInt(st);
6196 // Êîýôôèöèåíò èíâàëèäíîñòè
6197 FHandicap := utils.readLongInt(st);
6198 // Æèçíè
6199 FLives := utils.readByte(st);
6200 // Áðîíÿ
6201 FArmor := utils.readLongInt(st);
6202 // Çàïàñ âîçäóõà
6203 FAir := utils.readLongInt(st);
6204 // Çàïàñ ãîðþ÷åãî
6205 FJetFuel := utils.readLongInt(st);
6206 // Áîëü
6207 FPain := utils.readLongInt(st);
6208 // Óáèë
6209 FKills := utils.readLongInt(st);
6210 // Óáèë ìîíñòðîâ
6211 FMonsterKills := utils.readLongInt(st);
6212 // Ôðàãîâ
6213 FFrags := utils.readLongInt(st);
6214 // Ôðàãîâ ïîäðÿä
6215 FFragCombo := utils.readByte(st);
6216 // Âðåìÿ ïîñëåäíåãî ôðàãà
6217 FLastFrag := utils.readLongWord(st);
6218 // Ñìåðòåé
6219 FDeath := utils.readLongInt(st);
6220 // Êàêîé ôëàã íåñåò
6221 FFlag := utils.readByte(st);
6222 // Íàøåë ñåêðåòîâ
6223 FSecrets := utils.readLongInt(st);
6224 // Òåêóùåå îðóæèå
6225 FCurrWeap := utils.readByte(st);
6226 // Æåëàåìîå îðóæèå
6227 FNextWeap := utils.readWord(st);
6228 // ...è ïàóçà
6229 FNextWeapDelay := utils.readByte(st);
6230 // Âðåìÿ çàðÿäêè BFG
6231 FBFGFireCounter := utils.readSmallInt(st);
6232 // Áóôåð óðîíà
6233 FDamageBuffer := utils.readLongInt(st);
6234 // Ïîñëåäíèé óäàðèâøèé
6235 FLastSpawnerUID := utils.readWord(st);
6236 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6237 FLastHit := utils.readByte(st);
6238 // Îáúåêò èãðîêà
6239 Obj_LoadState(@FObj, st);
6240 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6241 for i := A_BULLETS to A_HIGH do FAmmo[i] := utils.readWord(st);
6242 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6243 for i := A_BULLETS to A_HIGH do FMaxAmmo[i] := utils.readWord(st);
6244 // Íàëè÷èå îðóæèÿ
6245 for i := WP_FIRST to WP_LAST do FWeapon[i] := utils.readBool(st);
6246 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6247 for i := WP_FIRST to WP_LAST do FReloading[i] := utils.readWord(st);
6248 // Íàëè÷èå ðþêçàêà
6249 if utils.readBool(st) then Include(FRulez, R_ITEM_BACKPACK);
6250 // Íàëè÷èå êðàñíîãî êëþ÷à
6251 if utils.readBool(st) then Include(FRulez, R_KEY_RED);
6252 // Íàëè÷èå çåëåíîãî êëþ÷à
6253 if utils.readBool(st) then Include(FRulez, R_KEY_GREEN);
6254 // Íàëè÷èå ñèíåãî êëþ÷à
6255 if utils.readBool(st) then Include(FRulez, R_KEY_BLUE);
6256 // Íàëè÷èå áåðñåðêà
6257 if utils.readBool(st) then Include(FRulez, R_BERSERK);
6258 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6259 for i := MR_SUIT to MR_MAX do FMegaRulez[i] := utils.readLongWord(st);
6260 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6261 for i := T_RESPAWN to T_FLAGCAP do FTime[i] := utils.readLongWord(st);
6262 // Íàçâàíèå ìîäåëè
6263 str := utils.readStr(st);
6264 // Öâåò ìîäåëè
6265 FColor.R := utils.readByte(st);
6266 FColor.G := utils.readByte(st);
6267 FColor.B := utils.readByte(st);
6268 if (self = gPlayer1) then
6269 begin
6270 str := gPlayer1Settings.Model;
6271 FColor := gPlayer1Settings.Color;
6272 end
6273 else if (self = gPlayer2) then
6274 begin
6275 str := gPlayer2Settings.Model;
6276 FColor := gPlayer2Settings.Color;
6277 end;
6278 // Îáíîâëÿåì ìîäåëü èãðîêà
6279 SetModel(str);
6280 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
6281 FModel.Color := TEAMCOLOR[FTeam]
6282 else
6283 FModel.Color := FColor;
6284 end;
6287 procedure TPlayer.AllRulez(Health: Boolean);
6288 var
6289 a: Integer;
6290 begin
6291 if Health then
6292 begin
6293 FHealth := PLAYER_HP_LIMIT;
6294 FArmor := PLAYER_AP_LIMIT;
6295 Exit;
6296 end;
6298 for a := WP_FIRST to WP_LAST do FWeapon[a] := True;
6299 for a := A_BULLETS to A_HIGH do FAmmo[a] := 30000;
6300 FRulez := FRulez+[R_KEY_RED, R_KEY_GREEN, R_KEY_BLUE];
6301 end;
6303 procedure TPlayer.RestoreHealthArmor();
6304 begin
6305 FHealth := PLAYER_HP_LIMIT;
6306 FArmor := PLAYER_AP_LIMIT;
6307 end;
6309 procedure TPlayer.FragCombo();
6310 var
6311 Param: Integer;
6312 begin
6313 if (gGameSettings.GameMode in [GM_COOP, GM_SINGLE]) or g_Game_IsClient then
6314 Exit;
6315 if gTime - FLastFrag < FRAG_COMBO_TIME then
6316 begin
6317 if FFragCombo < 5 then
6318 Inc(FFragCombo);
6319 Param := FUID or (FFragCombo shl 16);
6320 if (FComboEvnt >= Low(gDelayedEvents)) and
6321 (FComboEvnt <= High(gDelayedEvents)) and
6322 gDelayedEvents[FComboEvnt].Pending and
6323 (gDelayedEvents[FComboEvnt].DEType = DE_KILLCOMBO) and
6324 (gDelayedEvents[FComboEvnt].DENum and $FFFF = FUID) then
6325 begin
6326 gDelayedEvents[FComboEvnt].Time := gTime + 500;
6327 gDelayedEvents[FComboEvnt].DENum := Param;
6328 end
6329 else
6330 FComboEvnt := g_Game_DelayEvent(DE_KILLCOMBO, 500, Param);
6331 end
6332 else
6333 FFragCombo := 1;
6335 FLastFrag := gTime;
6336 end;
6338 procedure TPlayer.GiveItem(ItemType: Byte);
6339 begin
6340 case ItemType of
6341 ITEM_SUIT:
6342 if FMegaRulez[MR_SUIT] < gTime+PLAYER_SUIT_TIME then
6343 begin
6344 FMegaRulez[MR_SUIT] := gTime+PLAYER_SUIT_TIME;
6345 end;
6347 ITEM_OXYGEN:
6348 if FAir < AIR_MAX then
6349 begin
6350 FAir := AIR_MAX;
6351 end;
6353 ITEM_MEDKIT_BLACK:
6354 begin
6355 if not (R_BERSERK in FRulez) then
6356 begin
6357 Include(FRulez, R_BERSERK);
6358 if FBFGFireCounter < 1 then
6359 begin
6360 FCurrWeap := WEAPON_KASTET;
6361 resetWeaponQueue();
6362 FModel.SetWeapon(WEAPON_KASTET);
6363 end;
6364 if gFlash <> 0 then
6365 Inc(FPain, 100);
6366 FBerserk := gTime+30000;
6367 end;
6368 if FHealth < PLAYER_HP_SOFT then
6369 begin
6370 FHealth := PLAYER_HP_SOFT;
6371 FBerserk := gTime+30000;
6372 end;
6373 end;
6375 ITEM_INVUL:
6376 if FMegaRulez[MR_INVUL] < gTime+PLAYER_INVUL_TIME then
6377 begin
6378 FMegaRulez[MR_INVUL] := gTime+PLAYER_INVUL_TIME;
6379 FSpawnInvul := 0;
6380 end;
6382 ITEM_INVIS:
6383 if FMegaRulez[MR_INVIS] < gTime+PLAYER_INVIS_TIME then
6384 begin
6385 FMegaRulez[MR_INVIS] := gTime+PLAYER_INVIS_TIME;
6386 end;
6388 ITEM_JETPACK:
6389 if FJetFuel < JET_MAX then
6390 begin
6391 FJetFuel := JET_MAX;
6392 end;
6394 ITEM_MEDKIT_SMALL: if FHealth < PLAYER_HP_SOFT then IncMax(FHealth, 10, PLAYER_HP_SOFT);
6395 ITEM_MEDKIT_LARGE: if FHealth < PLAYER_HP_SOFT then IncMax(FHealth, 25, PLAYER_HP_SOFT);
6397 ITEM_ARMOR_GREEN: if FArmor < PLAYER_AP_SOFT then FArmor := PLAYER_AP_SOFT;
6398 ITEM_ARMOR_BLUE: if FArmor < PLAYER_AP_LIMIT then FArmor := PLAYER_AP_LIMIT;
6400 ITEM_SPHERE_BLUE: if FHealth < PLAYER_HP_LIMIT then IncMax(FHealth, 100, PLAYER_HP_LIMIT);
6401 ITEM_SPHERE_WHITE:
6402 if (FHealth < PLAYER_HP_LIMIT) or (FArmor < PLAYER_AP_LIMIT) then
6403 begin
6404 if FHealth < PLAYER_HP_LIMIT then FHealth := PLAYER_HP_LIMIT;
6405 if FArmor < PLAYER_AP_LIMIT then FArmor := PLAYER_AP_LIMIT;
6406 end;
6408 ITEM_WEAPON_SAW: FWeapon[WEAPON_SAW] := True;
6409 ITEM_WEAPON_SHOTGUN1: FWeapon[WEAPON_SHOTGUN1] := True;
6410 ITEM_WEAPON_SHOTGUN2: FWeapon[WEAPON_SHOTGUN2] := True;
6411 ITEM_WEAPON_CHAINGUN: FWeapon[WEAPON_CHAINGUN] := True;
6412 ITEM_WEAPON_ROCKETLAUNCHER: FWeapon[WEAPON_ROCKETLAUNCHER] := True;
6413 ITEM_WEAPON_PLASMA: FWeapon[WEAPON_PLASMA] := True;
6414 ITEM_WEAPON_BFG: FWeapon[WEAPON_BFG] := True;
6415 ITEM_WEAPON_SUPERPULEMET: FWeapon[WEAPON_SUPERPULEMET] := True;
6416 ITEM_WEAPON_FLAMETHROWER: FWeapon[WEAPON_FLAMETHROWER] := True;
6418 ITEM_AMMO_BULLETS: if FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS] then IncMax(FAmmo[A_BULLETS], 10, FMaxAmmo[A_BULLETS]);
6419 ITEM_AMMO_BULLETS_BOX: if FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS] then IncMax(FAmmo[A_BULLETS], 50, FMaxAmmo[A_BULLETS]);
6420 ITEM_AMMO_SHELLS: if FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS] then IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
6421 ITEM_AMMO_SHELLS_BOX: if FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS] then IncMax(FAmmo[A_SHELLS], 25, FMaxAmmo[A_SHELLS]);
6422 ITEM_AMMO_ROCKET: if FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS] then IncMax(FAmmo[A_ROCKETS], 1, FMaxAmmo[A_ROCKETS]);
6423 ITEM_AMMO_ROCKET_BOX: if FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS] then IncMax(FAmmo[A_ROCKETS], 5, FMaxAmmo[A_ROCKETS]);
6424 ITEM_AMMO_CELL: if FAmmo[A_CELLS] < FMaxAmmo[A_CELLS] then IncMax(FAmmo[A_CELLS], 40, FMaxAmmo[A_CELLS]);
6425 ITEM_AMMO_CELL_BIG: if FAmmo[A_CELLS] < FMaxAmmo[A_CELLS] then IncMax(FAmmo[A_CELLS], 100, FMaxAmmo[A_CELLS]);
6426 ITEM_AMMO_FUELCAN: if FAmmo[A_FUEL] < FMaxAmmo[A_FUEL] then IncMax(FAmmo[A_FUEL], 100, FMaxAmmo[A_FUEL]);
6428 ITEM_AMMO_BACKPACK:
6429 if (FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS]) or
6430 (FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS]) or
6431 (FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS]) or
6432 (FAmmo[A_CELLS] < FMaxAmmo[A_CELLS]) or
6433 (FMaxAmmo[A_FUEL] < AmmoLimits[1, A_FUEL]) then
6434 begin
6435 FMaxAmmo[A_BULLETS] := AmmoLimits[1, A_BULLETS];
6436 FMaxAmmo[A_SHELLS] := AmmoLimits[1, A_SHELLS];
6437 FMaxAmmo[A_ROCKETS] := AmmoLimits[1, A_ROCKETS];
6438 FMaxAmmo[A_CELLS] := AmmoLimits[1, A_CELLS];
6439 FMaxAmmo[A_FUEL] := AmmoLimits[1, A_FUEL];
6441 if FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS] then IncMax(FAmmo[A_BULLETS], 10, FMaxAmmo[A_BULLETS]);
6442 if FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS] then IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
6443 if FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS] then IncMax(FAmmo[A_ROCKETS], 1, FMaxAmmo[A_ROCKETS]);
6444 if FAmmo[A_CELLS] < FMaxAmmo[A_CELLS] then IncMax(FAmmo[A_CELLS], 40, FMaxAmmo[A_CELLS]);
6446 FRulez := FRulez + [R_ITEM_BACKPACK];
6447 end;
6449 ITEM_KEY_RED: if not (R_KEY_RED in FRulez) then Include(FRulez, R_KEY_RED);
6450 ITEM_KEY_GREEN: if not (R_KEY_GREEN in FRulez) then Include(FRulez, R_KEY_GREEN);
6451 ITEM_KEY_BLUE: if not (R_KEY_BLUE in FRulez) then Include(FRulez, R_KEY_BLUE);
6453 ITEM_BOTTLE: if FHealth < PLAYER_HP_LIMIT then IncMax(FHealth, 4, PLAYER_HP_LIMIT);
6454 ITEM_HELMET: if FArmor < PLAYER_AP_LIMIT then IncMax(FArmor, 5, PLAYER_AP_LIMIT);
6456 else
6457 Exit;
6458 end;
6459 if g_Game_IsNet and g_Game_IsServer then
6460 MH_SEND_PlayerStats(FUID);
6461 end;
6463 procedure TPlayer.FlySmoke(Times: DWORD = 1);
6464 var
6465 id, i: DWORD;
6466 Anim: TAnimation;
6467 begin
6468 if (Random(5) = 1) and (Times = 1) then
6469 Exit;
6471 if BodyInLiquid(0, 0) then
6472 begin
6473 g_GFX_Bubbles(Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2)+Random(3)-1,
6474 Obj.Y+Obj.Rect.Height+8, 1, 8, 4);
6475 if Random(2) = 0 then
6476 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj.X, FObj.Y)
6477 else
6478 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj.X, FObj.Y);
6479 Exit;
6480 end;
6482 if g_Frames_Get(id, 'FRAMES_SMOKE') then
6483 begin
6484 for i := 1 to Times do
6485 begin
6486 Anim := TAnimation.Create(id, False, 3);
6487 Anim.Alpha := 150;
6488 g_GFX_OnceAnim(Obj.X+Obj.Rect.X+Random(Obj.Rect.Width+Times*2)-(Anim.Width div 2),
6489 Obj.Y+Obj.Rect.Height-4+Random(8+Times*2), Anim, ONCEANIM_SMOKE);
6490 Anim.Free();
6491 end;
6492 end;
6493 end;
6495 procedure TPlayer.OnFireFlame(Times: DWORD = 1);
6496 var
6497 id, i: DWORD;
6498 Anim: TAnimation;
6499 begin
6500 if (Random(10) = 1) and (Times = 1) then
6501 Exit;
6503 if g_Frames_Get(id, 'FRAMES_FLAME') then
6504 begin
6505 for i := 1 to Times do
6506 begin
6507 Anim := TAnimation.Create(id, False, 3);
6508 Anim.Alpha := 0;
6509 g_GFX_OnceAnim(Obj.X+Obj.Rect.X+Random(Obj.Rect.Width+Times*2)-(Anim.Width div 2),
6510 Obj.Y+8+Random(8+Times*2), Anim, ONCEANIM_SMOKE);
6511 Anim.Free();
6512 end;
6513 end;
6514 end;
6516 procedure TPlayer.PauseSounds(Enable: Boolean);
6517 begin
6518 FSawSound.Pause(Enable);
6519 FSawSoundIdle.Pause(Enable);
6520 FSawSoundHit.Pause(Enable);
6521 FSawSoundSelect.Pause(Enable);
6522 FFlameSoundOn.Pause(Enable);
6523 FFlameSoundOff.Pause(Enable);
6524 FFlameSoundWork.Pause(Enable);
6525 FJetSoundFly.Pause(Enable);
6526 FJetSoundOn.Pause(Enable);
6527 FJetSoundOff.Pause(Enable);
6528 end;
6530 { T C o r p s e : }
6532 constructor TCorpse.Create(X, Y: Integer; ModelName: String; aMess: Boolean);
6533 begin
6534 g_Obj_Init(@FObj);
6535 FObj.X := X;
6536 FObj.Y := Y;
6537 FObj.Rect := PLAYER_CORPSERECT;
6538 FModelName := ModelName;
6539 FMess := aMess;
6541 if FMess then
6542 begin
6543 FState := CORPSE_STATE_MESS;
6544 g_PlayerModel_GetAnim(ModelName, A_DIE2, FAnimation, FAnimationMask);
6545 end
6546 else
6547 begin
6548 FState := CORPSE_STATE_NORMAL;
6549 g_PlayerModel_GetAnim(ModelName, A_DIE1, FAnimation, FAnimationMask);
6550 end;
6551 end;
6553 destructor TCorpse.Destroy();
6554 begin
6555 FAnimation.Free();
6557 inherited;
6558 end;
6560 function TCorpse.ObjPtr (): PObj; inline; begin result := @FObj; end;
6562 procedure TCorpse.positionChanged (); inline; begin end;
6564 procedure TCorpse.moveBy (dx, dy: Integer); inline;
6565 begin
6566 if (dx <> 0) or (dy <> 0) then
6567 begin
6568 FObj.X += dx;
6569 FObj.Y += dy;
6570 positionChanged();
6571 end;
6572 end;
6575 procedure TCorpse.getMapBox (out x, y, w, h: Integer); inline;
6576 begin
6577 x := FObj.X+PLAYER_CORPSERECT.X;
6578 y := FObj.Y+PLAYER_CORPSERECT.Y;
6579 w := PLAYER_CORPSERECT.Width;
6580 h := PLAYER_CORPSERECT.Height;
6581 end;
6584 procedure TCorpse.Damage(Value: Word; SpawnerUID: Word; vx, vy: Integer);
6585 var
6586 pm: TPlayerModel;
6587 Blood: TModelBlood;
6588 begin
6589 if FState = CORPSE_STATE_REMOVEME then
6590 Exit;
6592 FDamage := FDamage + Value;
6594 if FDamage > 150 then
6595 begin
6596 if FAnimation <> nil then
6597 begin
6598 FAnimation.Free();
6599 FAnimation := nil;
6601 FState := CORPSE_STATE_REMOVEME;
6603 g_Player_CreateGibs(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
6604 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
6605 FModelName, FColor);
6606 // Çâóê ìÿñà îò òðóïà:
6607 pm := g_PlayerModel_Get(FModelName);
6608 pm.PlaySound(MODELSOUND_DIE, 5, FObj.X, FObj.Y);
6609 pm.Free;
6611 // Çëîâåùèé ñìåõ:
6612 if (gBodyKillEvent <> -1)
6613 and gDelayedEvents[gBodyKillEvent].Pending then
6614 gDelayedEvents[gBodyKillEvent].Pending := False;
6615 gBodyKillEvent := g_Game_DelayEvent(DE_BODYKILL, 1050, SpawnerUID);
6616 end;
6617 end
6618 else
6619 begin
6620 Blood := g_PlayerModel_GetBlood(FModelName);
6621 FObj.Vel.X := FObj.Vel.X + vx;
6622 FObj.Vel.Y := FObj.Vel.Y + vy;
6623 g_GFX_Blood(FObj.X+PLAYER_CORPSERECT.X+(PLAYER_CORPSERECT.Width div 2),
6624 FObj.Y+PLAYER_CORPSERECT.Y+(PLAYER_CORPSERECT.Height div 2),
6625 Value, vx, vy, 16, (PLAYER_CORPSERECT.Height*2) div 3,
6626 Blood.R, Blood.G, Blood.B, Blood.Kind);
6627 end;
6628 end;
6630 procedure TCorpse.Draw();
6631 var
6632 fX, fY: Integer;
6633 begin
6634 if FState = CORPSE_STATE_REMOVEME then
6635 Exit;
6637 FObj.lerp(gLerpFactor, fX, fY);
6639 if FAnimation <> nil then
6640 FAnimation.Draw(fX, fY, TMirrorType.None);
6642 if FAnimationMask <> nil then
6643 begin
6644 e_Colors := FColor;
6645 FAnimationMask.Draw(fX, fY, TMirrorType.None);
6646 e_Colors.R := 255;
6647 e_Colors.G := 255;
6648 e_Colors.B := 255;
6649 end;
6650 end;
6652 procedure TCorpse.Update();
6653 var
6654 st: Word;
6655 begin
6656 if FState = CORPSE_STATE_REMOVEME then
6657 Exit;
6659 FObj.oldX := FObj.X;
6660 FObj.oldY := FObj.Y;
6662 if gTime mod (GAME_TICK*2) <> 0 then
6663 begin
6664 g_Obj_Move(@FObj, True, True, True);
6665 positionChanged(); // this updates spatial accelerators
6666 Exit;
6667 end;
6669 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6670 FObj.Vel.X := z_dec(FObj.Vel.X, 1);
6672 st := g_Obj_Move(@FObj, True, True, True);
6673 positionChanged(); // this updates spatial accelerators
6675 if WordBool(st and MOVE_FALLOUT) then
6676 begin
6677 FState := CORPSE_STATE_REMOVEME;
6678 Exit;
6679 end;
6681 if FAnimation <> nil then
6682 FAnimation.Update();
6683 if FAnimationMask <> nil then
6684 FAnimationMask.Update();
6685 end;
6688 procedure TCorpse.SaveState (st: TStream);
6689 var
6690 anim: Boolean;
6691 begin
6692 assert(st <> nil);
6694 // Ñèãíàòóðà òðóïà
6695 utils.writeSign(st, 'CORP');
6696 utils.writeInt(st, Byte(0));
6697 // Ñîñòîÿíèå
6698 utils.writeInt(st, Byte(FState));
6699 // Íàêîïëåííûé óðîí
6700 utils.writeInt(st, Byte(FDamage));
6701 // Öâåò
6702 utils.writeInt(st, Byte(FColor.R));
6703 utils.writeInt(st, Byte(FColor.G));
6704 utils.writeInt(st, Byte(FColor.B));
6705 // Îáúåêò òðóïà
6706 Obj_SaveState(st, @FObj);
6707 utils.writeInt(st, Word(FPlayerUID));
6708 // Åñòü ëè àíèìàöèÿ
6709 anim := (FAnimation <> nil);
6710 utils.writeBool(st, anim);
6711 // Åñëè åñòü - ñîõðàíÿåì
6712 if anim then FAnimation.SaveState(st);
6713 // Åñòü ëè ìàñêà àíèìàöèè
6714 anim := (FAnimationMask <> nil);
6715 utils.writeBool(st, anim);
6716 // Åñëè åñòü - ñîõðàíÿåì
6717 if anim then FAnimationMask.SaveState(st);
6718 end;
6721 procedure TCorpse.LoadState (st: TStream);
6722 var
6723 anim: Boolean;
6724 begin
6725 assert(st <> nil);
6727 // Ñèãíàòóðà òðóïà
6728 if not utils.checkSign(st, 'CORP') then raise XStreamError.Create('invalid corpse signature');
6729 if (utils.readByte(st) <> 0) then raise XStreamError.Create('invalid corpse version');
6730 // Ñîñòîÿíèå
6731 FState := utils.readByte(st);
6732 // Íàêîïëåííûé óðîí
6733 FDamage := utils.readByte(st);
6734 // Öâåò
6735 FColor.R := utils.readByte(st);
6736 FColor.G := utils.readByte(st);
6737 FColor.B := utils.readByte(st);
6738 // Îáúåêò òðóïà
6739 Obj_LoadState(@FObj, st);
6740 FPlayerUID := utils.readWord(st);
6741 // Åñòü ëè àíèìàöèÿ
6742 anim := utils.readBool(st);
6743 // Åñëè åñòü - çàãðóæàåì
6744 if anim then
6745 begin
6746 Assert(FAnimation <> nil, 'TCorpse.LoadState: no FAnimation');
6747 FAnimation.LoadState(st);
6748 end;
6749 // Åñòü ëè ìàñêà àíèìàöèè
6750 anim := utils.readBool(st);
6751 // Åñëè åñòü - çàãðóæàåì
6752 if anim then
6753 begin
6754 Assert(FAnimationMask <> nil, 'TCorpse.LoadState: no FAnimationMask');
6755 FAnimationMask.LoadState(st);
6756 end;
6757 end;
6759 { T B o t : }
6761 constructor TBot.Create();
6762 var
6763 a: Integer;
6764 begin
6765 inherited Create();
6767 FPhysics := True;
6768 FSpectator := False;
6769 FGhost := False;
6771 FIamBot := True;
6773 Inc(gNumBots);
6775 for a := WP_FIRST to WP_LAST do
6776 begin
6777 FDifficult.WeaponPrior[a] := WEAPON_PRIOR1[a];
6778 FDifficult.CloseWeaponPrior[a] := WEAPON_PRIOR2[a];
6779 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6780 end;
6781 end;
6783 destructor TBot.Destroy();
6784 begin
6785 Dec(gNumBots);
6786 inherited Destroy();
6787 end;
6789 procedure TBot.Draw();
6790 begin
6791 inherited Draw();
6793 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6794 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6795 end;
6797 procedure TBot.Respawn(Silent: Boolean; Force: Boolean = False);
6798 begin
6799 inherited Respawn(Silent, Force);
6801 FAIFlags := nil;
6802 FSelectedWeapon := FCurrWeap;
6803 resetWeaponQueue();
6804 FTargetUID := 0;
6805 end;
6807 procedure TBot.UpdateCombat();
6808 type
6809 TTarget = record
6810 UID: Word;
6811 X, Y: Integer;
6812 Rect: TRectWH;
6813 cX, cY: Integer;
6814 Dist: Word;
6815 Line: Boolean;
6816 Visible: Boolean;
6817 IsPlayer: Boolean;
6818 end;
6820 TTargetRecord = array of TTarget;
6822 function Compare(a, b: TTarget): Integer;
6823 begin
6824 if a.Line and not b.Line then // A íà ëèíèè îãíÿ
6825 Result := -1
6826 else
6827 if not a.Line and b.Line then // B íà ëèíèè îãíÿ
6828 Result := 1
6829 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6830 if (a.Line and b.Line) or ((not a.Line) and (not b.Line)) then
6831 begin
6832 if a.Dist > b.Dist then // B áëèæå
6833 Result := 1
6834 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6835 Result := -1;
6836 end
6837 else // Ñòðàííî -> A
6838 Result := -1;
6839 end;
6841 var
6842 a, x1, y1, x2, y2: Integer;
6843 targets: TTargetRecord;
6844 ammo: Word;
6845 Target, BestTarget: TTarget;
6846 firew, fireh: Integer;
6847 angle: SmallInt;
6848 mon: TMonster;
6849 pla, tpla: TPlayer;
6850 vsPlayer, vsMonster, ok: Boolean;
6853 function monsUpdate (mon: TMonster): Boolean;
6854 begin
6855 result := false; // don't stop
6856 if mon.alive and (mon.MonsterType <> MONSTER_BARREL) then
6857 begin
6858 if not TargetOnScreen(mon.Obj.X+mon.Obj.Rect.X, mon.Obj.Y+mon.Obj.Rect.Y) then exit;
6860 x2 := mon.Obj.X+mon.Obj.Rect.X+(mon.Obj.Rect.Width div 2);
6861 y2 := mon.Obj.Y+mon.Obj.Rect.Y+(mon.Obj.Rect.Height div 2);
6863 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6864 if g_TraceVector(x1, y1, x2, y2) then
6865 begin
6866 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6867 SetLength(targets, Length(targets)+1);
6868 with targets[High(targets)] do
6869 begin
6870 UID := mon.UID;
6871 X := mon.Obj.X;
6872 Y := mon.Obj.Y;
6873 cX := x2;
6874 cY := y2;
6875 Rect := mon.Obj.Rect;
6876 Dist := g_PatchLength(x1, y1, x2, y2);
6877 Line := (y1+4 < Target.Y + mon.Obj.Rect.Y + mon.Obj.Rect.Height) and
6878 (y1-4 > Target.Y + mon.Obj.Rect.Y);
6879 Visible := True;
6880 IsPlayer := False;
6881 end;
6882 end;
6883 end;
6884 end;
6886 begin
6887 vsPlayer := LongBool(gGameSettings.Options and GAME_OPTION_BOTVSPLAYER);
6888 vsMonster := LongBool(gGameSettings.Options and GAME_OPTION_BOTVSMONSTER);
6890 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6891 if FCurrWeap <> FSelectedWeapon then
6892 NextWeapon();
6894 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6895 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap = FSelectedWeapon) then
6896 begin
6897 RemoveAIFlag('NEEDFIRE');
6899 case FCurrWeap of
6900 WEAPON_PLASMA, WEAPON_SUPERPULEMET, WEAPON_CHAINGUN: PressKey(KEY_FIRE, 20);
6901 WEAPON_SAW, WEAPON_KASTET, WEAPON_FLAMETHROWER: PressKey(KEY_FIRE, 40);
6902 else PressKey(KEY_FIRE);
6903 end;
6904 end;
6906 // Êîîðäèíàòû ñòâîëà:
6907 x1 := FObj.X + WEAPONPOINT[FDirection].X;
6908 y1 := FObj.Y + WEAPONPOINT[FDirection].Y;
6910 Target.UID := FTargetUID;
6912 ok := False;
6913 if Target.UID <> 0 then
6914 begin // Öåëü åñòü - íàñòðàèâàåì
6915 if (g_GetUIDType(Target.UID) = UID_PLAYER) and
6916 vsPlayer then
6917 begin // Èãðîê
6918 tpla := g_Player_Get(Target.UID);
6919 if tpla <> nil then
6920 with tpla do
6921 begin
6922 if (@FObj) <> nil then
6923 begin
6924 Target.X := FObj.X;
6925 Target.Y := FObj.Y;
6926 end;
6927 end;
6929 Target.cX := Target.X + PLAYER_RECT_CX;
6930 Target.cY := Target.Y + PLAYER_RECT_CY;
6931 Target.Rect := PLAYER_RECT;
6932 Target.Visible := g_TraceVector(x1, y1, Target.cX, Target.cY);
6933 Target.Line := (y1+4 < Target.Y+PLAYER_RECT.Y+PLAYER_RECT.Height) and
6934 (y1-4 > Target.Y+PLAYER_RECT.Y);
6935 Target.IsPlayer := True;
6936 ok := True;
6937 end
6938 else
6939 if (g_GetUIDType(Target.UID) = UID_MONSTER) and
6940 vsMonster then
6941 begin // Ìîíñòð
6942 mon := g_Monsters_ByUID(Target.UID);
6943 if mon <> nil then
6944 begin
6945 Target.X := mon.Obj.X;
6946 Target.Y := mon.Obj.Y;
6948 Target.cX := Target.X + mon.Obj.Rect.X + (mon.Obj.Rect.Width div 2);
6949 Target.cY := Target.Y + mon.Obj.Rect.Y + (mon.Obj.Rect.Height div 2);
6950 Target.Rect := mon.Obj.Rect;
6951 Target.Visible := g_TraceVector(x1, y1, Target.cX, Target.cY);
6952 Target.Line := (y1+4 < Target.Y + mon.Obj.Rect.Y + mon.Obj.Rect.Height) and
6953 (y1-4 > Target.Y + mon.Obj.Rect.Y);
6954 Target.IsPlayer := False;
6955 ok := True;
6956 end;
6957 end;
6958 end;
6960 if not ok then
6961 begin // Öåëè íåò - îáíóëÿåì
6962 Target.X := 0;
6963 Target.Y := 0;
6964 Target.cX := 0;
6965 Target.cY := 0;
6966 Target.Visible := False;
6967 Target.Line := False;
6968 Target.IsPlayer := False;
6969 end;
6971 targets := nil;
6973 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6974 if (not Target.Line) or (not Target.Visible) then
6975 begin
6976 // Èãðîêè:
6977 if vsPlayer then
6978 for a := 0 to High(gPlayers) do
6979 if (gPlayers[a] <> nil) and (gPlayers[a].alive) and
6980 (gPlayers[a].FUID <> FUID) and
6981 (not SameTeam(FUID, gPlayers[a].FUID)) and
6982 (not gPlayers[a].NoTarget) and
6983 (gPlayers[a].FMegaRulez[MR_INVIS] < gTime) then
6984 begin
6985 if not TargetOnScreen(gPlayers[a].FObj.X + PLAYER_RECT.X,
6986 gPlayers[a].FObj.Y + PLAYER_RECT.Y) then
6987 Continue;
6989 x2 := gPlayers[a].FObj.X + PLAYER_RECT_CX;
6990 y2 := gPlayers[a].FObj.Y + PLAYER_RECT_CY;
6992 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6993 if g_TraceVector(x1, y1, x2, y2) then
6994 begin
6995 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6996 SetLength(targets, Length(targets)+1);
6997 with targets[High(targets)] do
6998 begin
6999 UID := gPlayers[a].FUID;
7000 X := gPlayers[a].FObj.X;
7001 Y := gPlayers[a].FObj.Y;
7002 cX := x2;
7003 cY := y2;
7004 Rect := PLAYER_RECT;
7005 Dist := g_PatchLength(x1, y1, x2, y2);
7006 Line := (y1+4 < Target.Y+PLAYER_RECT.Y+PLAYER_RECT.Height) and
7007 (y1-4 > Target.Y+PLAYER_RECT.Y);
7008 Visible := True;
7009 IsPlayer := True;
7010 end;
7011 end;
7012 end;
7014 // Ìîíñòðû:
7015 if vsMonster then g_Mons_ForEach(monsUpdate);
7016 end;
7018 // Åñëè åñòü âîçìîæíûå öåëè:
7019 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
7020 if targets <> nil then
7021 begin
7022 // Âûáèðàåì íàèëó÷øóþ öåëü:
7023 BestTarget := targets[0];
7024 if Length(targets) > 1 then
7025 for a := 1 to High(targets) do
7026 if Compare(BestTarget, targets[a]) = 1 then
7027 BestTarget := targets[a];
7029 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
7030 if ((not Target.Visible) and BestTarget.Visible and (Target.UID <> BestTarget.UID)) or
7031 ((not Target.Line) and BestTarget.Line and BestTarget.Visible) then
7032 begin
7033 Target := BestTarget;
7035 if (Healthy() = 3) or ((Healthy() = 2)) then
7036 begin // Åñëè çäîðîâû - äîãîíÿåì
7037 if ((RunDirection() = TDirection.D_LEFT) and (Target.X > FObj.X)) then
7038 SetAIFlag('GORIGHT', '1');
7039 if ((RunDirection() = TDirection.D_RIGHT) and (Target.X < FObj.X)) then
7040 SetAIFlag('GOLEFT', '1');
7041 end
7042 else
7043 begin // Åñëè ïîáèòû - óáåãàåì
7044 if ((RunDirection() = TDirection.D_LEFT) and (Target.X < FObj.X)) then
7045 SetAIFlag('GORIGHT', '1');
7046 if ((RunDirection() = TDirection.D_RIGHT) and (Target.X > FObj.X)) then
7047 SetAIFlag('GOLEFT', '1');
7048 end;
7050 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
7051 SelectWeapon(Abs(x1-Target.cX));
7052 end;
7053 end;
7055 // Åñëè åñòü öåëü:
7056 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
7057 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
7058 if Target.UID <> 0 then
7059 begin
7060 if not TargetOnScreen(Target.X + Target.Rect.X,
7061 Target.Y + Target.Rect.Y) then
7062 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
7063 if (Healthy() = 3) or ((Healthy() = 2)) then
7064 begin // Åñëè çäîðîâû - äîãîíÿåì
7065 if ((RunDirection() = TDirection.D_LEFT) and (Target.X > FObj.X)) then
7066 SetAIFlag('GORIGHT', '1');
7067 if ((RunDirection() = TDirection.D_RIGHT) and (Target.X < FObj.X)) then
7068 SetAIFlag('GOLEFT', '1');
7069 end
7070 else
7071 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
7072 Target.UID := 0;
7073 if ((RunDirection() = TDirection.D_LEFT) and (Target.X < FObj.X)) then
7074 SetAIFlag('GORIGHT', '1');
7075 if ((RunDirection() = TDirection.D_RIGHT) and (Target.X > FObj.X)) then
7076 SetAIFlag('GOLEFT', '1');
7077 end;
7078 end
7079 else
7080 begin // Öåëü ïîêà íà "ýêðàíå"
7081 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
7082 if g_TraceVector(x1, y1, Target.cX, Target.cY) then
7083 FLastVisible := gTime;
7084 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
7085 if (Abs(FObj.Y-Target.Y) <= 128) then
7086 begin
7087 if ((RunDirection() = TDirection.D_LEFT) and (Target.X > FObj.X)) then
7088 SetAIFlag('GORIGHT', '1');
7089 if ((RunDirection() = TDirection.D_RIGHT) and (Target.X < FObj.X)) then
7090 SetAIFlag('GOLEFT', '1');
7091 end;
7092 end;
7094 // Âûáèðàåì óãîë ââåðõ:
7095 if FDirection = TDirection.D_LEFT then
7096 angle := ANGLE_LEFTUP
7097 else
7098 angle := ANGLE_RIGHTUP;
7100 firew := Trunc(Cos(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
7101 fireh := Trunc(Sin(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
7103 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
7104 if g_CollideLine(x1, y1, x1+firew, y1+fireh,
7105 Target.X+Target.Rect.X+GetInterval(FDifficult.DiagPrecision, 128), //96
7106 Target.Y+Target.Rect.Y+GetInterval(FDifficult.DiagPrecision, 128),
7107 Target.Rect.Width, Target.Rect.Height) and
7108 g_TraceVector(x1, y1, Target.cX, Target.cY) then
7109 begin // òî íóæíî ñòðåëÿòü ââåðõ
7110 SetAIFlag('NEEDFIRE', '1');
7111 SetAIFlag('NEEDSEEUP', '1');
7112 end;
7114 // Âûáèðàåì óãîë âíèç:
7115 if FDirection = TDirection.D_LEFT then
7116 angle := ANGLE_LEFTDOWN
7117 else
7118 angle := ANGLE_RIGHTDOWN;
7120 firew := Trunc(Cos(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
7121 fireh := Trunc(Sin(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
7123 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
7124 if g_CollideLine(x1, y1, x1+firew, y1+fireh,
7125 Target.X+Target.Rect.X+GetInterval(FDifficult.DiagPrecision, 128),
7126 Target.Y+Target.Rect.Y+GetInterval(FDifficult.DiagPrecision, 128),
7127 Target.Rect.Width, Target.Rect.Height) and
7128 g_TraceVector(x1, y1, Target.cX, Target.cY) then
7129 begin // òî íóæíî ñòðåëÿòü âíèç
7130 SetAIFlag('NEEDFIRE', '1');
7131 SetAIFlag('NEEDSEEDOWN', '1');
7132 end;
7134 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
7135 if Target.Visible and
7136 (y1+4 < Target.Y+Target.Rect.Y+Target.Rect.Height) and
7137 (y1-4 > Target.Y+Target.Rect.Y) then
7138 begin
7139 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
7140 if ((FDirection = TDirection.D_LEFT) and (Target.X < FObj.X)) or
7141 ((FDirection = TDirection.D_RIGHT) and (Target.X > FObj.X)) then
7142 begin // òî íóæíî ñòðåëÿòü âïåðåä
7143 SetAIFlag('NEEDFIRE', '1');
7144 SetAIFlag('NEEDSEEDOWN', '');
7145 SetAIFlag('NEEDSEEUP', '');
7146 end;
7147 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
7148 if Abs(FObj.X-Target.X) < Trunc(gPlayerScreenSize.X*0.75) then
7149 if GetRnd(FDifficult.CloseJump) then
7150 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
7151 if Abs(FObj.X-Target.X) < 128 then
7152 a := 4
7153 else
7154 a := 30;
7155 if Random(a) = 0 then
7156 SetAIFlag('NEEDJUMP', '1');
7157 end;
7158 end;
7160 // Åñëè öåëü âñå åùå åñòü:
7161 if Target.UID <> 0 then
7162 if gTime-FLastVisible > 2000 then // Åñëè âèäåëè äàâíî
7163 Target.UID := 0 // òî çàáûòü öåëü
7164 else // Åñëè âèäåëè íåäàâíî
7165 begin // íî öåëü óáèëè
7166 if Target.IsPlayer then
7167 begin // Öåëü - èãðîê
7168 pla := g_Player_Get(Target.UID);
7169 if (pla = nil) or (not pla.alive) or pla.NoTarget or
7170 (pla.FMegaRulez[MR_INVIS] >= gTime) then
7171 Target.UID := 0; // òî çàáûòü öåëü
7172 end
7173 else
7174 begin // Öåëü - ìîíñòð
7175 mon := g_Monsters_ByUID(Target.UID);
7176 if (mon = nil) or (not mon.alive) then
7177 Target.UID := 0; // òî çàáûòü öåëü
7178 end;
7179 end;
7180 end; // if Target.UID <> 0
7182 FTargetUID := Target.UID;
7184 // Åñëè âîçìîæíûõ öåëåé íåò:
7185 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
7186 if targets = nil then
7187 if GetAIFlag('ATTACKLEFT') <> '' then
7188 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
7189 RemoveAIFlag('ATTACKLEFT');
7191 SetAIFlag('NEEDJUMP', '1');
7193 if RunDirection() = TDirection.D_RIGHT then
7194 begin // Èäåì íå â òó ñòîðîíó
7195 if (Healthy() > 1) and GetRnd(FDifficult.InvisFire) then
7196 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
7197 SetAIFlag('NEEDFIRE', '1');
7198 SetAIFlag('GOLEFT', '1');
7199 end;
7200 end
7201 else
7202 begin // Èäåì â íóæíóþ ñòîðîíó
7203 if GetRnd(FDifficult.InvisFire) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7204 SetAIFlag('NEEDFIRE', '1');
7205 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7206 SetAIFlag('GORIGHT', '1');
7207 end;
7208 end
7209 else
7210 if GetAIFlag('ATTACKRIGHT') <> '' then
7211 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
7212 RemoveAIFlag('ATTACKRIGHT');
7214 SetAIFlag('NEEDJUMP', '1');
7216 if RunDirection() = TDirection.D_LEFT then
7217 begin // Èäåì íå â òó ñòîðîíó
7218 if (Healthy() > 1) and GetRnd(FDifficult.InvisFire) then
7219 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
7220 SetAIFlag('NEEDFIRE', '1');
7221 SetAIFlag('GORIGHT', '1');
7222 end;
7223 end
7224 else
7225 begin
7226 if GetRnd(FDifficult.InvisFire) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7227 SetAIFlag('NEEDFIRE', '1');
7228 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7229 SetAIFlag('GOLEFT', '1');
7230 end;
7231 end;
7233 //HACK! (does it belongs there?)
7234 RealizeCurrentWeapon();
7236 // Åñëè åñòü âîçìîæíûå öåëè:
7237 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
7238 if (targets <> nil) and (GetAIFlag('NEEDFIRE') <> '') then
7239 for a := 0 to High(targets) do
7240 begin
7241 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
7242 if GetRnd(FDifficult.DiagFire) then
7243 begin
7244 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
7245 if FDirection = TDirection.D_LEFT then
7246 angle := ANGLE_LEFTUP
7247 else
7248 angle := ANGLE_RIGHTUP;
7250 firew := Trunc(Cos(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
7251 fireh := Trunc(Sin(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
7253 if g_CollideLine(x1, y1, x1+firew, y1+fireh,
7254 targets[a].X+targets[a].Rect.X+GetInterval(FDifficult.DiagPrecision, 128),
7255 targets[a].Y+targets[a].Rect.Y+GetInterval(FDifficult.DiagPrecision, 128),
7256 targets[a].Rect.Width, targets[a].Rect.Height) and
7257 g_TraceVector(x1, y1, targets[a].cX, targets[a].cY) then
7258 begin
7259 SetAIFlag('NEEDFIRE', '1');
7260 SetAIFlag('NEEDSEEUP', '1');
7261 end;
7263 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
7264 if FDirection = TDirection.D_LEFT then
7265 angle := ANGLE_LEFTDOWN
7266 else
7267 angle := ANGLE_RIGHTDOWN;
7269 firew := Trunc(Cos(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
7270 fireh := Trunc(Sin(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
7272 if g_CollideLine(x1, y1, x1+firew, y1+fireh,
7273 targets[a].X+targets[a].Rect.X+GetInterval(FDifficult.DiagPrecision, 128),
7274 targets[a].Y+targets[a].Rect.Y+GetInterval(FDifficult.DiagPrecision, 128),
7275 targets[a].Rect.Width, targets[a].Rect.Height) and
7276 g_TraceVector(x1, y1, targets[a].cX, targets[a].cY) then
7277 begin
7278 SetAIFlag('NEEDFIRE', '1');
7279 SetAIFlag('NEEDSEEDOWN', '1');
7280 end;
7281 end;
7283 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
7284 if targets[a].Line and targets[a].Visible and
7285 (((FDirection = TDirection.D_LEFT) and (targets[a].X < FObj.X)) or
7286 ((FDirection = TDirection.D_RIGHT) and (targets[a].X > FObj.X))) then
7287 begin
7288 SetAIFlag('NEEDFIRE', '1');
7289 Break;
7290 end;
7291 end;
7293 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
7294 if g_Weapon_Danger(FUID, FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y,
7295 PLAYER_RECT.Width, PLAYER_RECT.Height,
7296 40+GetInterval(FDifficult.Cover, 40)) then
7297 SetAIFlag('NEEDJUMP', '1');
7299 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
7300 ammo := GetAmmoByWeapon(FCurrWeap);
7301 if ((FCurrWeap = WEAPON_SHOTGUN2) and (ammo < 2)) or
7302 ((FCurrWeap = WEAPON_BFG) and (ammo < 40)) or
7303 (ammo = 0) then
7304 SetAIFlag('SELECTWEAPON', '1');
7306 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
7307 if GetAIFlag('SELECTWEAPON') = '1' then
7308 begin
7309 SelectWeapon(-1);
7310 RemoveAIFlag('SELECTWEAPON');
7311 end;
7312 end;
7314 procedure TBot.Update();
7315 var
7316 EnableAI: Boolean;
7317 begin
7318 if not FAlive then
7319 begin // Respawn
7320 ReleaseKeys();
7321 PressKey(KEY_UP);
7322 end
7323 else
7324 begin
7325 EnableAI := True;
7327 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
7328 if (g_debug_BotAIOff = 1) and (Team = TEAM_RED) then
7329 EnableAI := False;
7330 if (g_debug_BotAIOff = 2) and (Team = TEAM_BLUE) then
7331 EnableAI := False;
7332 if g_debug_BotAIOff = 3 then
7333 EnableAI := False;
7335 if EnableAI then
7336 begin
7337 UpdateMove();
7338 UpdateCombat();
7339 end
7340 else
7341 begin
7342 RealizeCurrentWeapon();
7343 end;
7344 end;
7346 inherited Update();
7347 end;
7349 procedure TBot.ReleaseKey(Key: Byte);
7350 begin
7351 with FKeys[Key] do
7352 begin
7353 Pressed := False;
7354 Time := 0;
7355 end;
7356 end;
7358 function TBot.KeyPressed(Key: Word): Boolean;
7359 begin
7360 Result := FKeys[Key].Pressed;
7361 end;
7363 function TBot.GetAIFlag(aName: String20): String20;
7364 var
7365 a: Integer;
7366 begin
7367 Result := '';
7369 aName := LowerCase(aName);
7371 if FAIFlags <> nil then
7372 for a := 0 to High(FAIFlags) do
7373 if LowerCase(FAIFlags[a].Name) = aName then
7374 begin
7375 Result := FAIFlags[a].Value;
7376 Break;
7377 end;
7378 end;
7380 procedure TBot.RemoveAIFlag(aName: String20);
7381 var
7382 a, b: Integer;
7383 begin
7384 if FAIFlags = nil then Exit;
7386 aName := LowerCase(aName);
7388 for a := 0 to High(FAIFlags) do
7389 if LowerCase(FAIFlags[a].Name) = aName then
7390 begin
7391 if a <> High(FAIFlags) then
7392 for b := a to High(FAIFlags)-1 do
7393 FAIFlags[b] := FAIFlags[b+1];
7395 SetLength(FAIFlags, Length(FAIFlags)-1);
7396 Break;
7397 end;
7398 end;
7400 procedure TBot.SetAIFlag(aName, fValue: String20);
7401 var
7402 a: Integer;
7403 ok: Boolean;
7404 begin
7405 a := 0;
7406 ok := False;
7408 aName := LowerCase(aName);
7410 if FAIFlags <> nil then
7411 for a := 0 to High(FAIFlags) do
7412 if LowerCase(FAIFlags[a].Name) = aName then
7413 begin
7414 ok := True;
7415 Break;
7416 end;
7418 if ok then FAIFlags[a].Value := fValue
7419 else
7420 begin
7421 SetLength(FAIFlags, Length(FAIFlags)+1);
7422 with FAIFlags[High(FAIFlags)] do
7423 begin
7424 Name := aName;
7425 Value := fValue;
7426 end;
7427 end;
7428 end;
7430 procedure TBot.UpdateMove;
7432 procedure GoLeft(Time: Word = 1);
7433 begin
7434 ReleaseKey(KEY_LEFT);
7435 ReleaseKey(KEY_RIGHT);
7436 PressKey(KEY_LEFT, Time);
7437 SetDirection(TDirection.D_LEFT);
7438 end;
7440 procedure GoRight(Time: Word = 1);
7441 begin
7442 ReleaseKey(KEY_LEFT);
7443 ReleaseKey(KEY_RIGHT);
7444 PressKey(KEY_RIGHT, Time);
7445 SetDirection(TDirection.D_RIGHT);
7446 end;
7448 function Rnd(a: Word): Boolean;
7449 begin
7450 Result := Random(a) = 0;
7451 end;
7453 procedure Turn(Time: Word = 1200);
7454 begin
7455 if RunDirection() = TDirection.D_LEFT then GoRight(Time) else GoLeft(Time);
7456 end;
7458 procedure Stop();
7459 begin
7460 ReleaseKey(KEY_LEFT);
7461 ReleaseKey(KEY_RIGHT);
7462 end;
7464 function CanRunLeft(): Boolean;
7465 begin
7466 Result := not CollideLevel(-1, 0);
7467 end;
7469 function CanRunRight(): Boolean;
7470 begin
7471 Result := not CollideLevel(1, 0);
7472 end;
7474 function CanRun(): Boolean;
7475 begin
7476 if RunDirection() = TDirection.D_LEFT then Result := CanRunLeft() else Result := CanRunRight();
7477 end;
7479 procedure Jump(Time: Word = 30);
7480 begin
7481 PressKey(KEY_JUMP, Time);
7482 end;
7484 function NearHole(): Boolean;
7485 var
7486 x, sx: Integer;
7487 begin
7488 { TODO 5 : Ëåñòíèöû }
7489 sx := IfThen(RunDirection() = TDirection.D_LEFT, -1, 1);
7490 for x := 1 to PLAYER_RECT.Width do
7491 if (not StayOnStep(x*sx, 0)) and
7492 (not CollideLevel(x*sx, PLAYER_RECT.Height)) and
7493 (not CollideLevel(x*sx, PLAYER_RECT.Height*2)) then
7494 begin
7495 Result := True;
7496 Exit;
7497 end;
7499 Result := False;
7500 end;
7502 function BorderHole(): Boolean;
7503 var
7504 x, sx, xx: Integer;
7505 begin
7506 { TODO 5 : Ëåñòíèöû }
7507 sx := IfThen(RunDirection() = TDirection.D_LEFT, -1, 1);
7508 for x := 1 to PLAYER_RECT.Width do
7509 if (not StayOnStep(x*sx, 0)) and
7510 (not CollideLevel(x*sx, PLAYER_RECT.Height)) and
7511 (not CollideLevel(x*sx, PLAYER_RECT.Height*2)) then
7512 begin
7513 for xx := x to x+32 do
7514 if CollideLevel(xx*sx, PLAYER_RECT.Height) then
7515 begin
7516 Result := True;
7517 Exit;
7518 end;
7519 end;
7521 Result := False;
7522 end;
7524 function NearDeepHole(): Boolean;
7525 var
7526 x, sx, y: Integer;
7527 begin
7528 Result := False;
7530 sx := IfThen(RunDirection() = TDirection.D_LEFT, -1, 1);
7531 y := 3;
7533 for x := 1 to PLAYER_RECT.Width do
7534 if (not StayOnStep(x*sx, 0)) and
7535 (not CollideLevel(x*sx, PLAYER_RECT.Height)) and
7536 (not CollideLevel(x*sx, PLAYER_RECT.Height*2)) then
7537 begin
7538 while FObj.Y+y*PLAYER_RECT.Height < gMapInfo.Height do
7539 begin
7540 if CollideLevel(x*sx, PLAYER_RECT.Height*y) then Exit;
7541 y := y+1;
7542 end;
7544 Result := True;
7545 end else Result := False;
7546 end;
7548 function OverDeepHole(): Boolean;
7549 var
7550 y: Integer;
7551 begin
7552 Result := False;
7554 y := 1;
7555 while FObj.Y+y*PLAYER_RECT.Height < gMapInfo.Height do
7556 begin
7557 if CollideLevel(0, PLAYER_RECT.Height*y) then Exit;
7558 y := y+1;
7559 end;
7561 Result := True;
7562 end;
7564 function OnGround(): Boolean;
7565 begin
7566 Result := StayOnStep(0, 0) or CollideLevel(0, 1);
7567 end;
7569 function OnLadder(): Boolean;
7570 begin
7571 Result := FullInStep(0, 0);
7572 end;
7574 function BelowLadder(): Boolean;
7575 begin
7576 Result := (FullInStep(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -PLAYER_RECT.Height) and
7577 not CollideLevel(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -PLAYER_RECT.Height)) or
7578 (FullInStep(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -BOT_MAXJUMP) and
7579 not CollideLevel(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -BOT_MAXJUMP));
7580 end;
7582 function BelowLiftUp(): Boolean;
7583 begin
7584 Result := ((FullInLift(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -PLAYER_RECT.Height) = -1) and
7585 not CollideLevel(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -PLAYER_RECT.Height)) or
7586 ((FullInLift(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -BOT_MAXJUMP) = -1) and
7587 not CollideLevel(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -BOT_MAXJUMP));
7588 end;
7590 function OnTopLift(): Boolean;
7591 begin
7592 Result := (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7593 end;
7595 function CanJumpOver(): Boolean;
7596 var
7597 sx, y: Integer;
7598 begin
7599 sx := IfThen(RunDirection() = TDirection.D_LEFT, -1, 1);
7601 Result := False;
7603 if not CollideLevel(sx, 0) then Exit;
7605 for y := 1 to BOT_MAXJUMP do
7606 if CollideLevel(0, -y) then Exit else
7607 if not CollideLevel(sx, -y) then
7608 begin
7609 Result := True;
7610 Exit;
7611 end;
7612 end;
7614 function CanJumpUp(Dist: ShortInt): Boolean;
7615 var
7616 y, yy: Integer;
7617 c: Boolean;
7618 begin
7619 Result := False;
7621 if CollideLevel(Dist, 0) then Exit;
7623 c := False;
7624 for y := 0 to BOT_MAXJUMP do
7625 if CollideLevel(Dist, -y) then
7626 begin
7627 c := True;
7628 Break;
7629 end;
7631 if not c then Exit;
7633 c := False;
7634 for yy := y+1 to BOT_MAXJUMP do
7635 if not CollideLevel(Dist, -yy) then
7636 begin
7637 c := True;
7638 Break;
7639 end;
7641 if not c then Exit;
7643 c := False;
7644 for y := 0 to BOT_MAXJUMP do
7645 if CollideLevel(0, -y) then
7646 begin
7647 c := True;
7648 Break;
7649 end;
7651 if c then Exit;
7653 if y < yy then Exit;
7655 Result := True;
7656 end;
7658 function IsSafeTrigger(): Boolean;
7659 var
7660 a: Integer;
7661 begin
7662 Result := True;
7663 if gTriggers = nil then
7664 Exit;
7665 for a := 0 to High(gTriggers) do
7666 if Collide(gTriggers[a].X,
7667 gTriggers[a].Y,
7668 gTriggers[a].Width,
7669 gTriggers[a].Height) and
7670 (gTriggers[a].TriggerType in [TRIGGER_EXIT, TRIGGER_CLOSEDOOR,
7671 TRIGGER_CLOSETRAP, TRIGGER_TRAP,
7672 TRIGGER_PRESS, TRIGGER_ON, TRIGGER_OFF,
7673 TRIGGER_ONOFF, TRIGGER_SPAWNMONSTER,
7674 TRIGGER_DAMAGE, TRIGGER_SHOT]) then
7675 Result := False;
7676 end;
7678 begin
7679 // Âîçìîæíî, íàæèìàåì êíîïêó:
7680 if Rnd(16) and IsSafeTrigger() then
7681 PressKey(KEY_OPEN);
7683 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7684 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7685 begin
7686 ReleaseKey(KEY_LEFT);
7687 ReleaseKey(KEY_RIGHT);
7688 Jump();
7689 end;
7691 // Èäåì âëåâî, åñëè íàäî áûëî:
7692 if GetAIFlag('GOLEFT') <> '' then
7693 begin
7694 RemoveAIFlag('GOLEFT');
7695 if CanRunLeft() then
7696 GoLeft(360);
7697 end;
7699 // Èäåì âïðàâî, åñëè íàäî áûëî:
7700 if GetAIFlag('GORIGHT') <> '' then
7701 begin
7702 RemoveAIFlag('GORIGHT');
7703 if CanRunRight() then
7704 GoRight(360);
7705 end;
7707 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7708 if FObj.X < -32 then
7709 GoRight(360)
7710 else
7711 if FObj.X+32 > gMapInfo.Width then
7712 GoLeft(360);
7714 // Ïðûãàåì, åñëè íàäî áûëî:
7715 if GetAIFlag('NEEDJUMP') <> '' then
7716 begin
7717 Jump(0);
7718 RemoveAIFlag('NEEDJUMP');
7719 end;
7721 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7722 if GetAIFlag('NEEDSEEUP') <> '' then
7723 begin
7724 ReleaseKey(KEY_UP);
7725 ReleaseKey(KEY_DOWN);
7726 PressKey(KEY_UP, 20);
7727 RemoveAIFlag('NEEDSEEUP');
7728 end;
7730 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7731 if GetAIFlag('NEEDSEEDOWN') <> '' then
7732 begin
7733 ReleaseKey(KEY_UP);
7734 ReleaseKey(KEY_DOWN);
7735 PressKey(KEY_DOWN, 20);
7736 RemoveAIFlag('NEEDSEEDOWN');
7737 end;
7739 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7740 if GetAIFlag('GOINHOLE') <> '' then
7741 if not OnGround() then
7742 begin
7743 ReleaseKey(KEY_LEFT);
7744 ReleaseKey(KEY_RIGHT);
7745 RemoveAIFlag('GOINHOLE');
7746 SetAIFlag('FALLINHOLE', '1');
7747 end;
7749 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7750 if GetAIFlag('FALLINHOLE') <> '' then
7751 if OnGround() then
7752 RemoveAIFlag('FALLINHOLE');
7754 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7755 if not (KeyPressed(KEY_LEFT) or KeyPressed(KEY_RIGHT)) then
7756 if GetAIFlag('FALLINHOLE') = '' then
7757 if (not OnLadder()) or (FObj.Vel.Y >= 0) or (OnTopLift()) then
7758 if Rnd(2) then
7759 GoLeft(360)
7760 else
7761 GoRight(360);
7763 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7764 if OnGround() and
7765 CanJumpUp(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*32) and
7766 Rnd(8) then
7767 Jump();
7769 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7770 if OnGround() and NearHole() then
7771 if NearDeepHole() then // Åñëè ýòî áåçäíà
7772 case Random(6) of
7773 0..3: Turn(); // Áåæèì îáðàòíî
7774 4: Jump(); // Ïðûãàåì
7775 5: begin // Ïðûãàåì îáðàòíî
7776 Turn();
7777 Jump();
7778 end;
7779 end
7780 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7781 if GetAIFlag('GOINHOLE') = '' then
7782 case Random(6) of
7783 0: Turn(); // Íå íóæíî òóäà
7784 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7785 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7786 if BorderHole() then
7787 SetAIFlag('GOINHOLE', '1');
7788 end;
7790 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7791 if (not CanRun()) and OnGround() then
7792 begin
7793 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7794 if CanJumpOver() or OnLadder() then
7795 Jump()
7796 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7797 if Random(2) = 0 then
7798 begin
7799 if IsSafeTrigger() then
7800 PressKey(KEY_OPEN);
7801 end else
7802 Turn();
7803 end;
7805 // Îñòàëîñü ìàëî âîçäóõà:
7806 if FAir < 36 * 2 then
7807 Jump(20);
7809 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7810 if (FMegaRulez[MR_SUIT] < gTime) and ((FLastHit = HIT_ACID) or (Healthy() <= 1)) then
7811 if BodyInAcid(0, 0) then
7812 Jump();
7813 end;
7815 function TBot.FullInStep(XInc, YInc: Integer): Boolean;
7816 begin
7817 Result := g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc,
7818 PLAYER_RECT.Width, PLAYER_RECT.Height, PANEL_STEP, False);
7819 end;
7821 {function TBot.NeedItem(Item: Byte): Byte;
7822 begin
7823 Result := 4;
7824 end;}
7826 procedure TBot.SelectWeapon(Dist: Integer);
7827 var
7828 a: Integer;
7830 function HaveAmmo(weapon: Byte): Boolean;
7831 begin
7832 case weapon of
7833 WEAPON_PISTOL: Result := FAmmo[A_BULLETS] >= 1;
7834 WEAPON_SHOTGUN1: Result := FAmmo[A_SHELLS] >= 1;
7835 WEAPON_SHOTGUN2: Result := FAmmo[A_SHELLS] >= 2;
7836 WEAPON_CHAINGUN: Result := FAmmo[A_BULLETS] >= 10;
7837 WEAPON_ROCKETLAUNCHER: Result := FAmmo[A_ROCKETS] >= 1;
7838 WEAPON_PLASMA: Result := FAmmo[A_CELLS] >= 10;
7839 WEAPON_BFG: Result := FAmmo[A_CELLS] >= 40;
7840 WEAPON_SUPERPULEMET: Result := FAmmo[A_SHELLS] >= 1;
7841 WEAPON_FLAMETHROWER: Result := FAmmo[A_FUEL] >= 1;
7842 else Result := True;
7843 end;
7844 end;
7846 begin
7847 if Dist = -1 then Dist := BOT_LONGDIST;
7849 if Dist > BOT_LONGDIST then
7850 begin // Äàëüíèé áîé
7851 for a := 0 to 9 do
7852 if FWeapon[FDifficult.WeaponPrior[a]] and HaveAmmo(FDifficult.WeaponPrior[a]) then
7853 begin
7854 FSelectedWeapon := FDifficult.WeaponPrior[a];
7855 Break;
7856 end;
7857 end
7858 else //if Dist > BOT_UNSAFEDIST then
7859 begin // Áëèæíèé áîé
7860 for a := 0 to 9 do
7861 if FWeapon[FDifficult.CloseWeaponPrior[a]] and HaveAmmo(FDifficult.CloseWeaponPrior[a]) then
7862 begin
7863 FSelectedWeapon := FDifficult.CloseWeaponPrior[a];
7864 Break;
7865 end;
7866 end;
7867 { else
7868 begin
7869 for a := 0 to 9 do
7870 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7871 begin
7872 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7873 Break;
7874 end;
7875 end;}
7876 end;
7878 function TBot.PickItem(ItemType: Byte; force: Boolean; var remove: Boolean): Boolean;
7879 begin
7880 Result := inherited PickItem(ItemType, force, remove);
7882 if Result then SetAIFlag('SELECTWEAPON', '1');
7883 end;
7885 function TBot.Heal(value: Word; Soft: Boolean): Boolean;
7886 begin
7887 Result := inherited Heal(value, Soft);
7888 end;
7890 function TBot.Healthy(): Byte;
7891 begin
7892 if FMegaRulez[MR_INVUL] >= gTime then Result := 3
7893 else if (FHealth > 80) or ((FHealth > 50) and (FArmor > 20)) then Result := 3
7894 else if (FHealth > 50) then Result := 2
7895 else if (FHealth > 20) then Result := 1
7896 else Result := 0;
7897 end;
7899 function TBot.TargetOnScreen(TX, TY: Integer): Boolean;
7900 begin
7901 Result := (Abs(FObj.X-TX) <= Trunc(gPlayerScreenSize.X*0.6)) and
7902 (Abs(FObj.Y-TY) <= Trunc(gPlayerScreenSize.Y*0.6));
7903 end;
7905 procedure TBot.OnDamage(Angle: SmallInt);
7906 var
7907 pla: TPlayer;
7908 mon: TMonster;
7909 ok: Boolean;
7910 begin
7911 inherited;
7913 if (Angle = 0) or (Angle = 180) then
7914 begin
7915 ok := False;
7916 if (g_GetUIDType(FLastSpawnerUID) = UID_PLAYER) and
7917 LongBool(gGameSettings.Options and GAME_OPTION_BOTVSPLAYER) then
7918 begin // Èãðîê
7919 pla := g_Player_Get(FLastSpawnerUID);
7920 ok := not TargetOnScreen(pla.FObj.X + PLAYER_RECT.X,
7921 pla.FObj.Y + PLAYER_RECT.Y);
7922 end
7923 else
7924 if (g_GetUIDType(FLastSpawnerUID) = UID_MONSTER) and
7925 LongBool(gGameSettings.Options and GAME_OPTION_BOTVSMONSTER) then
7926 begin // Ìîíñòð
7927 mon := g_Monsters_ByUID(FLastSpawnerUID);
7928 ok := not TargetOnScreen(mon.Obj.X + mon.Obj.Rect.X,
7929 mon.Obj.Y + mon.Obj.Rect.Y);
7930 end;
7932 if ok then
7933 if Angle = 0 then
7934 SetAIFlag('ATTACKLEFT', '1')
7935 else
7936 SetAIFlag('ATTACKRIGHT', '1');
7937 end;
7938 end;
7940 function TBot.RunDirection(): TDirection;
7941 begin
7942 if Abs(Vel.X) >= 1 then
7943 begin
7944 if Vel.X > 0 then Result := TDirection.D_RIGHT else Result := TDirection.D_LEFT;
7945 end else
7946 Result := FDirection;
7947 end;
7949 function TBot.GetRnd(a: Byte): Boolean;
7950 begin
7951 if a = 0 then Result := False
7952 else if a = 255 then Result := True
7953 else Result := Random(256) > 255-a;
7954 end;
7956 function TBot.GetInterval(a: Byte; radius: SmallInt): SmallInt;
7957 begin
7958 Result := Round((255-a)/255*radius*(Random(2)-1));
7959 end;
7962 procedure TDifficult.save (st: TStream);
7963 begin
7964 utils.writeInt(st, Byte(DiagFire));
7965 utils.writeInt(st, Byte(InvisFire));
7966 utils.writeInt(st, Byte(DiagPrecision));
7967 utils.writeInt(st, Byte(FlyPrecision));
7968 utils.writeInt(st, Byte(Cover));
7969 utils.writeInt(st, Byte(CloseJump));
7970 st.WriteBuffer(WeaponPrior[Low(WeaponPrior)], sizeof(WeaponPrior));
7971 st.WriteBuffer(CloseWeaponPrior[Low(CloseWeaponPrior)], sizeof(CloseWeaponPrior));
7972 end;
7974 procedure TDifficult.load (st: TStream);
7975 begin
7976 DiagFire := utils.readByte(st);
7977 InvisFire := utils.readByte(st);
7978 DiagPrecision := utils.readByte(st);
7979 FlyPrecision := utils.readByte(st);
7980 Cover := utils.readByte(st);
7981 CloseJump := utils.readByte(st);
7982 st.ReadBuffer(WeaponPrior[Low(WeaponPrior)], sizeof(WeaponPrior));
7983 st.ReadBuffer(CloseWeaponPrior[Low(CloseWeaponPrior)], sizeof(CloseWeaponPrior));
7984 end;
7987 procedure TBot.SaveState (st: TStream);
7988 var
7989 i: Integer;
7990 dw: Integer;
7991 begin
7992 inherited SaveState(st);
7993 utils.writeSign(st, 'BOT0');
7994 // Âûáðàííîå îðóæèå
7995 utils.writeInt(st, Byte(FSelectedWeapon));
7996 // UID öåëè
7997 utils.writeInt(st, Word(FTargetUID));
7998 // Âðåìÿ ïîòåðè öåëè
7999 utils.writeInt(st, LongWord(FLastVisible));
8000 // Êîëè÷åñòâî ôëàãîâ ÈÈ
8001 dw := Length(FAIFlags);
8002 utils.writeInt(st, LongInt(dw));
8003 // Ôëàãè ÈÈ
8004 for i := 0 to dw-1 do
8005 begin
8006 utils.writeStr(st, FAIFlags[i].Name, 20);
8007 utils.writeStr(st, FAIFlags[i].Value, 20);
8008 end;
8009 // Íàñòðîéêè ñëîæíîñòè
8010 FDifficult.save(st);
8011 end;
8014 procedure TBot.LoadState (st: TStream);
8015 var
8016 i: Integer;
8017 dw: Integer;
8018 begin
8019 inherited LoadState(st);
8020 if not utils.checkSign(st, 'BOT0') then raise XStreamError.Create('invalid bot signature');
8021 // Âûáðàííîå îðóæèå
8022 FSelectedWeapon := utils.readByte(st);
8023 // UID öåëè
8024 FTargetUID := utils.readWord(st);
8025 // Âðåìÿ ïîòåðè öåëè
8026 FLastVisible := utils.readLongWord(st);
8027 // Êîëè÷åñòâî ôëàãîâ ÈÈ
8028 dw := utils.readLongInt(st);
8029 if (dw < 0) or (dw > 16384) then raise XStreamError.Create('invalid number of bot AI flags');
8030 SetLength(FAIFlags, dw);
8031 // Ôëàãè ÈÈ
8032 for i := 0 to dw-1 do
8033 begin
8034 FAIFlags[i].Name := utils.readStr(st, 20);
8035 FAIFlags[i].Value := utils.readStr(st, 20);
8036 end;
8037 // Íàñòðîéêè ñëîæíîñòè
8038 FDifficult.load(st);
8039 end;
8042 begin
8043 conRegVar('cheat_berserk_autoswitch', @gBerserkAutoswitch, 'autoswitch to fist when berserk pack taken', '', true, true);
8044 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');
8045 conRegVar('player_indicator_style', @gPlayerIndicatorStyle, 'Visual appearance of indicator', 'Visual appearance of indicator');
8046 end.