DEADSOFTWARE

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