DEADSOFTWARE

Game: Fix missing sound from the bubble effect in liquids
[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();
637 function g_Bot_GetCount(): Integer;
639 implementation
641 uses
642 {$INCLUDE ../nogl/noGLuses.inc}
643 {$IFDEF ENABLE_HOLMES}
644 g_holmes,
645 {$ENDIF}
646 e_log, g_map, g_items, g_console, g_gfx, Math,
647 g_options, g_triggers, g_menu, g_game, g_grid, e_res,
648 wadreader, g_main, g_monsters, CONFIG, g_language,
649 g_net, g_netmsg, g_window,
650 utils, xstreams;
652 const PLR_SAVE_VERSION = 0;
654 type
655 TBotProfile = record
656 name: ShortString;
657 model: ShortString;
658 team: Byte;
659 color: TRGB;
660 diag_fire: Byte;
661 invis_fire: Byte;
662 diag_precision: Byte;
663 fly_precision: Byte;
664 cover: Byte;
665 close_jump: Byte;
666 w_prior1: Array [WP_FIRST..WP_LAST] of Byte;
667 w_prior2: Array [WP_FIRST..WP_LAST] of Byte;
668 w_prior3: Array [WP_FIRST..WP_LAST] of Byte;
669 end;
671 const
672 TIME_RESPAWN1 = 1500;
673 TIME_RESPAWN2 = 2000;
674 TIME_RESPAWN3 = 3000;
675 AIR_DEF = 360;
676 AIR_MAX = 1091;
677 JET_MAX = 540; // ~30 sec
678 PLAYER_SUIT_TIME = 30000;
679 PLAYER_INVUL_TIME = 30000;
680 PLAYER_INVIS_TIME = 35000;
681 FRAG_COMBO_TIME = 3000;
682 VEL_SW = 4;
683 VEL_FLY = 6;
684 ANGLE_RIGHTUP = 55;
685 ANGLE_RIGHTDOWN = -35;
686 ANGLE_LEFTUP = 125;
687 ANGLE_LEFTDOWN = -145;
688 PLAYER_HEADRECT: TRectWH = (X:24; Y:12; Width:20; Height:12);
689 WEAPONPOINT: Array [TDirection] of TDFPoint = ((X:16; Y:32), (X:47; Y:32));
690 BOT_MAXJUMP = 84;
691 BOT_LONGDIST = 300;
692 BOT_UNSAFEDIST = 128;
693 TEAMCOLOR: Array [TEAM_RED..TEAM_BLUE] of TRGB = ((R:255; G:0; B:0),
694 (R:0; G:0; B:255));
695 DIFFICULT_EASY: TDifficult = (DiagFire: 32; InvisFire: 32; DiagPrecision: 32;
696 FlyPrecision: 32; Cover: 32; CloseJump: 32;
697 WeaponPrior:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior:(0,0,0,0,0,0,0,0,0,0,0));
698 DIFFICULT_MEDIUM: TDifficult = (DiagFire: 127; InvisFire: 127; DiagPrecision: 127;
699 FlyPrecision: 127; Cover: 127; CloseJump: 127;
700 WeaponPrior:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior:(0,0,0,0,0,0,0,0,0,0,0));
701 DIFFICULT_HARD: TDifficult = (DiagFire: 255; InvisFire: 255; DiagPrecision: 255;
702 FlyPrecision: 255; Cover: 255; CloseJump: 255;
703 WeaponPrior:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior:(0,0,0,0,0,0,0,0,0,0,0));
704 WEAPON_PRIOR1: Array [WP_FIRST..WP_LAST] of Byte =
705 (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
706 WEAPON_SHOTGUN2, WEAPON_SHOTGUN1,
707 WEAPON_CHAINGUN, WEAPON_PLASMA, WEAPON_ROCKETLAUNCHER,
708 WEAPON_BFG, WEAPON_PISTOL, WEAPON_SAW, WEAPON_KASTET);
709 WEAPON_PRIOR2: Array [WP_FIRST..WP_LAST] of Byte =
710 (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
711 WEAPON_BFG, WEAPON_ROCKETLAUNCHER,
712 WEAPON_SHOTGUN2, WEAPON_PLASMA, WEAPON_SHOTGUN1,
713 WEAPON_CHAINGUN, WEAPON_PISTOL, WEAPON_SAW, WEAPON_KASTET);
714 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
715 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
716 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
717 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
718 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
719 WEAPON_RELOAD: Array [WP_FIRST..WP_LAST] of Byte =
720 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
722 PLAYER_SIGNATURE = $52594C50; // 'PLYR'
723 CORPSE_SIGNATURE = $50524F43; // 'CORP'
725 BOTNAMES_FILENAME = 'botnames.txt';
726 BOTLIST_FILENAME = 'botlist.txt';
728 var
729 MaxGibs: Word = 150;
730 MaxCorpses: Word = 20;
731 MaxShells: Word = 300;
732 CurrentGib: Integer = 0;
733 CurrentShell: Integer = 0;
734 BotNames: Array of String;
735 BotList: Array of TBotProfile;
736 SavedStates: Array of TPlayerSavedState;
739 function Lerp(X, Y, Factor: Integer): Integer;
740 begin
741 Result := X + ((Y - X) div Factor);
742 end;
744 function SameTeam(UID1, UID2: Word): Boolean;
745 begin
746 Result := False;
748 if (UID1 > UID_MAX_PLAYER) or (UID1 <= UID_MAX_GAME) or
749 (UID2 > UID_MAX_PLAYER) or (UID2 <= UID_MAX_GAME) then Exit;
751 if (g_Player_Get(UID1) = nil) or (g_Player_Get(UID2) = nil) then Exit;
753 if ((g_Player_Get(UID1).Team = TEAM_NONE) or
754 (g_Player_Get(UID2).Team = TEAM_NONE)) then Exit;
756 Result := g_Player_Get(UID1).FTeam = g_Player_Get(UID2).FTeam;
757 end;
759 procedure g_Gibs_SetMax(Count: Word);
760 begin
761 MaxGibs := Count;
762 SetLength(gGibs, Count);
764 if CurrentGib >= Count then
765 CurrentGib := 0;
766 end;
768 function g_Gibs_GetMax(): Word;
769 begin
770 Result := MaxGibs;
771 end;
773 procedure g_Shells_SetMax(Count: Word);
774 begin
775 MaxShells := Count;
776 SetLength(gShells, Count);
778 if CurrentShell >= Count then
779 CurrentShell := 0;
780 end;
782 function g_Shells_GetMax(): Word;
783 begin
784 Result := MaxShells;
785 end;
788 procedure g_Corpses_SetMax(Count: Word);
789 begin
790 MaxCorpses := Count;
791 SetLength(gCorpses, Count);
792 end;
794 function g_Corpses_GetMax(): Word;
795 begin
796 Result := MaxCorpses;
797 end;
799 function g_Player_Create(ModelName: String; Color: TRGB; Team: Byte; Bot: Boolean): Word;
800 var
801 a: Integer;
802 ok: Boolean;
803 begin
804 Result := 0;
806 ok := False;
807 a := 0;
809 // Åñòü ëè ìåñòî â gPlayers:
810 if gPlayers <> nil then
811 for a := 0 to High(gPlayers) do
812 if gPlayers[a] = nil then
813 begin
814 ok := True;
815 Break;
816 end;
818 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
819 if not ok then
820 begin
821 SetLength(gPlayers, Length(gPlayers)+1);
822 a := High(gPlayers);
823 end;
825 // Ñîçäàåì îáúåêò èãðîêà:
826 if Bot then
827 gPlayers[a] := TBot.Create()
828 else
829 gPlayers[a] := TPlayer.Create();
832 gPlayers[a].FActualModelName := ModelName;
833 gPlayers[a].SetModel(ModelName);
835 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
836 if gPlayers[a].FModel = nil then
837 begin
838 gPlayers[a].Free();
839 gPlayers[a] := nil;
840 g_FatalError(Format(_lc[I_GAME_ERROR_MODEL], [ModelName]));
841 Exit;
842 end;
844 if not (Team in [TEAM_RED, TEAM_BLUE]) then
845 if Random(2) = 0 then
846 Team := TEAM_RED
847 else
848 Team := TEAM_BLUE;
849 gPlayers[a].FPreferredTeam := Team;
851 case gGameSettings.GameMode of
852 GM_DM: gPlayers[a].FTeam := TEAM_NONE;
853 GM_TDM,
854 GM_CTF: gPlayers[a].FTeam := gPlayers[a].FPreferredTeam;
855 GM_SINGLE,
856 GM_COOP: gPlayers[a].FTeam := TEAM_COOP;
857 end;
859 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
860 gPlayers[a].FColor := Color;
861 if gPlayers[a].FTeam in [TEAM_RED, TEAM_BLUE] then
862 gPlayers[a].FModel.Color := TEAMCOLOR[gPlayers[a].FTeam]
863 else
864 gPlayers[a].FModel.Color := Color;
866 gPlayers[a].FUID := g_CreateUID(UID_PLAYER);
867 gPlayers[a].FAlive := False;
869 Result := gPlayers[a].FUID;
870 end;
872 function g_Player_CreateFromState (st: TStream): Word;
873 var a: Integer; ok, Bot: Boolean; pos: Int64;
874 begin
875 assert(st <> nil);
877 // check signature and entity type
878 pos := st.Position;
879 if not utils.checkSign(st, 'PLYR') then raise XStreamError.Create('invalid player signature');
880 if (utils.readByte(st) <> PLR_SAVE_VERSION) then raise XStreamError.Create('invalid player version');
881 Bot := utils.readBool(st);
882 st.Position := pos;
884 // find free player slot
885 ok := false;
886 for a := 0 to High(gPlayers) do
887 if gPlayers[a] = nil then
888 begin
889 ok := true;
890 break;
891 end;
893 // allocate player slot
894 if not ok then
895 begin
896 SetLength(gPlayers, Length(gPlayers)+1);
897 a := High(gPlayers);
898 end;
900 // create entity and load state
901 if Bot then
902 gPlayers[a] := TBot.Create()
903 else
904 gPlayers[a] := TPlayer.Create();
905 gPlayers[a].FPhysics := True; // ???
906 gPlayers[a].LoadState(st);
908 result := gPlayers[a].FUID;
909 end;
912 procedure g_Player_ResetTeams();
913 var
914 a: Integer;
915 begin
916 if g_Game_IsClient then
917 Exit;
918 if gPlayers = nil then
919 Exit;
920 for a := Low(gPlayers) to High(gPlayers) do
921 if gPlayers[a] <> nil then
922 case gGameSettings.GameMode of
923 GM_DM:
924 gPlayers[a].ChangeTeam(TEAM_NONE);
925 GM_TDM, GM_CTF:
926 if not (gPlayers[a].Team in [TEAM_RED, TEAM_BLUE]) then
927 if gPlayers[a].FPreferredTeam in [TEAM_RED, TEAM_BLUE] then
928 gPlayers[a].ChangeTeam(gPlayers[a].FPreferredTeam)
929 else
930 if a mod 2 = 0 then
931 gPlayers[a].ChangeTeam(TEAM_RED)
932 else
933 gPlayers[a].ChangeTeam(TEAM_BLUE);
934 GM_SINGLE,
935 GM_COOP:
936 gPlayers[a].ChangeTeam(TEAM_COOP);
937 end;
938 end;
940 procedure g_Bot_Add(Team, Difficult: Byte; Handicap: Integer = 100);
941 var
942 m: SSArray;
943 _name, _model: String;
944 a, tr, tb: Integer;
945 begin
946 if not g_Game_IsServer then Exit;
948 // Íå äîáàâëÿåì áîòîâ åñëè ëèìèò óæå äîñòèãíóò
949 if (g_Bot_GetCount() >= gMaxBots) then Exit;
951 // Ñïèñîê íàçâàíèé ìîäåëåé:
952 m := g_PlayerModel_GetNames();
953 if m = nil then
954 Exit;
956 // Êîìàíäà:
957 if (gGameSettings.GameType = GT_SINGLE) or (gGameSettings.GameMode = GM_COOP) then
958 Team := TEAM_COOP // COOP
959 else
960 if gGameSettings.GameMode = GM_DM then
961 Team := TEAM_NONE // DM
962 else
963 if Team = TEAM_NONE then // CTF / TDM
964 begin
965 // Àâòîáàëàíñ êîìàíä:
966 tr := 0;
967 tb := 0;
969 for a := 0 to High(gPlayers) do
970 if gPlayers[a] <> nil then
971 begin
972 if gPlayers[a].Team = TEAM_RED then
973 Inc(tr)
974 else
975 if gPlayers[a].Team = TEAM_BLUE then
976 Inc(tb);
977 end;
979 if tr > tb then
980 Team := TEAM_BLUE
981 else
982 if tb > tr then
983 Team := TEAM_RED
984 else // tr = tb
985 if Random(2) = 0 then
986 Team := TEAM_RED
987 else
988 Team := TEAM_BLUE;
989 end;
991 // Âûáèðàåì áîòó èìÿ:
992 _name := '';
993 if BotNames <> nil then
994 for a := 0 to High(BotNames) do
995 if g_Player_ValidName(BotNames[a]) then
996 begin
997 _name := BotNames[a];
998 Break;
999 end;
1001 // Âûáèðàåì ñëó÷àéíóþ ìîäåëü:
1002 _model := m[Random(Length(m))];
1004 // Ñîçäàåì áîòà:
1005 with g_Player_Get(g_Player_Create(_model,
1006 _RGB(Min(Random(9)*32, 255),
1007 Min(Random(9)*32, 255),
1008 Min(Random(9)*32, 255)),
1009 Team, True)) as TBot do
1010 begin
1011 // Åñëè èìåíè íåò, äåëàåì åãî èç UID áîòà
1012 if _name = '' then
1013 Name := Format('DFBOT%.5d', [UID])
1014 else
1015 Name := _name;
1017 case Difficult of
1018 1: FDifficult := DIFFICULT_EASY;
1019 2: FDifficult := DIFFICULT_MEDIUM;
1020 else FDifficult := DIFFICULT_HARD;
1021 end;
1023 for a := WP_FIRST to WP_LAST do
1024 begin
1025 FDifficult.WeaponPrior[a] := WEAPON_PRIOR1[a];
1026 FDifficult.CloseWeaponPrior[a] := WEAPON_PRIOR2[a];
1027 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1028 end;
1030 FHandicap := Handicap;
1032 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [Name]), True);
1034 if g_Game_IsNet then MH_SEND_PlayerCreate(UID);
1035 if g_Game_IsServer and (gGameSettings.MaxLives > 0) then
1036 Spectate();
1037 end;
1038 end;
1040 procedure g_Bot_AddList(Team: Byte; lName: ShortString; num: Integer = -1; Handicap: Integer = 100);
1041 var
1042 m: SSArray;
1043 _name, _model: String;
1044 a: Integer;
1045 begin
1046 if not g_Game_IsServer then Exit;
1048 // Íå äîáàâëÿåì áîòîâ åñëè ëèìèò óæå äîñòèãíóò
1049 if (g_Bot_GetCount() >= gMaxBots) then Exit;
1051 // Ñïèñîê íàçâàíèé ìîäåëåé:
1052 m := g_PlayerModel_GetNames();
1053 if m = nil then
1054 Exit;
1056 // Êîìàíäà:
1057 if (gGameSettings.GameType = GT_SINGLE) or (gGameSettings.GameMode = GM_COOP) then
1058 Team := TEAM_COOP // COOP
1059 else
1060 if gGameSettings.GameMode = GM_DM then
1061 Team := TEAM_NONE // DM
1062 else
1063 if Team = TEAM_NONE then
1064 Team := BotList[num].team; // CTF / TDM
1066 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1067 lName := AnsiLowerCase(lName);
1068 if (num < 0) or (num > Length(BotList)-1) then
1069 num := -1;
1070 if (num = -1) and (lName <> '') and (BotList <> nil) then
1071 for a := 0 to High(BotList) do
1072 if AnsiLowerCase(BotList[a].name) = lName then
1073 begin
1074 num := a;
1075 Break;
1076 end;
1077 if num = -1 then
1078 Exit;
1080 // Èìÿ áîòà:
1081 _name := BotList[num].name;
1082 // Çàíÿòî - âûáèðàåì ñëó÷àéíîå:
1083 if not g_Player_ValidName(_name) then
1084 repeat
1085 _name := Format('DFBOT%.2d', [Random(100)]);
1086 until g_Player_ValidName(_name);
1088 // Ìîäåëü:
1089 _model := BotList[num].model;
1090 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1091 if not InSArray(_model, m) then
1092 _model := m[Random(Length(m))];
1094 // Ñîçäàåì áîòà:
1095 with g_Player_Get(g_Player_Create(_model, BotList[num].color, Team, True)) as TBot do
1096 begin
1097 Name := _name;
1099 FDifficult.DiagFire := BotList[num].diag_fire;
1100 FDifficult.InvisFire := BotList[num].invis_fire;
1101 FDifficult.DiagPrecision := BotList[num].diag_precision;
1102 FDifficult.FlyPrecision := BotList[num].fly_precision;
1103 FDifficult.Cover := BotList[num].cover;
1104 FDifficult.CloseJump := BotList[num].close_jump;
1106 FHandicap := Handicap;
1108 for a := WP_FIRST to WP_LAST do
1109 begin
1110 FDifficult.WeaponPrior[a] := BotList[num].w_prior1[a];
1111 FDifficult.CloseWeaponPrior[a] := BotList[num].w_prior2[a];
1112 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1113 end;
1115 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [Name]), True);
1117 if g_Game_IsNet then MH_SEND_PlayerCreate(UID);
1118 end;
1119 end;
1121 procedure g_Bot_RemoveAll();
1122 var
1123 a: Integer;
1124 begin
1125 if not g_Game_IsServer then Exit;
1126 if gPlayers = nil then Exit;
1128 for a := 0 to High(gPlayers) do
1129 if gPlayers[a] <> nil then
1130 if gPlayers[a] is TBot then
1131 begin
1132 gPlayers[a].Lives := 0;
1133 gPlayers[a].Kill(K_SIMPLEKILL, 0, HIT_DISCON);
1134 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [gPlayers[a].Name]), True);
1135 g_Player_Remove(gPlayers[a].FUID);
1136 end;
1138 g_Bot_MixNames();
1139 end;
1141 procedure g_Bot_MixNames();
1142 var
1143 s: String;
1144 a, b: Integer;
1145 begin
1146 if BotNames <> nil then
1147 for a := 0 to High(BotNames) do
1148 begin
1149 b := Random(Length(BotNames));
1150 s := BotNames[a];
1151 Botnames[a] := BotNames[b];
1152 BotNames[b] := s;
1153 end;
1154 end;
1156 procedure g_Player_Remove(UID: Word);
1157 var
1158 i: Integer;
1159 begin
1160 if gPlayers = nil then Exit;
1162 if g_Game_IsServer and g_Game_IsNet then
1163 MH_SEND_PlayerDelete(UID);
1165 for i := 0 to High(gPlayers) do
1166 if gPlayers[i] <> nil then
1167 if gPlayers[i].FUID = UID then
1168 begin
1169 if gPlayers[i] is TPlayer then
1170 TPlayer(gPlayers[i]).Free()
1171 else
1172 TBot(gPlayers[i]).Free();
1173 gPlayers[i] := nil;
1174 Exit;
1175 end;
1176 end;
1178 procedure g_Player_Init();
1179 var
1180 F: TextFile;
1181 s: String;
1182 a, b: Integer;
1183 config: TConfig;
1184 sa: SSArray;
1185 path: AnsiString;
1186 begin
1187 BotNames := nil;
1189 path := BOTNAMES_FILENAME;
1190 if e_FindResource(DataDirs, path) = false then
1191 Exit;
1193 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1194 AssignFile(F, path);
1195 Reset(F);
1197 while not EOF(F) do
1198 begin
1199 ReadLn(F, s);
1201 s := Trim(s);
1202 if s = '' then
1203 Continue;
1205 SetLength(BotNames, Length(BotNames)+1);
1206 BotNames[High(BotNames)] := s;
1207 end;
1209 CloseFile(F);
1211 // Ïåðåìåøèâàåì èõ:
1212 g_Bot_MixNames();
1214 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1215 config := TConfig.CreateFile(path);
1216 BotList := nil;
1217 a := 0;
1219 while config.SectionExists(IntToStr(a)) do
1220 begin
1221 SetLength(BotList, Length(BotList)+1);
1223 with BotList[High(BotList)] do
1224 begin
1225 // Èìÿ áîòà:
1226 name := config.ReadStr(IntToStr(a), 'name', '');
1227 // Ìîäåëü:
1228 model := config.ReadStr(IntToStr(a), 'model', '');
1229 // Êîìàíäà:
1230 if config.ReadStr(IntToStr(a), 'team', 'red') = 'red' then
1231 team := TEAM_RED
1232 else
1233 team := TEAM_BLUE;
1234 // Öâåò ìîäåëè:
1235 sa := parse(config.ReadStr(IntToStr(a), 'color', ''));
1236 color.R := StrToIntDef(sa[0], 0);
1237 color.G := StrToIntDef(sa[1], 0);
1238 color.B := StrToIntDef(sa[2], 0);
1239 // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì:
1240 diag_fire := config.ReadInt(IntToStr(a), 'diag_fire', 0);
1241 // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó:
1242 invis_fire := config.ReadInt(IntToStr(a), 'invis_fire', 0);
1243 // Òî÷íîñòü ñòðåëüáû ïîä óãëîì:
1244 diag_precision := config.ReadInt(IntToStr(a), 'diag_precision', 0);
1245 // Òî÷íîñòü ñòðåëüáû â ïîëåòå:
1246 fly_precision := config.ReadInt(IntToStr(a), 'fly_precision', 0);
1247 // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ:
1248 cover := config.ReadInt(IntToStr(a), 'cover', 0);
1249 // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà:
1250 close_jump := config.ReadInt(IntToStr(a), 'close_jump', 0);
1251 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ:
1252 sa := parse(config.ReadStr(IntToStr(a), 'w_prior1', ''));
1253 if Length(sa) = 10 then
1254 for b := 0 to 9 do
1255 w_prior1[b] := EnsureRange(StrToInt(sa[b]), 0, 9);
1256 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ:
1257 sa := parse(config.ReadStr(IntToStr(a), 'w_prior2', ''));
1258 if Length(sa) = 10 then
1259 for b := 0 to 9 do
1260 w_prior2[b] := EnsureRange(StrToInt(sa[b]), 0, 9);
1262 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1263 if Length(sa) = 10 then
1264 for b := 0 to 9 do
1265 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1266 end;
1268 a := a + 1;
1269 end;
1271 config.Free();
1272 SetLength(SavedStates, 0);
1273 end;
1275 procedure g_Player_Free();
1276 var
1277 i: Integer;
1278 begin
1279 if gPlayers <> nil then
1280 begin
1281 for i := 0 to High(gPlayers) do
1282 if gPlayers[i] <> nil then
1283 begin
1284 if gPlayers[i] is TPlayer then
1285 TPlayer(gPlayers[i]).Free()
1286 else
1287 TBot(gPlayers[i]).Free();
1288 gPlayers[i] := nil;
1289 end;
1291 gPlayers := nil;
1292 end;
1294 gPlayer1 := nil;
1295 gPlayer2 := nil;
1296 SetLength(SavedStates, 0);
1297 end;
1299 procedure g_Player_PreUpdate();
1300 var
1301 i: Integer;
1302 begin
1303 if gPlayers = nil then Exit;
1304 for i := 0 to High(gPlayers) do
1305 if gPlayers[i] <> nil then
1306 gPlayers[i].PreUpdate();
1307 end;
1309 procedure g_Player_UpdateAll();
1310 var
1311 i: Integer;
1312 begin
1313 if gPlayers = nil then Exit;
1315 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1316 for i := 0 to High(gPlayers) do
1317 begin
1318 if gPlayers[i] <> nil then
1319 begin
1320 if gPlayers[i] is TPlayer then
1321 begin
1322 gPlayers[i].Update();
1323 gPlayers[i].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1324 end
1325 else
1326 begin
1327 // bot updates weapons in `UpdateCombat()`
1328 TBot(gPlayers[i]).Update();
1329 end;
1330 end;
1331 end;
1332 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1333 end;
1335 procedure g_Player_DrawAll();
1336 var
1337 i: Integer;
1338 begin
1339 if gPlayers = nil then Exit;
1341 for i := 0 to High(gPlayers) do
1342 if gPlayers[i] <> nil then
1343 if gPlayers[i] is TPlayer then gPlayers[i].Draw()
1344 else TBot(gPlayers[i]).Draw();
1345 end;
1347 procedure g_Player_DrawDebug(p: TPlayer);
1348 var
1349 fW, fH: Byte;
1350 begin
1351 if p = nil then Exit;
1352 if (@p.FObj) = nil then Exit;
1354 e_TextureFontGetSize(gStdFont, fW, fH);
1356 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p.FObj.X), gStdFont);
1357 e_TextureFontPrint(0, fH , 'Pos Y: ' + IntToStr(p.FObj.Y), gStdFont);
1358 e_TextureFontPrint(0, fH * 2, 'Vel X: ' + IntToStr(p.FObj.Vel.X), gStdFont);
1359 e_TextureFontPrint(0, fH * 3, 'Vel Y: ' + IntToStr(p.FObj.Vel.Y), gStdFont);
1360 e_TextureFontPrint(0, fH * 4, 'Acc X: ' + IntToStr(p.FObj.Accel.X), gStdFont);
1361 e_TextureFontPrint(0, fH * 5, 'Acc Y: ' + IntToStr(p.FObj.Accel.Y), gStdFont);
1362 e_TextureFontPrint(0, fH * 6, 'Old X: ' + IntToStr(p.FObj.oldX), gStdFont);
1363 e_TextureFontPrint(0, fH * 7, 'Old Y: ' + IntToStr(p.FObj.oldY), gStdFont);
1364 end;
1366 procedure g_Player_DrawHealth();
1367 var
1368 i: Integer;
1369 fW, fH: Byte;
1370 begin
1371 if gPlayers = nil then Exit;
1372 e_TextureFontGetSize(gStdFont, fW, fH);
1374 for i := 0 to High(gPlayers) do
1375 if gPlayers[i] <> nil then
1376 begin
1377 e_TextureFontPrint(gPlayers[i].FObj.X + gPlayers[i].FObj.Rect.X,
1378 gPlayers[i].FObj.Y + gPlayers[i].FObj.Rect.Y + gPlayers[i].FObj.Rect.Height - fH * 2,
1379 IntToStr(gPlayers[i].FHealth), gStdFont);
1380 e_TextureFontPrint(gPlayers[i].FObj.X + gPlayers[i].FObj.Rect.X,
1381 gPlayers[i].FObj.Y + gPlayers[i].FObj.Rect.Y + gPlayers[i].FObj.Rect.Height - fH,
1382 IntToStr(gPlayers[i].FArmor), gStdFont);
1383 end;
1384 end;
1386 function g_Player_Get(UID: Word): TPlayer;
1387 var
1388 a: Integer;
1389 begin
1390 Result := nil;
1392 if gPlayers = nil then
1393 Exit;
1395 for a := 0 to High(gPlayers) do
1396 if gPlayers[a] <> nil then
1397 if gPlayers[a].FUID = UID then
1398 begin
1399 Result := gPlayers[a];
1400 Exit;
1401 end;
1402 end;
1404 function g_Player_GetCount(): Byte;
1405 var
1406 a: Integer;
1407 begin
1408 Result := 0;
1410 if gPlayers = nil then
1411 Exit;
1413 for a := 0 to High(gPlayers) do
1414 if gPlayers[a] <> nil then
1415 Result := Result + 1;
1416 end;
1418 function g_Bot_GetCount(): Integer;
1419 var
1420 a: Integer;
1421 begin
1422 Result := 0;
1424 if gPlayers = nil then
1425 Exit;
1427 for a := 0 to High(gPlayers) do
1428 if (gPlayers[a] <> nil) and (gPlayers[a] is TBot) then
1429 Result := Result + 1;
1430 end;
1432 function g_Player_GetStats(): TPlayerStatArray;
1433 var
1434 a: Integer;
1435 begin
1436 Result := nil;
1438 if gPlayers = nil then Exit;
1440 for a := 0 to High(gPlayers) do
1441 if gPlayers[a] <> nil then
1442 begin
1443 SetLength(Result, Length(Result)+1);
1444 with Result[High(Result)] do
1445 begin
1446 Num := a;
1447 Ping := gPlayers[a].FPing;
1448 Loss := gPlayers[a].FLoss;
1449 Name := gPlayers[a].FName;
1450 Team := gPlayers[a].FTeam;
1451 Frags := gPlayers[a].FFrags;
1452 Deaths := gPlayers[a].FDeath;
1453 Kills := gPlayers[a].FKills;
1454 Color := gPlayers[a].FModel.Color;
1455 Lives := gPlayers[a].FLives;
1456 Spectator := gPlayers[a].FSpectator;
1457 UID := gPlayers[a].FUID;
1458 end;
1459 end;
1460 end;
1462 procedure g_Player_ResetReady();
1463 var
1464 a: Integer;
1465 begin
1466 if not g_Game_IsServer then Exit;
1467 if gPlayers = nil then Exit;
1469 for a := 0 to High(gPlayers) do
1470 if gPlayers[a] <> nil then
1471 begin
1472 gPlayers[a].FReady := False;
1473 if g_Game_IsNet then
1474 MH_SEND_GameEvent(NET_EV_INTER_READY, gPlayers[a].UID, 'N');
1475 end;
1476 end;
1478 procedure g_Player_RememberAll;
1479 var
1480 i: Integer;
1481 begin
1482 for i := Low(gPlayers) to High(gPlayers) do
1483 if (gPlayers[i] <> nil) and gPlayers[i].alive then
1484 gPlayers[i].RememberState;
1485 end;
1487 procedure g_Player_ResetAll(Force, Silent: Boolean);
1488 var
1489 i: Integer;
1490 begin
1491 gTeamStat[TEAM_RED].Goals := 0;
1492 gTeamStat[TEAM_BLUE].Goals := 0;
1494 if gPlayers <> nil then
1495 for i := 0 to High(gPlayers) do
1496 if gPlayers[i] <> nil then
1497 begin
1498 gPlayers[i].Reset(Force);
1500 if gPlayers[i] is TPlayer then
1501 begin
1502 if (not gPlayers[i].FSpectator) or gPlayers[i].FWantsInGame then
1503 gPlayers[i].Respawn(Silent)
1504 else
1505 gPlayers[i].Spectate();
1506 end
1507 else
1508 TBot(gPlayers[i]).Respawn(Silent);
1509 end;
1510 end;
1512 function g_Player_CreateCorpse(Player: TPlayer): Integer;
1513 var
1514 i: Integer;
1515 find_id: DWORD;
1516 ok: Boolean;
1517 begin
1518 Result := -1;
1520 if Player.alive then
1521 Exit;
1523 // Ðàçðûâàåì ñâÿçü ñ ïðåæíèì òðóïîì:
1524 i := Player.FCorpse;
1525 if (i >= 0) and (i < Length(gCorpses)) then
1526 begin
1527 if (gCorpses[i] <> nil) and (gCorpses[i].FPlayerUID = Player.FUID) then
1528 gCorpses[i].FPlayerUID := 0;
1529 end;
1531 if Player.FObj.Y >= gMapInfo.Height+128 then
1532 Exit;
1534 with Player do
1535 begin
1536 if (FHealth >= -50) or (gGibsCount = 0) then
1537 begin
1538 if (gCorpses = nil) or (Length(gCorpses) = 0) then
1539 Exit;
1541 ok := False;
1542 for find_id := 0 to High(gCorpses) do
1543 if gCorpses[find_id] = nil then
1544 begin
1545 ok := True;
1546 Break;
1547 end;
1549 if not ok then
1550 find_id := Random(Length(gCorpses));
1552 gCorpses[find_id] := TCorpse.Create(FObj.X, FObj.Y, FModel.Name, FHealth < -20);
1553 gCorpses[find_id].FColor := FModel.Color;
1554 gCorpses[find_id].FObj.Vel := FObj.Vel;
1555 gCorpses[find_id].FObj.Accel := FObj.Accel;
1556 gCorpses[find_id].FPlayerUID := FUID;
1558 Result := find_id;
1559 end
1560 else
1561 g_Player_CreateGibs(FObj.X + PLAYER_RECT_CX,
1562 FObj.Y + PLAYER_RECT_CY,
1563 FModel.Name, FModel.Color);
1564 end;
1565 end;
1567 procedure g_Player_CreateShell(fX, fY, dX, dY: Integer; T: Byte);
1568 var
1569 SID: DWORD;
1570 begin
1571 if (gShells = nil) or (Length(gShells) = 0) then
1572 Exit;
1574 with gShells[CurrentShell] do
1575 begin
1576 SpriteID := 0;
1577 g_Obj_Init(@Obj);
1578 Obj.Rect.X := 0;
1579 Obj.Rect.Y := 0;
1580 if T = SHELL_BULLET then
1581 begin
1582 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID) then
1583 SpriteID := SID;
1584 CX := 2;
1585 CY := 1;
1586 Obj.Rect.Width := 4;
1587 Obj.Rect.Height := 2;
1588 end
1589 else
1590 begin
1591 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID) then
1592 SpriteID := SID;
1593 CX := 4;
1594 CY := 2;
1595 Obj.Rect.Width := 7;
1596 Obj.Rect.Height := 3;
1597 end;
1598 SType := T;
1599 alive := True;
1600 Obj.X := fX;
1601 Obj.Y := fY;
1602 g_Obj_Push(@Obj, dX + Random(4)-Random(4), dY-Random(4));
1603 positionChanged(); // this updates spatial accelerators
1604 RAngle := Random(360);
1605 Timeout := gTime + SHELL_TIMEOUT;
1607 if CurrentShell >= High(gShells) then
1608 CurrentShell := 0
1609 else
1610 Inc(CurrentShell);
1611 end;
1612 end;
1614 procedure g_Player_CreateGibs(fX, fY: Integer; ModelName: string; fColor: TRGB);
1615 var
1616 a: Integer;
1617 GibsArray: TGibsArray;
1618 Blood: TModelBlood;
1619 begin
1620 if (gGibs = nil) or (Length(gGibs) = 0) then
1621 Exit;
1622 if not g_PlayerModel_GetGibs(ModelName, GibsArray) then
1623 Exit;
1624 Blood := g_PlayerModel_GetBlood(ModelName);
1626 for a := 0 to High(GibsArray) do
1627 with gGibs[CurrentGib] do
1628 begin
1629 Color := fColor;
1630 ID := GibsArray[a].ID;
1631 MaskID := GibsArray[a].MaskID;
1632 alive := True;
1633 g_Obj_Init(@Obj);
1634 Obj.Rect := GibsArray[a].Rect;
1635 Obj.X := fX-GibsArray[a].Rect.X-(GibsArray[a].Rect.Width div 2);
1636 Obj.Y := fY-GibsArray[a].Rect.Y-(GibsArray[a].Rect.Height div 2);
1637 g_Obj_PushA(@Obj, 25 + Random(10), Random(361));
1638 positionChanged(); // this updates spatial accelerators
1639 RAngle := Random(360);
1641 if gBloodCount > 0 then
1642 g_GFX_Blood(fX, fY, 16*gBloodCount+Random(5*gBloodCount), -16+Random(33), -16+Random(33),
1643 Random(48), Random(48), Blood.R, Blood.G, Blood.B, Blood.Kind);
1645 if CurrentGib >= High(gGibs) then
1646 CurrentGib := 0
1647 else
1648 Inc(CurrentGib);
1649 end;
1650 end;
1652 procedure g_Player_UpdatePhysicalObjects();
1653 var
1654 i: Integer;
1655 vel: TPoint2i;
1656 mr: Word;
1658 procedure ShellSound_Bounce(X, Y: Integer; T: Byte);
1659 var
1660 k: Integer;
1661 begin
1662 k := 1 + Random(2);
1663 if T = SHELL_BULLET then
1664 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k), X, Y)
1665 else
1666 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k), X, Y);
1667 end;
1669 begin
1670 // Êóñêè ìÿñà:
1671 if gGibs <> nil then
1672 for i := 0 to High(gGibs) do
1673 if gGibs[i].alive then
1674 with gGibs[i] do
1675 begin
1676 Obj.oldX := Obj.X;
1677 Obj.oldY := Obj.Y;
1679 vel := Obj.Vel;
1680 mr := g_Obj_Move(@Obj, True, False, True);
1681 positionChanged(); // this updates spatial accelerators
1683 if WordBool(mr and MOVE_FALLOUT) then
1684 begin
1685 alive := False;
1686 Continue;
1687 end;
1689 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1690 if WordBool(mr and MOVE_HITWALL) then
1691 Obj.Vel.X := -(vel.X div 2);
1692 if WordBool(mr and (MOVE_HITCEIL or MOVE_HITLAND)) then
1693 Obj.Vel.Y := -(vel.Y div 2);
1695 if (Obj.Vel.X >= 0) then
1696 begin // Clockwise
1697 RAngle := RAngle + Abs(Obj.Vel.X)*6 + Abs(Obj.Vel.Y);
1698 if RAngle >= 360 then
1699 RAngle := RAngle mod 360;
1700 end else begin // Counter-clockwise
1701 RAngle := RAngle - Abs(Obj.Vel.X)*6 - Abs(Obj.Vel.Y);
1702 if RAngle < 0 then
1703 RAngle := (360 - (Abs(RAngle) mod 360)) mod 360;
1704 end;
1706 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1707 if gTime mod (GAME_TICK*3) = 0 then
1708 Obj.Vel.X := z_dec(Obj.Vel.X, 1);
1709 end;
1711 // Òðóïû:
1712 if gCorpses <> nil then
1713 for i := 0 to High(gCorpses) do
1714 if gCorpses[i] <> nil then
1715 if gCorpses[i].State = CORPSE_STATE_REMOVEME then
1716 begin
1717 gCorpses[i].Free();
1718 gCorpses[i] := nil;
1719 end
1720 else
1721 gCorpses[i].Update();
1723 // Ãèëüçû:
1724 if gShells <> nil then
1725 for i := 0 to High(gShells) do
1726 if gShells[i].alive then
1727 with gShells[i] do
1728 begin
1729 Obj.oldX := Obj.X;
1730 Obj.oldY := Obj.Y;
1732 vel := Obj.Vel;
1733 mr := g_Obj_Move(@Obj, True, False, True);
1734 positionChanged(); // this updates spatial accelerators
1736 if WordBool(mr and MOVE_FALLOUT) or (gShells[i].Timeout < gTime) then
1737 begin
1738 alive := False;
1739 Continue;
1740 end;
1742 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1743 if WordBool(mr and MOVE_HITWALL) then
1744 begin
1745 Obj.Vel.X := -(vel.X div 2);
1746 if not WordBool(mr and MOVE_INWATER) then
1747 ShellSound_Bounce(Obj.X, Obj.Y, SType);
1748 end;
1749 if WordBool(mr and (MOVE_HITCEIL or MOVE_HITLAND)) then
1750 begin
1751 Obj.Vel.Y := -(vel.Y div 2);
1752 if Obj.Vel.X <> 0 then Obj.Vel.X := Obj.Vel.X div 2;
1753 if (Obj.Vel.X = 0) and (Obj.Vel.Y = 0) then
1754 begin
1755 if RAngle mod 90 <> 0 then
1756 RAngle := (RAngle div 90) * 90;
1757 end
1758 else if not WordBool(mr and MOVE_INWATER) then
1759 ShellSound_Bounce(Obj.X, Obj.Y, SType);
1760 end;
1762 if (Obj.Vel.X >= 0) then
1763 begin // Clockwise
1764 RAngle := RAngle + Abs(Obj.Vel.X)*8 + Abs(Obj.Vel.Y);
1765 if RAngle >= 360 then
1766 RAngle := RAngle mod 360;
1767 end else begin // Counter-clockwise
1768 RAngle := RAngle - Abs(Obj.Vel.X)*8 - Abs(Obj.Vel.Y);
1769 if RAngle < 0 then
1770 RAngle := (360 - (Abs(RAngle) mod 360)) mod 360;
1771 end;
1772 end;
1773 end;
1776 procedure TGib.getMapBox (out x, y, w, h: Integer); inline;
1777 begin
1778 x := Obj.X+Obj.Rect.X;
1779 y := Obj.Y+Obj.Rect.Y;
1780 w := Obj.Rect.Width;
1781 h := Obj.Rect.Height;
1782 end;
1784 procedure TGib.moveBy (dx, dy: Integer); inline;
1785 begin
1786 if (dx <> 0) or (dy <> 0) then
1787 begin
1788 Obj.X += dx;
1789 Obj.Y += dy;
1790 positionChanged();
1791 end;
1792 end;
1795 procedure TShell.getMapBox (out x, y, w, h: Integer); inline;
1796 begin
1797 x := Obj.X;
1798 y := Obj.Y;
1799 w := Obj.Rect.Width;
1800 h := Obj.Rect.Height;
1801 end;
1803 procedure TShell.moveBy (dx, dy: Integer); inline;
1804 begin
1805 if (dx <> 0) or (dy <> 0) then
1806 begin
1807 Obj.X += dx;
1808 Obj.Y += dy;
1809 positionChanged();
1810 end;
1811 end;
1814 procedure TGib.positionChanged (); inline; begin end;
1815 procedure TShell.positionChanged (); inline; begin end;
1818 procedure g_Player_DrawCorpses();
1819 var
1820 i, fX, fY: Integer;
1821 a: TDFPoint;
1822 begin
1823 if gGibs <> nil then
1824 for i := 0 to High(gGibs) do
1825 if gGibs[i].alive then
1826 with gGibs[i] do
1827 begin
1828 if not g_Obj_Collide(sX, sY, sWidth, sHeight, @Obj) then
1829 Continue;
1831 Obj.lerp(gLerpFactor, fX, fY);
1833 a.X := Obj.Rect.X+(Obj.Rect.Width div 2);
1834 a.y := Obj.Rect.Y+(Obj.Rect.Height div 2);
1836 e_DrawAdv(ID, fX, fY, 0, True, False, RAngle, @a, TMirrorType.None);
1838 e_Colors := Color;
1839 e_DrawAdv(MaskID, fX, fY, 0, True, False, RAngle, @a, TMirrorType.None);
1840 e_Colors.R := 255;
1841 e_Colors.G := 255;
1842 e_Colors.B := 255;
1843 end;
1845 if gCorpses <> nil then
1846 for i := 0 to High(gCorpses) do
1847 if gCorpses[i] <> nil then
1848 gCorpses[i].Draw();
1849 end;
1851 procedure g_Player_DrawShells();
1852 var
1853 i, fX, fY: Integer;
1854 a: TDFPoint;
1855 begin
1856 if gShells <> nil then
1857 for i := 0 to High(gShells) do
1858 if gShells[i].alive then
1859 with gShells[i] do
1860 begin
1861 if not g_Obj_Collide(sX, sY, sWidth, sHeight, @Obj) then
1862 Continue;
1864 Obj.lerp(gLerpFactor, fX, fY);
1866 a.X := CX;
1867 a.Y := CY;
1869 e_DrawAdv(SpriteID, fX, fY, 0, True, False, RAngle, @a, TMirrorType.None);
1870 end;
1871 end;
1873 procedure g_Player_RemoveAllCorpses();
1874 var
1875 i: Integer;
1876 begin
1877 gGibs := nil;
1878 gShells := nil;
1879 SetLength(gGibs, MaxGibs);
1880 SetLength(gShells, MaxGibs);
1881 CurrentGib := 0;
1882 CurrentShell := 0;
1884 if gCorpses <> nil then
1885 for i := 0 to High(gCorpses) do
1886 gCorpses[i].Free();
1888 gCorpses := nil;
1889 SetLength(gCorpses, MaxCorpses);
1890 end;
1892 procedure g_Player_Corpses_SaveState (st: TStream);
1893 var
1894 count, i: Integer;
1895 begin
1896 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ
1897 count := 0;
1898 for i := 0 to High(gCorpses) do if (gCorpses[i] <> nil) then Inc(count);
1900 // Êîëè÷åñòâî òðóïîâ
1901 utils.writeInt(st, LongInt(count));
1903 if (count = 0) then exit;
1905 // Ñîõðàíÿåì òðóïû
1906 for i := 0 to High(gCorpses) do
1907 begin
1908 if gCorpses[i] <> nil then
1909 begin
1910 // Íàçâàíèå ìîäåëè
1911 utils.writeStr(st, gCorpses[i].FModelName);
1912 // Òèï ñìåðòè
1913 utils.writeBool(st, gCorpses[i].Mess);
1914 // Ñîõðàíÿåì äàííûå òðóïà:
1915 gCorpses[i].SaveState(st);
1916 end;
1917 end;
1918 end;
1921 procedure g_Player_Corpses_LoadState (st: TStream);
1922 var
1923 count, i: Integer;
1924 str: String;
1925 b: Boolean;
1926 begin
1927 assert(st <> nil);
1929 g_Player_RemoveAllCorpses();
1931 // Êîëè÷åñòâî òðóïîâ:
1932 count := utils.readLongInt(st);
1933 if (count < 0) or (count > Length(gCorpses)) then raise XStreamError.Create('invalid number of corpses');
1935 if (count = 0) then exit;
1937 // Çàãðóæàåì òðóïû
1938 for i := 0 to count-1 do
1939 begin
1940 // Íàçâàíèå ìîäåëè:
1941 str := utils.readStr(st);
1942 // Òèï ñìåðòè
1943 b := utils.readBool(st);
1944 // Ñîçäàåì òðóï
1945 gCorpses[i] := TCorpse.Create(0, 0, str, b);
1946 // Çàãðóæàåì äàííûå òðóïà
1947 gCorpses[i].LoadState(st);
1948 end;
1949 end;
1952 { T P l a y e r : }
1954 function TPlayer.isValidViewPort (): Boolean; inline; begin result := (viewPortW > 0) and (viewPortH > 0); end;
1956 procedure TPlayer.BFGHit();
1957 begin
1958 g_Weapon_BFGHit(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
1959 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2));
1960 if g_Game_IsServer and g_Game_IsNet then
1961 MH_SEND_Effect(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
1962 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
1963 0, NET_GFX_BFGHIT);
1964 end;
1966 procedure TPlayer.ChangeModel(ModelName: string);
1967 var
1968 locModel: TPlayerModel;
1969 begin
1970 locModel := g_PlayerModel_Get(ModelName);
1971 if locModel = nil then Exit;
1973 FModel.Free();
1974 FModel := locModel;
1975 end;
1977 procedure TPlayer.SetModel(ModelName: string);
1978 var
1979 m: TPlayerModel;
1980 begin
1981 m := g_PlayerModel_Get(ModelName);
1982 if m = nil then
1983 begin
1984 g_SimpleError(Format(_lc[I_GAME_ERROR_MODEL_FALLBACK], [ModelName]));
1985 m := g_PlayerModel_Get('doomer');
1986 if m = nil then
1987 begin
1988 g_FatalError(Format(_lc[I_GAME_ERROR_MODEL], ['doomer']));
1989 Exit;
1990 end;
1991 end;
1993 if FModel <> nil then
1994 FModel.Free();
1996 FModel := m;
1998 if not (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
1999 FModel.Color := FColor
2000 else
2001 FModel.Color := TEAMCOLOR[FTeam];
2002 FModel.SetWeapon(FCurrWeap);
2003 FModel.SetFlag(FFlag);
2004 SetDirection(FDirection);
2005 end;
2007 procedure TPlayer.SetColor(Color: TRGB);
2008 begin
2009 FColor := Color;
2010 if not (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
2011 if FModel <> nil then FModel.Color := Color;
2012 end;
2016 function TPlayer.GetColor(): TRGB;
2017 begin
2018 result := FModel.Color;
2019 end;
2021 procedure TPlayer.SetWeaponPrefs(Prefs: Array of Byte);
2022 var
2023 i: Integer;
2024 begin
2025 for i := WP_FIRST to WP_LAST + 1 do
2026 begin
2027 if (Prefs[i] > WP_LAST + 1) then
2028 FWeapPreferences[i] := 0
2029 else
2030 FWeapPreferences[i] := Prefs[i];
2031 end;
2032 end;
2034 procedure TPlayer.SetWeaponPref(Weapon, Pref: Byte);
2035 begin
2036 if (Weapon > WP_LAST + 1) then
2037 exit
2038 else if (Pref <= WP_LAST + 1) and (Weapon <= WP_LAST + 1) then
2039 FWeapPreferences[Weapon] := Pref
2040 else if (Weapon <= WP_LAST + 1) and (Pref > WP_LAST + 1) then
2041 FWeapPreferences[Weapon] := 0;
2042 end;
2044 function TPlayer.GetWeaponPref(Weapon: Byte) : Byte;
2045 begin
2046 if (Weapon > WP_LAST + 1) then
2047 result := 0
2048 else if (FWeapPreferences[Weapon] > WP_LAST + 1) then
2049 result := 0
2050 else
2051 result := FWeapPreferences[Weapon];
2052 end;
2054 function TPlayer.GetMorePrefered() : Byte;
2055 var
2056 testedWeap, i: Byte;
2057 begin
2058 testedWeap := FCurrWeap;
2059 for i := WP_FIRST to WP_LAST do
2060 if FWeapon[i] and maySwitch(i) and (FWeapPreferences[i] > FWeapPreferences[testedWeap]) then
2061 testedWeap := i;
2062 if (R_BERSERK in FRulez) and (FWeapPreferences[WP_LAST + 1] > FWeapPreferences[testedWeap]) then
2063 testedWeap := WEAPON_KASTET;
2064 result := testedWeap;
2065 end;
2067 function TPlayer.maySwitch(Weapon: Byte) : Boolean;
2068 begin
2069 result := true;
2070 if (Weapon = WEAPON_KASTET) and (FSkipFist <> 0) then
2071 begin
2072 if (FSkipFist = 1) and (not (R_BERSERK in FRulez)) then
2073 result := false;
2074 end
2075 else if (FSwitchToEmpty = 0) and (not hasAmmoForShooting(Weapon)) then
2076 result := false;
2077 end;
2079 procedure TPlayer.SwitchTeam;
2080 begin
2081 if g_Game_IsClient then
2082 Exit;
2083 if not (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then Exit;
2085 if gGameOn and FAlive then
2086 Kill(K_SIMPLEKILL, FUID, HIT_SELF);
2088 if FTeam = TEAM_RED then
2089 begin
2090 ChangeTeam(TEAM_BLUE);
2091 g_Console_Add(Format(_lc[I_PLAYER_CHTEAM_BLUE], [FName]), True);
2092 if g_Game_IsNet then
2093 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM, TEAM_BLUE, FName);
2094 end
2095 else
2096 begin
2097 ChangeTeam(TEAM_RED);
2098 g_Console_Add(Format(_lc[I_PLAYER_CHTEAM_RED], [FName]), True);
2099 if g_Game_IsNet then
2100 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM, TEAM_RED, FName);
2101 end;
2102 FPreferredTeam := FTeam;
2103 end;
2105 procedure TPlayer.ChangeTeam(Team: Byte);
2106 var
2107 OldTeam: Byte;
2108 begin
2109 OldTeam := FTeam;
2110 FTeam := Team;
2111 case Team of
2112 TEAM_RED, TEAM_BLUE:
2113 FModel.Color := TEAMCOLOR[Team];
2114 else
2115 FModel.Color := FColor;
2116 end;
2117 if (FTeam <> OldTeam) and g_Game_IsNet and g_Game_IsServer then
2118 MH_SEND_PlayerStats(FUID);
2119 end;
2122 procedure TPlayer.CollideItem();
2123 var
2124 i: Integer;
2125 r: Boolean;
2126 begin
2127 if gItems = nil then Exit;
2128 if not FAlive then Exit;
2130 for i := 0 to High(gItems) do
2131 with gItems[i] do
2132 begin
2133 if (ItemType <> ITEM_NONE) and alive then
2134 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
2135 PLAYER_RECT.Height, @Obj) then
2136 begin
2137 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
2139 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
2140 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
2141 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
2142 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
2143 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
2145 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
2146 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
2147 (gGameSettings.GameType = GT_SINGLE) and
2148 (g_Player_GetCount() > 1)) then
2149 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
2150 end;
2151 end;
2152 end;
2155 function TPlayer.CollideLevel(XInc, YInc: Integer): Boolean;
2156 begin
2157 Result := g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc,
2158 PLAYER_RECT.Width, PLAYER_RECT.Height, PANEL_WALL,
2159 False);
2160 end;
2162 constructor TPlayer.Create();
2163 begin
2164 viewPortX := 0;
2165 viewPortY := 0;
2166 viewPortW := 0;
2167 viewPortH := 0;
2168 mEDamageType := HIT_SOME;
2170 FIamBot := False;
2171 FDummy := False;
2172 FSpawned := False;
2174 FSawSound := TPlayableSound.Create();
2175 FSawSoundIdle := TPlayableSound.Create();
2176 FSawSoundHit := TPlayableSound.Create();
2177 FSawSoundSelect := TPlayableSound.Create();
2178 FFlameSoundOn := TPlayableSound.Create();
2179 FFlameSoundOff := TPlayableSound.Create();
2180 FFlameSoundWork := TPlayableSound.Create();
2181 FJetSoundFly := TPlayableSound.Create();
2182 FJetSoundOn := TPlayableSound.Create();
2183 FJetSoundOff := TPlayableSound.Create();
2185 FSawSound.SetByName('SOUND_WEAPON_FIRESAW');
2186 FSawSoundIdle.SetByName('SOUND_WEAPON_IDLESAW');
2187 FSawSoundHit.SetByName('SOUND_WEAPON_HITSAW');
2188 FSawSoundSelect.SetByName('SOUND_WEAPON_SELECTSAW');
2189 FFlameSoundOn.SetByName('SOUND_WEAPON_FLAMEON');
2190 FFlameSoundOff.SetByName('SOUND_WEAPON_FLAMEOFF');
2191 FFlameSoundWork.SetByName('SOUND_WEAPON_FLAMEWORK');
2192 FJetSoundFly.SetByName('SOUND_PLAYER_JETFLY');
2193 FJetSoundOn.SetByName('SOUND_PLAYER_JETON');
2194 FJetSoundOff.SetByName('SOUND_PLAYER_JETOFF');
2196 FSpectatePlayer := -1;
2197 FClientID := -1;
2198 FPing := 0;
2199 FLoss := 0;
2200 FSavedStateNum := -1;
2201 FShellTimer := -1;
2202 FFireTime := 0;
2203 FFirePainTime := 0;
2204 FFireAttacker := 0;
2205 FHandicap := 100;
2206 FCorpse := -1;
2208 FActualModelName := 'doomer';
2210 g_Obj_Init(@FObj);
2211 FObj.Rect := PLAYER_RECT;
2213 FBFGFireCounter := -1;
2214 FJustTeleported := False;
2215 FNetTime := 0;
2217 FWaitForFirstSpawn := false;
2219 resetWeaponQueue();
2220 end;
2222 procedure TPlayer.positionChanged (); inline;
2223 begin
2224 end;
2226 procedure TPlayer.doDamage (v: Integer);
2227 begin
2228 if (v <= 0) then exit;
2229 if (v > 32767) then v := 32767;
2230 Damage(v, 0, 0, 0, mEDamageType);
2231 end;
2233 procedure TPlayer.Damage(value: Word; SpawnerUID: Word; vx, vy: Integer; t: Byte);
2234 var
2235 c: Word;
2236 begin
2237 if (not g_Game_IsClient) and (not FAlive) then
2238 Exit;
2240 FLastHit := t;
2242 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2243 if ((t = HIT_TRAP) or (t = HIT_SELF)) and (not FGodMode) then
2244 begin
2245 if not g_Game_IsClient then
2246 begin
2247 FArmor := 0;
2248 if t = HIT_TRAP then
2249 begin
2250 // Ëîâóøêà óáèâàåò ñðàçó:
2251 FHealth := -100;
2252 Kill(K_EXTRAHARDKILL, SpawnerUID, t);
2253 end;
2254 if t = HIT_SELF then
2255 begin
2256 // Ñàìîóáèéñòâî:
2257 FHealth := 0;
2258 Kill(K_SIMPLEKILL, SpawnerUID, t);
2259 end;
2260 end;
2261 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2262 FMegaRulez[MR_SUIT] := 0;
2263 FMegaRulez[MR_INVUL] := 0;
2264 FMegaRulez[MR_INVIS] := 0;
2265 FSpawnInvul := 0;
2266 FBerserk := 0;
2267 end;
2269 // Íî îò îñòàëüíîãî ñïàñàåò:
2270 if FMegaRulez[MR_INVUL] >= gTime then
2271 Exit;
2273 // ×èò-êîä "ÃÎÐÅÖ":
2274 if FGodMode then
2275 Exit;
2277 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2278 if LongBool(gGameSettings.Options and GAME_OPTION_TEAMDAMAGE) or
2279 (SpawnerUID = FUID) or
2280 (not SameTeam(FUID, SpawnerUID)) then
2281 begin
2282 FLastSpawnerUID := SpawnerUID;
2284 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2285 if gBloodCount > 0 then
2286 begin
2287 c := Min(value, 200)*gBloodCount + Random(Min(value, 200) div 2);
2288 if value div 4 <= c then
2289 c := c - (value div 4)
2290 else
2291 c := 0;
2293 if (t = HIT_SOME) and (vx = 0) and (vy = 0) then
2294 MakeBloodSimple(c)
2295 else
2296 case t of
2297 HIT_TRAP, HIT_ACID, HIT_FLAME, HIT_SELF: MakeBloodSimple(c);
2298 HIT_BFG, HIT_ROCKET, HIT_SOME: MakeBloodVector(c, vx, vy);
2299 end;
2301 if t = HIT_WATER then
2302 begin
2303 g_GFX_Bubbles(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2),
2304 FObj.Y+PLAYER_RECT.Y-4, value div 2, 8, 4);
2305 if Random(2) = 0
2306 then g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj.X, FObj.Y)
2307 else g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj.X, FObj.Y);
2308 end;
2309 end;
2311 // Áóôåð óðîíà:
2312 if FAlive then
2313 Inc(FDamageBuffer, value);
2315 // Âñïûøêà áîëè:
2316 if gFlash <> 0 then
2317 FPain := FPain + value;
2318 end;
2320 if g_Game_IsServer and g_Game_IsNet then
2321 begin
2322 MH_SEND_PlayerDamage(FUID, t, SpawnerUID, value, vx, vy);
2323 MH_SEND_PlayerStats(FUID);
2324 MH_SEND_PlayerPos(False, FUID);
2325 end;
2326 end;
2328 function TPlayer.Heal(value: Word; Soft: Boolean): Boolean;
2329 begin
2330 Result := False;
2331 if g_Game_IsClient then
2332 Exit;
2333 if not FAlive then
2334 Exit;
2336 if Soft and (FHealth < PLAYER_HP_SOFT) then
2337 begin
2338 IncMax(FHealth, value, PLAYER_HP_SOFT);
2339 Result := True;
2340 end;
2341 if (not Soft) and (FHealth < PLAYER_HP_LIMIT) then
2342 begin
2343 IncMax(FHealth, value, PLAYER_HP_LIMIT);
2344 Result := True;
2345 end;
2347 if Result and g_Game_IsServer and g_Game_IsNet then
2348 MH_SEND_PlayerStats(FUID);
2349 end;
2351 destructor TPlayer.Destroy();
2352 begin
2353 if (gPlayer1 <> nil) and (gPlayer1.FUID = FUID) then
2354 gPlayer1 := nil;
2355 if (gPlayer2 <> nil) and (gPlayer2.FUID = FUID) then
2356 gPlayer2 := nil;
2358 FSawSound.Free();
2359 FSawSoundIdle.Free();
2360 FSawSoundHit.Free();
2361 FSawSoundSelect.Free();
2362 FFlameSoundOn.Free();
2363 FFlameSoundOff.Free();
2364 FFlameSoundWork.Free();
2365 FJetSoundFly.Free();
2366 FJetSoundOn.Free();
2367 FJetSoundOff.Free();
2368 FModel.Free();
2369 if FPunchAnim <> nil then
2370 FPunchAnim.Free();
2372 inherited;
2373 end;
2375 procedure TPlayer.DrawIndicator(Color: TRGB);
2376 var
2377 indX, indY, fX, fY, fSlope: Integer;
2378 indW, indH: Word;
2379 indA: Single;
2380 a: TDFPoint;
2381 nW, nH: Byte;
2382 ID: DWORD;
2383 c: TRGB;
2384 begin
2385 if FAlive then
2386 begin
2387 FObj.lerp(gLerpFactor, fX, fY);
2388 fSlope := nlerp(FSlopeOld, FObj.slopeUpLeft, gLerpFactor);
2390 case gPlayerIndicatorStyle of
2391 0:
2392 begin
2393 if g_Texture_Get('TEXTURE_PLAYER_INDICATOR', ID) then
2394 begin
2395 e_GetTextureSize(ID, @indW, @indH);
2396 a.X := indW div 2;
2397 a.Y := indH div 2;
2399 if (FObj.X + FObj.Rect.X) < 0 then
2400 begin
2401 indA := 90;
2402 indX := fX + FObj.Rect.X + FObj.Rect.Width;
2403 indY := fY + FObj.Rect.Y + (FObj.Rect.Height - indW) div 2;
2404 end
2406 else if (FObj.X + FObj.Rect.X + FObj.Rect.Width) > Max(gMapInfo.Width, gPlayerScreenSize.X) then
2407 begin
2408 indA := 270;
2409 indX := fX + FObj.Rect.X - indH;
2410 indY := fY + FObj.Rect.Y + (FObj.Rect.Height - indW) div 2;
2411 end
2413 else if (FObj.Y - indH) < 0 then
2414 begin
2415 indA := 180;
2416 indX := fX + FObj.Rect.X + (FObj.Rect.Width - indW) div 2;
2417 indY := fY + FObj.Rect.Y + FObj.Rect.Height;
2418 end
2420 else
2421 begin
2422 indA := 0;
2423 indX := fX + FObj.Rect.X + (FObj.Rect.Width - indW) div 2;
2424 indY := fY - indH;
2425 end;
2427 indY := indY + fSlope;
2428 indX := EnsureRange(indX, 0, Max(gMapInfo.Width, gPlayerScreenSize.X) - indW);
2429 indY := EnsureRange(indY, 0, Max(gMapInfo.Height, gPlayerScreenSize.Y) - indH);
2431 c := e_Colors;
2432 e_Colors := Color;
2433 e_DrawAdv(ID, indX, indY, 0, True, False, indA, @a);
2434 e_Colors := c;
2435 end;
2436 end;
2438 1:
2439 begin
2440 e_TextureFontGetSize(gStdFont, nW, nH);
2441 indX := fX + FObj.Rect.X + (FObj.Rect.Width - Length(FName) * nW) div 2;
2442 indY := fY - nH + fSlope;
2443 e_TextureFontPrintEx(indX, indY, FName, gStdFont, Color.R, Color.G, Color.B, 1.0, True);
2444 end;
2445 end;
2446 end;
2447 end;
2449 procedure TPlayer.DrawBubble();
2450 var
2451 bubX, bubY, fX, fY: Integer;
2452 ID: LongWord;
2453 Rb, Gb, Bb,
2454 Rw, Gw, Bw: SmallInt;
2455 Dot: Byte;
2456 CObj: TObj;
2457 begin
2458 CObj := getCameraObj();
2459 CObj.lerp(gLerpFactor, fX, fY);
2460 // NB: _F_Obj.Rect is used to keep the bubble higher; this is not a mistake
2461 bubX := fX+FObj.Rect.X + IfThen(FDirection = TDirection.D_LEFT, -4, 18);
2462 bubY := fY+FObj.Rect.Y - 18;
2463 Rb := 64;
2464 Gb := 64;
2465 Bb := 64;
2466 Rw := 240;
2467 Gw := 240;
2468 Bw := 240;
2469 case gChatBubble of
2470 1: // simple textual non-bubble
2471 begin
2472 bubX := fX+FObj.Rect.X - 11;
2473 bubY := fY+FObj.Rect.Y - 17;
2474 e_TextureFontPrint(bubX, bubY, '[...]', gStdFont);
2475 Exit;
2476 end;
2477 2: // advanced pixel-perfect bubble
2478 begin
2479 if FTeam = TEAM_RED then
2480 Rb := 255
2481 else
2482 if FTeam = TEAM_BLUE then
2483 Bb := 255;
2484 end;
2485 3: // colored bubble
2486 begin
2487 Rb := FModel.Color.R;
2488 Gb := FModel.Color.G;
2489 Bb := FModel.Color.B;
2490 Rw := Min(Rb * 2 + 64, 255);
2491 Gw := Min(Gb * 2 + 64, 255);
2492 Bw := Min(Bb * 2 + 64, 255);
2493 if (Abs(Rw - Rb) < 32)
2494 or (Abs(Gw - Gb) < 32)
2495 or (Abs(Bw - Bb) < 32) then
2496 begin
2497 Rb := Max(Rw div 2 - 16, 0);
2498 Gb := Max(Gw div 2 - 16, 0);
2499 Bb := Max(Bw div 2 - 16, 0);
2500 end;
2501 end;
2502 4: // custom textured bubble
2503 begin
2504 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID) then
2505 if FDirection = TDirection.D_RIGHT then
2506 e_Draw(ID, bubX - 6, bubY - 7, 0, True, False)
2507 else
2508 e_Draw(ID, bubX - 6, bubY - 7, 0, True, False, TMirrorType.Horizontal);
2509 Exit;
2510 end;
2511 end;
2513 // Outer borders
2514 e_DrawQuad(bubX + 1, bubY , bubX + 18, bubY + 13, Rb, Gb, Bb);
2515 e_DrawQuad(bubX , bubY + 1, bubX + 19, bubY + 12, Rb, Gb, Bb);
2516 // Inner box
2517 e_DrawFillQuad(bubX + 1, bubY + 1, bubX + 18, bubY + 12, Rw, Gw, Bw, 0);
2519 // Tail
2520 Dot := IfThen(FDirection = TDirection.D_LEFT, 14, 5);
2521 e_DrawLine(1, bubX + Dot, bubY + 14, bubX + Dot, bubY + 16, Rb, Gb, Bb);
2522 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);
2523 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);
2524 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);
2525 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);
2527 // Dots
2528 Dot := 6;
2529 e_DrawFillQuad(bubX + Dot, bubY + 8, bubX + Dot + 1, bubY + 9, Rb, Gb, Bb, 0);
2530 e_DrawFillQuad(bubX + Dot + 3, bubY + 8, bubX + Dot + 4, bubY + 9, Rb, Gb, Bb, 0);
2531 e_DrawFillQuad(bubX + Dot + 6, bubY + 8, bubX + Dot + 7, bubY + 9, Rb, Gb, Bb, 0);
2532 end;
2534 procedure TPlayer.Draw();
2535 var
2536 ID: DWORD;
2537 w, h: Word;
2538 dr: Boolean;
2539 Mirror: TMirrorType;
2540 fX, fY, fSlope: Integer;
2541 begin
2542 FObj.lerp(gLerpFactor, fX, fY);
2543 fSlope := nlerp(FSlopeOld, FObj.slopeUpLeft, gLerpFactor);
2545 if FAlive then
2546 begin
2547 if Direction = TDirection.D_RIGHT then
2548 Mirror := TMirrorType.None
2549 else
2550 Mirror := TMirrorType.Horizontal;
2552 if FPunchAnim <> nil then
2553 begin
2554 FPunchAnim.Draw(fX+IfThen(Direction = TDirection.D_LEFT, 15-FObj.Rect.X, FObj.Rect.X-15),
2555 fY+fSlope+FObj.Rect.Y-11, Mirror);
2556 if FPunchAnim.played then
2557 begin
2558 FPunchAnim.Free;
2559 FPunchAnim := nil;
2560 end;
2561 end;
2563 if (FMegaRulez[MR_INVUL] > gTime) and ((gPlayerDrawn <> Self) or (FSpawnInvul >= gTime)) then
2564 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID) then
2565 begin
2566 e_GetTextureSize(ID, @w, @h);
2567 if FDirection = TDirection.D_LEFT then
2568 e_Draw(ID, fX+FObj.Rect.X+(FObj.Rect.Width div 2)-(w div 2)+4,
2569 fY+FObj.Rect.Y+(FObj.Rect.Height div 2)-(h div 2)-7+fSlope, 0, True, False)
2570 else
2571 e_Draw(ID, fX+FObj.Rect.X+(FObj.Rect.Width div 2)-(w div 2)-2,
2572 fY+FObj.Rect.Y+(FObj.Rect.Height div 2)-(h div 2)-7+fSlope, 0, True, False);
2573 end;
2575 if FMegaRulez[MR_INVIS] > gTime then
2576 begin
2577 if (gPlayerDrawn <> nil) and ((Self = gPlayerDrawn) or
2578 ((FTeam = gPlayerDrawn.Team) and (gGameSettings.GameMode <> GM_DM))) then
2579 begin
2580 if (FMegaRulez[MR_INVIS] - gTime) <= 2100 then
2581 dr := not Odd((FMegaRulez[MR_INVIS] - gTime) div 300)
2582 else
2583 dr := True;
2584 if dr then
2585 FModel.Draw(fX, fY+fSlope, 200)
2586 else
2587 FModel.Draw(fX, fY+fSlope);
2588 end
2589 else
2590 FModel.Draw(fX, fY+fSlope, 254);
2591 end
2592 else
2593 FModel.Draw(fX, fY+fSlope);
2594 end;
2596 if g_debug_Frames then
2597 begin
2598 e_DrawQuad(FObj.X+FObj.Rect.X,
2599 FObj.Y+FObj.Rect.Y,
2600 FObj.X+FObj.Rect.X+FObj.Rect.Width-1,
2601 FObj.Y+FObj.Rect.Y+FObj.Rect.Height-1,
2602 0, 255, 0);
2603 end;
2605 if (gChatBubble > 0) and (FKeys[KEY_CHAT].Pressed) and not FGhost then
2606 if (FMegaRulez[MR_INVIS] <= gTime) or ((gPlayerDrawn <> nil) and ((Self = gPlayerDrawn) or
2607 ((FTeam = gPlayerDrawn.Team) and (gGameSettings.GameMode <> GM_DM)))) then
2608 DrawBubble();
2609 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2610 if gAimLine and alive and
2611 ((Self = gPlayer1) or (Self = gPlayer2)) then
2612 DrawAim();
2613 end;
2616 procedure TPlayer.DrawAim();
2617 procedure drawCast (sz: Integer; ax0, ay0, ax1, ay1: Integer);
2618 var
2619 ex, ey: Integer;
2620 begin
2622 {$IFDEF ENABLE_HOLMES}
2623 if isValidViewPort and (self = gPlayer1) then
2624 begin
2625 g_Holmes_plrLaser(ax0, ay0, ax1, ay1);
2626 end;
2627 {$ENDIF}
2629 e_DrawLine(sz, ax0, ay0, ax1, ay1, 255, 0, 0, 96);
2630 if (g_Map_traceToNearestWall(ax0, ay0, ax1, ay1, @ex, @ey) <> nil) then
2631 begin
2632 e_DrawLine(sz, ax0, ay0, ex, ey, 0, 255, 0, 96);
2633 end
2634 else
2635 begin
2636 e_DrawLine(sz, ax0, ay0, ex, ey, 0, 0, 255, 96);
2637 end;
2638 end;
2640 var
2641 wx, wy, xx, yy: Integer;
2642 angle: SmallInt;
2643 sz, len: Word;
2644 begin
2645 wx := FObj.X + WEAPONPOINT[FDirection].X + IfThen(FDirection = TDirection.D_LEFT, 7, -7);
2646 wy := FObj.Y + WEAPONPOINT[FDirection].Y;
2647 angle := FAngle;
2648 len := 1024;
2649 sz := 2;
2650 case FCurrWeap of
2651 0: begin // Punch
2652 len := 12;
2653 sz := 4;
2654 end;
2655 1: begin // Chainsaw
2656 len := 24;
2657 sz := 6;
2658 end;
2659 2: begin // Pistol
2660 len := 1024;
2661 sz := 2;
2662 if angle = ANGLE_RIGHTUP then Dec(angle, 2);
2663 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2664 if angle = ANGLE_LEFTUP then Inc(angle, 2);
2665 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2666 end;
2667 3: begin // Shotgun
2668 len := 1024;
2669 sz := 3;
2670 if angle = ANGLE_RIGHTUP then Dec(angle, 2);
2671 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2672 if angle = ANGLE_LEFTUP then Inc(angle, 2);
2673 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2674 end;
2675 4: begin // Double Shotgun
2676 len := 1024;
2677 sz := 4;
2678 if angle = ANGLE_RIGHTUP then Dec(angle, 2);
2679 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2680 if angle = ANGLE_LEFTUP then Inc(angle, 2);
2681 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2682 end;
2683 5: begin // Chaingun
2684 len := 1024;
2685 sz := 3;
2686 if angle = ANGLE_RIGHTUP then Dec(angle, 2);
2687 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2688 if angle = ANGLE_LEFTUP then Inc(angle, 2);
2689 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2690 end;
2691 6: begin // Rocket Launcher
2692 len := 1024;
2693 sz := 7;
2694 if angle = ANGLE_RIGHTUP then Inc(angle, 2);
2695 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2696 if angle = ANGLE_LEFTUP then Dec(angle, 2);
2697 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2698 end;
2699 7: begin // Plasmagun
2700 len := 1024;
2701 sz := 5;
2702 if angle = ANGLE_RIGHTUP then Inc(angle);
2703 if angle = ANGLE_RIGHTDOWN then Inc(angle, 3);
2704 if angle = ANGLE_LEFTUP then Dec(angle);
2705 if angle = ANGLE_LEFTDOWN then Dec(angle, 3);
2706 end;
2707 8: begin // BFG
2708 len := 1024;
2709 sz := 12;
2710 if angle = ANGLE_RIGHTUP then Inc(angle, 1);
2711 if angle = ANGLE_RIGHTDOWN then Inc(angle, 2);
2712 if angle = ANGLE_LEFTUP then Dec(angle, 1);
2713 if angle = ANGLE_LEFTDOWN then Dec(angle, 2);
2714 end;
2715 9: begin // Super Chaingun
2716 len := 1024;
2717 sz := 4;
2718 if angle = ANGLE_RIGHTUP then Dec(angle, 2);
2719 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2720 if angle = ANGLE_LEFTUP then Inc(angle, 2);
2721 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2722 end;
2723 end;
2724 xx := Trunc(Cos(-DegToRad(angle)) * len) + wx;
2725 yy := Trunc(Sin(-DegToRad(angle)) * len) + wy;
2726 {$IF DEFINED(D2F_DEBUG)}
2727 drawCast(sz, wx, wy, xx, yy);
2728 {$ELSE}
2729 e_DrawLine(sz, wx, wy, xx, yy, 255, 0, 0, 96);
2730 {$ENDIF}
2731 end;
2733 procedure TPlayer.DrawGUI();
2734 var
2735 ID: DWORD;
2736 X, Y, SY, a, p, m: Integer;
2737 tw, th: Word;
2738 cw, ch: Byte;
2739 s: string;
2740 stat: TPlayerStatArray;
2741 begin
2742 X := gPlayerScreenSize.X;
2743 SY := gPlayerScreenSize.Y;
2744 Y := 0;
2746 if gShowGoals and (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
2747 begin
2748 if gGameSettings.GameMode = GM_CTF then
2749 a := 32 + 8
2750 else
2751 a := 0;
2752 if gGameSettings.GameMode = GM_CTF then
2753 begin
2754 s := 'TEXTURE_PLAYER_REDFLAG';
2755 if gFlags[FLAG_RED].State = FLAG_STATE_CAPTURED then
2756 s := 'TEXTURE_PLAYER_REDFLAG_S';
2757 if gFlags[FLAG_RED].State = FLAG_STATE_DROPPED then
2758 s := 'TEXTURE_PLAYER_REDFLAG_D';
2759 if g_Texture_Get(s, ID) then
2760 e_Draw(ID, X-16-32, 240-72-4, 0, True, False);
2761 end;
2763 s := IntToStr(gTeamStat[TEAM_RED].Goals);
2764 e_CharFont_GetSize(gMenuFont, s, tw, th);
2765 e_CharFont_PrintEx(gMenuFont, X-16-a-tw, 240-72-4, s, TEAMCOLOR[TEAM_RED]);
2767 if gGameSettings.GameMode = GM_CTF then
2768 begin
2769 s := 'TEXTURE_PLAYER_BLUEFLAG';
2770 if gFlags[FLAG_BLUE].State = FLAG_STATE_CAPTURED then
2771 s := 'TEXTURE_PLAYER_BLUEFLAG_S';
2772 if gFlags[FLAG_BLUE].State = FLAG_STATE_DROPPED then
2773 s := 'TEXTURE_PLAYER_BLUEFLAG_D';
2774 if g_Texture_Get(s, ID) then
2775 e_Draw(ID, X-16-32, 240-32-4, 0, True, False);
2776 end;
2778 s := IntToStr(gTeamStat[TEAM_BLUE].Goals);
2779 e_CharFont_GetSize(gMenuFont, s, tw, th);
2780 e_CharFont_PrintEx(gMenuFont, X-16-a-tw, 240-32-4, s, TEAMCOLOR[TEAM_BLUE]);
2781 end;
2783 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID) then
2784 e_DrawFill(ID, X, 0, 1, (gPlayerScreenSize.Y div 256)+IfThen(gPlayerScreenSize.Y mod 256 > 0, 1, 0),
2785 0, False, False);
2787 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID) then
2788 e_Draw(ID, X+2, Y, 0, True, False);
2790 if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
2791 begin
2792 if gShowStat then
2793 begin
2794 s := IntToStr(Frags);
2795 e_CharFont_GetSize(gMenuFont, s, tw, th);
2796 e_CharFont_PrintEx(gMenuFont, X-16-tw, Y, s, _RGB(255, 0, 0));
2798 s := '';
2799 p := 1;
2800 m := 0;
2801 stat := g_Player_GetStats();
2802 if stat <> nil then
2803 begin
2804 p := 1;
2806 for a := 0 to High(stat) do
2807 if stat[a].Name <> Name then
2808 begin
2809 if stat[a].Frags > m then m := stat[a].Frags;
2810 if stat[a].Frags > Frags then p := p+1;
2811 end;
2812 end;
2814 s := IntToStr(p)+' / '+IntToStr(Length(stat))+' ';
2815 if Frags >= m then s := s+'+' else s := s+'-';
2816 s := s+IntToStr(Abs(Frags-m));
2818 e_CharFont_GetSize(gMenuSmallFont, s, tw, th);
2819 e_CharFont_PrintEx(gMenuSmallFont, X-16-tw, Y+32, s, _RGB(255, 0, 0));
2820 end;
2822 if gLMSRespawn > LMS_RESPAWN_NONE then
2823 begin
2824 s := _lc[I_GAME_WARMUP];
2825 e_CharFont_GetSize(gMenuFont, s, tw, th);
2826 s := s + ': ' + IntToStr((gLMSRespawnTime - gTime) div 1000);
2827 e_CharFont_PrintEx(gMenuFont, X-64-tw, SY-32, s, _RGB(0, 255, 0));
2828 end
2829 else if gShowLives and (gGameSettings.MaxLives > 0) then
2830 begin
2831 s := IntToStr(Lives);
2832 e_CharFont_GetSize(gMenuFont, s, tw, th);
2833 e_CharFont_PrintEx(gMenuFont, X-16-tw, SY-32, s, _RGB(0, 255, 0));
2834 end;
2835 end;
2837 e_CharFont_GetSize(gMenuSmallFont, FName, tw, th);
2838 e_CharFont_PrintEx(gMenuSmallFont, X+98-(tw div 2), Y+8, FName, _RGB(255, 0, 0));
2840 if R_BERSERK in FRulez then
2841 e_Draw(gItemsTexturesID[ITEM_MEDKIT_BLACK], X+37, Y+45, 0, True, False)
2842 else
2843 e_Draw(gItemsTexturesID[ITEM_MEDKIT_LARGE], X+37, Y+45, 0, True, False);
2845 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID) then
2846 e_Draw(ID, X+36, Y+77, 0, True, False);
2848 s := IntToStr(IfThen(FHealth > 0, FHealth, 0));
2849 e_CharFont_GetSize(gMenuFont, s, tw, th);
2850 e_CharFont_PrintEx(gMenuFont, X+178-tw, Y+40, s, _RGB(255, 0, 0));
2852 s := IntToStr(FArmor);
2853 e_CharFont_GetSize(gMenuFont, s, tw, th);
2854 e_CharFont_PrintEx(gMenuFont, X+178-tw, Y+68, s, _RGB(255, 0, 0));
2856 s := IntToStr(GetAmmoByWeapon(FCurrWeap));
2858 case FCurrWeap of
2859 WEAPON_KASTET:
2860 begin
2861 s := '--';
2862 ID := gItemsTexturesID[ITEM_WEAPON_KASTET];
2863 end;
2864 WEAPON_SAW:
2865 begin
2866 s := '--';
2867 ID := gItemsTexturesID[ITEM_WEAPON_SAW];
2868 end;
2869 WEAPON_PISTOL: ID := gItemsTexturesID[ITEM_WEAPON_PISTOL];
2870 WEAPON_CHAINGUN: ID := gItemsTexturesID[ITEM_WEAPON_CHAINGUN];
2871 WEAPON_SHOTGUN1: ID := gItemsTexturesID[ITEM_WEAPON_SHOTGUN1];
2872 WEAPON_SHOTGUN2: ID := gItemsTexturesID[ITEM_WEAPON_SHOTGUN2];
2873 WEAPON_SUPERPULEMET: ID := gItemsTexturesID[ITEM_WEAPON_SUPERPULEMET];
2874 WEAPON_ROCKETLAUNCHER: ID := gItemsTexturesID[ITEM_WEAPON_ROCKETLAUNCHER];
2875 WEAPON_PLASMA: ID := gItemsTexturesID[ITEM_WEAPON_PLASMA];
2876 WEAPON_BFG: ID := gItemsTexturesID[ITEM_WEAPON_BFG];
2877 WEAPON_FLAMETHROWER: ID := gItemsTexturesID[ITEM_WEAPON_FLAMETHROWER];
2878 end;
2880 e_CharFont_GetSize(gMenuFont, s, tw, th);
2881 e_CharFont_PrintEx(gMenuFont, X+178-tw, Y+158, s, _RGB(255, 0, 0));
2882 e_Draw(ID, X+20, Y+160, 0, True, False);
2884 if R_KEY_RED in FRulez then
2885 e_Draw(gItemsTexturesID[ITEM_KEY_RED], X+78, Y+214, 0, True, False);
2887 if R_KEY_GREEN in FRulez then
2888 e_Draw(gItemsTexturesID[ITEM_KEY_GREEN], X+95, Y+214, 0, True, False);
2890 if R_KEY_BLUE in FRulez then
2891 e_Draw(gItemsTexturesID[ITEM_KEY_BLUE], X+112, Y+214, 0, True, False);
2893 if FJetFuel > 0 then
2894 begin
2895 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID) then
2896 e_Draw(ID, X+2, Y+116, 0, True, False);
2897 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID) then
2898 e_Draw(ID, X+2, Y+126, 0, True, False);
2899 e_DrawLine(4, X+16, Y+122, X+16+Trunc(168*IfThen(FAir > 0, FAir, 0)/AIR_MAX), Y+122, 0, 0, 196);
2900 e_DrawLine(4, X+16, Y+132, X+16+Trunc(168*FJetFuel/JET_MAX), Y+132, 208, 0, 0);
2901 end
2902 else
2903 begin
2904 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID) then
2905 e_Draw(ID, X+2, Y+124, 0, True, False);
2906 e_DrawLine(4, X+16, Y+130, X+16+Trunc(168*IfThen(FAir > 0, FAir, 0)/AIR_MAX), Y+130, 0, 0, 196);
2907 end;
2909 if gShowPing and g_Game_IsClient then
2910 begin
2911 s := _lc[I_GAME_PING_HUD] + IntToStr(NetPeer.lastRoundTripTime) + _lc[I_NET_SLIST_PING_MS];
2912 e_TextureFontPrint(X + 4, Y + 242, s, gStdFont);
2913 Y := Y + 16;
2914 end;
2916 if FSpectator then
2917 begin
2918 e_TextureFontPrint(X + 4, Y + 242, _lc[I_PLAYER_SPECT], gStdFont);
2919 e_TextureFontPrint(X + 4, Y + 258, _lc[I_PLAYER_SPECT2], gStdFont);
2920 e_TextureFontPrint(X + 4, Y + 274, _lc[I_PLAYER_SPECT1], gStdFont);
2921 if FNoRespawn then
2922 begin
2923 e_TextureFontGetSize(gStdFont, cw, ch);
2924 s := _lc[I_PLAYER_SPECT4];
2925 e_TextureFontPrintEx(gScreenWidth div 2 - cw*(Length(s) div 2),
2926 gScreenHeight-4-ch, s, gStdFont, 255, 255, 255, 1, True);
2927 e_TextureFontPrint(X + 4, Y + 290, _lc[I_PLAYER_SPECT1S], gStdFont);
2928 end;
2930 end;
2931 end;
2933 procedure TPlayer.DrawRulez();
2934 var
2935 dr: Boolean;
2936 begin
2937 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2938 if (FMegaRulez[MR_INVUL] >= gTime) and (FSpawnInvul < gTime) then
2939 begin
2940 if (FMegaRulez[MR_INVUL]-gTime) <= 2100 then
2941 dr := not Odd((FMegaRulez[MR_INVUL]-gTime) div 300)
2942 else
2943 dr := True;
2945 if dr then
2946 e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1,
2947 191, 191, 191, 0, TBlending.Invert);
2948 end;
2950 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2951 if FMegaRulez[MR_SUIT] >= gTime then
2952 begin
2953 if (FMegaRulez[MR_SUIT]-gTime) <= 2100 then
2954 dr := not Odd((FMegaRulez[MR_SUIT]-gTime) div 300)
2955 else
2956 dr := True;
2958 if dr then
2959 e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1,
2960 0, 96, 0, 200, TBlending.None);
2961 end;
2963 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2964 if (FBerserk >= 0) and (LongWord(FBerserk) >= gTime) and (gFlash = 2) then
2965 begin
2966 e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1,
2967 255, 0, 0, 200, TBlending.None);
2968 end;
2969 end;
2971 procedure TPlayer.DrawPain();
2972 var
2973 a, h: Integer;
2974 begin
2975 if FPain = 0 then Exit;
2977 a := FPain;
2979 if a < 15 then h := 0
2980 else if a < 35 then h := 1
2981 else if a < 55 then h := 2
2982 else if a < 75 then h := 3
2983 else if a < 95 then h := 4
2984 else h := 5;
2986 //if a > 255 then a := 255;
2988 e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255, 0, 0, 255-h*50);
2989 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2990 end;
2992 procedure TPlayer.DrawPickup();
2993 var
2994 a, h: Integer;
2995 begin
2996 if FPickup = 0 then Exit;
2998 a := FPickup;
3000 if a < 15 then h := 1
3001 else if a < 35 then h := 2
3002 else if a < 55 then h := 3
3003 else if a < 75 then h := 4
3004 else h := 5;
3006 e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 150, 200, 150, 255-h*50);
3007 end;
3009 procedure TPlayer.DoPunch();
3010 var
3011 id: DWORD;
3012 st: String;
3013 begin
3014 if FPunchAnim <> nil then begin
3015 FPunchAnim.reset();
3016 FPunchAnim.Free;
3017 FPunchAnim := nil;
3018 end;
3019 st := 'FRAMES_PUNCH';
3020 if R_BERSERK in FRulez then
3021 st := st + '_BERSERK';
3022 if FKeys[KEY_UP].Pressed then
3023 st := st + '_UP'
3024 else if FKeys[KEY_DOWN].Pressed then
3025 st := st + '_DN';
3026 g_Frames_Get(id, st);
3027 FPunchAnim := TAnimation.Create(id, False, 1);
3028 end;
3030 procedure TPlayer.Fire();
3031 var
3032 f, DidFire: Boolean;
3033 wx, wy, xd, yd: Integer;
3034 locobj: TObj;
3035 begin
3036 if g_Game_IsClient then Exit;
3037 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
3038 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
3040 if FSpectator then
3041 begin
3042 Respawn(False);
3043 Exit;
3044 end;
3046 if FReloading[FCurrWeap] <> 0 then Exit;
3048 DidFire := False;
3050 f := False;
3051 wx := FObj.X+WEAPONPOINT[FDirection].X;
3052 wy := FObj.Y+WEAPONPOINT[FDirection].Y;
3053 xd := wx+IfThen(FDirection = TDirection.D_LEFT, -30, 30);
3054 yd := wy+firediry();
3056 case FCurrWeap of
3057 WEAPON_KASTET:
3058 begin
3059 DoPunch();
3060 if R_BERSERK in FRulez then
3061 begin
3062 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
3063 locobj.X := FObj.X+FObj.Rect.X;
3064 locobj.Y := FObj.Y+FObj.Rect.Y;
3065 locobj.rect.X := 0;
3066 locobj.rect.Y := 0;
3067 locobj.rect.Width := 39;
3068 locobj.rect.Height := 52;
3069 locobj.Vel.X := (xd-wx) div 2;
3070 locobj.Vel.Y := (yd-wy) div 2;
3071 locobj.Accel.X := xd-wx;
3072 locobj.Accel.y := yd-wy;
3074 if g_Weapon_Hit(@locobj, 50, FUID, HIT_SOME) <> 0 then
3075 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj.X, FObj.Y)
3076 else
3077 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj.X, FObj.Y);
3079 if (gFlash = 1) and (FPain < 50) then FPain := min(FPain + 25, 50);
3080 end
3081 else
3082 begin
3083 g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 3, FUID);
3084 end;
3086 DidFire := True;
3087 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3088 end;
3090 WEAPON_SAW:
3091 begin
3092 if g_Weapon_chainsaw(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y,
3093 IfThen(gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF], 9, 3), FUID) <> 0 then
3094 begin
3095 FSawSoundSelect.Stop();
3096 FSawSound.Stop();
3097 FSawSoundHit.PlayAt(FObj.X, FObj.Y);
3098 end
3099 else if not FSawSoundHit.IsPlaying() then
3100 begin
3101 FSawSoundSelect.Stop();
3102 FSawSound.PlayAt(FObj.X, FObj.Y);
3103 end;
3105 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3106 DidFire := True;
3107 f := True;
3108 end;
3110 WEAPON_PISTOL:
3111 if FAmmo[A_BULLETS] > 0 then
3112 begin
3113 g_Weapon_pistol(wx, wy, xd, yd, FUID);
3114 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3115 Dec(FAmmo[A_BULLETS]);
3116 FFireAngle := FAngle;
3117 f := True;
3118 DidFire := True;
3119 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
3120 GameVelX, GameVelY-2, SHELL_BULLET);
3121 end;
3123 WEAPON_SHOTGUN1:
3124 if FAmmo[A_SHELLS] > 0 then
3125 begin
3126 g_Weapon_shotgun(wx, wy, xd, yd, FUID);
3127 if not gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx, wy);
3128 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3129 Dec(FAmmo[A_SHELLS]);
3130 FFireAngle := FAngle;
3131 f := True;
3132 DidFire := True;
3133 FShellTimer := 10;
3134 FShellType := SHELL_SHELL;
3135 end;
3137 WEAPON_SHOTGUN2:
3138 if FAmmo[A_SHELLS] >= 2 then
3139 begin
3140 g_Weapon_dshotgun(wx, wy, xd, yd, FUID);
3141 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3142 Dec(FAmmo[A_SHELLS], 2);
3143 FFireAngle := FAngle;
3144 f := True;
3145 DidFire := True;
3146 FShellTimer := 13;
3147 FShellType := SHELL_DBLSHELL;
3148 end;
3150 WEAPON_CHAINGUN:
3151 if FAmmo[A_BULLETS] > 0 then
3152 begin
3153 g_Weapon_mgun(wx, wy, xd, yd, FUID);
3154 if not gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx, wy);
3155 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3156 Dec(FAmmo[A_BULLETS]);
3157 FFireAngle := FAngle;
3158 f := True;
3159 DidFire := True;
3160 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
3161 GameVelX, GameVelY-2, SHELL_BULLET);
3162 end;
3164 WEAPON_ROCKETLAUNCHER:
3165 if FAmmo[A_ROCKETS] > 0 then
3166 begin
3167 g_Weapon_rocket(wx, wy, xd, yd, FUID);
3168 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3169 Dec(FAmmo[A_ROCKETS]);
3170 FFireAngle := FAngle;
3171 f := True;
3172 DidFire := True;
3173 end;
3175 WEAPON_PLASMA:
3176 if FAmmo[A_CELLS] > 0 then
3177 begin
3178 g_Weapon_plasma(wx, wy, xd, yd, FUID);
3179 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3180 Dec(FAmmo[A_CELLS]);
3181 FFireAngle := FAngle;
3182 f := True;
3183 DidFire := True;
3184 end;
3186 WEAPON_BFG:
3187 if (FAmmo[A_CELLS] >= 40) and (FBFGFireCounter = -1) then
3188 begin
3189 FBFGFireCounter := 17;
3190 if not FNoReload then
3191 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj.X, FObj.Y);
3192 Dec(FAmmo[A_CELLS], 40);
3193 DidFire := True;
3194 end;
3196 WEAPON_SUPERPULEMET:
3197 if FAmmo[A_SHELLS] > 0 then
3198 begin
3199 g_Weapon_shotgun(wx, wy, xd, yd, FUID);
3200 if not gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx, wy);
3201 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3202 Dec(FAmmo[A_SHELLS]);
3203 FFireAngle := FAngle;
3204 f := True;
3205 DidFire := True;
3206 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
3207 GameVelX, GameVelY-2, SHELL_SHELL);
3208 end;
3210 WEAPON_FLAMETHROWER:
3211 if FAmmo[A_FUEL] > 0 then
3212 begin
3213 g_Weapon_flame(wx, wy, xd, yd, FUID);
3214 FlamerOn;
3215 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3216 Dec(FAmmo[A_FUEL]);
3217 FFireAngle := FAngle;
3218 f := True;
3219 DidFire := True;
3220 end
3221 else
3222 begin
3223 FlamerOff;
3224 if g_Game_IsNet and g_Game_IsServer then MH_SEND_PlayerStats(FUID);
3225 end;
3226 end;
3228 if g_Game_IsNet then
3229 begin
3230 if DidFire then
3231 begin
3232 if FCurrWeap <> WEAPON_BFG then
3233 MH_SEND_PlayerFire(FUID, FCurrWeap, wx, wy, xd, yd, LastShotID)
3234 else
3235 if not FNoReload then
3236 MH_SEND_Sound(FObj.X, FObj.Y, 'SOUND_WEAPON_STARTFIREBFG');
3237 end;
3239 MH_SEND_PlayerStats(FUID);
3240 end;
3242 if not f then Exit;
3244 if (FAngle = 0) or (FAngle = 180) then SetAction(A_ATTACK)
3245 else if (FAngle = ANGLE_LEFTDOWN) or (FAngle = ANGLE_RIGHTDOWN) then SetAction(A_ATTACKDOWN)
3246 else if (FAngle = ANGLE_LEFTUP) or (FAngle = ANGLE_RIGHTUP) then SetAction(A_ATTACKUP);
3247 end;
3249 function TPlayer.GetAmmoByWeapon(Weapon: Byte): Word;
3250 begin
3251 case Weapon of
3252 WEAPON_PISTOL, WEAPON_CHAINGUN: Result := FAmmo[A_BULLETS];
3253 WEAPON_SHOTGUN1, WEAPON_SHOTGUN2, WEAPON_SUPERPULEMET: Result := FAmmo[A_SHELLS];
3254 WEAPON_ROCKETLAUNCHER: Result := FAmmo[A_ROCKETS];
3255 WEAPON_PLASMA, WEAPON_BFG: Result := FAmmo[A_CELLS];
3256 WEAPON_FLAMETHROWER: Result := FAmmo[A_FUEL];
3257 else Result := 0;
3258 end;
3259 end;
3261 function TPlayer.HeadInLiquid(XInc, YInc: Integer): Boolean;
3262 begin
3263 Result := g_Map_CollidePanel(FObj.X+PLAYER_HEADRECT.X+XInc, FObj.Y+PLAYER_HEADRECT.Y+YInc,
3264 PLAYER_HEADRECT.Width, PLAYER_HEADRECT.Height,
3265 PANEL_WATER or PANEL_ACID1 or PANEL_ACID2, True);
3266 end;
3268 procedure TPlayer.FlamerOn;
3269 begin
3270 FFlameSoundOff.Stop();
3271 FFlameSoundOff.SetPosition(0);
3272 if FFlaming then
3273 begin
3274 if (not FFlameSoundOn.IsPlaying()) and (not FFlameSoundWork.IsPlaying()) then
3275 FFlameSoundWork.PlayAt(FObj.X, FObj.Y);
3276 end
3277 else
3278 begin
3279 FFlameSoundOn.PlayAt(FObj.X, FObj.Y);
3280 FFlaming := True;
3281 end;
3282 end;
3284 procedure TPlayer.FlamerOff;
3285 begin
3286 if FFlaming then
3287 begin
3288 FFlameSoundOn.Stop();
3289 FFlameSoundOn.SetPosition(0);
3290 FFlameSoundWork.Stop();
3291 FFlameSoundWork.SetPosition(0);
3292 FFlameSoundOff.PlayAt(FObj.X, FObj.Y);
3293 FFlaming := False;
3294 end;
3295 end;
3297 procedure TPlayer.JetpackOn;
3298 begin
3299 FJetSoundFly.Stop;
3300 FJetSoundOff.Stop;
3301 FJetSoundOn.SetPosition(0);
3302 FJetSoundOn.PlayAt(FObj.X, FObj.Y);
3303 FlySmoke(8);
3304 end;
3306 procedure TPlayer.JetpackOff;
3307 begin
3308 FJetSoundFly.Stop;
3309 FJetSoundOn.Stop;
3310 FJetSoundOff.SetPosition(0);
3311 FJetSoundOff.PlayAt(FObj.X, FObj.Y);
3312 end;
3314 procedure TPlayer.CatchFire(Attacker: Word; Timeout: Integer = PLAYER_BURN_TIME);
3315 begin
3316 if Timeout <= 0 then
3317 exit;
3318 if (FMegaRulez[MR_SUIT] > gTime) or (FMegaRulez[MR_INVUL] > gTime) then
3319 exit; // Íå çàãîðàåìñÿ êîãäà åñòü çàùèòà
3320 if g_Obj_CollidePanel(@FObj, 0, 0, PANEL_WATER or PANEL_ACID1 or PANEL_ACID2) then
3321 exit; // Íå ïîäãîðàåì â âîäå íà âñÿêèé ñëó÷àé
3322 if FFireTime <= 0 then
3323 g_Sound_PlayExAt('SOUND_IGNITE', FObj.X, FObj.Y);
3324 FFireTime := Timeout;
3325 FFireAttacker := Attacker;
3326 if g_Game_IsNet and g_Game_IsServer then
3327 MH_SEND_PlayerStats(FUID);
3328 end;
3330 procedure TPlayer.Jump();
3331 begin
3332 if gFly or FJetpack then
3333 begin
3334 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
3335 if FObj.Vel.Y > -VEL_FLY then
3336 FObj.Vel.Y := FObj.Vel.Y - 3;
3337 if FJetpack then
3338 begin
3339 if FJetFuel > 0 then
3340 Dec(FJetFuel);
3341 if (FJetFuel < 1) and g_Game_IsServer then
3342 begin
3343 FJetpack := False;
3344 JetpackOff;
3345 if g_Game_IsNet then
3346 MH_SEND_PlayerStats(FUID);
3347 end;
3348 end;
3349 Exit;
3350 end;
3352 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
3353 if FGhost then
3354 FCanJetpack := False;
3356 // Ïðûãàåì èëè âñïëûâàåì:
3357 if (CollideLevel(0, 1) or
3358 g_Map_CollidePanel(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y+36, PLAYER_RECT.Width,
3359 PLAYER_RECT.Height-33, PANEL_STEP, False)
3360 ) and (FObj.Accel.Y = 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
3361 begin
3362 FObj.Vel.Y := -VEL_JUMP;
3363 FCanJetpack := False;
3364 end
3365 else
3366 begin
3367 if BodyInLiquid(0, 0) then
3368 FObj.Vel.Y := -VEL_SW
3369 else if (FJetFuel > 0) and FCanJetpack and
3370 g_Game_IsServer and (not g_Obj_CollideLiquid(@FObj, 0, 0)) then
3371 begin
3372 FJetpack := True;
3373 JetpackOn;
3374 if g_Game_IsNet then
3375 MH_SEND_PlayerStats(FUID);
3376 end;
3377 end;
3378 end;
3380 procedure TPlayer.Kill(KillType: Byte; SpawnerUID: Word; t: Byte);
3381 var
3382 a, i, k, ab, ar: Byte;
3383 s: String;
3384 mon: TMonster;
3385 plr: TPlayer;
3386 srv, netsrv: Boolean;
3387 DoFrags: Boolean;
3388 OldLR: Byte;
3389 KP: TPlayer;
3390 it: PItem;
3392 procedure PushItem(t: Byte);
3393 var
3394 id: DWORD;
3395 begin
3396 id := g_Items_Create(FObj.X, FObj.Y, t, True, False);
3397 it := g_Items_ByIdx(id);
3398 if KillType = K_EXTRAHARDKILL then // -7..+7; -8..0
3399 begin
3400 g_Obj_Push(@it.Obj, (FObj.Vel.X div 2)-7+Random(15),
3401 (FObj.Vel.Y div 2)-Random(9));
3402 it.positionChanged(); // this updates spatial accelerators
3403 end
3404 else
3405 begin
3406 if KillType = K_HARDKILL then // -5..+5; -5..0
3407 begin
3408 g_Obj_Push(@it.Obj, (FObj.Vel.X div 2)-5+Random(11),
3409 (FObj.Vel.Y div 2)-Random(6));
3410 end
3411 else // -3..+3; -3..0
3412 begin
3413 g_Obj_Push(@it.Obj, (FObj.Vel.X div 2)-3+Random(7),
3414 (FObj.Vel.Y div 2)-Random(4));
3415 end;
3416 it.positionChanged(); // this updates spatial accelerators
3417 end;
3419 if g_Game_IsNet and g_Game_IsServer then
3420 MH_SEND_ItemSpawn(True, id);
3421 end;
3423 begin
3424 DoFrags := (gGameSettings.MaxLives = 0) or (gGameSettings.GameMode = GM_COOP);
3425 Srv := g_Game_IsServer;
3426 Netsrv := g_Game_IsServer and g_Game_IsNet;
3427 if Srv then FDeath := FDeath + 1;
3428 if FAlive then
3429 begin
3430 if FGhost then
3431 FGhost := False;
3432 if not FPhysics then
3433 FPhysics := True;
3434 FAlive := False;
3435 end;
3436 FShellTimer := -1;
3438 if (gGameSettings.MaxLives > 0) and Srv and (gLMSRespawn = LMS_RESPAWN_NONE) then
3439 begin
3440 if FLives > 0 then FLives := FLives - 1;
3441 if FLives = 0 then FNoRespawn := True;
3442 end;
3444 // Íîìåð òèïà ñìåðòè:
3445 a := 1;
3446 case KillType of
3447 K_SIMPLEKILL: a := 1;
3448 K_HARDKILL: a := 2;
3449 K_EXTRAHARDKILL: a := 3;
3450 K_FALLKILL: a := 4;
3451 end;
3453 // Çâóê ñìåðòè:
3454 if not FModel.PlaySound(MODELSOUND_DIE, a, FObj.X, FObj.Y) then
3455 for i := 1 to 3 do
3456 if FModel.PlaySound(MODELSOUND_DIE, i, FObj.X, FObj.Y) then
3457 Break;
3459 // Âðåìÿ ðåñïàóíà:
3460 if Srv then
3461 case KillType of
3462 K_SIMPLEKILL:
3463 FTime[T_RESPAWN] := gTime + TIME_RESPAWN1;
3464 K_HARDKILL:
3465 FTime[T_RESPAWN] := gTime + TIME_RESPAWN2;
3466 K_EXTRAHARDKILL, K_FALLKILL:
3467 FTime[T_RESPAWN] := gTime + TIME_RESPAWN3;
3468 end;
3470 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3471 case KillType of
3472 K_SIMPLEKILL:
3473 SetAction(A_DIE1);
3474 K_HARDKILL, K_EXTRAHARDKILL:
3475 SetAction(A_DIE2);
3476 end;
3478 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3479 if (KillType <> K_FALLKILL) and (Srv) then
3480 g_Monsters_killedp();
3482 if SpawnerUID = FUID then
3483 begin // Ñàìîóáèëñÿ
3484 if Srv then
3485 begin
3486 if gGameSettings.GameMode = GM_TDM then
3487 Dec(gTeamStat[FTeam].Goals);
3488 if DoFrags or (gGameSettings.GameMode = GM_TDM) then
3489 begin
3490 Dec(FFrags);
3491 FLastFrag := 0;
3492 end;
3493 end;
3494 g_Console_Add(Format(_lc[I_PLAYER_KILL_SELF], [FName]), True);
3495 end
3496 else
3497 if g_GetUIDType(SpawnerUID) = UID_PLAYER then
3498 begin // Óáèò äðóãèì èãðîêîì
3499 KP := g_Player_Get(SpawnerUID);
3500 if (KP <> nil) and Srv then
3501 begin
3502 if (DoFrags or (gGameSettings.GameMode = GM_TDM)) then
3503 if SameTeam(FUID, SpawnerUID) then
3504 begin
3505 Dec(KP.FFrags);
3506 KP.FLastFrag := 0;
3507 end else
3508 begin
3509 Inc(KP.FFrags);
3510 KP.FragCombo();
3511 end;
3513 if (gGameSettings.GameMode = GM_TDM) and DoFrags then
3514 Inc(gTeamStat[KP.Team].Goals,
3515 IfThen(SameTeam(FUID, SpawnerUID), -1, 1));
3517 if netsrv then MH_SEND_PlayerStats(SpawnerUID);
3518 end;
3520 plr := g_Player_Get(SpawnerUID);
3521 if plr = nil then
3522 s := '?'
3523 else
3524 s := plr.FName;
3526 case KillType of
3527 K_HARDKILL:
3528 g_Console_Add(Format(_lc[I_PLAYER_KILL_EXTRAHARD_2],
3529 [FName, s]),
3530 gShowKillMsg);
3531 K_EXTRAHARDKILL:
3532 g_Console_Add(Format(_lc[I_PLAYER_KILL_EXTRAHARD_1],
3533 [FName, s]),
3534 gShowKillMsg);
3535 else
3536 g_Console_Add(Format(_lc[I_PLAYER_KILL],
3537 [FName, s]),
3538 gShowKillMsg);
3539 end;
3540 end
3541 else if g_GetUIDType(SpawnerUID) = UID_MONSTER then
3542 begin // Óáèò ìîíñòðîì
3543 mon := g_Monsters_ByUID(SpawnerUID);
3544 if mon = nil then
3545 s := '?'
3546 else
3547 s := g_Mons_GetKilledByTypeId(mon.MonsterType);
3549 case KillType of
3550 K_HARDKILL:
3551 g_Console_Add(Format(_lc[I_PLAYER_KILL_EXTRAHARD_2],
3552 [FName, s]),
3553 gShowKillMsg);
3554 K_EXTRAHARDKILL:
3555 g_Console_Add(Format(_lc[I_PLAYER_KILL_EXTRAHARD_1],
3556 [FName, s]),
3557 gShowKillMsg);
3558 else
3559 g_Console_Add(Format(_lc[I_PLAYER_KILL],
3560 [FName, s]),
3561 gShowKillMsg);
3562 end;
3563 end
3564 else // Îñîáûå òèïû ñìåðòè
3565 case t of
3566 HIT_DISCON: ;
3567 HIT_SELF: g_Console_Add(Format(_lc[I_PLAYER_KILL_SELF], [FName]), True);
3568 HIT_FALL: g_Console_Add(Format(_lc[I_PLAYER_KILL_FALL], [FName]), True);
3569 HIT_WATER: g_Console_Add(Format(_lc[I_PLAYER_KILL_WATER], [FName]), True);
3570 HIT_ACID: g_Console_Add(Format(_lc[I_PLAYER_KILL_ACID], [FName]), True);
3571 HIT_TRAP: g_Console_Add(Format(_lc[I_PLAYER_KILL_TRAP], [FName]), True);
3572 else g_Console_Add(Format(_lc[I_PLAYER_DIED], [FName]), True);
3573 end;
3575 if Srv then
3576 begin
3577 // Âûáðîñ îðóæèÿ:
3578 for a := WP_FIRST to WP_LAST do
3579 if FWeapon[a] then
3580 begin
3581 case a of
3582 WEAPON_SAW: i := ITEM_WEAPON_SAW;
3583 WEAPON_SHOTGUN1: i := ITEM_WEAPON_SHOTGUN1;
3584 WEAPON_SHOTGUN2: i := ITEM_WEAPON_SHOTGUN2;
3585 WEAPON_CHAINGUN: i := ITEM_WEAPON_CHAINGUN;
3586 WEAPON_ROCKETLAUNCHER: i := ITEM_WEAPON_ROCKETLAUNCHER;
3587 WEAPON_PLASMA: i := ITEM_WEAPON_PLASMA;
3588 WEAPON_BFG: i := ITEM_WEAPON_BFG;
3589 WEAPON_SUPERPULEMET: i := ITEM_WEAPON_SUPERPULEMET;
3590 WEAPON_FLAMETHROWER: i := ITEM_WEAPON_FLAMETHROWER;
3591 else i := 0;
3592 end;
3594 if i <> 0 then
3595 PushItem(i);
3596 end;
3598 // Âûáðîñ ðþêçàêà:
3599 if R_ITEM_BACKPACK in FRulez then
3600 PushItem(ITEM_AMMO_BACKPACK);
3602 // Âûáðîñ ðàêåòíîãî ðàíöà:
3603 if FJetFuel > 0 then
3604 PushItem(ITEM_JETPACK);
3606 // Âûáðîñ êëþ÷åé:
3607 if (not (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF])) or
3608 (not LongBool(gGameSettings.Options and GAME_OPTION_DMKEYS)) then
3609 begin
3610 if R_KEY_RED in FRulez then
3611 PushItem(ITEM_KEY_RED);
3613 if R_KEY_GREEN in FRulez then
3614 PushItem(ITEM_KEY_GREEN);
3616 if R_KEY_BLUE in FRulez then
3617 PushItem(ITEM_KEY_BLUE);
3618 end;
3620 // Âûáðîñ ôëàãà:
3621 DropFlag(KillType = K_FALLKILL);
3622 end;
3624 FCorpse := g_Player_CreateCorpse(Self);
3626 if Srv and (gGameSettings.MaxLives > 0) and FNoRespawn and
3627 (gLMSRespawn = LMS_RESPAWN_NONE) then
3628 begin
3629 a := 0;
3630 k := 0;
3631 ar := 0;
3632 ab := 0;
3633 for i := Low(gPlayers) to High(gPlayers) do
3634 begin
3635 if gPlayers[i] = nil then continue;
3636 if (not gPlayers[i].FNoRespawn) and (not gPlayers[i].FSpectator) then
3637 begin
3638 Inc(a);
3639 if gPlayers[i].FTeam = TEAM_RED then Inc(ar)
3640 else if gPlayers[i].FTeam = TEAM_BLUE then Inc(ab);
3641 k := i;
3642 end;
3643 end;
3645 OldLR := gLMSRespawn;
3646 if (gGameSettings.GameMode = GM_COOP) then
3647 begin
3648 if (a = 0) then
3649 begin
3650 // everyone is dead, restart the map
3651 g_Game_Message(_lc[I_MESSAGE_LMS_LOSE], 144);
3652 if Netsrv then
3653 MH_SEND_GameEvent(NET_EV_LMS_LOSE);
3654 gLMSRespawn := LMS_RESPAWN_FINAL;
3655 gLMSRespawnTime := gTime + 5000;
3656 end
3657 else if (a = 1) then
3658 begin
3659 if (gPlayers[k] <> nil) and not (gPlayers[k] is TBot) then
3660 if (gPlayers[k] = gPlayer1) or
3661 (gPlayers[k] = gPlayer2) then
3662 g_Console_Add('*** ' + _lc[I_MESSAGE_LMS_SURVIVOR] + ' ***', True)
3663 else if Netsrv and (gPlayers[k].FClientID >= 0) then
3664 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR, 0, 'N', gPlayers[k].FClientID);
3665 end;
3666 end
3667 else if (gGameSettings.GameMode = GM_TDM) then
3668 begin
3669 if (ab = 0) and (ar <> 0) then
3670 begin
3671 // blu team ded
3672 g_Game_Message(Format(_lc[I_MESSAGE_TLMS_WIN], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 144);
3673 if Netsrv then
3674 MH_SEND_GameEvent(NET_EV_TLMS_WIN, TEAM_RED);
3675 Inc(gTeamStat[TEAM_RED].Goals);
3676 gLMSRespawn := LMS_RESPAWN_FINAL;
3677 gLMSRespawnTime := gTime + 5000;
3678 end
3679 else if (ar = 0) and (ab <> 0) then
3680 begin
3681 // red team ded
3682 g_Game_Message(Format(_lc[I_MESSAGE_TLMS_WIN], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 144);
3683 if Netsrv then
3684 MH_SEND_GameEvent(NET_EV_TLMS_WIN, TEAM_BLUE);
3685 Inc(gTeamStat[TEAM_BLUE].Goals);
3686 gLMSRespawn := LMS_RESPAWN_FINAL;
3687 gLMSRespawnTime := gTime + 5000;
3688 end
3689 else if (ar = 0) and (ab = 0) then
3690 begin
3691 // everyone ded
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 else if (gGameSettings.GameMode = GM_DM) then
3700 begin
3701 if (a = 1) then
3702 begin
3703 if gPlayers[k] <> nil then
3704 with gPlayers[k] do
3705 begin
3706 // survivor is the winner
3707 g_Game_Message(Format(_lc[I_MESSAGE_LMS_WIN], [AnsiUpperCase(FName)]), 144);
3708 if Netsrv then
3709 MH_SEND_GameEvent(NET_EV_LMS_WIN, 0, FName);
3710 Inc(FFrags);
3711 end;
3712 gLMSRespawn := LMS_RESPAWN_FINAL;
3713 gLMSRespawnTime := gTime + 5000;
3714 end
3715 else if (a = 0) then
3716 begin
3717 // everyone is dead, restart the map
3718 g_Game_Message(_lc[I_GAME_WIN_DRAW], 144);
3719 if Netsrv then
3720 MH_SEND_GameEvent(NET_EV_LMS_DRAW, 0, FName);
3721 gLMSRespawn := LMS_RESPAWN_FINAL;
3722 gLMSRespawnTime := gTime + 5000;
3723 end;
3724 end;
3725 if srv and (OldLR = LMS_RESPAWN_NONE) and (gLMSRespawn > LMS_RESPAWN_NONE) then
3726 begin
3727 if NetMode = NET_SERVER then
3728 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, gLMSRespawnTime - gTime)
3729 else
3730 g_Console_Add(Format(_lc[I_MSG_WARMUP_START], [(gLMSRespawnTime - gTime) div 1000]), True);
3731 end;
3732 end;
3734 if Netsrv then
3735 begin
3736 MH_SEND_PlayerStats(FUID);
3737 MH_SEND_PlayerDeath(FUID, KillType, t, SpawnerUID);
3738 if gGameSettings.GameMode = GM_TDM then MH_SEND_GameStats;
3739 end;
3741 if srv and FNoRespawn then Spectate(True);
3742 FWantsInGame := True;
3743 end;
3745 function TPlayer.BodyInLiquid(XInc, YInc: Integer): Boolean;
3746 begin
3747 Result := g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc, PLAYER_RECT.Width,
3748 PLAYER_RECT.Height-20, PANEL_WATER or PANEL_ACID1 or PANEL_ACID2, False);
3749 end;
3751 function TPlayer.BodyInAcid(XInc, YInc: Integer): Boolean;
3752 begin
3753 Result := g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc, PLAYER_RECT.Width,
3754 PLAYER_RECT.Height-20, PANEL_ACID1 or PANEL_ACID2, False);
3755 end;
3757 procedure TPlayer.MakeBloodSimple(Count: Word);
3758 begin
3759 g_GFX_Blood(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)+8,
3760 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2),
3761 Count div 2, 3, -1, 16, (PLAYER_RECT.Height*2 div 3),
3762 FModel.Blood.R, FModel.Blood.G, FModel.Blood.B, FModel.Blood.Kind);
3763 g_GFX_Blood(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-8,
3764 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2),
3765 Count div 2, -3, -1, 16, (PLAYER_RECT.Height*2) div 3,
3766 FModel.Blood.R, FModel.Blood.G, FModel.Blood.B, FModel.Blood.Kind);
3767 end;
3769 procedure TPlayer.MakeBloodVector(Count: Word; VelX, VelY: Integer);
3770 begin
3771 g_GFX_Blood(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2),
3772 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2),
3773 Count, VelX, VelY, 16, (PLAYER_RECT.Height*2) div 3,
3774 FModel.Blood.R, FModel.Blood.G, FModel.Blood.B, FModel.Blood.Kind);
3775 end;
3777 procedure TPlayer.ProcessWeaponAction(Action: Byte);
3778 begin
3779 if g_Game_IsClient then Exit;
3780 case Action of
3781 WP_PREV: PrevWeapon();
3782 WP_NEXT: NextWeapon();
3783 end;
3784 end;
3786 procedure TPlayer.QueueWeaponSwitch(Weapon: Byte);
3787 begin
3788 if g_Game_IsClient then Exit;
3789 if Weapon > High(FWeapon) then Exit;
3790 FNextWeap := FNextWeap or (1 shl Weapon);
3791 end;
3793 procedure TPlayer.resetWeaponQueue ();
3794 begin
3795 FNextWeap := 0;
3796 FNextWeapDelay := 0;
3797 end;
3799 function TPlayer.hasAmmoForWeapon (weapon: Byte): Boolean;
3800 begin
3801 result := false;
3802 case weapon of
3803 WEAPON_KASTET, WEAPON_SAW: result := true;
3804 WEAPON_SHOTGUN1, WEAPON_SHOTGUN2, WEAPON_SUPERPULEMET: result := (FAmmo[A_SHELLS] > 0);
3805 WEAPON_PISTOL, WEAPON_CHAINGUN: result := (FAmmo[A_BULLETS] > 0);
3806 WEAPON_ROCKETLAUNCHER: result := (FAmmo[A_ROCKETS] > 0);
3807 WEAPON_PLASMA, WEAPON_BFG: result := (FAmmo[A_CELLS] > 0);
3808 WEAPON_FLAMETHROWER: result := (FAmmo[A_FUEL] > 0);
3809 else result := (weapon < length(FWeapon));
3810 end;
3811 end;
3813 function TPlayer.hasAmmoForShooting (weapon: Byte): Boolean;
3814 begin
3815 result := false;
3816 case weapon of
3817 WEAPON_KASTET, WEAPON_SAW: result := true;
3818 WEAPON_SHOTGUN1, WEAPON_SUPERPULEMET: result := (FAmmo[A_SHELLS] > 0);
3819 WEAPON_SHOTGUN2: result := (FAmmo[A_SHELLS] > 1);
3820 WEAPON_PISTOL, WEAPON_CHAINGUN: result := (FAmmo[A_BULLETS] > 0);
3821 WEAPON_ROCKETLAUNCHER: result := (FAmmo[A_ROCKETS] > 0);
3822 WEAPON_PLASMA: result := (FAmmo[A_CELLS] > 0);
3823 WEAPON_BFG: result := (FAmmo[A_CELLS] >= 40);
3824 WEAPON_FLAMETHROWER: result := (FAmmo[A_FUEL] > 0);
3825 else result := (weapon < length(FWeapon));
3826 end;
3827 end;
3829 function TPlayer.shouldSwitch (weapon: Byte; hadWeapon: Boolean): Boolean;
3830 begin
3831 result := false;
3832 if (weapon > WP_LAST + 1) then
3833 begin
3834 result := false;
3835 exit;
3836 end;
3837 if (FWeapSwitchMode = 1) and not hadWeapon then
3838 result := true
3839 else if (FWeapSwitchMode = 2) then
3840 result := (FWeapPreferences[weapon] > FWeapPreferences[FCurrWeap]);
3841 end;
3843 // return 255 for "no switch"
3844 function TPlayer.getNextWeaponIndex (): Byte;
3845 var
3846 i: Word;
3847 wantThisWeapon: array[0..64] of Boolean;
3848 wwc: Integer = 0; //HACK!
3849 dir, cwi: Integer;
3850 begin
3851 result := 255; // default result: "no switch"
3852 //e_LogWriteFln('FSWITCHTOEMPTY: %s', [FSwitchToEmpty], TMsgType.Notify);
3853 // had weapon cycling on previous frame? remove that flag
3854 if (FNextWeap and $2000) <> 0 then
3855 begin
3856 FNextWeap := FNextWeap and $1FFF;
3857 FNextWeapDelay := 0;
3858 end;
3859 // cycling has priority
3860 if (FNextWeap and $C000) <> 0 then
3861 begin
3862 if (FNextWeap and $8000) <> 0 then
3863 dir := 1
3864 else
3865 dir := -1;
3866 FNextWeap := FNextWeap or $2000; // we need this
3867 if FNextWeapDelay > 0 then
3868 exit; // cooldown time
3869 cwi := FCurrWeap;
3870 for i := 0 to High(FWeapon) do
3871 begin
3872 cwi := (cwi+length(FWeapon)+dir) mod length(FWeapon);
3873 if FWeapon[cwi] and maySwitch(cwi) then
3874 begin
3875 //e_LogWriteFln(' SWITCH: cur=%d; new=%d %s %s', [FCurrWeap, cwi, FSwitchToEmpty, hasAmmoForWeapon(cwi)], TMsgType.Notify);
3876 result := Byte(cwi);
3877 FNextWeapDelay := WEAPON_DELAY;
3878 exit;
3879 end;
3880 end;
3881 resetWeaponQueue();
3882 exit;
3883 end;
3884 // no cycling
3885 for i := 0 to High(wantThisWeapon) do
3886 wantThisWeapon[i] := false;
3887 for i := 0 to High(FWeapon) do
3888 if (FNextWeap and (1 shl i)) <> 0 then
3889 begin
3890 wantThisWeapon[i] := true;
3891 Inc(wwc);
3892 end;
3894 // exclude currently selected weapon from the set
3895 wantThisWeapon[FCurrWeap] := false;
3896 // slow down alterations a little
3897 if wwc > 1 then
3898 begin
3899 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3900 // more than one weapon requested, assume "alteration" and check alteration delay
3901 if FNextWeapDelay > 0 then
3902 begin
3903 FNextWeap := 0;
3904 exit;
3905 end; // yeah
3906 end;
3907 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3908 // but clear all counters if no weapon should be switched
3909 if wwc < 1 then
3910 begin
3911 resetWeaponQueue();
3912 exit;
3913 end;
3914 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3915 // try weapons in descending order
3916 for i := High(FWeapon) downto 0 do
3917 begin
3918 if wantThisWeapon[i] and FWeapon[i] and ((wwc = 1) or hasAmmoForWeapon(i)) then
3919 begin
3920 // i found her!
3921 result := Byte(i);
3922 resetWeaponQueue();
3923 FNextWeapDelay := WEAPON_DELAY * 2; // anyway, 'cause why not
3924 //e_LogWriteFln('FOUND %s %s %s', [result, FSwitchToEmpty, hasAmmoForWeapon(i)], TMsgType.Notify);
3925 exit;
3926 end;
3927 end;
3928 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3929 resetWeaponQueue();
3930 end;
3932 procedure TPlayer.RealizeCurrentWeapon();
3933 function switchAllowed (): Boolean;
3934 var
3935 i: Byte;
3936 begin
3937 result := false;
3938 if FBFGFireCounter <> -1 then
3939 exit;
3940 if FTime[T_SWITCH] > gTime then
3941 exit;
3942 for i := WP_FIRST to WP_LAST do
3943 if FReloading[i] > 0 then
3944 exit;
3945 result := true;
3946 end;
3948 var
3949 nw: Byte;
3950 begin
3951 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3952 //FNextWeap := FNextWeap and $1FFF;
3953 if FNextWeapDelay > 0 then Dec(FNextWeapDelay); // "alteration delay"
3955 if not switchAllowed then
3956 begin
3957 //HACK for weapon cycling
3958 if (FNextWeap and $E000) <> 0 then FNextWeap := 0;
3959 exit;
3960 end;
3962 nw := getNextWeaponIndex();
3963 //
3964 if nw = 255 then exit; // don't reset anything here
3965 if nw > High(FWeapon) then
3966 begin
3967 // don't forget to reset queue here!
3968 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
3969 resetWeaponQueue();
3970 exit;
3971 end;
3973 if FWeapon[nw] then
3974 begin
3975 FCurrWeap := nw;
3976 FTime[T_SWITCH] := gTime+156;
3977 if FCurrWeap = WEAPON_SAW then FSawSoundSelect.PlayAt(FObj.X, FObj.Y);
3978 FModel.SetWeapon(FCurrWeap);
3979 if g_Game_IsNet then MH_SEND_PlayerStats(FUID);
3980 end;
3981 end;
3983 procedure TPlayer.NextWeapon();
3984 begin
3985 if g_Game_IsClient then Exit;
3986 FNextWeap := $8000;
3987 end;
3989 procedure TPlayer.PrevWeapon();
3990 begin
3991 if g_Game_IsClient then Exit;
3992 FNextWeap := $4000;
3993 end;
3995 procedure TPlayer.SetWeapon(W: Byte);
3996 begin
3997 if FCurrWeap <> W then
3998 if W = WEAPON_SAW then
3999 FSawSoundSelect.PlayAt(FObj.X, FObj.Y);
4001 FCurrWeap := W;
4002 FModel.SetWeapon(CurrWeap);
4003 resetWeaponQueue();
4004 end;
4006 function TPlayer.PickItem(ItemType: Byte; arespawn: Boolean; var remove: Boolean): Boolean;
4007 var
4008 a: Boolean;
4009 switchWeapon: Byte = 255;
4010 hadWeapon: Boolean = False;
4011 begin
4012 Result := False;
4013 if g_Game_IsClient then Exit;
4015 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
4016 a := LongBool(gGameSettings.Options and GAME_OPTION_WEAPONSTAY) and arespawn;
4017 remove := not a;
4018 case ItemType of
4019 ITEM_MEDKIT_SMALL:
4020 if (FHealth < PLAYER_HP_SOFT) or (FFireTime > 0) then
4021 begin
4022 if FHealth < PLAYER_HP_SOFT then IncMax(FHealth, 10, PLAYER_HP_SOFT);
4023 Result := True;
4024 remove := True;
4025 FFireTime := 0;
4026 if gFlash = 2 then Inc(FPickup, 5);
4027 end;
4029 ITEM_MEDKIT_LARGE:
4030 if (FHealth < PLAYER_HP_SOFT) or (FFireTime > 0) then
4031 begin
4032 if FHealth < PLAYER_HP_SOFT then IncMax(FHealth, 25, PLAYER_HP_SOFT);
4033 Result := True;
4034 remove := True;
4035 FFireTime := 0;
4036 if gFlash = 2 then Inc(FPickup, 5);
4037 end;
4039 ITEM_ARMOR_GREEN:
4040 if FArmor < PLAYER_AP_SOFT then
4041 begin
4042 FArmor := PLAYER_AP_SOFT;
4043 Result := True;
4044 remove := True;
4045 if gFlash = 2 then Inc(FPickup, 5);
4046 end;
4048 ITEM_ARMOR_BLUE:
4049 if FArmor < PLAYER_AP_LIMIT then
4050 begin
4051 FArmor := PLAYER_AP_LIMIT;
4052 Result := True;
4053 remove := True;
4054 if gFlash = 2 then Inc(FPickup, 5);
4055 end;
4057 ITEM_SPHERE_BLUE:
4058 if (FHealth < PLAYER_HP_LIMIT) or (FFireTime > 0) then
4059 begin
4060 if FHealth < PLAYER_HP_LIMIT then IncMax(FHealth, 100, PLAYER_HP_LIMIT);
4061 Result := True;
4062 remove := True;
4063 FFireTime := 0;
4064 if gFlash = 2 then Inc(FPickup, 5);
4065 end;
4067 ITEM_SPHERE_WHITE:
4068 if (FHealth < PLAYER_HP_LIMIT) or (FArmor < PLAYER_AP_LIMIT) or (FFireTime > 0) then
4069 begin
4070 if FHealth < PLAYER_HP_LIMIT then
4071 FHealth := PLAYER_HP_LIMIT;
4072 if FArmor < PLAYER_AP_LIMIT then
4073 FArmor := PLAYER_AP_LIMIT;
4074 Result := True;
4075 remove := True;
4076 FFireTime := 0;
4077 if gFlash = 2 then Inc(FPickup, 5);
4078 end;
4080 ITEM_WEAPON_SAW:
4081 if (not FWeapon[WEAPON_SAW]) or ((not arespawn) and (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF])) then
4082 begin
4083 hadWeapon := FWeapon[WEAPON_SAW];
4084 switchWeapon := WEAPON_SAW;
4085 FWeapon[WEAPON_SAW] := True;
4086 Result := True;
4087 if gFlash = 2 then Inc(FPickup, 5);
4088 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
4089 end;
4091 ITEM_WEAPON_SHOTGUN1:
4092 if (FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS]) or not FWeapon[WEAPON_SHOTGUN1] then
4093 begin
4094 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
4095 if a and FWeapon[WEAPON_SHOTGUN1] then Exit;
4096 hadWeapon := FWeapon[WEAPON_SHOTGUN1];
4097 switchWeapon := WEAPON_SHOTGUN1;
4098 IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
4099 FWeapon[WEAPON_SHOTGUN1] := True;
4100 Result := True;
4101 if gFlash = 2 then Inc(FPickup, 5);
4102 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
4103 end;
4105 ITEM_WEAPON_SHOTGUN2:
4106 if (FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS]) or not FWeapon[WEAPON_SHOTGUN2] then
4107 begin
4108 if a and FWeapon[WEAPON_SHOTGUN2] then Exit;
4109 hadWeapon := FWeapon[WEAPON_SHOTGUN2];
4110 switchWeapon := WEAPON_SHOTGUN2;
4111 IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
4112 FWeapon[WEAPON_SHOTGUN2] := True;
4113 Result := True;
4114 if gFlash = 2 then Inc(FPickup, 5);
4115 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
4116 end;
4118 ITEM_WEAPON_CHAINGUN:
4119 if (FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS]) or not FWeapon[WEAPON_CHAINGUN] then
4120 begin
4121 if a and FWeapon[WEAPON_CHAINGUN] then Exit;
4122 hadWeapon := FWeapon[WEAPON_CHAINGUN];
4123 switchWeapon := WEAPON_CHAINGUN;
4124 IncMax(FAmmo[A_BULLETS], 50, FMaxAmmo[A_BULLETS]);
4125 FWeapon[WEAPON_CHAINGUN] := True;
4126 Result := True;
4127 if gFlash = 2 then Inc(FPickup, 5);
4128 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
4129 end;
4131 ITEM_WEAPON_ROCKETLAUNCHER:
4132 if (FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS]) or not FWeapon[WEAPON_ROCKETLAUNCHER] then
4133 begin
4134 if a and FWeapon[WEAPON_ROCKETLAUNCHER] then Exit;
4135 switchWeapon := WEAPON_ROCKETLAUNCHER;
4136 hadWeapon := FWeapon[WEAPON_ROCKETLAUNCHER];
4137 IncMax(FAmmo[A_ROCKETS], 2, FMaxAmmo[A_ROCKETS]);
4138 FWeapon[WEAPON_ROCKETLAUNCHER] := True;
4139 Result := True;
4140 if gFlash = 2 then Inc(FPickup, 5);
4141 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
4142 end;
4144 ITEM_WEAPON_PLASMA:
4145 if (FAmmo[A_CELLS] < FMaxAmmo[A_CELLS]) or not FWeapon[WEAPON_PLASMA] then
4146 begin
4147 if a and FWeapon[WEAPON_PLASMA] then Exit;
4148 switchWeapon := WEAPON_PLASMA;
4149 hadWeapon := FWeapon[WEAPON_PLASMA];
4150 IncMax(FAmmo[A_CELLS], 40, FMaxAmmo[A_CELLS]);
4151 FWeapon[WEAPON_PLASMA] := True;
4152 Result := True;
4153 if gFlash = 2 then Inc(FPickup, 5);
4154 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
4155 end;
4157 ITEM_WEAPON_BFG:
4158 if (FAmmo[A_CELLS] < FMaxAmmo[A_CELLS]) or not FWeapon[WEAPON_BFG] then
4159 begin
4160 if a and FWeapon[WEAPON_BFG] then Exit;
4161 switchWeapon := WEAPON_BFG;
4162 hadWeapon := FWeapon[WEAPON_BFG];
4163 IncMax(FAmmo[A_CELLS], 40, FMaxAmmo[A_CELLS]);
4164 FWeapon[WEAPON_BFG] := True;
4165 Result := True;
4166 if gFlash = 2 then Inc(FPickup, 5);
4167 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
4168 end;
4170 ITEM_WEAPON_SUPERPULEMET:
4171 if (FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS]) or not FWeapon[WEAPON_SUPERPULEMET] then
4172 begin
4173 if a and FWeapon[WEAPON_SUPERPULEMET] then Exit;
4174 switchWeapon := WEAPON_SUPERPULEMET;
4175 hadWeapon := FWeapon[WEAPON_SUPERPULEMET];
4176 IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
4177 FWeapon[WEAPON_SUPERPULEMET] := True;
4178 Result := True;
4179 if gFlash = 2 then Inc(FPickup, 5);
4180 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
4181 end;
4183 ITEM_WEAPON_FLAMETHROWER:
4184 if (FAmmo[A_FUEL] < FMaxAmmo[A_FUEL]) or not FWeapon[WEAPON_FLAMETHROWER] then
4185 begin
4186 if a and FWeapon[WEAPON_FLAMETHROWER] then Exit;
4187 switchWeapon := WEAPON_FLAMETHROWER;
4188 hadWeapon := FWeapon[WEAPON_FLAMETHROWER];
4189 IncMax(FAmmo[A_FUEL], 100, FMaxAmmo[A_FUEL]);
4190 FWeapon[WEAPON_FLAMETHROWER] := True;
4191 Result := True;
4192 if gFlash = 2 then Inc(FPickup, 5);
4193 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
4194 end;
4196 ITEM_AMMO_BULLETS:
4197 if FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS] then
4198 begin
4199 IncMax(FAmmo[A_BULLETS], 10, FMaxAmmo[A_BULLETS]);
4200 Result := True;
4201 remove := True;
4202 if gFlash = 2 then Inc(FPickup, 5);
4203 end;
4205 ITEM_AMMO_BULLETS_BOX:
4206 if FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS] then
4207 begin
4208 IncMax(FAmmo[A_BULLETS], 50, FMaxAmmo[A_BULLETS]);
4209 Result := True;
4210 remove := True;
4211 if gFlash = 2 then Inc(FPickup, 5);
4212 end;
4214 ITEM_AMMO_SHELLS:
4215 if FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS] then
4216 begin
4217 IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
4218 Result := True;
4219 remove := True;
4220 if gFlash = 2 then Inc(FPickup, 5);
4221 end;
4223 ITEM_AMMO_SHELLS_BOX:
4224 if FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS] then
4225 begin
4226 IncMax(FAmmo[A_SHELLS], 25, FMaxAmmo[A_SHELLS]);
4227 Result := True;
4228 remove := True;
4229 if gFlash = 2 then Inc(FPickup, 5);
4230 end;
4232 ITEM_AMMO_ROCKET:
4233 if FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS] then
4234 begin
4235 IncMax(FAmmo[A_ROCKETS], 1, FMaxAmmo[A_ROCKETS]);
4236 Result := True;
4237 remove := True;
4238 if gFlash = 2 then Inc(FPickup, 5);
4239 end;
4241 ITEM_AMMO_ROCKET_BOX:
4242 if FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS] then
4243 begin
4244 IncMax(FAmmo[A_ROCKETS], 5, FMaxAmmo[A_ROCKETS]);
4245 Result := True;
4246 remove := True;
4247 if gFlash = 2 then Inc(FPickup, 5);
4248 end;
4250 ITEM_AMMO_CELL:
4251 if FAmmo[A_CELLS] < FMaxAmmo[A_CELLS] then
4252 begin
4253 IncMax(FAmmo[A_CELLS], 40, FMaxAmmo[A_CELLS]);
4254 Result := True;
4255 remove := True;
4256 if gFlash = 2 then Inc(FPickup, 5);
4257 end;
4259 ITEM_AMMO_CELL_BIG:
4260 if FAmmo[A_CELLS] < FMaxAmmo[A_CELLS] then
4261 begin
4262 IncMax(FAmmo[A_CELLS], 100, FMaxAmmo[A_CELLS]);
4263 Result := True;
4264 remove := True;
4265 if gFlash = 2 then Inc(FPickup, 5);
4266 end;
4268 ITEM_AMMO_FUELCAN:
4269 if FAmmo[A_FUEL] < FMaxAmmo[A_FUEL] then
4270 begin
4271 IncMax(FAmmo[A_FUEL], 100, FMaxAmmo[A_FUEL]);
4272 Result := True;
4273 remove := True;
4274 if gFlash = 2 then Inc(FPickup, 5);
4275 end;
4277 ITEM_AMMO_BACKPACK:
4278 if not(R_ITEM_BACKPACK in FRulez) or
4279 (FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS]) or
4280 (FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS]) or
4281 (FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS]) or
4282 (FAmmo[A_CELLS] < FMaxAmmo[A_CELLS]) or
4283 (FAmmo[A_FUEL] < FMaxAmmo[A_FUEL]) then
4284 begin
4285 FMaxAmmo[A_BULLETS] := AmmoLimits[1, A_BULLETS];
4286 FMaxAmmo[A_SHELLS] := AmmoLimits[1, A_SHELLS];
4287 FMaxAmmo[A_ROCKETS] := AmmoLimits[1, A_ROCKETS];
4288 FMaxAmmo[A_CELLS] := AmmoLimits[1, A_CELLS];
4289 FMaxAmmo[A_FUEL] := AmmoLimits[1, A_FUEL];
4291 if FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS] then
4292 IncMax(FAmmo[A_BULLETS], 10, FMaxAmmo[A_BULLETS]);
4293 if FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS] then
4294 IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
4295 if FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS] then
4296 IncMax(FAmmo[A_ROCKETS], 1, FMaxAmmo[A_ROCKETS]);
4297 if FAmmo[A_CELLS] < FMaxAmmo[A_CELLS] then
4298 IncMax(FAmmo[A_CELLS], 40, FMaxAmmo[A_CELLS]);
4299 if FAmmo[A_FUEL] < FMaxAmmo[A_FUEL] then
4300 IncMax(FAmmo[A_FUEL], 50, FMaxAmmo[A_FUEL]);
4302 FRulez := FRulez + [R_ITEM_BACKPACK];
4303 Result := True;
4304 remove := True;
4305 if gFlash = 2 then Inc(FPickup, 5);
4306 end;
4308 ITEM_KEY_RED:
4309 if not(R_KEY_RED in FRulez) then
4310 begin
4311 Include(FRulez, R_KEY_RED);
4312 Result := True;
4313 remove := (gGameSettings.GameMode <> GM_COOP) and (g_Player_GetCount() < 2);
4314 if gFlash = 2 then Inc(FPickup, 5);
4315 if (not remove) and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETITEM');
4316 end;
4318 ITEM_KEY_GREEN:
4319 if not(R_KEY_GREEN in FRulez) then
4320 begin
4321 Include(FRulez, R_KEY_GREEN);
4322 Result := True;
4323 remove := (gGameSettings.GameMode <> GM_COOP) and (g_Player_GetCount() < 2);
4324 if gFlash = 2 then Inc(FPickup, 5);
4325 if (not remove) and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETITEM');
4326 end;
4328 ITEM_KEY_BLUE:
4329 if not(R_KEY_BLUE in FRulez) then
4330 begin
4331 Include(FRulez, R_KEY_BLUE);
4332 Result := True;
4333 remove := (gGameSettings.GameMode <> GM_COOP) and (g_Player_GetCount() < 2);
4334 if gFlash = 2 then Inc(FPickup, 5);
4335 if (not remove) and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETITEM');
4336 end;
4338 ITEM_SUIT:
4339 if FMegaRulez[MR_SUIT] < gTime+PLAYER_SUIT_TIME then
4340 begin
4341 FMegaRulez[MR_SUIT] := gTime+PLAYER_SUIT_TIME;
4342 Result := True;
4343 remove := True;
4344 FFireTime := 0;
4345 if gFlash = 2 then Inc(FPickup, 5);
4346 end;
4348 ITEM_OXYGEN:
4349 if FAir < AIR_MAX then
4350 begin
4351 FAir := AIR_MAX;
4352 Result := True;
4353 remove := True;
4354 if gFlash = 2 then Inc(FPickup, 5);
4355 end;
4357 ITEM_MEDKIT_BLACK:
4358 begin
4359 if not (R_BERSERK in FRulez) then
4360 begin
4361 Include(FRulez, R_BERSERK);
4362 if (FBFGFireCounter = -1) then
4363 begin
4364 FCurrWeap := WEAPON_KASTET;
4365 resetWeaponQueue();
4366 FModel.SetWeapon(WEAPON_KASTET);
4367 end;
4368 if gFlash <> 0 then
4369 begin
4370 Inc(FPain, 100);
4371 if gFlash = 2 then Inc(FPickup, 5);
4372 end;
4373 FBerserk := gTime+30000;
4374 Result := True;
4375 remove := True;
4376 FFireTime := 0;
4377 end;
4378 if (FHealth < PLAYER_HP_SOFT) or (FFireTime > 0) then
4379 begin
4380 if FHealth < PLAYER_HP_SOFT then FHealth := PLAYER_HP_SOFT;
4381 FBerserk := gTime+30000;
4382 Result := True;
4383 remove := True;
4384 FFireTime := 0;
4385 end;
4386 end;
4388 ITEM_INVUL:
4389 if FMegaRulez[MR_INVUL] < gTime+PLAYER_INVUL_TIME then
4390 begin
4391 FMegaRulez[MR_INVUL] := gTime+PLAYER_INVUL_TIME;
4392 FSpawnInvul := 0;
4393 Result := True;
4394 remove := True;
4395 if gFlash = 2 then Inc(FPickup, 5);
4396 end;
4398 ITEM_BOTTLE:
4399 if (FHealth < PLAYER_HP_LIMIT) or (FFireTime > 0) then
4400 begin
4401 if FHealth < PLAYER_HP_LIMIT then IncMax(FHealth, 4, PLAYER_HP_LIMIT);
4402 Result := True;
4403 remove := True;
4404 FFireTime := 0;
4405 if gFlash = 2 then Inc(FPickup, 5);
4406 end;
4408 ITEM_HELMET:
4409 if FArmor < PLAYER_AP_LIMIT then
4410 begin
4411 IncMax(FArmor, 5, PLAYER_AP_LIMIT);
4412 Result := True;
4413 remove := True;
4414 if gFlash = 2 then Inc(FPickup, 5);
4415 end;
4417 ITEM_JETPACK:
4418 if FJetFuel < JET_MAX then
4419 begin
4420 FJetFuel := JET_MAX;
4421 Result := True;
4422 remove := True;
4423 if gFlash = 2 then Inc(FPickup, 5);
4424 end;
4426 ITEM_INVIS:
4427 if FMegaRulez[MR_INVIS] < gTime+PLAYER_INVIS_TIME then
4428 begin
4429 FMegaRulez[MR_INVIS] := gTime+PLAYER_INVIS_TIME;
4430 Result := True;
4431 remove := True;
4432 if gFlash = 2 then Inc(FPickup, 5);
4433 end;
4434 end;
4436 if (shouldSwitch(switchWeapon, hadWeapon)) then
4437 QueueWeaponSwitch(switchWeapon);
4438 end;
4440 procedure TPlayer.Touch();
4441 begin
4442 if not FAlive then
4443 Exit;
4444 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4445 if FIamBot then
4446 begin
4447 // Áðîñèòü ôëàã òîâàðèùó:
4448 if gGameSettings.GameMode = GM_CTF then
4449 DropFlag();
4450 end;
4451 end;
4453 procedure TPlayer.Push(vx, vy: Integer);
4454 begin
4455 if (not FPhysics) and FGhost then
4456 Exit;
4457 FObj.Accel.X := FObj.Accel.X + vx;
4458 FObj.Accel.Y := FObj.Accel.Y + vy;
4459 if g_Game_IsNet and g_Game_IsServer then
4460 MH_SEND_PlayerPos(True, FUID, NET_EVERYONE);
4461 end;
4463 procedure TPlayer.Reset(Force: Boolean);
4464 begin
4465 if Force then
4466 FAlive := False;
4468 FSpawned := False;
4469 FTime[T_RESPAWN] := 0;
4470 FTime[T_FLAGCAP] := 0;
4471 FGodMode := False;
4472 FNoTarget := False;
4473 FNoReload := False;
4474 FFrags := 0;
4475 FLastFrag := 0;
4476 FComboEvnt := -1;
4477 FKills := 0;
4478 FMonsterKills := 0;
4479 FDeath := 0;
4480 FSecrets := 0;
4481 FSpawnInvul := 0;
4482 FCorpse := -1;
4483 FReady := False;
4484 if FNoRespawn then
4485 begin
4486 FSpectator := False;
4487 FGhost := False;
4488 FPhysics := True;
4489 FSpectatePlayer := -1;
4490 FNoRespawn := False;
4491 end;
4492 FLives := gGameSettings.MaxLives;
4494 SetFlag(FLAG_NONE);
4495 end;
4497 procedure TPlayer.SoftReset();
4498 begin
4499 ReleaseKeys();
4501 FDamageBuffer := 0;
4502 FSlopeOld := 0;
4503 FIncCamOld := 0;
4504 FIncCam := 0;
4505 FBFGFireCounter := -1;
4506 FShellTimer := -1;
4507 FPain := 0;
4508 FLastHit := 0;
4509 FLastFrag := 0;
4510 FComboEvnt := -1;
4512 SetFlag(FLAG_NONE);
4513 SetAction(A_STAND, True);
4514 end;
4516 function TPlayer.GetRespawnPoint(): Byte;
4517 var
4518 c: Byte;
4519 begin
4520 Result := 255;
4521 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4523 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4524 if gGameSettings.GameMode in [GM_COOP, GM_SINGLE] then
4525 begin
4526 if Self = gPlayer1 then
4527 begin
4528 // player 1 should try to spawn on the player 1 point
4529 if g_Map_GetPointCount(RESPAWNPOINT_PLAYER1) > 0 then
4530 Exit(RESPAWNPOINT_PLAYER1)
4531 else if g_Map_GetPointCount(RESPAWNPOINT_PLAYER2) > 0 then
4532 Exit(RESPAWNPOINT_PLAYER2);
4533 end
4534 else if Self = gPlayer2 then
4535 begin
4536 // player 2 should try to spawn on the player 2 point
4537 if g_Map_GetPointCount(RESPAWNPOINT_PLAYER2) > 0 then
4538 Exit(RESPAWNPOINT_PLAYER2)
4539 else if g_Map_GetPointCount(RESPAWNPOINT_PLAYER1) > 0 then
4540 Exit(RESPAWNPOINT_PLAYER1);
4541 end
4542 else
4543 begin
4544 // other players randomly pick either the first or the second point
4545 c := IfThen((Random(2) = 0), RESPAWNPOINT_PLAYER1, RESPAWNPOINT_PLAYER2);
4546 if g_Map_GetPointCount(c) > 0 then
4547 Exit(c);
4548 // try the other one
4549 c := IfThen((c = RESPAWNPOINT_PLAYER1), RESPAWNPOINT_PLAYER2, RESPAWNPOINT_PLAYER1);
4550 if g_Map_GetPointCount(c) > 0 then
4551 Exit(c);
4552 end;
4553 end;
4555 // Ìÿñîïîâàë
4556 if gGameSettings.GameMode = GM_DM then
4557 begin
4558 // try DM points first
4559 if g_Map_GetPointCount(RESPAWNPOINT_DM) > 0 then
4560 Exit(RESPAWNPOINT_DM);
4561 end;
4563 // Êîìàíäíûå
4564 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
4565 begin
4566 // try team points first
4567 c := RESPAWNPOINT_DM;
4568 if FTeam = TEAM_RED then
4569 c := RESPAWNPOINT_RED
4570 else if FTeam = TEAM_BLUE then
4571 c := RESPAWNPOINT_BLUE;
4572 if g_Map_GetPointCount(c) > 0 then
4573 Exit(c);
4574 end;
4576 // still haven't found a spawnpoint, try random shit
4577 Result := g_Map_GetRandomPointType();
4578 end;
4580 procedure TPlayer.Respawn(Silent: Boolean; Force: Boolean = False);
4581 var
4582 RespawnPoint: TRespawnPoint;
4583 a, b, c: Byte;
4584 Anim: TAnimation;
4585 ID: DWORD;
4586 begin
4587 FSlopeOld := 0;
4588 FIncCamOld := 0;
4589 FIncCam := 0;
4590 FBFGFireCounter := -1;
4591 FShellTimer := -1;
4592 FPain := 0;
4593 FLastHit := 0;
4594 FSpawnInvul := 0;
4595 FCorpse := -1;
4597 if not g_Game_IsServer then
4598 Exit;
4599 if FDummy then
4600 Exit;
4601 FWantsInGame := True;
4602 FJustTeleported := True;
4603 if Force then
4604 begin
4605 FTime[T_RESPAWN] := 0;
4606 FAlive := False;
4607 end;
4608 FNetTime := 0;
4609 // if server changes MaxLives we gotta be ready
4610 if gGameSettings.MaxLives = 0 then FNoRespawn := False;
4612 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4613 if FTime[T_RESPAWN] > gTime then
4614 Exit;
4616 // Ïðîñðàë âñå æèçíè:
4617 if FNoRespawn then
4618 begin
4619 if not FSpectator then Spectate(True);
4620 FWantsInGame := True;
4621 Exit;
4622 end;
4624 if (gGameSettings.GameType <> GT_SINGLE) and (gGameSettings.GameMode <> GM_COOP) then
4625 begin // "Ñâîÿ èãðà"
4626 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4627 FRulez := FRulez-[R_BERSERK];
4628 end
4629 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4630 begin
4631 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4632 FRulez := FRulez-[R_KEY_RED, R_KEY_GREEN, R_KEY_BLUE, R_BERSERK];
4633 end;
4635 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4636 c := GetRespawnPoint();
4638 ReleaseKeys();
4639 SetFlag(FLAG_NONE);
4641 // Âîñêðåøåíèå áåç îðóæèÿ:
4642 if not FAlive then
4643 begin
4644 FHealth := Round(PLAYER_HP_SOFT * (FHandicap / 100));
4645 FArmor := 0;
4646 FAlive := True;
4647 FAir := AIR_DEF;
4648 FJetFuel := 0;
4650 for a := WP_FIRST to WP_LAST do
4651 begin
4652 FWeapon[a] := False;
4653 FReloading[a] := 0;
4654 end;
4656 FWeapon[WEAPON_PISTOL] := True;
4657 FWeapon[WEAPON_KASTET] := True;
4658 FCurrWeap := WEAPON_PISTOL;
4659 resetWeaponQueue();
4661 FModel.SetWeapon(FCurrWeap);
4663 for b := A_BULLETS to A_HIGH do
4664 FAmmo[b] := 0;
4666 FAmmo[A_BULLETS] := 50;
4668 FMaxAmmo[A_BULLETS] := AmmoLimits[0, A_BULLETS];
4669 FMaxAmmo[A_SHELLS] := AmmoLimits[0, A_SHELLS];
4670 FMaxAmmo[A_ROCKETS] := AmmoLimits[0, A_SHELLS];
4671 FMaxAmmo[A_CELLS] := AmmoLimits[0, A_CELLS];
4672 FMaxAmmo[A_FUEL] := AmmoLimits[0, A_FUEL];
4674 if (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF]) and
4675 LongBool(gGameSettings.Options and GAME_OPTION_DMKEYS) then
4676 FRulez := [R_KEY_RED, R_KEY_GREEN, R_KEY_BLUE]
4677 else
4678 FRulez := [];
4679 end;
4681 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4682 if not g_Map_GetPoint(c, RespawnPoint) then
4683 begin
4684 g_FatalError(_lc[I_GAME_ERROR_GET_SPAWN]);
4685 Exit;
4686 end;
4688 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4689 FObj.X := RespawnPoint.X-PLAYER_RECT.X;
4690 FObj.Y := RespawnPoint.Y-PLAYER_RECT.Y;
4691 FObj.oldX := FObj.X; // don't interpolate after respawn
4692 FObj.oldY := FObj.Y;
4693 FObj.Vel.X := 0;
4694 FObj.Vel.Y := 0;
4695 FObj.Accel.X := 0;
4696 FObj.Accel.Y := 0;
4698 FDirection := RespawnPoint.Direction;
4699 if FDirection = TDirection.D_LEFT then
4700 FAngle := 180
4701 else
4702 FAngle := 0;
4704 SetAction(A_STAND, True);
4705 FModel.Direction := FDirection;
4707 for a := Low(FTime) to High(FTime) do
4708 FTime[a] := 0;
4710 for a := Low(FMegaRulez) to High(FMegaRulez) do
4711 FMegaRulez[a] := 0;
4713 // Respawn invulnerability
4714 if (gGameSettings.GameType <> GT_SINGLE) and (gGameSettings.SpawnInvul > 0) then
4715 begin
4716 FMegaRulez[MR_INVUL] := gTime + gGameSettings.SpawnInvul * 1000;
4717 FSpawnInvul := FMegaRulez[MR_INVUL];
4718 end;
4720 FDamageBuffer := 0;
4721 FJetpack := False;
4722 FCanJetpack := False;
4723 FFlaming := False;
4724 FFireTime := 0;
4725 FFirePainTime := 0;
4726 FFireAttacker := 0;
4728 // Àíèìàöèÿ âîçðîæäåíèÿ:
4729 if (not gLoadGameMode) and (not Silent) then
4730 if g_Frames_Get(ID, 'FRAMES_TELEPORT') then
4731 begin
4732 Anim := TAnimation.Create(ID, False, 3);
4733 g_GFX_OnceAnim(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
4734 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32, Anim);
4735 Anim.Free();
4736 end;
4738 FSpectator := False;
4739 FGhost := False;
4740 FPhysics := True;
4741 FSpectatePlayer := -1;
4742 FSpawned := True;
4744 if (gPlayer1 = nil) and (gSpectLatchPID1 = FUID) then
4745 gPlayer1 := self;
4746 if (gPlayer2 = nil) and (gSpectLatchPID2 = FUID) then
4747 gPlayer2 := self;
4749 if g_Game_IsNet then
4750 begin
4751 MH_SEND_PlayerPos(True, FUID, NET_EVERYONE);
4752 MH_SEND_PlayerStats(FUID, NET_EVERYONE);
4753 if not Silent then
4754 MH_SEND_Effect(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
4755 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32,
4756 0, NET_GFX_TELE);
4757 end;
4758 end;
4760 procedure TPlayer.Spectate(NoMove: Boolean = False);
4761 begin
4762 if FAlive then
4763 Kill(K_EXTRAHARDKILL, FUID, HIT_SOME)
4764 else if (not NoMove) then
4765 begin
4766 GameX := gMapInfo.Width div 2;
4767 GameY := gMapInfo.Height div 2;
4768 end;
4769 FXTo := GameX;
4770 FYTo := GameY;
4772 FAlive := False;
4773 FSpectator := True;
4774 FGhost := True;
4775 FPhysics := False;
4776 FWantsInGame := False;
4777 FSpawned := False;
4778 FCorpse := -1;
4780 if FNoRespawn then
4781 begin
4782 if Self = gPlayer1 then
4783 begin
4784 gSpectLatchPID1 := FUID;
4785 gPlayer1 := nil;
4786 end
4787 else if Self = gPlayer2 then
4788 begin
4789 gSpectLatchPID2 := FUID;
4790 gPlayer2 := nil;
4791 end;
4792 end;
4794 if g_Game_IsNet then
4795 MH_SEND_PlayerStats(FUID);
4796 end;
4798 procedure TPlayer.SwitchNoClip;
4799 begin
4800 if not FAlive then
4801 Exit;
4802 FGhost := not FGhost;
4803 FPhysics := not FGhost;
4804 if FGhost then
4805 begin
4806 FXTo := FObj.X;
4807 FYTo := FObj.Y;
4808 end else
4809 begin
4810 FObj.Accel.X := 0;
4811 FObj.Accel.Y := 0;
4812 end;
4813 end;
4815 procedure TPlayer.Run(Direction: TDirection);
4816 var
4817 a, b: Integer;
4818 begin
4819 if MAX_RUNVEL > 8 then
4820 FlySmoke();
4822 // Áåæèì:
4823 if Direction = TDirection.D_LEFT then
4824 begin
4825 if FObj.Vel.X > -MAX_RUNVEL then
4826 FObj.Vel.X := FObj.Vel.X - (MAX_RUNVEL shr 3);
4827 end
4828 else
4829 if FObj.Vel.X < MAX_RUNVEL then
4830 FObj.Vel.X := FObj.Vel.X + (MAX_RUNVEL shr 3);
4832 // Âîçìîæíî, ïèíàåì êóñêè:
4833 if (FObj.Vel.X <> 0) and (gGibs <> nil) then
4834 begin
4835 b := Abs(FObj.Vel.X);
4836 if b > 1 then b := b * (Random(8 div b) + 1);
4837 for a := 0 to High(gGibs) do
4838 begin
4839 if gGibs[a].alive and
4840 g_Obj_Collide(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y+FObj.Rect.Height-4,
4841 FObj.Rect.Width, 8, @gGibs[a].Obj) and (Random(3) = 0) then
4842 begin
4843 // Ïèíàåì êóñêè
4844 if FObj.Vel.X < 0 then
4845 begin
4846 g_Obj_PushA(@gGibs[a].Obj, b, Random(61)+120) // íàëåâî
4847 end
4848 else
4849 begin
4850 g_Obj_PushA(@gGibs[a].Obj, b, Random(61)); // íàïðàâî
4851 end;
4852 gGibs[a].positionChanged(); // this updates spatial accelerators
4853 end;
4854 end;
4855 end;
4857 SetAction(A_WALK);
4858 end;
4860 procedure TPlayer.SeeDown();
4861 begin
4862 SetAction(A_SEEDOWN);
4864 if FDirection = TDirection.D_LEFT then FAngle := ANGLE_LEFTDOWN else FAngle := ANGLE_RIGHTDOWN;
4866 if FIncCam > -120 then DecMin(FIncCam, 5, -120);
4867 end;
4869 procedure TPlayer.SeeUp();
4870 begin
4871 SetAction(A_SEEUP);
4873 if FDirection = TDirection.D_LEFT then FAngle := ANGLE_LEFTUP else FAngle := ANGLE_RIGHTUP;
4875 if FIncCam < 120 then IncMax(FIncCam, 5, 120);
4876 end;
4878 procedure TPlayer.SetAction(Action: Byte; Force: Boolean = False);
4879 var
4880 Prior: Byte;
4881 begin
4882 case Action of
4883 A_WALK: Prior := 3;
4884 A_DIE1: Prior := 5;
4885 A_DIE2: Prior := 5;
4886 A_ATTACK: Prior := 2;
4887 A_SEEUP: Prior := 1;
4888 A_SEEDOWN: Prior := 1;
4889 A_ATTACKUP: Prior := 2;
4890 A_ATTACKDOWN: Prior := 2;
4891 A_PAIN: Prior := 4;
4892 else Prior := 0;
4893 end;
4895 if (Prior > FActionPrior) or Force then
4896 if not ((Prior = 2) and (FCurrWeap = WEAPON_SAW)) then
4897 begin
4898 FActionPrior := Prior;
4899 FActionAnim := Action;
4900 FActionForce := Force;
4901 FActionChanged := True;
4902 end;
4904 if Action in [A_ATTACK, A_ATTACKUP, A_ATTACKDOWN] then FModel.SetFire(True);
4905 end;
4907 function TPlayer.StayOnStep(XInc, YInc: Integer): Boolean;
4908 begin
4909 Result := not g_Map_CollidePanel(FObj.X+PLAYER_RECT.X, FObj.Y+YInc+PLAYER_RECT.Y+PLAYER_RECT.Height-1,
4910 PLAYER_RECT.Width, 1, PANEL_STEP, False)
4911 and g_Map_CollidePanel(FObj.X+PLAYER_RECT.X, FObj.Y+YInc+PLAYER_RECT.Y+PLAYER_RECT.Height,
4912 PLAYER_RECT.Width, 1, PANEL_STEP, False);
4913 end;
4915 function TPlayer.TeleportTo(X, Y: Integer; silent: Boolean; dir: Byte): Boolean;
4916 var
4917 Anim: TAnimation;
4918 ID: DWORD;
4919 begin
4920 Result := False;
4922 if g_CollideLevel(X, Y, PLAYER_RECT.Width, PLAYER_RECT.Height) then
4923 begin
4924 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj.X, FObj.Y);
4925 if g_Game_IsServer and g_Game_IsNet then
4926 MH_SEND_Sound(FObj.X, FObj.Y, 'SOUND_GAME_NOTELEPORT');
4927 Exit;
4928 end;
4930 FJustTeleported := True;
4932 Anim := nil;
4933 if not silent then
4934 begin
4935 if g_Frames_Get(ID, 'FRAMES_TELEPORT') then
4936 begin
4937 Anim := TAnimation.Create(ID, False, 3);
4938 end;
4940 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj.X, FObj.Y);
4941 g_GFX_OnceAnim(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
4942 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32, Anim);
4943 if g_Game_IsServer and g_Game_IsNet then
4944 MH_SEND_Effect(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
4945 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32, 1,
4946 NET_GFX_TELE);
4947 end;
4949 FObj.X := X-PLAYER_RECT.X;
4950 FObj.Y := Y-PLAYER_RECT.Y;
4951 FObj.oldX := FObj.X; // don't interpolate after respawn
4952 FObj.oldY := FObj.Y;
4953 if FAlive and FGhost then
4954 begin
4955 FXTo := FObj.X;
4956 FYTo := FObj.Y;
4957 end;
4959 if not g_Game_IsNet then
4960 begin
4961 if dir = 1 then
4962 begin
4963 SetDirection(TDirection.D_LEFT);
4964 FAngle := 180;
4965 end
4966 else
4967 if dir = 2 then
4968 begin
4969 SetDirection(TDirection.D_RIGHT);
4970 FAngle := 0;
4971 end
4972 else
4973 if dir = 3 then
4974 begin // îáðàòíîå
4975 if FDirection = TDirection.D_RIGHT then
4976 begin
4977 SetDirection(TDirection.D_LEFT);
4978 FAngle := 180;
4979 end
4980 else
4981 begin
4982 SetDirection(TDirection.D_RIGHT);
4983 FAngle := 0;
4984 end;
4985 end;
4986 end;
4988 if not silent and (Anim <> nil) then
4989 begin
4990 g_GFX_OnceAnim(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
4991 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32, Anim);
4992 Anim.Free();
4994 if g_Game_IsServer and g_Game_IsNet then
4995 MH_SEND_Effect(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
4996 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32, 0,
4997 NET_GFX_TELE);
4998 end;
5000 Result := True;
5001 end;
5003 function nonz(a: Single): Single;
5004 begin
5005 if a <> 0 then
5006 Result := a
5007 else
5008 Result := 1;
5009 end;
5011 function TPlayer.refreshCorpse(): Boolean;
5012 var
5013 i: Integer;
5014 begin
5015 Result := False;
5016 FCorpse := -1;
5017 if FAlive or FSpectator then
5018 Exit;
5019 if (gCorpses = nil) or (Length(gCorpses) = 0) then
5020 Exit;
5021 for i := 0 to High(gCorpses) do
5022 if gCorpses[i] <> nil then
5023 if gCorpses[i].FPlayerUID = FUID then
5024 begin
5025 Result := True;
5026 FCorpse := i;
5027 break;
5028 end;
5029 end;
5031 function TPlayer.getCameraObj(): TObj;
5032 begin
5033 if (not FAlive) and (not FSpectator) and
5034 (FCorpse >= 0) and (FCorpse < Length(gCorpses)) and
5035 (gCorpses[FCorpse] <> nil) and (gCorpses[FCorpse].FPlayerUID = FUID) then
5036 begin
5037 gCorpses[FCorpse].FObj.slopeUpLeft := FObj.slopeUpLeft;
5038 Result := gCorpses[FCorpse].FObj;
5039 end
5040 else
5041 begin
5042 Result := FObj;
5043 end;
5044 end;
5046 procedure TPlayer.PreUpdate();
5047 begin
5048 FSlopeOld := FObj.slopeUpLeft;
5049 FIncCamOld := FIncCam;
5050 FObj.oldX := FObj.X;
5051 FObj.oldY := FObj.Y;
5052 end;
5054 procedure TPlayer.Update();
5055 var
5056 b: Byte;
5057 i, ii, wx, wy, xd, yd, k: Integer;
5058 blockmon, headwater, dospawn: Boolean;
5059 NetServer: Boolean;
5060 AnyServer: Boolean;
5061 SetSpect: Boolean;
5062 begin
5063 NetServer := g_Game_IsNet and g_Game_IsServer;
5064 AnyServer := g_Game_IsServer;
5066 if g_Game_IsClient and (NetInterpLevel > 0) then
5067 DoLerp(NetInterpLevel + 1)
5068 else
5069 if FGhost then
5070 DoLerp(4);
5072 if NetServer then
5073 if (FClientID >= 0) and (NetClients[FClientID].Peer <> nil) then
5074 begin
5075 FPing := NetClients[FClientID].Peer^.lastRoundTripTime;
5076 if NetClients[FClientID].Peer^.packetsSent > 0 then
5077 FLoss := Round(100*NetClients[FClientID].Peer^.packetsLost/NetClients[FClientID].Peer^.packetsSent)
5078 else
5079 FLoss := 0;
5080 end else
5081 begin
5082 FPing := 0;
5083 FLoss := 0;
5084 end;
5086 if FAlive and (FPunchAnim <> nil) then
5087 FPunchAnim.Update();
5089 if FAlive and (gFly or FJetpack) then
5090 FlySmoke();
5092 if FDirection = TDirection.D_LEFT then
5093 FAngle := 180
5094 else
5095 FAngle := 0;
5097 if FAlive and (not FGhost) then
5098 begin
5099 if FKeys[KEY_UP].Pressed then
5100 SeeUp();
5101 if FKeys[KEY_DOWN].Pressed then
5102 SeeDown();
5103 end;
5105 if (not (FKeys[KEY_UP].Pressed or FKeys[KEY_DOWN].Pressed)) and
5106 (FIncCam <> 0) then
5107 begin
5108 i := g_basic.Sign(FIncCam);
5109 FIncCam := Abs(FIncCam);
5110 DecMin(FIncCam, 5, 0);
5111 FIncCam := FIncCam*i;
5112 end;
5114 if gTime mod (GAME_TICK*2) <> 0 then
5115 begin
5116 if (FObj.Vel.X = 0) and FAlive then
5117 begin
5118 if FKeys[KEY_LEFT].Pressed then
5119 Run(TDirection.D_LEFT);
5120 if FKeys[KEY_RIGHT].Pressed then
5121 Run(TDirection.D_RIGHT);
5122 end;
5124 if FPhysics then
5125 begin
5126 g_Obj_Move(@FObj, True, True, True);
5127 positionChanged(); // this updates spatial accelerators
5128 end;
5130 Exit;
5131 end;
5133 FActionChanged := False;
5135 if FAlive then
5136 begin
5137 // Let alive player do some actions
5138 if FKeys[KEY_LEFT].Pressed then Run(TDirection.D_LEFT);
5139 if FKeys[KEY_RIGHT].Pressed then Run(TDirection.D_RIGHT);
5140 if FKeys[KEY_FIRE].Pressed and AnyServer then Fire()
5141 else
5142 begin
5143 if AnyServer then
5144 begin
5145 FlamerOff;
5146 if NetServer then MH_SEND_PlayerStats(FUID);
5147 end;
5148 end;
5149 if FKeys[KEY_OPEN].Pressed and AnyServer then Use();
5150 if FKeys[KEY_JUMP].Pressed then Jump()
5151 else
5152 begin
5153 if AnyServer and FJetpack then
5154 begin
5155 FJetpack := False;
5156 JetpackOff;
5157 if NetServer then MH_SEND_PlayerStats(FUID);
5158 end;
5159 FCanJetpack := True;
5160 end;
5161 end
5162 else // Dead
5163 begin
5164 dospawn := False;
5165 if not FGhost then
5166 for k := Low(FKeys) to KEY_CHAT-1 do
5167 begin
5168 if FKeys[k].Pressed then
5169 begin
5170 dospawn := True;
5171 break;
5172 end;
5173 end;
5174 if dospawn then
5175 begin
5176 if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
5177 Respawn(False)
5178 else // Single
5179 if (FTime[T_RESPAWN] <= gTime) and
5180 gGameOn and (not FAlive) then
5181 begin
5182 if (g_Player_GetCount() > 1) then
5183 Respawn(False)
5184 else
5185 begin
5186 gExit := EXIT_RESTART;
5187 Exit;
5188 end;
5189 end;
5190 end;
5191 // Dead spectator actions
5192 if FGhost then
5193 begin
5194 if FKeys[KEY_OPEN].Pressed and AnyServer then Fire();
5195 if FKeys[KEY_FIRE].Pressed and AnyServer then
5196 begin
5197 if FSpectator then
5198 begin
5199 if (FSpectatePlayer >= High(gPlayers)) then
5200 FSpectatePlayer := -1
5201 else
5202 begin
5203 SetSpect := False;
5204 for I := FSpectatePlayer + 1 to High(gPlayers) do
5205 if gPlayers[I] <> nil then
5206 if gPlayers[I].alive then
5207 if gPlayers[I].UID <> FUID then
5208 begin
5209 FSpectatePlayer := I;
5210 SetSpect := True;
5211 break;
5212 end;
5214 if not SetSpect then FSpectatePlayer := -1;
5215 end;
5217 ReleaseKeys;
5218 end;
5219 end;
5220 end;
5221 end;
5222 // No clipping
5223 if FGhost then
5224 begin
5225 if FKeys[KEY_UP].Pressed or FKeys[KEY_JUMP].Pressed then
5226 begin
5227 FYTo := FObj.Y - 32;
5228 FSpectatePlayer := -1;
5229 end;
5230 if FKeys[KEY_DOWN].Pressed then
5231 begin
5232 FYTo := FObj.Y + 32;
5233 FSpectatePlayer := -1;
5234 end;
5235 if FKeys[KEY_LEFT].Pressed then
5236 begin
5237 FXTo := FObj.X - 32;
5238 FSpectatePlayer := -1;
5239 end;
5240 if FKeys[KEY_RIGHT].Pressed then
5241 begin
5242 FXTo := FObj.X + 32;
5243 FSpectatePlayer := -1;
5244 end;
5246 if (FXTo < -64) then
5247 FXTo := -64
5248 else if (FXTo > gMapInfo.Width + 32) then
5249 FXTo := gMapInfo.Width + 32;
5250 if (FYTo < -72) then
5251 FYTo := -72
5252 else if (FYTo > gMapInfo.Height + 32) then
5253 FYTo := gMapInfo.Height + 32;
5254 end;
5256 if FPhysics then
5257 begin
5258 g_Obj_Move(@FObj, True, True, True);
5259 positionChanged(); // this updates spatial accelerators
5260 end
5261 else
5262 begin
5263 FObj.Vel.X := 0;
5264 FObj.Vel.Y := 0;
5265 if FSpectator then
5266 if (FSpectatePlayer <= High(gPlayers)) and (FSpectatePlayer >= 0) then
5267 if gPlayers[FSpectatePlayer] <> nil then
5268 if gPlayers[FSpectatePlayer].alive then
5269 begin
5270 FXTo := gPlayers[FSpectatePlayer].GameX;
5271 FYTo := gPlayers[FSpectatePlayer].GameY;
5272 end;
5273 end;
5275 blockmon := g_Map_CollidePanel(FObj.X+PLAYER_HEADRECT.X, FObj.Y+PLAYER_HEADRECT.Y,
5276 PLAYER_HEADRECT.Width, PLAYER_HEADRECT.Height,
5277 PANEL_BLOCKMON, True);
5278 headwater := HeadInLiquid(0, 0);
5280 // Ñîïðîòèâëåíèå âîçäóõà:
5281 if (not FAlive) or not (FKeys[KEY_LEFT].Pressed or FKeys[KEY_RIGHT].Pressed) then
5282 if FObj.Vel.X <> 0 then
5283 FObj.Vel.X := z_dec(FObj.Vel.X, 1);
5285 if (FLastHit = HIT_TRAP) and (FPain > 90) then FPain := 90;
5286 DecMin(FPain, 5, 0);
5287 DecMin(FPickup, 1, 0);
5289 if FAlive and (FObj.Y > Integer(gMapInfo.Height)+128) and AnyServer then
5290 begin
5291 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
5292 FMegaRulez[MR_SUIT] := 0;
5293 FMegaRulez[MR_INVUL] := 0;
5294 FMegaRulez[MR_INVIS] := 0;
5295 Kill(K_FALLKILL, 0, HIT_FALL);
5296 end;
5298 i := 9;
5300 if FAlive then
5301 begin
5302 if FCurrWeap = WEAPON_SAW then
5303 if not (FSawSound.IsPlaying() or FSawSoundHit.IsPlaying() or
5304 FSawSoundSelect.IsPlaying()) then
5305 FSawSoundIdle.PlayAt(FObj.X, FObj.Y);
5307 if FJetpack then
5308 if (not FJetSoundFly.IsPlaying()) and (not FJetSoundOn.IsPlaying()) and
5309 (not FJetSoundOff.IsPlaying()) then
5310 begin
5311 FJetSoundFly.SetPosition(0);
5312 FJetSoundFly.PlayAt(FObj.X, FObj.Y);
5313 end;
5315 for b := WP_FIRST to WP_LAST do
5316 if FReloading[b] > 0 then
5317 if FNoReload then
5318 FReloading[b] := 0
5319 else
5320 Dec(FReloading[b]);
5322 if FShellTimer > -1 then
5323 if FShellTimer = 0 then
5324 begin
5325 if FShellType = SHELL_SHELL then
5326 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
5327 GameVelX, GameVelY-2, SHELL_SHELL)
5328 else if FShellType = SHELL_DBLSHELL then
5329 begin
5330 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
5331 GameVelX+1, GameVelY-2, SHELL_SHELL);
5332 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
5333 GameVelX-1, GameVelY-2, SHELL_SHELL);
5334 end;
5335 FShellTimer := -1;
5336 end else Dec(FShellTimer);
5338 if (FBFGFireCounter > -1) then
5339 if FBFGFireCounter = 0 then
5340 begin
5341 if AnyServer then
5342 begin
5343 wx := FObj.X+WEAPONPOINT[FDirection].X;
5344 wy := FObj.Y+WEAPONPOINT[FDirection].Y;
5345 xd := wx+IfThen(FDirection = TDirection.D_LEFT, -30, 30);
5346 yd := wy+firediry();
5347 g_Weapon_bfgshot(wx, wy, xd, yd, FUID);
5348 if NetServer then MH_SEND_PlayerFire(FUID, WEAPON_BFG, wx, wy, xd, yd);
5349 if (FAngle = 0) or (FAngle = 180) then SetAction(A_ATTACK)
5350 else if (FAngle = ANGLE_LEFTDOWN) or (FAngle = ANGLE_RIGHTDOWN) then SetAction(A_ATTACKDOWN)
5351 else if (FAngle = ANGLE_LEFTUP) or (FAngle = ANGLE_RIGHTUP) then SetAction(A_ATTACKUP);
5352 end;
5354 FReloading[WEAPON_BFG] := WEAPON_RELOAD[WEAPON_BFG];
5355 FBFGFireCounter := -1;
5356 end else
5357 if FNoReload then
5358 FBFGFireCounter := 0
5359 else
5360 Dec(FBFGFireCounter);
5362 if (FMegaRulez[MR_SUIT] < gTime) and AnyServer then
5363 begin
5364 b := g_GetAcidHit(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width, PLAYER_RECT.Height);
5366 if (b > 0) and (gTime mod (15*GAME_TICK) = 0) then Damage(b, 0, 0, 0, HIT_ACID);
5367 end;
5369 if (headwater or blockmon) then
5370 begin
5371 Dec(FAir);
5373 if FAir < -9 then
5374 begin
5375 if AnyServer then Damage(10, 0, 0, 0, HIT_WATER);
5376 FAir := 0;
5377 end
5378 else if (FAir mod 31 = 0) and not blockmon then
5379 begin
5380 g_GFX_Bubbles(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2), FObj.Y+PLAYER_RECT.Y-4, 5+Random(6), 8, 4);
5381 if Random(2) = 0
5382 then g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj.X, FObj.Y)
5383 else g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj.X, FObj.Y);
5384 end;
5385 end else if FAir < AIR_DEF then
5386 FAir := AIR_DEF;
5388 if FFireTime > 0 then
5389 begin
5390 if BodyInLiquid(0, 0) then
5391 begin
5392 FFireTime := 0;
5393 FFirePainTime := 0;
5394 end
5395 else if FMegaRulez[MR_SUIT] >= gTime then
5396 begin
5397 if FMegaRulez[MR_SUIT] = gTime then
5398 FFireTime := 1;
5399 FFirePainTime := 0;
5400 end
5401 else
5402 begin
5403 OnFireFlame(1);
5404 if FFirePainTime <= 0 then
5405 begin
5406 if g_Game_IsServer then
5407 Damage(2, FFireAttacker, 0, 0, HIT_FLAME);
5408 FFirePainTime := 12 - FFireTime div 12;
5409 end;
5410 FFirePainTime := FFirePainTime - 1;
5411 FFireTime := FFireTime - 1;
5412 if ((FFireTime mod 33) = 0) and (FMegaRulez[MR_INVUL] < gTime) then
5413 FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
5414 if (FFireTime = 0) and g_Game_IsNet and g_Game_IsServer then
5415 MH_SEND_PlayerStats(FUID);
5416 end;
5417 end;
5419 if FDamageBuffer > 0 then
5420 begin
5421 if FDamageBuffer >= 9 then
5422 begin
5423 SetAction(A_PAIN);
5425 if FDamageBuffer < 30 then i := 9
5426 else if FDamageBuffer < 100 then i := 18
5427 else i := 27;
5428 end;
5430 ii := Round(FDamageBuffer*FHealth / nonz(FArmor*(3/4)+FHealth));
5431 FArmor := FArmor-(FDamageBuffer-ii);
5432 FHealth := FHealth-ii;
5433 if FArmor < 0 then
5434 begin
5435 FHealth := FHealth+FArmor;
5436 FArmor := 0;
5437 end;
5439 if AnyServer then
5440 if FHealth <= 0 then
5441 if FHealth > -30 then Kill(K_SIMPLEKILL, FLastSpawnerUID, FLastHit)
5442 else if FHealth > -50 then Kill(K_HARDKILL, FLastSpawnerUID, FLastHit)
5443 else Kill(K_EXTRAHARDKILL, FLastSpawnerUID, FLastHit);
5445 if FAlive and ((FLastHit <> HIT_FLAME) or (FFireTime <= 0)) then
5446 begin
5447 if FDamageBuffer <= 20 then FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y)
5448 else if FDamageBuffer <= 55 then FModel.PlaySound(MODELSOUND_PAIN, 2, FObj.X, FObj.Y)
5449 else if FDamageBuffer <= 120 then FModel.PlaySound(MODELSOUND_PAIN, 3, FObj.X, FObj.Y)
5450 else FModel.PlaySound(MODELSOUND_PAIN, 4, FObj.X, FObj.Y);
5451 end;
5453 FDamageBuffer := 0;
5454 end;
5456 {CollideItem();}
5457 end; // if FAlive then ...
5459 if (FActionAnim = A_PAIN) and (FModel.Animation <> A_PAIN) then
5460 begin
5461 FModel.ChangeAnimation(FActionAnim, FActionForce);
5462 FModel.GetCurrentAnimation.MinLength := i;
5463 FModel.GetCurrentAnimationMask.MinLength := i;
5464 end else FModel.ChangeAnimation(FActionAnim, FActionForce and (FModel.Animation <> A_STAND));
5466 if (FModel.GetCurrentAnimation.Played or ((not FActionChanged) and (FModel.Animation = A_WALK)))
5467 then SetAction(A_STAND, True);
5469 if not ((FModel.Animation = A_WALK) and (Abs(FObj.Vel.X) < 4) and not FModel.Fire) then FModel.Update;
5471 for b := Low(FKeys) to High(FKeys) do
5472 if FKeys[b].Time = 0 then FKeys[b].Pressed := False else Dec(FKeys[b].Time);
5473 end;
5476 procedure TPlayer.getMapBox (out x, y, w, h: Integer); inline;
5477 begin
5478 x := FObj.X+PLAYER_RECT.X;
5479 y := FObj.Y+PLAYER_RECT.Y;
5480 w := PLAYER_RECT.Width;
5481 h := PLAYER_RECT.Height;
5482 end;
5485 procedure TPlayer.moveBy (dx, dy: Integer); inline;
5486 begin
5487 if (dx <> 0) or (dy <> 0) then
5488 begin
5489 FObj.X += dx;
5490 FObj.Y += dy;
5491 positionChanged();
5492 end;
5493 end;
5496 function TPlayer.Collide(X, Y: Integer; Width, Height: Word): Boolean;
5497 begin
5498 Result := g_Collide(FObj.X+PLAYER_RECT.X,
5499 FObj.Y+PLAYER_RECT.Y,
5500 PLAYER_RECT.Width,
5501 PLAYER_RECT.Height,
5502 X, Y,
5503 Width, Height);
5504 end;
5506 function TPlayer.Collide(Panel: TPanel): Boolean;
5507 begin
5508 Result := g_Collide(FObj.X+PLAYER_RECT.X,
5509 FObj.Y+PLAYER_RECT.Y,
5510 PLAYER_RECT.Width,
5511 PLAYER_RECT.Height,
5512 Panel.X, Panel.Y,
5513 Panel.Width, Panel.Height);
5514 end;
5516 function TPlayer.Collide(X, Y: Integer): Boolean;
5517 begin
5518 X := X-FObj.X-PLAYER_RECT.X;
5519 Y := Y-FObj.Y-PLAYER_RECT.Y;
5520 Result := (x >= 0) and (x <= PLAYER_RECT.Width) and
5521 (y >= 0) and (y <= PLAYER_RECT.Height);
5522 end;
5524 function g_Player_ValidName(Name: string): Boolean;
5525 var
5526 a: Integer;
5527 begin
5528 Result := True;
5530 if gPlayers = nil then Exit;
5532 for a := 0 to High(gPlayers) do
5533 if gPlayers[a] <> nil then
5534 if LowerCase(Name) = LowerCase(gPlayers[a].FName) then
5535 begin
5536 Result := False;
5537 Exit;
5538 end;
5539 end;
5541 procedure TPlayer.SetDirection(Direction: TDirection);
5542 var
5543 d: TDirection;
5544 begin
5545 d := FModel.Direction;
5547 FModel.Direction := Direction;
5548 if d <> Direction then FModel.ChangeAnimation(FModel.Animation, True);
5550 FDirection := Direction;
5551 end;
5553 function TPlayer.GetKeys(): Byte;
5554 begin
5555 Result := 0;
5557 if R_KEY_RED in FRulez then Result := KEY_RED;
5558 if R_KEY_GREEN in FRulez then Result := Result or KEY_GREEN;
5559 if R_KEY_BLUE in FRulez then Result := Result or KEY_BLUE;
5561 if FTeam = TEAM_RED then Result := Result or KEY_REDTEAM;
5562 if FTeam = TEAM_BLUE then Result := Result or KEY_BLUETEAM;
5563 end;
5565 procedure TPlayer.Use();
5566 var
5567 a: Integer;
5568 begin
5569 if FTime[T_USE] > gTime then Exit;
5571 g_Triggers_PressR(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
5572 PLAYER_RECT.Height, FUID, ACTIVATE_PLAYERPRESS);
5574 for a := 0 to High(gPlayers) do
5575 if (gPlayers[a] <> nil) and (gPlayers[a] <> Self) and
5576 gPlayers[a].alive and SameTeam(FUID, gPlayers[a].FUID) and
5577 g_Obj_Collide(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y,
5578 FObj.Rect.Width, FObj.Rect.Height, @gPlayers[a].FObj) then
5579 begin
5580 gPlayers[a].Touch();
5581 if g_Game_IsNet and g_Game_IsServer then
5582 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH, gPlayers[a].FUID);
5583 end;
5585 FTime[T_USE] := gTime+120;
5586 end;
5588 procedure TPlayer.NetFire(Wpn: Byte; X, Y, AX, AY: Integer; WID: Integer = -1);
5589 var
5590 locObj: TObj;
5591 visible: Boolean = True;
5592 WX, WY, XD, YD: Integer;
5593 begin
5594 WX := X;
5595 WY := Y;
5596 XD := AX;
5597 YD := AY;
5599 case FCurrWeap of
5600 WEAPON_KASTET:
5601 begin
5602 visible := False;
5603 DoPunch();
5604 if R_BERSERK in FRulez then
5605 begin
5606 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5607 locobj.X := FObj.X+FObj.Rect.X;
5608 locobj.Y := FObj.Y+FObj.Rect.Y;
5609 locobj.rect.X := 0;
5610 locobj.rect.Y := 0;
5611 locobj.rect.Width := 39;
5612 locobj.rect.Height := 52;
5613 locobj.Vel.X := (xd-wx) div 2;
5614 locobj.Vel.Y := (yd-wy) div 2;
5615 locobj.Accel.X := xd-wx;
5616 locobj.Accel.y := yd-wy;
5618 if g_Weapon_Hit(@locobj, 50, FUID, HIT_SOME) <> 0 then
5619 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj.X, FObj.Y)
5620 else
5621 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj.X, FObj.Y);
5623 if gFlash = 1 then
5624 if FPain < 50 then
5625 FPain := min(FPain + 25, 50);
5626 end else
5627 g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 3, FUID);
5628 end;
5630 WEAPON_SAW:
5631 begin
5632 if g_Weapon_chainsaw(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y,
5633 IfThen(gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF], 9, 3), FUID) <> 0 then
5634 begin
5635 FSawSoundSelect.Stop();
5636 FSawSound.Stop();
5637 FSawSoundHit.PlayAt(FObj.X, FObj.Y);
5638 end
5639 else if not FSawSoundHit.IsPlaying() then
5640 begin
5641 FSawSoundSelect.Stop();
5642 FSawSound.PlayAt(FObj.X, FObj.Y);
5643 end;
5644 end;
5646 WEAPON_PISTOL:
5647 begin
5648 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX, Gamey);
5649 FFireAngle := FAngle;
5650 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
5651 GameVelX, GameVelY-2, SHELL_BULLET);
5652 end;
5654 WEAPON_SHOTGUN1:
5655 begin
5656 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex, Gamey);
5657 FFireAngle := FAngle;
5658 FShellTimer := 10;
5659 FShellType := SHELL_SHELL;
5660 end;
5662 WEAPON_SHOTGUN2:
5663 begin
5664 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex, Gamey);
5665 FFireAngle := FAngle;
5666 FShellTimer := 13;
5667 FShellType := SHELL_DBLSHELL;
5668 end;
5670 WEAPON_CHAINGUN:
5671 begin
5672 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex, Gamey);
5673 FFireAngle := FAngle;
5674 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
5675 GameVelX, GameVelY-2, SHELL_BULLET);
5676 end;
5678 WEAPON_ROCKETLAUNCHER:
5679 begin
5680 g_Weapon_Rocket(wx, wy, xd, yd, FUID, WID);
5681 FFireAngle := FAngle;
5682 end;
5684 WEAPON_PLASMA:
5685 begin
5686 g_Weapon_Plasma(wx, wy, xd, yd, FUID, WID);
5687 FFireAngle := FAngle;
5688 end;
5690 WEAPON_BFG:
5691 begin
5692 g_Weapon_BFGShot(wx, wy, xd, yd, FUID, WID);
5693 FFireAngle := FAngle;
5694 end;
5696 WEAPON_SUPERPULEMET:
5697 begin
5698 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex, Gamey);
5699 FFireAngle := FAngle;
5700 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
5701 GameVelX, GameVelY-2, SHELL_SHELL);
5702 end;
5704 WEAPON_FLAMETHROWER:
5705 begin
5706 g_Weapon_flame(wx, wy, xd, yd, FUID, WID);
5707 FlamerOn;
5708 FFireAngle := FAngle;
5709 end;
5710 end;
5712 if not visible then Exit;
5714 if (FAngle = 0) or (FAngle = 180) then SetAction(A_ATTACK)
5715 else if (FAngle = ANGLE_LEFTDOWN) or (FAngle = ANGLE_RIGHTDOWN) then SetAction(A_ATTACKDOWN)
5716 else if (FAngle = ANGLE_LEFTUP) or (FAngle = ANGLE_RIGHTUP) then SetAction(A_ATTACKUP);
5717 end;
5719 procedure TPlayer.DoLerp(Level: Integer = 2);
5720 begin
5721 if FObj.X <> FXTo then FObj.X := Lerp(FObj.X, FXTo, Level);
5722 if FObj.Y <> FYTo then FObj.Y := Lerp(FObj.Y, FYTo, Level);
5723 end;
5725 procedure TPlayer.SetLerp(XTo, YTo: Integer);
5726 var
5727 AX, AY: Integer;
5728 begin
5729 FXTo := XTo;
5730 FYTo := YTo;
5731 if FJustTeleported or (NetInterpLevel < 1) then
5732 begin
5733 FObj.X := XTo;
5734 FObj.Y := YTo;
5735 if FJustTeleported then
5736 begin
5737 FObj.oldX := FObj.X;
5738 FObj.oldY := FObj.Y;
5739 end;
5740 end
5741 else
5742 begin
5743 AX := Abs(FXTo - FObj.X);
5744 AY := Abs(FYTo - FObj.Y);
5745 if (AX > 32) or (AX <= NetInterpLevel) then
5746 FObj.X := FXTo;
5747 if (AY > 32) or (AY <= NetInterpLevel) then
5748 FObj.Y := FYTo;
5749 end;
5750 end;
5752 function TPlayer.FullInLift(XInc, YInc: Integer): Integer;
5753 begin
5754 if g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc,
5755 PLAYER_RECT.Width, PLAYER_RECT.Height-8,
5756 PANEL_LIFTUP, False) then Result := -1
5757 else
5758 if g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc,
5759 PLAYER_RECT.Width, PLAYER_RECT.Height-8,
5760 PANEL_LIFTDOWN, False) then Result := 1
5761 else Result := 0;
5762 end;
5764 function TPlayer.GetFlag(Flag: Byte): Boolean;
5765 var
5766 s, ts: String;
5767 evtype, a: Byte;
5768 begin
5769 Result := False;
5771 if Flag = FLAG_NONE then
5772 Exit;
5774 if not g_Game_IsServer then Exit;
5776 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5777 if (Flag = FTeam) and
5778 (gFlags[Flag].State = FLAG_STATE_NORMAL) and
5779 (FFlag <> FLAG_NONE) then
5780 begin
5781 if FFlag = FLAG_RED then
5782 s := _lc[I_PLAYER_FLAG_RED]
5783 else
5784 s := _lc[I_PLAYER_FLAG_BLUE];
5786 evtype := FLAG_STATE_SCORED;
5788 ts := Format('%.4d', [gFlags[FFlag].CaptureTime]);
5789 Insert('.', ts, Length(ts) + 1 - 3);
5790 g_Console_Add(Format(_lc[I_PLAYER_FLAG_CAPTURE], [FName, s, ts]), True);
5792 g_Map_ResetFlag(FFlag);
5793 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_CAPTURE], [AnsiUpperCase(s)]), 144);
5795 if ((Self = gPlayer1) or (Self = gPlayer2)
5796 or ((gPlayer1 <> nil) and (gPlayer1.Team = FTeam))
5797 or ((gPlayer2 <> nil) and (gPlayer2.Team = FTeam))) then
5798 a := 0
5799 else
5800 a := 1;
5802 if not sound_cap_flag[a].IsPlaying() then
5803 sound_cap_flag[a].Play();
5805 gTeamStat[FTeam].Goals := gTeamStat[FTeam].Goals + 1;
5807 Result := True;
5808 if g_Game_IsNet then
5809 begin
5810 MH_SEND_FlagEvent(evtype, FFlag, FUID, False);
5811 MH_SEND_GameStats;
5812 end;
5814 gFlags[FFlag].CaptureTime := 0;
5815 SetFlag(FLAG_NONE);
5816 Exit;
5817 end;
5819 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5820 if (Flag = FTeam) and
5821 (gFlags[Flag].State = FLAG_STATE_DROPPED) then
5822 begin
5823 if Flag = FLAG_RED then
5824 s := _lc[I_PLAYER_FLAG_RED]
5825 else
5826 s := _lc[I_PLAYER_FLAG_BLUE];
5828 evtype := FLAG_STATE_RETURNED;
5829 gFlags[Flag].CaptureTime := 0;
5831 g_Console_Add(Format(_lc[I_PLAYER_FLAG_RETURN], [FName, s]), True);
5833 g_Map_ResetFlag(Flag);
5834 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_RETURN], [AnsiUpperCase(s)]), 144);
5836 if ((Self = gPlayer1) or (Self = gPlayer2)
5837 or ((gPlayer1 <> nil) and (gPlayer1.Team = FTeam))
5838 or ((gPlayer2 <> nil) and (gPlayer2.Team = FTeam))) then
5839 a := 0
5840 else
5841 a := 1;
5843 if not sound_ret_flag[a].IsPlaying() then
5844 sound_ret_flag[a].Play();
5846 Result := True;
5847 if g_Game_IsNet then
5848 begin
5849 MH_SEND_FlagEvent(evtype, Flag, FUID, False);
5850 MH_SEND_GameStats;
5851 end;
5852 Exit;
5853 end;
5855 // Ïîäîáðàë ÷óæîé ôëàã:
5856 if (Flag <> FTeam) and (FTime[T_FLAGCAP] <= gTime) then
5857 begin
5858 SetFlag(Flag);
5860 if Flag = FLAG_RED then
5861 s := _lc[I_PLAYER_FLAG_RED]
5862 else
5863 s := _lc[I_PLAYER_FLAG_BLUE];
5865 evtype := FLAG_STATE_CAPTURED;
5867 g_Console_Add(Format(_lc[I_PLAYER_FLAG_GET], [FName, s]), True);
5869 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_GET], [AnsiUpperCase(s)]), 144);
5871 gFlags[Flag].State := FLAG_STATE_CAPTURED;
5873 if ((Self = gPlayer1) or (Self = gPlayer2)
5874 or ((gPlayer1 <> nil) and (gPlayer1.Team = FTeam))
5875 or ((gPlayer2 <> nil) and (gPlayer2.Team = FTeam))) then
5876 a := 0
5877 else
5878 a := 1;
5880 if not sound_get_flag[a].IsPlaying() then
5881 sound_get_flag[a].Play();
5883 Result := True;
5884 if g_Game_IsNet then
5885 begin
5886 MH_SEND_FlagEvent(evtype, Flag, FUID, False);
5887 MH_SEND_GameStats;
5888 end;
5889 end;
5890 end;
5892 procedure TPlayer.SetFlag(Flag: Byte);
5893 begin
5894 FFlag := Flag;
5895 if FModel <> nil then
5896 FModel.SetFlag(FFlag);
5897 end;
5899 function TPlayer.TryDropFlag(): Boolean;
5900 begin
5901 if LongBool(gGameSettings.Options and GAME_OPTION_ALLOWDROPFLAG) then
5902 Result := DropFlag(False, LongBool(gGameSettings.Options and GAME_OPTION_THROWFLAG))
5903 else
5904 Result := False;
5905 end;
5907 function TPlayer.DropFlag(Silent: Boolean = True; DoThrow: Boolean = False): Boolean;
5908 var
5909 s: String;
5910 a: Byte;
5911 xv, yv: Integer;
5912 begin
5913 Result := False;
5914 if (not g_Game_IsServer) or (FFlag = FLAG_NONE) then
5915 Exit;
5916 FTime[T_FLAGCAP] := gTime + 2000;
5917 with gFlags[FFlag] do
5918 begin
5919 Obj.X := FObj.X;
5920 Obj.Y := FObj.Y;
5921 Direction := FDirection;
5922 State := FLAG_STATE_DROPPED;
5923 Count := FLAG_TIME;
5924 if DoThrow then
5925 begin
5926 xv := FObj.Vel.X + IfThen(Direction = TDirection.D_RIGHT, 10, -10);
5927 yv := FObj.Vel.Y - 2;
5928 end
5929 else
5930 begin
5931 xv := (FObj.Vel.X div 2);
5932 yv := (FObj.Vel.Y div 2) - 2;
5933 end;
5934 g_Obj_Push(@Obj, xv, yv);
5936 positionChanged(); // this updates spatial accelerators
5938 if FFlag = FLAG_RED then
5939 s := _lc[I_PLAYER_FLAG_RED]
5940 else
5941 s := _lc[I_PLAYER_FLAG_BLUE];
5943 g_Console_Add(Format(_lc[I_PLAYER_FLAG_DROP], [FName, s]), True);
5944 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_DROP], [AnsiUpperCase(s)]), 144);
5946 if ((Self = gPlayer1) or (Self = gPlayer2)
5947 or ((gPlayer1 <> nil) and (gPlayer1.Team = FTeam))
5948 or ((gPlayer2 <> nil) and (gPlayer2.Team = FTeam))) then
5949 a := 0
5950 else
5951 a := 1;
5953 if (not Silent) and (not sound_lost_flag[a].IsPlaying()) then
5954 sound_lost_flag[a].Play();
5956 if g_Game_IsNet then
5957 MH_SEND_FlagEvent(FLAG_STATE_DROPPED, Flag, FUID, False);
5958 end;
5959 SetFlag(FLAG_NONE);
5960 Result := True;
5961 end;
5963 procedure TPlayer.GetSecret();
5964 begin
5965 if (self = gPlayer1) or (self = gPlayer2) then
5966 begin
5967 g_Console_Add(Format(_lc[I_PLAYER_SECRET], [FName]), True);
5968 g_Sound_PlayEx('SOUND_GAME_SECRET');
5969 end;
5970 Inc(FSecrets);
5971 end;
5973 procedure TPlayer.PressKey(Key: Byte; Time: Word = 1);
5974 begin
5975 Assert(Key <= High(FKeys));
5977 FKeys[Key].Pressed := True;
5978 FKeys[Key].Time := Time;
5979 end;
5981 function TPlayer.IsKeyPressed(K: Byte): Boolean;
5982 begin
5983 Result := FKeys[K].Pressed;
5984 end;
5986 procedure TPlayer.ReleaseKeys();
5987 var
5988 a: Integer;
5989 begin
5990 for a := Low(FKeys) to High(FKeys) do
5991 begin
5992 FKeys[a].Pressed := False;
5993 FKeys[a].Time := 0;
5994 end;
5995 end;
5997 procedure TPlayer.OnDamage(Angle: SmallInt);
5998 begin
5999 end;
6001 function TPlayer.firediry(): Integer;
6002 begin
6003 if FKeys[KEY_UP].Pressed then Result := -42
6004 else if FKeys[KEY_DOWN].Pressed then Result := 19
6005 else Result := 0;
6006 end;
6008 procedure TPlayer.RememberState();
6009 var
6010 i: Integer;
6011 SavedState: TPlayerSavedState;
6012 begin
6013 SavedState.Health := FHealth;
6014 SavedState.Armor := FArmor;
6015 SavedState.Air := FAir;
6016 SavedState.JetFuel := FJetFuel;
6017 SavedState.CurrWeap := FCurrWeap;
6018 SavedState.NextWeap := FNextWeap;
6019 SavedState.NextWeapDelay := FNextWeapDelay;
6020 for i := Low(FWeapon) to High(FWeapon) do
6021 SavedState.Weapon[i] := FWeapon[i];
6022 for i := Low(FAmmo) to High(FAmmo) do
6023 SavedState.Ammo[i] := FAmmo[i];
6024 for i := Low(FMaxAmmo) to High(FMaxAmmo) do
6025 SavedState.MaxAmmo[i] := FMaxAmmo[i];
6026 SavedState.Rulez := FRulez - [R_KEY_RED, R_KEY_GREEN, R_KEY_BLUE];
6028 FSavedStateNum := -1;
6029 for i := Low(SavedStates) to High(SavedStates) do
6030 if not SavedStates[i].Used then
6031 begin
6032 FSavedStateNum := i;
6033 break;
6034 end;
6035 if FSavedStateNum < 0 then
6036 begin
6037 SetLength(SavedStates, Length(SavedStates) + 1);
6038 FSavedStateNum := High(SavedStates);
6039 end;
6041 SavedState.Used := True;
6042 SavedStates[FSavedStateNum] := SavedState;
6043 end;
6045 procedure TPlayer.RecallState();
6046 var
6047 i: Integer;
6048 SavedState: TPlayerSavedState;
6049 begin
6050 if(FSavedStateNum < 0) or (FSavedStateNum > High(SavedStates)) then
6051 Exit;
6053 SavedState := SavedStates[FSavedStateNum];
6054 SavedStates[FSavedStateNum].Used := False;
6055 FSavedStateNum := -1;
6057 FHealth := SavedState.Health;
6058 FArmor := SavedState.Armor;
6059 FAir := SavedState.Air;
6060 FJetFuel := SavedState.JetFuel;
6061 FCurrWeap := SavedState.CurrWeap;
6062 FNextWeap := SavedState.NextWeap;
6063 FNextWeapDelay := SavedState.NextWeapDelay;
6064 for i := Low(FWeapon) to High(FWeapon) do
6065 FWeapon[i] := SavedState.Weapon[i];
6066 for i := Low(FAmmo) to High(FAmmo) do
6067 FAmmo[i] := SavedState.Ammo[i];
6068 for i := Low(FMaxAmmo) to High(FMaxAmmo) do
6069 FMaxAmmo[i] := SavedState.MaxAmmo[i];
6070 FRulez := SavedState.Rulez;
6072 if gGameSettings.GameType = GT_SERVER then
6073 MH_SEND_PlayerStats(FUID);
6074 end;
6076 procedure TPlayer.SaveState (st: TStream);
6077 var
6078 i: Integer;
6079 b: Byte;
6080 begin
6081 // Ñèãíàòóðà èãðîêà
6082 utils.writeSign(st, 'PLYR');
6083 utils.writeInt(st, Byte(PLR_SAVE_VERSION)); // version
6084 // Áîò èëè ÷åëîâåê
6085 utils.writeBool(st, FIamBot);
6086 // UID èãðîêà
6087 utils.writeInt(st, Word(FUID));
6088 // Èìÿ èãðîêà
6089 utils.writeStr(st, FName);
6090 // Êîìàíäà
6091 utils.writeInt(st, Byte(FTeam));
6092 // Æèâ ëè
6093 utils.writeBool(st, FAlive);
6094 // Èçðàñõîäîâàë ëè âñå æèçíè
6095 utils.writeBool(st, FNoRespawn);
6096 // Íàïðàâëåíèå
6097 if FDirection = TDirection.D_LEFT then b := 1 else b := 2; // D_RIGHT
6098 utils.writeInt(st, Byte(b));
6099 // Çäîðîâüå
6100 utils.writeInt(st, LongInt(FHealth));
6101 // Êîýôôèöèåíò èíâàëèäíîñòè
6102 utils.writeInt(st, LongInt(FHandicap));
6103 // Æèçíè
6104 utils.writeInt(st, Byte(FLives));
6105 // Áðîíÿ
6106 utils.writeInt(st, LongInt(FArmor));
6107 // Çàïàñ âîçäóõà
6108 utils.writeInt(st, LongInt(FAir));
6109 // Çàïàñ ãîðþ÷åãî
6110 utils.writeInt(st, LongInt(FJetFuel));
6111 // Áîëü
6112 utils.writeInt(st, LongInt(FPain));
6113 // Óáèë
6114 utils.writeInt(st, LongInt(FKills));
6115 // Óáèë ìîíñòðîâ
6116 utils.writeInt(st, LongInt(FMonsterKills));
6117 // Ôðàãîâ
6118 utils.writeInt(st, LongInt(FFrags));
6119 // Ôðàãîâ ïîäðÿä
6120 utils.writeInt(st, Byte(FFragCombo));
6121 // Âðåìÿ ïîñëåäíåãî ôðàãà
6122 utils.writeInt(st, LongWord(FLastFrag));
6123 // Ñìåðòåé
6124 utils.writeInt(st, LongInt(FDeath));
6125 // Êàêîé ôëàã íåñåò
6126 utils.writeInt(st, Byte(FFlag));
6127 // Íàøåë ñåêðåòîâ
6128 utils.writeInt(st, LongInt(FSecrets));
6129 // Òåêóùåå îðóæèå
6130 utils.writeInt(st, Byte(FCurrWeap));
6131 // Æåëàåìîå îðóæèå
6132 utils.writeInt(st, Word(FNextWeap));
6133 // ...è ïàóçà
6134 utils.writeInt(st, Byte(FNextWeapDelay));
6135 // Âðåìÿ çàðÿäêè BFG
6136 utils.writeInt(st, SmallInt(FBFGFireCounter));
6137 // Áóôåð óðîíà
6138 utils.writeInt(st, LongInt(FDamageBuffer));
6139 // Ïîñëåäíèé óäàðèâøèé
6140 utils.writeInt(st, Word(FLastSpawnerUID));
6141 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6142 utils.writeInt(st, Byte(FLastHit));
6143 // Îáúåêò èãðîêà
6144 Obj_SaveState(st, @FObj);
6145 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6146 for i := A_BULLETS to A_HIGH do utils.writeInt(st, Word(FAmmo[i]));
6147 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6148 for i := A_BULLETS to A_HIGH do utils.writeInt(st, Word(FMaxAmmo[i]));
6149 // Íàëè÷èå îðóæèÿ
6150 for i := WP_FIRST to WP_LAST do utils.writeBool(st, FWeapon[i]);
6151 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6152 for i := WP_FIRST to WP_LAST do utils.writeInt(st, Word(FReloading[i]));
6153 // Íàëè÷èå ðþêçàêà
6154 utils.writeBool(st, (R_ITEM_BACKPACK in FRulez));
6155 // Íàëè÷èå êðàñíîãî êëþ÷à
6156 utils.writeBool(st, (R_KEY_RED in FRulez));
6157 // Íàëè÷èå çåëåíîãî êëþ÷à
6158 utils.writeBool(st, (R_KEY_GREEN in FRulez));
6159 // Íàëè÷èå ñèíåãî êëþ÷à
6160 utils.writeBool(st, (R_KEY_BLUE in FRulez));
6161 // Íàëè÷èå áåðñåðêà
6162 utils.writeBool(st, (R_BERSERK in FRulez));
6163 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6164 for i := MR_SUIT to MR_MAX do utils.writeInt(st, LongWord(FMegaRulez[i]));
6165 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6166 for i := T_RESPAWN to T_FLAGCAP do utils.writeInt(st, LongWord(FTime[i]));
6167 // Íàçâàíèå ìîäåëè
6168 utils.writeStr(st, FModel.Name);
6169 // Öâåò ìîäåëè
6170 utils.writeInt(st, Byte(FColor.R));
6171 utils.writeInt(st, Byte(FColor.G));
6172 utils.writeInt(st, Byte(FColor.B));
6173 end;
6176 procedure TPlayer.LoadState (st: TStream);
6177 var
6178 i: Integer;
6179 str: String;
6180 b: Byte;
6181 begin
6182 assert(st <> nil);
6184 // Ñèãíàòóðà èãðîêà
6185 if not utils.checkSign(st, 'PLYR') then raise XStreamError.Create('invalid player signature');
6186 if (utils.readByte(st) <> PLR_SAVE_VERSION) then raise XStreamError.Create('invalid player version');
6187 // Áîò èëè ÷åëîâåê:
6188 FIamBot := utils.readBool(st);
6189 // UID èãðîêà
6190 FUID := utils.readWord(st);
6191 // Èìÿ èãðîêà
6192 str := utils.readStr(st);
6193 if (self <> gPlayer1) and (self <> gPlayer2) then FName := str;
6194 // Êîìàíäà
6195 FTeam := utils.readByte(st);
6196 // Æèâ ëè
6197 FAlive := utils.readBool(st);
6198 // Èçðàñõîäîâàë ëè âñå æèçíè
6199 FNoRespawn := utils.readBool(st);
6200 // Íàïðàâëåíèå
6201 b := utils.readByte(st);
6202 if b = 1 then FDirection := TDirection.D_LEFT else FDirection := TDirection.D_RIGHT; // b = 2
6203 // Çäîðîâüå
6204 FHealth := utils.readLongInt(st);
6205 // Êîýôôèöèåíò èíâàëèäíîñòè
6206 FHandicap := utils.readLongInt(st);
6207 // Æèçíè
6208 FLives := utils.readByte(st);
6209 // Áðîíÿ
6210 FArmor := utils.readLongInt(st);
6211 // Çàïàñ âîçäóõà
6212 FAir := utils.readLongInt(st);
6213 // Çàïàñ ãîðþ÷åãî
6214 FJetFuel := utils.readLongInt(st);
6215 // Áîëü
6216 FPain := utils.readLongInt(st);
6217 // Óáèë
6218 FKills := utils.readLongInt(st);
6219 // Óáèë ìîíñòðîâ
6220 FMonsterKills := utils.readLongInt(st);
6221 // Ôðàãîâ
6222 FFrags := utils.readLongInt(st);
6223 // Ôðàãîâ ïîäðÿä
6224 FFragCombo := utils.readByte(st);
6225 // Âðåìÿ ïîñëåäíåãî ôðàãà
6226 FLastFrag := utils.readLongWord(st);
6227 // Ñìåðòåé
6228 FDeath := utils.readLongInt(st);
6229 // Êàêîé ôëàã íåñåò
6230 FFlag := utils.readByte(st);
6231 // Íàøåë ñåêðåòîâ
6232 FSecrets := utils.readLongInt(st);
6233 // Òåêóùåå îðóæèå
6234 FCurrWeap := utils.readByte(st);
6235 // Æåëàåìîå îðóæèå
6236 FNextWeap := utils.readWord(st);
6237 // ...è ïàóçà
6238 FNextWeapDelay := utils.readByte(st);
6239 // Âðåìÿ çàðÿäêè BFG
6240 FBFGFireCounter := utils.readSmallInt(st);
6241 // Áóôåð óðîíà
6242 FDamageBuffer := utils.readLongInt(st);
6243 // Ïîñëåäíèé óäàðèâøèé
6244 FLastSpawnerUID := utils.readWord(st);
6245 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6246 FLastHit := utils.readByte(st);
6247 // Îáúåêò èãðîêà
6248 Obj_LoadState(@FObj, st);
6249 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6250 for i := A_BULLETS to A_HIGH do FAmmo[i] := utils.readWord(st);
6251 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6252 for i := A_BULLETS to A_HIGH do FMaxAmmo[i] := utils.readWord(st);
6253 // Íàëè÷èå îðóæèÿ
6254 for i := WP_FIRST to WP_LAST do FWeapon[i] := utils.readBool(st);
6255 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6256 for i := WP_FIRST to WP_LAST do FReloading[i] := utils.readWord(st);
6257 // Íàëè÷èå ðþêçàêà
6258 if utils.readBool(st) then Include(FRulez, R_ITEM_BACKPACK);
6259 // Íàëè÷èå êðàñíîãî êëþ÷à
6260 if utils.readBool(st) then Include(FRulez, R_KEY_RED);
6261 // Íàëè÷èå çåëåíîãî êëþ÷à
6262 if utils.readBool(st) then Include(FRulez, R_KEY_GREEN);
6263 // Íàëè÷èå ñèíåãî êëþ÷à
6264 if utils.readBool(st) then Include(FRulez, R_KEY_BLUE);
6265 // Íàëè÷èå áåðñåðêà
6266 if utils.readBool(st) then Include(FRulez, R_BERSERK);
6267 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6268 for i := MR_SUIT to MR_MAX do FMegaRulez[i] := utils.readLongWord(st);
6269 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6270 for i := T_RESPAWN to T_FLAGCAP do FTime[i] := utils.readLongWord(st);
6271 // Íàçâàíèå ìîäåëè
6272 str := utils.readStr(st);
6273 // Öâåò ìîäåëè
6274 FColor.R := utils.readByte(st);
6275 FColor.G := utils.readByte(st);
6276 FColor.B := utils.readByte(st);
6277 if (self = gPlayer1) then
6278 begin
6279 str := gPlayer1Settings.Model;
6280 FColor := gPlayer1Settings.Color;
6281 end
6282 else if (self = gPlayer2) then
6283 begin
6284 str := gPlayer2Settings.Model;
6285 FColor := gPlayer2Settings.Color;
6286 end;
6287 // Îáíîâëÿåì ìîäåëü èãðîêà
6288 SetModel(str);
6289 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
6290 FModel.Color := TEAMCOLOR[FTeam]
6291 else
6292 FModel.Color := FColor;
6293 end;
6296 procedure TPlayer.AllRulez(Health: Boolean);
6297 var
6298 a: Integer;
6299 begin
6300 if Health then
6301 begin
6302 FHealth := PLAYER_HP_LIMIT;
6303 FArmor := PLAYER_AP_LIMIT;
6304 Exit;
6305 end;
6307 for a := WP_FIRST to WP_LAST do FWeapon[a] := True;
6308 for a := A_BULLETS to A_HIGH do FAmmo[a] := 30000;
6309 FRulez := FRulez+[R_KEY_RED, R_KEY_GREEN, R_KEY_BLUE];
6310 end;
6312 procedure TPlayer.RestoreHealthArmor();
6313 begin
6314 FHealth := PLAYER_HP_LIMIT;
6315 FArmor := PLAYER_AP_LIMIT;
6316 end;
6318 procedure TPlayer.FragCombo();
6319 var
6320 Param: Integer;
6321 begin
6322 if (gGameSettings.GameMode in [GM_COOP, GM_SINGLE]) or g_Game_IsClient then
6323 Exit;
6324 if gTime - FLastFrag < FRAG_COMBO_TIME then
6325 begin
6326 if FFragCombo < 5 then
6327 Inc(FFragCombo);
6328 Param := FUID or (FFragCombo shl 16);
6329 if (FComboEvnt >= Low(gDelayedEvents)) and
6330 (FComboEvnt <= High(gDelayedEvents)) and
6331 gDelayedEvents[FComboEvnt].Pending and
6332 (gDelayedEvents[FComboEvnt].DEType = DE_KILLCOMBO) and
6333 (gDelayedEvents[FComboEvnt].DENum and $FFFF = FUID) then
6334 begin
6335 gDelayedEvents[FComboEvnt].Time := gTime + 500;
6336 gDelayedEvents[FComboEvnt].DENum := Param;
6337 end
6338 else
6339 FComboEvnt := g_Game_DelayEvent(DE_KILLCOMBO, 500, Param);
6340 end
6341 else
6342 FFragCombo := 1;
6344 FLastFrag := gTime;
6345 end;
6347 procedure TPlayer.GiveItem(ItemType: Byte);
6348 begin
6349 case ItemType of
6350 ITEM_SUIT:
6351 if FMegaRulez[MR_SUIT] < gTime+PLAYER_SUIT_TIME then
6352 begin
6353 FMegaRulez[MR_SUIT] := gTime+PLAYER_SUIT_TIME;
6354 end;
6356 ITEM_OXYGEN:
6357 if FAir < AIR_MAX then
6358 begin
6359 FAir := AIR_MAX;
6360 end;
6362 ITEM_MEDKIT_BLACK:
6363 begin
6364 if not (R_BERSERK in FRulez) then
6365 begin
6366 Include(FRulez, R_BERSERK);
6367 if FBFGFireCounter < 1 then
6368 begin
6369 FCurrWeap := WEAPON_KASTET;
6370 resetWeaponQueue();
6371 FModel.SetWeapon(WEAPON_KASTET);
6372 end;
6373 if gFlash <> 0 then
6374 Inc(FPain, 100);
6375 FBerserk := gTime+30000;
6376 end;
6377 if FHealth < PLAYER_HP_SOFT then
6378 begin
6379 FHealth := PLAYER_HP_SOFT;
6380 FBerserk := gTime+30000;
6381 end;
6382 end;
6384 ITEM_INVUL:
6385 if FMegaRulez[MR_INVUL] < gTime+PLAYER_INVUL_TIME then
6386 begin
6387 FMegaRulez[MR_INVUL] := gTime+PLAYER_INVUL_TIME;
6388 FSpawnInvul := 0;
6389 end;
6391 ITEM_INVIS:
6392 if FMegaRulez[MR_INVIS] < gTime+PLAYER_INVIS_TIME then
6393 begin
6394 FMegaRulez[MR_INVIS] := gTime+PLAYER_INVIS_TIME;
6395 end;
6397 ITEM_JETPACK:
6398 if FJetFuel < JET_MAX then
6399 begin
6400 FJetFuel := JET_MAX;
6401 end;
6403 ITEM_MEDKIT_SMALL: if FHealth < PLAYER_HP_SOFT then IncMax(FHealth, 10, PLAYER_HP_SOFT);
6404 ITEM_MEDKIT_LARGE: if FHealth < PLAYER_HP_SOFT then IncMax(FHealth, 25, PLAYER_HP_SOFT);
6406 ITEM_ARMOR_GREEN: if FArmor < PLAYER_AP_SOFT then FArmor := PLAYER_AP_SOFT;
6407 ITEM_ARMOR_BLUE: if FArmor < PLAYER_AP_LIMIT then FArmor := PLAYER_AP_LIMIT;
6409 ITEM_SPHERE_BLUE: if FHealth < PLAYER_HP_LIMIT then IncMax(FHealth, 100, PLAYER_HP_LIMIT);
6410 ITEM_SPHERE_WHITE:
6411 if (FHealth < PLAYER_HP_LIMIT) or (FArmor < PLAYER_AP_LIMIT) then
6412 begin
6413 if FHealth < PLAYER_HP_LIMIT then FHealth := PLAYER_HP_LIMIT;
6414 if FArmor < PLAYER_AP_LIMIT then FArmor := PLAYER_AP_LIMIT;
6415 end;
6417 ITEM_WEAPON_SAW: FWeapon[WEAPON_SAW] := True;
6418 ITEM_WEAPON_SHOTGUN1: FWeapon[WEAPON_SHOTGUN1] := True;
6419 ITEM_WEAPON_SHOTGUN2: FWeapon[WEAPON_SHOTGUN2] := True;
6420 ITEM_WEAPON_CHAINGUN: FWeapon[WEAPON_CHAINGUN] := True;
6421 ITEM_WEAPON_ROCKETLAUNCHER: FWeapon[WEAPON_ROCKETLAUNCHER] := True;
6422 ITEM_WEAPON_PLASMA: FWeapon[WEAPON_PLASMA] := True;
6423 ITEM_WEAPON_BFG: FWeapon[WEAPON_BFG] := True;
6424 ITEM_WEAPON_SUPERPULEMET: FWeapon[WEAPON_SUPERPULEMET] := True;
6425 ITEM_WEAPON_FLAMETHROWER: FWeapon[WEAPON_FLAMETHROWER] := True;
6427 ITEM_AMMO_BULLETS: if FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS] then IncMax(FAmmo[A_BULLETS], 10, FMaxAmmo[A_BULLETS]);
6428 ITEM_AMMO_BULLETS_BOX: if FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS] then IncMax(FAmmo[A_BULLETS], 50, FMaxAmmo[A_BULLETS]);
6429 ITEM_AMMO_SHELLS: if FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS] then IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
6430 ITEM_AMMO_SHELLS_BOX: if FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS] then IncMax(FAmmo[A_SHELLS], 25, FMaxAmmo[A_SHELLS]);
6431 ITEM_AMMO_ROCKET: if FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS] then IncMax(FAmmo[A_ROCKETS], 1, FMaxAmmo[A_ROCKETS]);
6432 ITEM_AMMO_ROCKET_BOX: if FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS] then IncMax(FAmmo[A_ROCKETS], 5, FMaxAmmo[A_ROCKETS]);
6433 ITEM_AMMO_CELL: if FAmmo[A_CELLS] < FMaxAmmo[A_CELLS] then IncMax(FAmmo[A_CELLS], 40, FMaxAmmo[A_CELLS]);
6434 ITEM_AMMO_CELL_BIG: if FAmmo[A_CELLS] < FMaxAmmo[A_CELLS] then IncMax(FAmmo[A_CELLS], 100, FMaxAmmo[A_CELLS]);
6435 ITEM_AMMO_FUELCAN: if FAmmo[A_FUEL] < FMaxAmmo[A_FUEL] then IncMax(FAmmo[A_FUEL], 100, FMaxAmmo[A_FUEL]);
6437 ITEM_AMMO_BACKPACK:
6438 if (FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS]) or
6439 (FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS]) or
6440 (FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS]) or
6441 (FAmmo[A_CELLS] < FMaxAmmo[A_CELLS]) or
6442 (FMaxAmmo[A_FUEL] < AmmoLimits[1, A_FUEL]) then
6443 begin
6444 FMaxAmmo[A_BULLETS] := AmmoLimits[1, A_BULLETS];
6445 FMaxAmmo[A_SHELLS] := AmmoLimits[1, A_SHELLS];
6446 FMaxAmmo[A_ROCKETS] := AmmoLimits[1, A_ROCKETS];
6447 FMaxAmmo[A_CELLS] := AmmoLimits[1, A_CELLS];
6448 FMaxAmmo[A_FUEL] := AmmoLimits[1, A_FUEL];
6450 if FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS] then IncMax(FAmmo[A_BULLETS], 10, FMaxAmmo[A_BULLETS]);
6451 if FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS] then IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
6452 if FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS] then IncMax(FAmmo[A_ROCKETS], 1, FMaxAmmo[A_ROCKETS]);
6453 if FAmmo[A_CELLS] < FMaxAmmo[A_CELLS] then IncMax(FAmmo[A_CELLS], 40, FMaxAmmo[A_CELLS]);
6455 FRulez := FRulez + [R_ITEM_BACKPACK];
6456 end;
6458 ITEM_KEY_RED: if not (R_KEY_RED in FRulez) then Include(FRulez, R_KEY_RED);
6459 ITEM_KEY_GREEN: if not (R_KEY_GREEN in FRulez) then Include(FRulez, R_KEY_GREEN);
6460 ITEM_KEY_BLUE: if not (R_KEY_BLUE in FRulez) then Include(FRulez, R_KEY_BLUE);
6462 ITEM_BOTTLE: if FHealth < PLAYER_HP_LIMIT then IncMax(FHealth, 4, PLAYER_HP_LIMIT);
6463 ITEM_HELMET: if FArmor < PLAYER_AP_LIMIT then IncMax(FArmor, 5, PLAYER_AP_LIMIT);
6465 else
6466 Exit;
6467 end;
6468 if g_Game_IsNet and g_Game_IsServer then
6469 MH_SEND_PlayerStats(FUID);
6470 end;
6472 procedure TPlayer.FlySmoke(Times: DWORD = 1);
6473 var
6474 id, i: DWORD;
6475 Anim: TAnimation;
6476 begin
6477 if (Random(5) = 1) and (Times = 1) then
6478 Exit;
6480 if BodyInLiquid(0, 0) then
6481 begin
6482 g_GFX_Bubbles(Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2)+Random(3)-1,
6483 Obj.Y+Obj.Rect.Height+8, 1, 8, 4);
6484 if Random(2) = 0
6485 then g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj.X, FObj.Y)
6486 else g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj.X, FObj.Y);
6487 Exit;
6488 end;
6490 if g_Frames_Get(id, 'FRAMES_SMOKE') then
6491 begin
6492 for i := 1 to Times do
6493 begin
6494 Anim := TAnimation.Create(id, False, 3);
6495 Anim.Alpha := 150;
6496 g_GFX_OnceAnim(Obj.X+Obj.Rect.X+Random(Obj.Rect.Width+Times*2)-(Anim.Width div 2),
6497 Obj.Y+Obj.Rect.Height-4+Random(8+Times*2), Anim, ONCEANIM_SMOKE);
6498 Anim.Free();
6499 end;
6500 end;
6501 end;
6503 procedure TPlayer.OnFireFlame(Times: DWORD = 1);
6504 var
6505 id, i: DWORD;
6506 Anim: TAnimation;
6507 begin
6508 if (Random(10) = 1) and (Times = 1) then
6509 Exit;
6511 if g_Frames_Get(id, 'FRAMES_FLAME') then
6512 begin
6513 for i := 1 to Times do
6514 begin
6515 Anim := TAnimation.Create(id, False, 3);
6516 Anim.Alpha := 0;
6517 g_GFX_OnceAnim(Obj.X+Obj.Rect.X+Random(Obj.Rect.Width+Times*2)-(Anim.Width div 2),
6518 Obj.Y+8+Random(8+Times*2), Anim, ONCEANIM_SMOKE);
6519 Anim.Free();
6520 end;
6521 end;
6522 end;
6524 procedure TPlayer.PauseSounds(Enable: Boolean);
6525 begin
6526 FSawSound.Pause(Enable);
6527 FSawSoundIdle.Pause(Enable);
6528 FSawSoundHit.Pause(Enable);
6529 FSawSoundSelect.Pause(Enable);
6530 FFlameSoundOn.Pause(Enable);
6531 FFlameSoundOff.Pause(Enable);
6532 FFlameSoundWork.Pause(Enable);
6533 FJetSoundFly.Pause(Enable);
6534 FJetSoundOn.Pause(Enable);
6535 FJetSoundOff.Pause(Enable);
6536 end;
6538 { T C o r p s e : }
6540 constructor TCorpse.Create(X, Y: Integer; ModelName: String; aMess: Boolean);
6541 begin
6542 g_Obj_Init(@FObj);
6543 FObj.X := X;
6544 FObj.Y := Y;
6545 FObj.Rect := PLAYER_CORPSERECT;
6546 FModelName := ModelName;
6547 FMess := aMess;
6549 if FMess then
6550 begin
6551 FState := CORPSE_STATE_MESS;
6552 g_PlayerModel_GetAnim(ModelName, A_DIE2, FAnimation, FAnimationMask);
6553 end
6554 else
6555 begin
6556 FState := CORPSE_STATE_NORMAL;
6557 g_PlayerModel_GetAnim(ModelName, A_DIE1, FAnimation, FAnimationMask);
6558 end;
6559 end;
6561 destructor TCorpse.Destroy();
6562 begin
6563 FAnimation.Free();
6565 inherited;
6566 end;
6568 function TCorpse.ObjPtr (): PObj; inline; begin result := @FObj; end;
6570 procedure TCorpse.positionChanged (); inline; begin end;
6572 procedure TCorpse.moveBy (dx, dy: Integer); inline;
6573 begin
6574 if (dx <> 0) or (dy <> 0) then
6575 begin
6576 FObj.X += dx;
6577 FObj.Y += dy;
6578 positionChanged();
6579 end;
6580 end;
6583 procedure TCorpse.getMapBox (out x, y, w, h: Integer); inline;
6584 begin
6585 x := FObj.X+PLAYER_CORPSERECT.X;
6586 y := FObj.Y+PLAYER_CORPSERECT.Y;
6587 w := PLAYER_CORPSERECT.Width;
6588 h := PLAYER_CORPSERECT.Height;
6589 end;
6592 procedure TCorpse.Damage(Value: Word; SpawnerUID: Word; vx, vy: Integer);
6593 var
6594 pm: TPlayerModel;
6595 Blood: TModelBlood;
6596 begin
6597 if FState = CORPSE_STATE_REMOVEME then
6598 Exit;
6600 FDamage := FDamage + Value;
6602 if FDamage > 150 then
6603 begin
6604 if FAnimation <> nil then
6605 begin
6606 FAnimation.Free();
6607 FAnimation := nil;
6609 FState := CORPSE_STATE_REMOVEME;
6611 g_Player_CreateGibs(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
6612 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
6613 FModelName, FColor);
6614 // Çâóê ìÿñà îò òðóïà:
6615 pm := g_PlayerModel_Get(FModelName);
6616 pm.PlaySound(MODELSOUND_DIE, 5, FObj.X, FObj.Y);
6617 pm.Free;
6619 // Çëîâåùèé ñìåõ:
6620 if (gBodyKillEvent <> -1)
6621 and gDelayedEvents[gBodyKillEvent].Pending then
6622 gDelayedEvents[gBodyKillEvent].Pending := False;
6623 gBodyKillEvent := g_Game_DelayEvent(DE_BODYKILL, 1050, SpawnerUID);
6624 end;
6625 end
6626 else
6627 begin
6628 Blood := g_PlayerModel_GetBlood(FModelName);
6629 FObj.Vel.X := FObj.Vel.X + vx;
6630 FObj.Vel.Y := FObj.Vel.Y + vy;
6631 g_GFX_Blood(FObj.X+PLAYER_CORPSERECT.X+(PLAYER_CORPSERECT.Width div 2),
6632 FObj.Y+PLAYER_CORPSERECT.Y+(PLAYER_CORPSERECT.Height div 2),
6633 Value, vx, vy, 16, (PLAYER_CORPSERECT.Height*2) div 3,
6634 Blood.R, Blood.G, Blood.B, Blood.Kind);
6635 end;
6636 end;
6638 procedure TCorpse.Draw();
6639 var
6640 fX, fY: Integer;
6641 begin
6642 if FState = CORPSE_STATE_REMOVEME then
6643 Exit;
6645 FObj.lerp(gLerpFactor, fX, fY);
6647 if FAnimation <> nil then
6648 FAnimation.Draw(fX, fY, TMirrorType.None);
6650 if FAnimationMask <> nil then
6651 begin
6652 e_Colors := FColor;
6653 FAnimationMask.Draw(fX, fY, TMirrorType.None);
6654 e_Colors.R := 255;
6655 e_Colors.G := 255;
6656 e_Colors.B := 255;
6657 end;
6658 end;
6660 procedure TCorpse.Update();
6661 var
6662 st: Word;
6663 begin
6664 if FState = CORPSE_STATE_REMOVEME then
6665 Exit;
6667 FObj.oldX := FObj.X;
6668 FObj.oldY := FObj.Y;
6670 if gTime mod (GAME_TICK*2) <> 0 then
6671 begin
6672 g_Obj_Move(@FObj, True, True, True);
6673 positionChanged(); // this updates spatial accelerators
6674 Exit;
6675 end;
6677 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6678 FObj.Vel.X := z_dec(FObj.Vel.X, 1);
6680 st := g_Obj_Move(@FObj, True, True, True);
6681 positionChanged(); // this updates spatial accelerators
6683 if WordBool(st and MOVE_FALLOUT) then
6684 begin
6685 FState := CORPSE_STATE_REMOVEME;
6686 Exit;
6687 end;
6689 if FAnimation <> nil then
6690 FAnimation.Update();
6691 if FAnimationMask <> nil then
6692 FAnimationMask.Update();
6693 end;
6696 procedure TCorpse.SaveState (st: TStream);
6697 var
6698 anim: Boolean;
6699 begin
6700 assert(st <> nil);
6702 // Ñèãíàòóðà òðóïà
6703 utils.writeSign(st, 'CORP');
6704 utils.writeInt(st, Byte(0));
6705 // Ñîñòîÿíèå
6706 utils.writeInt(st, Byte(FState));
6707 // Íàêîïëåííûé óðîí
6708 utils.writeInt(st, Byte(FDamage));
6709 // Öâåò
6710 utils.writeInt(st, Byte(FColor.R));
6711 utils.writeInt(st, Byte(FColor.G));
6712 utils.writeInt(st, Byte(FColor.B));
6713 // Îáúåêò òðóïà
6714 Obj_SaveState(st, @FObj);
6715 utils.writeInt(st, Word(FPlayerUID));
6716 // Åñòü ëè àíèìàöèÿ
6717 anim := (FAnimation <> nil);
6718 utils.writeBool(st, anim);
6719 // Åñëè åñòü - ñîõðàíÿåì
6720 if anim then FAnimation.SaveState(st);
6721 // Åñòü ëè ìàñêà àíèìàöèè
6722 anim := (FAnimationMask <> nil);
6723 utils.writeBool(st, anim);
6724 // Åñëè åñòü - ñîõðàíÿåì
6725 if anim then FAnimationMask.SaveState(st);
6726 end;
6729 procedure TCorpse.LoadState (st: TStream);
6730 var
6731 anim: Boolean;
6732 begin
6733 assert(st <> nil);
6735 // Ñèãíàòóðà òðóïà
6736 if not utils.checkSign(st, 'CORP') then raise XStreamError.Create('invalid corpse signature');
6737 if (utils.readByte(st) <> 0) then raise XStreamError.Create('invalid corpse version');
6738 // Ñîñòîÿíèå
6739 FState := utils.readByte(st);
6740 // Íàêîïëåííûé óðîí
6741 FDamage := utils.readByte(st);
6742 // Öâåò
6743 FColor.R := utils.readByte(st);
6744 FColor.G := utils.readByte(st);
6745 FColor.B := utils.readByte(st);
6746 // Îáúåêò òðóïà
6747 Obj_LoadState(@FObj, st);
6748 FPlayerUID := utils.readWord(st);
6749 // Åñòü ëè àíèìàöèÿ
6750 anim := utils.readBool(st);
6751 // Åñëè åñòü - çàãðóæàåì
6752 if anim then
6753 begin
6754 Assert(FAnimation <> nil, 'TCorpse.LoadState: no FAnimation');
6755 FAnimation.LoadState(st);
6756 end;
6757 // Åñòü ëè ìàñêà àíèìàöèè
6758 anim := utils.readBool(st);
6759 // Åñëè åñòü - çàãðóæàåì
6760 if anim then
6761 begin
6762 Assert(FAnimationMask <> nil, 'TCorpse.LoadState: no FAnimationMask');
6763 FAnimationMask.LoadState(st);
6764 end;
6765 end;
6767 { T B o t : }
6769 constructor TBot.Create();
6770 var
6771 a: Integer;
6772 begin
6773 inherited Create();
6775 FPhysics := True;
6776 FSpectator := False;
6777 FGhost := False;
6779 FIamBot := True;
6781 Inc(gNumBots);
6783 for a := WP_FIRST to WP_LAST do
6784 begin
6785 FDifficult.WeaponPrior[a] := WEAPON_PRIOR1[a];
6786 FDifficult.CloseWeaponPrior[a] := WEAPON_PRIOR2[a];
6787 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6788 end;
6789 end;
6791 destructor TBot.Destroy();
6792 begin
6793 Dec(gNumBots);
6794 inherited Destroy();
6795 end;
6797 procedure TBot.Draw();
6798 begin
6799 inherited Draw();
6801 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6802 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6803 end;
6805 procedure TBot.Respawn(Silent: Boolean; Force: Boolean = False);
6806 begin
6807 inherited Respawn(Silent, Force);
6809 FAIFlags := nil;
6810 FSelectedWeapon := FCurrWeap;
6811 resetWeaponQueue();
6812 FTargetUID := 0;
6813 end;
6815 procedure TBot.UpdateCombat();
6816 type
6817 TTarget = record
6818 UID: Word;
6819 X, Y: Integer;
6820 Rect: TRectWH;
6821 cX, cY: Integer;
6822 Dist: Word;
6823 Line: Boolean;
6824 Visible: Boolean;
6825 IsPlayer: Boolean;
6826 end;
6828 TTargetRecord = array of TTarget;
6830 function Compare(a, b: TTarget): Integer;
6831 begin
6832 if a.Line and not b.Line then // A íà ëèíèè îãíÿ
6833 Result := -1
6834 else
6835 if not a.Line and b.Line then // B íà ëèíèè îãíÿ
6836 Result := 1
6837 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6838 if (a.Line and b.Line) or ((not a.Line) and (not b.Line)) then
6839 begin
6840 if a.Dist > b.Dist then // B áëèæå
6841 Result := 1
6842 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6843 Result := -1;
6844 end
6845 else // Ñòðàííî -> A
6846 Result := -1;
6847 end;
6849 var
6850 a, x1, y1, x2, y2: Integer;
6851 targets: TTargetRecord;
6852 ammo: Word;
6853 Target, BestTarget: TTarget;
6854 firew, fireh: Integer;
6855 angle: SmallInt;
6856 mon: TMonster;
6857 pla, tpla: TPlayer;
6858 vsPlayer, vsMonster, ok: Boolean;
6861 function monsUpdate (mon: TMonster): Boolean;
6862 begin
6863 result := false; // don't stop
6864 if mon.alive and (mon.MonsterType <> MONSTER_BARREL) then
6865 begin
6866 if not TargetOnScreen(mon.Obj.X+mon.Obj.Rect.X, mon.Obj.Y+mon.Obj.Rect.Y) then exit;
6868 x2 := mon.Obj.X+mon.Obj.Rect.X+(mon.Obj.Rect.Width div 2);
6869 y2 := mon.Obj.Y+mon.Obj.Rect.Y+(mon.Obj.Rect.Height div 2);
6871 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6872 if g_TraceVector(x1, y1, x2, y2) then
6873 begin
6874 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6875 SetLength(targets, Length(targets)+1);
6876 with targets[High(targets)] do
6877 begin
6878 UID := mon.UID;
6879 X := mon.Obj.X;
6880 Y := mon.Obj.Y;
6881 cX := x2;
6882 cY := y2;
6883 Rect := mon.Obj.Rect;
6884 Dist := g_PatchLength(x1, y1, x2, y2);
6885 Line := (y1+4 < Target.Y + mon.Obj.Rect.Y + mon.Obj.Rect.Height) and
6886 (y1-4 > Target.Y + mon.Obj.Rect.Y);
6887 Visible := True;
6888 IsPlayer := False;
6889 end;
6890 end;
6891 end;
6892 end;
6894 begin
6895 vsPlayer := LongBool(gGameSettings.Options and GAME_OPTION_BOTVSPLAYER);
6896 vsMonster := LongBool(gGameSettings.Options and GAME_OPTION_BOTVSMONSTER);
6898 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6899 if FCurrWeap <> FSelectedWeapon then
6900 NextWeapon();
6902 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6903 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap = FSelectedWeapon) then
6904 begin
6905 RemoveAIFlag('NEEDFIRE');
6907 case FCurrWeap of
6908 WEAPON_PLASMA, WEAPON_SUPERPULEMET, WEAPON_CHAINGUN: PressKey(KEY_FIRE, 20);
6909 WEAPON_SAW, WEAPON_KASTET, WEAPON_FLAMETHROWER: PressKey(KEY_FIRE, 40);
6910 else PressKey(KEY_FIRE);
6911 end;
6912 end;
6914 // Êîîðäèíàòû ñòâîëà:
6915 x1 := FObj.X + WEAPONPOINT[FDirection].X;
6916 y1 := FObj.Y + WEAPONPOINT[FDirection].Y;
6918 Target.UID := FTargetUID;
6920 ok := False;
6921 if Target.UID <> 0 then
6922 begin // Öåëü åñòü - íàñòðàèâàåì
6923 if (g_GetUIDType(Target.UID) = UID_PLAYER) and
6924 vsPlayer then
6925 begin // Èãðîê
6926 tpla := g_Player_Get(Target.UID);
6927 if tpla <> nil then
6928 with tpla do
6929 begin
6930 if (@FObj) <> nil then
6931 begin
6932 Target.X := FObj.X;
6933 Target.Y := FObj.Y;
6934 end;
6935 end;
6937 Target.cX := Target.X + PLAYER_RECT_CX;
6938 Target.cY := Target.Y + PLAYER_RECT_CY;
6939 Target.Rect := PLAYER_RECT;
6940 Target.Visible := g_TraceVector(x1, y1, Target.cX, Target.cY);
6941 Target.Line := (y1+4 < Target.Y+PLAYER_RECT.Y+PLAYER_RECT.Height) and
6942 (y1-4 > Target.Y+PLAYER_RECT.Y);
6943 Target.IsPlayer := True;
6944 ok := True;
6945 end
6946 else
6947 if (g_GetUIDType(Target.UID) = UID_MONSTER) and
6948 vsMonster then
6949 begin // Ìîíñòð
6950 mon := g_Monsters_ByUID(Target.UID);
6951 if mon <> nil then
6952 begin
6953 Target.X := mon.Obj.X;
6954 Target.Y := mon.Obj.Y;
6956 Target.cX := Target.X + mon.Obj.Rect.X + (mon.Obj.Rect.Width div 2);
6957 Target.cY := Target.Y + mon.Obj.Rect.Y + (mon.Obj.Rect.Height div 2);
6958 Target.Rect := mon.Obj.Rect;
6959 Target.Visible := g_TraceVector(x1, y1, Target.cX, Target.cY);
6960 Target.Line := (y1+4 < Target.Y + mon.Obj.Rect.Y + mon.Obj.Rect.Height) and
6961 (y1-4 > Target.Y + mon.Obj.Rect.Y);
6962 Target.IsPlayer := False;
6963 ok := True;
6964 end;
6965 end;
6966 end;
6968 if not ok then
6969 begin // Öåëè íåò - îáíóëÿåì
6970 Target.X := 0;
6971 Target.Y := 0;
6972 Target.cX := 0;
6973 Target.cY := 0;
6974 Target.Visible := False;
6975 Target.Line := False;
6976 Target.IsPlayer := False;
6977 end;
6979 targets := nil;
6981 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6982 if (not Target.Line) or (not Target.Visible) then
6983 begin
6984 // Èãðîêè:
6985 if vsPlayer then
6986 for a := 0 to High(gPlayers) do
6987 if (gPlayers[a] <> nil) and (gPlayers[a].alive) and
6988 (gPlayers[a].FUID <> FUID) and
6989 (not SameTeam(FUID, gPlayers[a].FUID)) and
6990 (not gPlayers[a].NoTarget) and
6991 (gPlayers[a].FMegaRulez[MR_INVIS] < gTime) then
6992 begin
6993 if not TargetOnScreen(gPlayers[a].FObj.X + PLAYER_RECT.X,
6994 gPlayers[a].FObj.Y + PLAYER_RECT.Y) then
6995 Continue;
6997 x2 := gPlayers[a].FObj.X + PLAYER_RECT_CX;
6998 y2 := gPlayers[a].FObj.Y + PLAYER_RECT_CY;
7000 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
7001 if g_TraceVector(x1, y1, x2, y2) then
7002 begin
7003 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
7004 SetLength(targets, Length(targets)+1);
7005 with targets[High(targets)] do
7006 begin
7007 UID := gPlayers[a].FUID;
7008 X := gPlayers[a].FObj.X;
7009 Y := gPlayers[a].FObj.Y;
7010 cX := x2;
7011 cY := y2;
7012 Rect := PLAYER_RECT;
7013 Dist := g_PatchLength(x1, y1, x2, y2);
7014 Line := (y1+4 < Target.Y+PLAYER_RECT.Y+PLAYER_RECT.Height) and
7015 (y1-4 > Target.Y+PLAYER_RECT.Y);
7016 Visible := True;
7017 IsPlayer := True;
7018 end;
7019 end;
7020 end;
7022 // Ìîíñòðû:
7023 if vsMonster then g_Mons_ForEach(monsUpdate);
7024 end;
7026 // Åñëè åñòü âîçìîæíûå öåëè:
7027 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
7028 if targets <> nil then
7029 begin
7030 // Âûáèðàåì íàèëó÷øóþ öåëü:
7031 BestTarget := targets[0];
7032 if Length(targets) > 1 then
7033 for a := 1 to High(targets) do
7034 if Compare(BestTarget, targets[a]) = 1 then
7035 BestTarget := targets[a];
7037 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
7038 if ((not Target.Visible) and BestTarget.Visible and (Target.UID <> BestTarget.UID)) or
7039 ((not Target.Line) and BestTarget.Line and BestTarget.Visible) then
7040 begin
7041 Target := BestTarget;
7043 if (Healthy() = 3) or ((Healthy() = 2)) then
7044 begin // Åñëè çäîðîâû - äîãîíÿåì
7045 if ((RunDirection() = TDirection.D_LEFT) and (Target.X > FObj.X)) then
7046 SetAIFlag('GORIGHT', '1');
7047 if ((RunDirection() = TDirection.D_RIGHT) and (Target.X < FObj.X)) then
7048 SetAIFlag('GOLEFT', '1');
7049 end
7050 else
7051 begin // Åñëè ïîáèòû - óáåãàåì
7052 if ((RunDirection() = TDirection.D_LEFT) and (Target.X < FObj.X)) then
7053 SetAIFlag('GORIGHT', '1');
7054 if ((RunDirection() = TDirection.D_RIGHT) and (Target.X > FObj.X)) then
7055 SetAIFlag('GOLEFT', '1');
7056 end;
7058 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
7059 SelectWeapon(Abs(x1-Target.cX));
7060 end;
7061 end;
7063 // Åñëè åñòü öåëü:
7064 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
7065 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
7066 if Target.UID <> 0 then
7067 begin
7068 if not TargetOnScreen(Target.X + Target.Rect.X,
7069 Target.Y + Target.Rect.Y) then
7070 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
7071 if (Healthy() = 3) or ((Healthy() = 2)) then
7072 begin // Åñëè çäîðîâû - äîãîíÿåì
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 else
7079 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
7080 Target.UID := 0;
7081 if ((RunDirection() = TDirection.D_LEFT) and (Target.X < FObj.X)) then
7082 SetAIFlag('GORIGHT', '1');
7083 if ((RunDirection() = TDirection.D_RIGHT) and (Target.X > FObj.X)) then
7084 SetAIFlag('GOLEFT', '1');
7085 end;
7086 end
7087 else
7088 begin // Öåëü ïîêà íà "ýêðàíå"
7089 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
7090 if g_TraceVector(x1, y1, Target.cX, Target.cY) then
7091 FLastVisible := gTime;
7092 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
7093 if (Abs(FObj.Y-Target.Y) <= 128) then
7094 begin
7095 if ((RunDirection() = TDirection.D_LEFT) and (Target.X > FObj.X)) then
7096 SetAIFlag('GORIGHT', '1');
7097 if ((RunDirection() = TDirection.D_RIGHT) and (Target.X < FObj.X)) then
7098 SetAIFlag('GOLEFT', '1');
7099 end;
7100 end;
7102 // Âûáèðàåì óãîë ââåðõ:
7103 if FDirection = TDirection.D_LEFT then
7104 angle := ANGLE_LEFTUP
7105 else
7106 angle := ANGLE_RIGHTUP;
7108 firew := Trunc(Cos(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
7109 fireh := Trunc(Sin(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
7111 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
7112 if g_CollideLine(x1, y1, x1+firew, y1+fireh,
7113 Target.X+Target.Rect.X+GetInterval(FDifficult.DiagPrecision, 128), //96
7114 Target.Y+Target.Rect.Y+GetInterval(FDifficult.DiagPrecision, 128),
7115 Target.Rect.Width, Target.Rect.Height) and
7116 g_TraceVector(x1, y1, Target.cX, Target.cY) then
7117 begin // òî íóæíî ñòðåëÿòü ââåðõ
7118 SetAIFlag('NEEDFIRE', '1');
7119 SetAIFlag('NEEDSEEUP', '1');
7120 end;
7122 // Âûáèðàåì óãîë âíèç:
7123 if FDirection = TDirection.D_LEFT then
7124 angle := ANGLE_LEFTDOWN
7125 else
7126 angle := ANGLE_RIGHTDOWN;
7128 firew := Trunc(Cos(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
7129 fireh := Trunc(Sin(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
7131 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
7132 if g_CollideLine(x1, y1, x1+firew, y1+fireh,
7133 Target.X+Target.Rect.X+GetInterval(FDifficult.DiagPrecision, 128),
7134 Target.Y+Target.Rect.Y+GetInterval(FDifficult.DiagPrecision, 128),
7135 Target.Rect.Width, Target.Rect.Height) and
7136 g_TraceVector(x1, y1, Target.cX, Target.cY) then
7137 begin // òî íóæíî ñòðåëÿòü âíèç
7138 SetAIFlag('NEEDFIRE', '1');
7139 SetAIFlag('NEEDSEEDOWN', '1');
7140 end;
7142 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
7143 if Target.Visible and
7144 (y1+4 < Target.Y+Target.Rect.Y+Target.Rect.Height) and
7145 (y1-4 > Target.Y+Target.Rect.Y) then
7146 begin
7147 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
7148 if ((FDirection = TDirection.D_LEFT) and (Target.X < FObj.X)) or
7149 ((FDirection = TDirection.D_RIGHT) and (Target.X > FObj.X)) then
7150 begin // òî íóæíî ñòðåëÿòü âïåðåä
7151 SetAIFlag('NEEDFIRE', '1');
7152 SetAIFlag('NEEDSEEDOWN', '');
7153 SetAIFlag('NEEDSEEUP', '');
7154 end;
7155 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
7156 if Abs(FObj.X-Target.X) < Trunc(gPlayerScreenSize.X*0.75) then
7157 if GetRnd(FDifficult.CloseJump) then
7158 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
7159 if Abs(FObj.X-Target.X) < 128 then
7160 a := 4
7161 else
7162 a := 30;
7163 if Random(a) = 0 then
7164 SetAIFlag('NEEDJUMP', '1');
7165 end;
7166 end;
7168 // Åñëè öåëü âñå åùå åñòü:
7169 if Target.UID <> 0 then
7170 if gTime-FLastVisible > 2000 then // Åñëè âèäåëè äàâíî
7171 Target.UID := 0 // òî çàáûòü öåëü
7172 else // Åñëè âèäåëè íåäàâíî
7173 begin // íî öåëü óáèëè
7174 if Target.IsPlayer then
7175 begin // Öåëü - èãðîê
7176 pla := g_Player_Get(Target.UID);
7177 if (pla = nil) or (not pla.alive) or pla.NoTarget or
7178 (pla.FMegaRulez[MR_INVIS] >= gTime) then
7179 Target.UID := 0; // òî çàáûòü öåëü
7180 end
7181 else
7182 begin // Öåëü - ìîíñòð
7183 mon := g_Monsters_ByUID(Target.UID);
7184 if (mon = nil) or (not mon.alive) then
7185 Target.UID := 0; // òî çàáûòü öåëü
7186 end;
7187 end;
7188 end; // if Target.UID <> 0
7190 FTargetUID := Target.UID;
7192 // Åñëè âîçìîæíûõ öåëåé íåò:
7193 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
7194 if targets = nil then
7195 if GetAIFlag('ATTACKLEFT') <> '' then
7196 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
7197 RemoveAIFlag('ATTACKLEFT');
7199 SetAIFlag('NEEDJUMP', '1');
7201 if RunDirection() = TDirection.D_RIGHT then
7202 begin // Èäåì íå â òó ñòîðîíó
7203 if (Healthy() > 1) and GetRnd(FDifficult.InvisFire) then
7204 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
7205 SetAIFlag('NEEDFIRE', '1');
7206 SetAIFlag('GOLEFT', '1');
7207 end;
7208 end
7209 else
7210 begin // Èäåì â íóæíóþ ñòîðîíó
7211 if GetRnd(FDifficult.InvisFire) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7212 SetAIFlag('NEEDFIRE', '1');
7213 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7214 SetAIFlag('GORIGHT', '1');
7215 end;
7216 end
7217 else
7218 if GetAIFlag('ATTACKRIGHT') <> '' then
7219 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
7220 RemoveAIFlag('ATTACKRIGHT');
7222 SetAIFlag('NEEDJUMP', '1');
7224 if RunDirection() = TDirection.D_LEFT then
7225 begin // Èäåì íå â òó ñòîðîíó
7226 if (Healthy() > 1) and GetRnd(FDifficult.InvisFire) then
7227 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
7228 SetAIFlag('NEEDFIRE', '1');
7229 SetAIFlag('GORIGHT', '1');
7230 end;
7231 end
7232 else
7233 begin
7234 if GetRnd(FDifficult.InvisFire) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7235 SetAIFlag('NEEDFIRE', '1');
7236 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7237 SetAIFlag('GOLEFT', '1');
7238 end;
7239 end;
7241 //HACK! (does it belongs there?)
7242 RealizeCurrentWeapon();
7244 // Åñëè åñòü âîçìîæíûå öåëè:
7245 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
7246 if (targets <> nil) and (GetAIFlag('NEEDFIRE') <> '') then
7247 for a := 0 to High(targets) do
7248 begin
7249 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
7250 if GetRnd(FDifficult.DiagFire) then
7251 begin
7252 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
7253 if FDirection = TDirection.D_LEFT then
7254 angle := ANGLE_LEFTUP
7255 else
7256 angle := ANGLE_RIGHTUP;
7258 firew := Trunc(Cos(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
7259 fireh := Trunc(Sin(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
7261 if g_CollideLine(x1, y1, x1+firew, y1+fireh,
7262 targets[a].X+targets[a].Rect.X+GetInterval(FDifficult.DiagPrecision, 128),
7263 targets[a].Y+targets[a].Rect.Y+GetInterval(FDifficult.DiagPrecision, 128),
7264 targets[a].Rect.Width, targets[a].Rect.Height) and
7265 g_TraceVector(x1, y1, targets[a].cX, targets[a].cY) then
7266 begin
7267 SetAIFlag('NEEDFIRE', '1');
7268 SetAIFlag('NEEDSEEUP', '1');
7269 end;
7271 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
7272 if FDirection = TDirection.D_LEFT then
7273 angle := ANGLE_LEFTDOWN
7274 else
7275 angle := ANGLE_RIGHTDOWN;
7277 firew := Trunc(Cos(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
7278 fireh := Trunc(Sin(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
7280 if g_CollideLine(x1, y1, x1+firew, y1+fireh,
7281 targets[a].X+targets[a].Rect.X+GetInterval(FDifficult.DiagPrecision, 128),
7282 targets[a].Y+targets[a].Rect.Y+GetInterval(FDifficult.DiagPrecision, 128),
7283 targets[a].Rect.Width, targets[a].Rect.Height) and
7284 g_TraceVector(x1, y1, targets[a].cX, targets[a].cY) then
7285 begin
7286 SetAIFlag('NEEDFIRE', '1');
7287 SetAIFlag('NEEDSEEDOWN', '1');
7288 end;
7289 end;
7291 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
7292 if targets[a].Line and targets[a].Visible and
7293 (((FDirection = TDirection.D_LEFT) and (targets[a].X < FObj.X)) or
7294 ((FDirection = TDirection.D_RIGHT) and (targets[a].X > FObj.X))) then
7295 begin
7296 SetAIFlag('NEEDFIRE', '1');
7297 Break;
7298 end;
7299 end;
7301 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
7302 if g_Weapon_Danger(FUID, FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y,
7303 PLAYER_RECT.Width, PLAYER_RECT.Height,
7304 40+GetInterval(FDifficult.Cover, 40)) then
7305 SetAIFlag('NEEDJUMP', '1');
7307 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
7308 ammo := GetAmmoByWeapon(FCurrWeap);
7309 if ((FCurrWeap = WEAPON_SHOTGUN2) and (ammo < 2)) or
7310 ((FCurrWeap = WEAPON_BFG) and (ammo < 40)) or
7311 (ammo = 0) then
7312 SetAIFlag('SELECTWEAPON', '1');
7314 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
7315 if GetAIFlag('SELECTWEAPON') = '1' then
7316 begin
7317 SelectWeapon(-1);
7318 RemoveAIFlag('SELECTWEAPON');
7319 end;
7320 end;
7322 procedure TBot.Update();
7323 var
7324 EnableAI: Boolean;
7325 begin
7326 if not FAlive then
7327 begin // Respawn
7328 ReleaseKeys();
7329 PressKey(KEY_UP);
7330 end
7331 else
7332 begin
7333 EnableAI := True;
7335 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
7336 if (g_debug_BotAIOff = 1) and (Team = TEAM_RED) then
7337 EnableAI := False;
7338 if (g_debug_BotAIOff = 2) and (Team = TEAM_BLUE) then
7339 EnableAI := False;
7340 if g_debug_BotAIOff = 3 then
7341 EnableAI := False;
7343 if EnableAI then
7344 begin
7345 UpdateMove();
7346 UpdateCombat();
7347 end
7348 else
7349 begin
7350 RealizeCurrentWeapon();
7351 end;
7352 end;
7354 inherited Update();
7355 end;
7357 procedure TBot.ReleaseKey(Key: Byte);
7358 begin
7359 with FKeys[Key] do
7360 begin
7361 Pressed := False;
7362 Time := 0;
7363 end;
7364 end;
7366 function TBot.KeyPressed(Key: Word): Boolean;
7367 begin
7368 Result := FKeys[Key].Pressed;
7369 end;
7371 function TBot.GetAIFlag(aName: String20): String20;
7372 var
7373 a: Integer;
7374 begin
7375 Result := '';
7377 aName := LowerCase(aName);
7379 if FAIFlags <> nil then
7380 for a := 0 to High(FAIFlags) do
7381 if LowerCase(FAIFlags[a].Name) = aName then
7382 begin
7383 Result := FAIFlags[a].Value;
7384 Break;
7385 end;
7386 end;
7388 procedure TBot.RemoveAIFlag(aName: String20);
7389 var
7390 a, b: Integer;
7391 begin
7392 if FAIFlags = nil then Exit;
7394 aName := LowerCase(aName);
7396 for a := 0 to High(FAIFlags) do
7397 if LowerCase(FAIFlags[a].Name) = aName then
7398 begin
7399 if a <> High(FAIFlags) then
7400 for b := a to High(FAIFlags)-1 do
7401 FAIFlags[b] := FAIFlags[b+1];
7403 SetLength(FAIFlags, Length(FAIFlags)-1);
7404 Break;
7405 end;
7406 end;
7408 procedure TBot.SetAIFlag(aName, fValue: String20);
7409 var
7410 a: Integer;
7411 ok: Boolean;
7412 begin
7413 a := 0;
7414 ok := False;
7416 aName := LowerCase(aName);
7418 if FAIFlags <> nil then
7419 for a := 0 to High(FAIFlags) do
7420 if LowerCase(FAIFlags[a].Name) = aName then
7421 begin
7422 ok := True;
7423 Break;
7424 end;
7426 if ok then FAIFlags[a].Value := fValue
7427 else
7428 begin
7429 SetLength(FAIFlags, Length(FAIFlags)+1);
7430 with FAIFlags[High(FAIFlags)] do
7431 begin
7432 Name := aName;
7433 Value := fValue;
7434 end;
7435 end;
7436 end;
7438 procedure TBot.UpdateMove;
7440 procedure GoLeft(Time: Word = 1);
7441 begin
7442 ReleaseKey(KEY_LEFT);
7443 ReleaseKey(KEY_RIGHT);
7444 PressKey(KEY_LEFT, Time);
7445 SetDirection(TDirection.D_LEFT);
7446 end;
7448 procedure GoRight(Time: Word = 1);
7449 begin
7450 ReleaseKey(KEY_LEFT);
7451 ReleaseKey(KEY_RIGHT);
7452 PressKey(KEY_RIGHT, Time);
7453 SetDirection(TDirection.D_RIGHT);
7454 end;
7456 function Rnd(a: Word): Boolean;
7457 begin
7458 Result := Random(a) = 0;
7459 end;
7461 procedure Turn(Time: Word = 1200);
7462 begin
7463 if RunDirection() = TDirection.D_LEFT then GoRight(Time) else GoLeft(Time);
7464 end;
7466 procedure Stop();
7467 begin
7468 ReleaseKey(KEY_LEFT);
7469 ReleaseKey(KEY_RIGHT);
7470 end;
7472 function CanRunLeft(): Boolean;
7473 begin
7474 Result := not CollideLevel(-1, 0);
7475 end;
7477 function CanRunRight(): Boolean;
7478 begin
7479 Result := not CollideLevel(1, 0);
7480 end;
7482 function CanRun(): Boolean;
7483 begin
7484 if RunDirection() = TDirection.D_LEFT then Result := CanRunLeft() else Result := CanRunRight();
7485 end;
7487 procedure Jump(Time: Word = 30);
7488 begin
7489 PressKey(KEY_JUMP, Time);
7490 end;
7492 function NearHole(): Boolean;
7493 var
7494 x, sx: Integer;
7495 begin
7496 { TODO 5 : Ëåñòíèöû }
7497 sx := IfThen(RunDirection() = TDirection.D_LEFT, -1, 1);
7498 for x := 1 to PLAYER_RECT.Width do
7499 if (not StayOnStep(x*sx, 0)) and
7500 (not CollideLevel(x*sx, PLAYER_RECT.Height)) and
7501 (not CollideLevel(x*sx, PLAYER_RECT.Height*2)) then
7502 begin
7503 Result := True;
7504 Exit;
7505 end;
7507 Result := False;
7508 end;
7510 function BorderHole(): Boolean;
7511 var
7512 x, sx, xx: Integer;
7513 begin
7514 { TODO 5 : Ëåñòíèöû }
7515 sx := IfThen(RunDirection() = TDirection.D_LEFT, -1, 1);
7516 for x := 1 to PLAYER_RECT.Width do
7517 if (not StayOnStep(x*sx, 0)) and
7518 (not CollideLevel(x*sx, PLAYER_RECT.Height)) and
7519 (not CollideLevel(x*sx, PLAYER_RECT.Height*2)) then
7520 begin
7521 for xx := x to x+32 do
7522 if CollideLevel(xx*sx, PLAYER_RECT.Height) then
7523 begin
7524 Result := True;
7525 Exit;
7526 end;
7527 end;
7529 Result := False;
7530 end;
7532 function NearDeepHole(): Boolean;
7533 var
7534 x, sx, y: Integer;
7535 begin
7536 Result := False;
7538 sx := IfThen(RunDirection() = TDirection.D_LEFT, -1, 1);
7539 y := 3;
7541 for x := 1 to PLAYER_RECT.Width do
7542 if (not StayOnStep(x*sx, 0)) and
7543 (not CollideLevel(x*sx, PLAYER_RECT.Height)) and
7544 (not CollideLevel(x*sx, PLAYER_RECT.Height*2)) then
7545 begin
7546 while FObj.Y+y*PLAYER_RECT.Height < gMapInfo.Height do
7547 begin
7548 if CollideLevel(x*sx, PLAYER_RECT.Height*y) then Exit;
7549 y := y+1;
7550 end;
7552 Result := True;
7553 end else Result := False;
7554 end;
7556 function OverDeepHole(): Boolean;
7557 var
7558 y: Integer;
7559 begin
7560 Result := False;
7562 y := 1;
7563 while FObj.Y+y*PLAYER_RECT.Height < gMapInfo.Height do
7564 begin
7565 if CollideLevel(0, PLAYER_RECT.Height*y) then Exit;
7566 y := y+1;
7567 end;
7569 Result := True;
7570 end;
7572 function OnGround(): Boolean;
7573 begin
7574 Result := StayOnStep(0, 0) or CollideLevel(0, 1);
7575 end;
7577 function OnLadder(): Boolean;
7578 begin
7579 Result := FullInStep(0, 0);
7580 end;
7582 function BelowLadder(): Boolean;
7583 begin
7584 Result := (FullInStep(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -PLAYER_RECT.Height) and
7585 not CollideLevel(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -PLAYER_RECT.Height)) or
7586 (FullInStep(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -BOT_MAXJUMP) and
7587 not CollideLevel(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -BOT_MAXJUMP));
7588 end;
7590 function BelowLiftUp(): Boolean;
7591 begin
7592 Result := ((FullInLift(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -PLAYER_RECT.Height) = -1) and
7593 not CollideLevel(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -PLAYER_RECT.Height)) or
7594 ((FullInLift(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -BOT_MAXJUMP) = -1) and
7595 not CollideLevel(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -BOT_MAXJUMP));
7596 end;
7598 function OnTopLift(): Boolean;
7599 begin
7600 Result := (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7601 end;
7603 function CanJumpOver(): Boolean;
7604 var
7605 sx, y: Integer;
7606 begin
7607 sx := IfThen(RunDirection() = TDirection.D_LEFT, -1, 1);
7609 Result := False;
7611 if not CollideLevel(sx, 0) then Exit;
7613 for y := 1 to BOT_MAXJUMP do
7614 if CollideLevel(0, -y) then Exit else
7615 if not CollideLevel(sx, -y) then
7616 begin
7617 Result := True;
7618 Exit;
7619 end;
7620 end;
7622 function CanJumpUp(Dist: ShortInt): Boolean;
7623 var
7624 y, yy: Integer;
7625 c: Boolean;
7626 begin
7627 Result := False;
7629 if CollideLevel(Dist, 0) then Exit;
7631 c := False;
7632 for y := 0 to BOT_MAXJUMP do
7633 if CollideLevel(Dist, -y) then
7634 begin
7635 c := True;
7636 Break;
7637 end;
7639 if not c then Exit;
7641 c := False;
7642 for yy := y+1 to BOT_MAXJUMP do
7643 if not CollideLevel(Dist, -yy) then
7644 begin
7645 c := True;
7646 Break;
7647 end;
7649 if not c then Exit;
7651 c := False;
7652 for y := 0 to BOT_MAXJUMP do
7653 if CollideLevel(0, -y) then
7654 begin
7655 c := True;
7656 Break;
7657 end;
7659 if c then Exit;
7661 if y < yy then Exit;
7663 Result := True;
7664 end;
7666 function IsSafeTrigger(): Boolean;
7667 var
7668 a: Integer;
7669 begin
7670 Result := True;
7671 if gTriggers = nil then
7672 Exit;
7673 for a := 0 to High(gTriggers) do
7674 if Collide(gTriggers[a].X,
7675 gTriggers[a].Y,
7676 gTriggers[a].Width,
7677 gTriggers[a].Height) and
7678 (gTriggers[a].TriggerType in [TRIGGER_EXIT, TRIGGER_CLOSEDOOR,
7679 TRIGGER_CLOSETRAP, TRIGGER_TRAP,
7680 TRIGGER_PRESS, TRIGGER_ON, TRIGGER_OFF,
7681 TRIGGER_ONOFF, TRIGGER_SPAWNMONSTER,
7682 TRIGGER_DAMAGE, TRIGGER_SHOT]) then
7683 Result := False;
7684 end;
7686 begin
7687 // Âîçìîæíî, íàæèìàåì êíîïêó:
7688 if Rnd(16) and IsSafeTrigger() then
7689 PressKey(KEY_OPEN);
7691 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7692 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7693 begin
7694 ReleaseKey(KEY_LEFT);
7695 ReleaseKey(KEY_RIGHT);
7696 Jump();
7697 end;
7699 // Èäåì âëåâî, åñëè íàäî áûëî:
7700 if GetAIFlag('GOLEFT') <> '' then
7701 begin
7702 RemoveAIFlag('GOLEFT');
7703 if CanRunLeft() then
7704 GoLeft(360);
7705 end;
7707 // Èäåì âïðàâî, åñëè íàäî áûëî:
7708 if GetAIFlag('GORIGHT') <> '' then
7709 begin
7710 RemoveAIFlag('GORIGHT');
7711 if CanRunRight() then
7712 GoRight(360);
7713 end;
7715 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7716 if FObj.X < -32 then
7717 GoRight(360)
7718 else
7719 if FObj.X+32 > gMapInfo.Width then
7720 GoLeft(360);
7722 // Ïðûãàåì, åñëè íàäî áûëî:
7723 if GetAIFlag('NEEDJUMP') <> '' then
7724 begin
7725 Jump(0);
7726 RemoveAIFlag('NEEDJUMP');
7727 end;
7729 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7730 if GetAIFlag('NEEDSEEUP') <> '' then
7731 begin
7732 ReleaseKey(KEY_UP);
7733 ReleaseKey(KEY_DOWN);
7734 PressKey(KEY_UP, 20);
7735 RemoveAIFlag('NEEDSEEUP');
7736 end;
7738 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7739 if GetAIFlag('NEEDSEEDOWN') <> '' then
7740 begin
7741 ReleaseKey(KEY_UP);
7742 ReleaseKey(KEY_DOWN);
7743 PressKey(KEY_DOWN, 20);
7744 RemoveAIFlag('NEEDSEEDOWN');
7745 end;
7747 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7748 if GetAIFlag('GOINHOLE') <> '' then
7749 if not OnGround() then
7750 begin
7751 ReleaseKey(KEY_LEFT);
7752 ReleaseKey(KEY_RIGHT);
7753 RemoveAIFlag('GOINHOLE');
7754 SetAIFlag('FALLINHOLE', '1');
7755 end;
7757 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7758 if GetAIFlag('FALLINHOLE') <> '' then
7759 if OnGround() then
7760 RemoveAIFlag('FALLINHOLE');
7762 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7763 if not (KeyPressed(KEY_LEFT) or KeyPressed(KEY_RIGHT)) then
7764 if GetAIFlag('FALLINHOLE') = '' then
7765 if (not OnLadder()) or (FObj.Vel.Y >= 0) or (OnTopLift()) then
7766 if Rnd(2) then
7767 GoLeft(360)
7768 else
7769 GoRight(360);
7771 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7772 if OnGround() and
7773 CanJumpUp(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*32) and
7774 Rnd(8) then
7775 Jump();
7777 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7778 if OnGround() and NearHole() then
7779 if NearDeepHole() then // Åñëè ýòî áåçäíà
7780 case Random(6) of
7781 0..3: Turn(); // Áåæèì îáðàòíî
7782 4: Jump(); // Ïðûãàåì
7783 5: begin // Ïðûãàåì îáðàòíî
7784 Turn();
7785 Jump();
7786 end;
7787 end
7788 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7789 if GetAIFlag('GOINHOLE') = '' then
7790 case Random(6) of
7791 0: Turn(); // Íå íóæíî òóäà
7792 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7793 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7794 if BorderHole() then
7795 SetAIFlag('GOINHOLE', '1');
7796 end;
7798 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7799 if (not CanRun()) and OnGround() then
7800 begin
7801 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7802 if CanJumpOver() or OnLadder() then
7803 Jump()
7804 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7805 if Random(2) = 0 then
7806 begin
7807 if IsSafeTrigger() then
7808 PressKey(KEY_OPEN);
7809 end else
7810 Turn();
7811 end;
7813 // Îñòàëîñü ìàëî âîçäóõà:
7814 if FAir < 36 * 2 then
7815 Jump(20);
7817 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7818 if (FMegaRulez[MR_SUIT] < gTime) and ((FLastHit = HIT_ACID) or (Healthy() <= 1)) then
7819 if BodyInAcid(0, 0) then
7820 Jump();
7821 end;
7823 function TBot.FullInStep(XInc, YInc: Integer): Boolean;
7824 begin
7825 Result := g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc,
7826 PLAYER_RECT.Width, PLAYER_RECT.Height, PANEL_STEP, False);
7827 end;
7829 {function TBot.NeedItem(Item: Byte): Byte;
7830 begin
7831 Result := 4;
7832 end;}
7834 procedure TBot.SelectWeapon(Dist: Integer);
7835 var
7836 a: Integer;
7838 function HaveAmmo(weapon: Byte): Boolean;
7839 begin
7840 case weapon of
7841 WEAPON_PISTOL: Result := FAmmo[A_BULLETS] >= 1;
7842 WEAPON_SHOTGUN1: Result := FAmmo[A_SHELLS] >= 1;
7843 WEAPON_SHOTGUN2: Result := FAmmo[A_SHELLS] >= 2;
7844 WEAPON_CHAINGUN: Result := FAmmo[A_BULLETS] >= 10;
7845 WEAPON_ROCKETLAUNCHER: Result := FAmmo[A_ROCKETS] >= 1;
7846 WEAPON_PLASMA: Result := FAmmo[A_CELLS] >= 10;
7847 WEAPON_BFG: Result := FAmmo[A_CELLS] >= 40;
7848 WEAPON_SUPERPULEMET: Result := FAmmo[A_SHELLS] >= 1;
7849 WEAPON_FLAMETHROWER: Result := FAmmo[A_FUEL] >= 1;
7850 else Result := True;
7851 end;
7852 end;
7854 begin
7855 if Dist = -1 then Dist := BOT_LONGDIST;
7857 if Dist > BOT_LONGDIST then
7858 begin // Äàëüíèé áîé
7859 for a := 0 to 9 do
7860 if FWeapon[FDifficult.WeaponPrior[a]] and HaveAmmo(FDifficult.WeaponPrior[a]) then
7861 begin
7862 FSelectedWeapon := FDifficult.WeaponPrior[a];
7863 Break;
7864 end;
7865 end
7866 else //if Dist > BOT_UNSAFEDIST then
7867 begin // Áëèæíèé áîé
7868 for a := 0 to 9 do
7869 if FWeapon[FDifficult.CloseWeaponPrior[a]] and HaveAmmo(FDifficult.CloseWeaponPrior[a]) then
7870 begin
7871 FSelectedWeapon := FDifficult.CloseWeaponPrior[a];
7872 Break;
7873 end;
7874 end;
7875 { else
7876 begin
7877 for a := 0 to 9 do
7878 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7879 begin
7880 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7881 Break;
7882 end;
7883 end;}
7884 end;
7886 function TBot.PickItem(ItemType: Byte; force: Boolean; var remove: Boolean): Boolean;
7887 begin
7888 Result := inherited PickItem(ItemType, force, remove);
7890 if Result then SetAIFlag('SELECTWEAPON', '1');
7891 end;
7893 function TBot.Heal(value: Word; Soft: Boolean): Boolean;
7894 begin
7895 Result := inherited Heal(value, Soft);
7896 end;
7898 function TBot.Healthy(): Byte;
7899 begin
7900 if FMegaRulez[MR_INVUL] >= gTime then Result := 3
7901 else if (FHealth > 80) or ((FHealth > 50) and (FArmor > 20)) then Result := 3
7902 else if (FHealth > 50) then Result := 2
7903 else if (FHealth > 20) then Result := 1
7904 else Result := 0;
7905 end;
7907 function TBot.TargetOnScreen(TX, TY: Integer): Boolean;
7908 begin
7909 Result := (Abs(FObj.X-TX) <= Trunc(gPlayerScreenSize.X*0.6)) and
7910 (Abs(FObj.Y-TY) <= Trunc(gPlayerScreenSize.Y*0.6));
7911 end;
7913 procedure TBot.OnDamage(Angle: SmallInt);
7914 var
7915 pla: TPlayer;
7916 mon: TMonster;
7917 ok: Boolean;
7918 begin
7919 inherited;
7921 if (Angle = 0) or (Angle = 180) then
7922 begin
7923 ok := False;
7924 if (g_GetUIDType(FLastSpawnerUID) = UID_PLAYER) and
7925 LongBool(gGameSettings.Options and GAME_OPTION_BOTVSPLAYER) then
7926 begin // Èãðîê
7927 pla := g_Player_Get(FLastSpawnerUID);
7928 ok := not TargetOnScreen(pla.FObj.X + PLAYER_RECT.X,
7929 pla.FObj.Y + PLAYER_RECT.Y);
7930 end
7931 else
7932 if (g_GetUIDType(FLastSpawnerUID) = UID_MONSTER) and
7933 LongBool(gGameSettings.Options and GAME_OPTION_BOTVSMONSTER) then
7934 begin // Ìîíñòð
7935 mon := g_Monsters_ByUID(FLastSpawnerUID);
7936 ok := not TargetOnScreen(mon.Obj.X + mon.Obj.Rect.X,
7937 mon.Obj.Y + mon.Obj.Rect.Y);
7938 end;
7940 if ok then
7941 if Angle = 0 then
7942 SetAIFlag('ATTACKLEFT', '1')
7943 else
7944 SetAIFlag('ATTACKRIGHT', '1');
7945 end;
7946 end;
7948 function TBot.RunDirection(): TDirection;
7949 begin
7950 if Abs(Vel.X) >= 1 then
7951 begin
7952 if Vel.X > 0 then Result := TDirection.D_RIGHT else Result := TDirection.D_LEFT;
7953 end else
7954 Result := FDirection;
7955 end;
7957 function TBot.GetRnd(a: Byte): Boolean;
7958 begin
7959 if a = 0 then Result := False
7960 else if a = 255 then Result := True
7961 else Result := Random(256) > 255-a;
7962 end;
7964 function TBot.GetInterval(a: Byte; radius: SmallInt): SmallInt;
7965 begin
7966 Result := Round((255-a)/255*radius*(Random(2)-1));
7967 end;
7970 procedure TDifficult.save (st: TStream);
7971 begin
7972 utils.writeInt(st, Byte(DiagFire));
7973 utils.writeInt(st, Byte(InvisFire));
7974 utils.writeInt(st, Byte(DiagPrecision));
7975 utils.writeInt(st, Byte(FlyPrecision));
7976 utils.writeInt(st, Byte(Cover));
7977 utils.writeInt(st, Byte(CloseJump));
7978 st.WriteBuffer(WeaponPrior[Low(WeaponPrior)], sizeof(WeaponPrior));
7979 st.WriteBuffer(CloseWeaponPrior[Low(CloseWeaponPrior)], sizeof(CloseWeaponPrior));
7980 end;
7982 procedure TDifficult.load (st: TStream);
7983 begin
7984 DiagFire := utils.readByte(st);
7985 InvisFire := utils.readByte(st);
7986 DiagPrecision := utils.readByte(st);
7987 FlyPrecision := utils.readByte(st);
7988 Cover := utils.readByte(st);
7989 CloseJump := utils.readByte(st);
7990 st.ReadBuffer(WeaponPrior[Low(WeaponPrior)], sizeof(WeaponPrior));
7991 st.ReadBuffer(CloseWeaponPrior[Low(CloseWeaponPrior)], sizeof(CloseWeaponPrior));
7992 end;
7995 procedure TBot.SaveState (st: TStream);
7996 var
7997 i: Integer;
7998 dw: Integer;
7999 begin
8000 inherited SaveState(st);
8001 utils.writeSign(st, 'BOT0');
8002 // Âûáðàííîå îðóæèå
8003 utils.writeInt(st, Byte(FSelectedWeapon));
8004 // UID öåëè
8005 utils.writeInt(st, Word(FTargetUID));
8006 // Âðåìÿ ïîòåðè öåëè
8007 utils.writeInt(st, LongWord(FLastVisible));
8008 // Êîëè÷åñòâî ôëàãîâ ÈÈ
8009 dw := Length(FAIFlags);
8010 utils.writeInt(st, LongInt(dw));
8011 // Ôëàãè ÈÈ
8012 for i := 0 to dw-1 do
8013 begin
8014 utils.writeStr(st, FAIFlags[i].Name, 20);
8015 utils.writeStr(st, FAIFlags[i].Value, 20);
8016 end;
8017 // Íàñòðîéêè ñëîæíîñòè
8018 FDifficult.save(st);
8019 end;
8022 procedure TBot.LoadState (st: TStream);
8023 var
8024 i: Integer;
8025 dw: Integer;
8026 begin
8027 inherited LoadState(st);
8028 if not utils.checkSign(st, 'BOT0') then raise XStreamError.Create('invalid bot signature');
8029 // Âûáðàííîå îðóæèå
8030 FSelectedWeapon := utils.readByte(st);
8031 // UID öåëè
8032 FTargetUID := utils.readWord(st);
8033 // Âðåìÿ ïîòåðè öåëè
8034 FLastVisible := utils.readLongWord(st);
8035 // Êîëè÷åñòâî ôëàãîâ ÈÈ
8036 dw := utils.readLongInt(st);
8037 if (dw < 0) or (dw > 16384) then raise XStreamError.Create('invalid number of bot AI flags');
8038 SetLength(FAIFlags, dw);
8039 // Ôëàãè ÈÈ
8040 for i := 0 to dw-1 do
8041 begin
8042 FAIFlags[i].Name := utils.readStr(st, 20);
8043 FAIFlags[i].Value := utils.readStr(st, 20);
8044 end;
8045 // Íàñòðîéêè ñëîæíîñòè
8046 FDifficult.load(st);
8047 end;
8050 begin
8051 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');
8052 conRegVar('player_indicator_style', @gPlayerIndicatorStyle, 'Visual appearance of indicator', 'Visual appearance of indicator');
8053 end.