DEADSOFTWARE

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