DEADSOFTWARE

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