DEADSOFTWARE

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