DEADSOFTWARE

Select bot preset randomly if no arguments are given to the 'bot_addlist' console...
[d2df-sdl.git] / src / game / g_player.pas
1 (* Copyright (C) Doom 2D: Forever Developers
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 *)
15 {$INCLUDE ../shared/a_modes.inc}
16 {$M+}
17 unit g_player;
19 interface
21 uses
22 SysUtils, Classes,
23 {$IFDEF USE_MEMPOOL}mempool,{$ENDIF}
24 e_graphics, g_playermodel, g_basic, g_textures,
25 g_weapons, g_phys, g_sound, g_saveload, MAPDEF,
26 g_panel;
28 const
29 KEY_LEFT = 1;
30 KEY_RIGHT = 2;
31 KEY_UP = 3;
32 KEY_DOWN = 4;
33 KEY_FIRE = 5;
34 KEY_OPEN = 6;
35 KEY_JUMP = 7;
36 KEY_CHAT = 8;
38 WP_PREV = 0;
39 WP_NEXT = 1;
40 WP_FACT = WP_PREV;
41 WP_LACT = WP_NEXT;
43 R_ITEM_BACKPACK = 0;
44 R_KEY_RED = 1;
45 R_KEY_GREEN = 2;
46 R_KEY_BLUE = 3;
47 R_BERSERK = 4;
49 MR_SUIT = 0;
50 MR_INVUL = 1;
51 MR_INVIS = 2;
52 MR_MAX = 2;
54 A_BULLETS = 0;
55 A_SHELLS = 1;
56 A_ROCKETS = 2;
57 A_CELLS = 3;
58 A_FUEL = 4;
59 A_HIGH = 4;
61 AmmoLimits: Array [0..1] of Array [A_BULLETS..A_HIGH] of Word =
62 ((200, 50, 50, 300, 100),
63 (400, 100, 100, 600, 200));
65 K_SIMPLEKILL = 0;
66 K_HARDKILL = 1;
67 K_EXTRAHARDKILL = 2;
68 K_FALLKILL = 3;
70 T_RESPAWN = 0;
71 T_SWITCH = 1;
72 T_USE = 2;
73 T_FLAGCAP = 3;
75 TEAM_NONE = 0;
76 TEAM_RED = 1;
77 TEAM_BLUE = 2;
78 TEAM_COOP = 3;
80 SHELL_BULLET = 0;
81 SHELL_SHELL = 1;
82 SHELL_DBLSHELL = 2;
84 ANGLE_NONE = Low(SmallInt);
86 CORPSE_STATE_REMOVEME = 0;
87 CORPSE_STATE_NORMAL = 1;
88 CORPSE_STATE_MESS = 2;
90 PLAYER_RECT: TRectWH = (X:15; Y:12; Width:34; Height:52);
91 PLAYER_RECT_CX = 15+(34 div 2);
92 PLAYER_RECT_CY = 12+(52 div 2);
93 PLAYER_CORPSERECT: TRectWH = (X:15; Y:48; Width:34; Height:16);
95 PLAYER_HP_SOFT = 100;
96 PLAYER_HP_LIMIT = 200;
97 PLAYER_AP_SOFT = 100;
98 PLAYER_AP_LIMIT = 200;
99 SUICIDE_DAMAGE = 112;
100 WEAPON_DELAY = 5;
102 PLAYER_BURN_TIME = 110;
104 PLAYER1_DEF_COLOR: TRGB = (R:64; G:175; B:48);
105 PLAYER2_DEF_COLOR: TRGB = (R:96; G:96; B:96);
107 type
108 TPlayerStat = record
109 Num: Integer;
110 Ping: Word;
111 Loss: Byte;
112 Name: String;
113 Team: Byte;
114 Frags: SmallInt;
115 Deaths: SmallInt;
116 Lives: Byte;
117 Kills: Word;
118 Color: TRGB;
119 Spectator: Boolean;
120 UID: Word;
121 end;
123 TPlayerStatArray = Array of TPlayerStat;
125 TPlayerSavedState = record
126 Health: Integer;
127 Armor: Integer;
128 Air: Integer;
129 JetFuel: Integer;
130 CurrWeap: Byte;
131 NextWeap: WORD;
132 NextWeapDelay: Byte;
133 Ammo: Array [A_BULLETS..A_HIGH] of Word;
134 MaxAmmo: Array [A_BULLETS..A_HIGH] of Word;
135 Weapon: Array [WP_FIRST..WP_LAST] of Boolean;
136 Rulez: Set of R_ITEM_BACKPACK..R_BERSERK;
137 Used: Boolean;
138 end;
140 TKeyState = record
141 Pressed: Boolean;
142 Time: Word;
143 end;
145 TPlayer = class{$IFDEF USE_MEMPOOL}(TPoolObject){$ENDIF}
146 private
147 FIamBot: Boolean;
148 FUID: Word;
149 FName: String;
150 FTeam: Byte;
151 FAlive: Boolean;
152 FSpawned: Boolean;
153 FDirection: TDirection;
154 FHealth: Integer;
155 FLives: Byte;
156 FArmor: Integer;
157 FAir: Integer;
158 FPain: Integer;
159 FPickup: Integer;
160 FKills: Integer;
161 FMonsterKills: Integer;
162 FFrags: Integer;
163 FFragCombo: Byte;
164 FLastFrag: LongWord;
165 FComboEvnt: Integer;
166 FDeath: Integer;
167 FCanJetpack: Boolean;
168 FJetFuel: Integer;
169 FFlag: Byte;
170 FSecrets: Integer;
171 FCurrWeap: Byte;
172 FNextWeap: WORD;
173 FNextWeapDelay: Byte; // frames
174 FBFGFireCounter: SmallInt;
175 FLastSpawnerUID: Word;
176 FLastHit: Byte;
177 FObj: TObj;
178 FXTo, FYTo: Integer;
179 FSpectatePlayer: Integer;
180 FFirePainTime: Integer;
181 FFireAttacker: Word;
183 FSavedStateNum: Integer;
185 FModel: TPlayerModel;
186 FPunchAnim: TAnimation;
187 FActionPrior: Byte;
188 FActionAnim: Byte;
189 FActionForce: Boolean;
190 FActionChanged: Boolean;
191 FAngle: SmallInt;
192 FFireAngle: SmallInt;
193 FIncCamOld: Integer;
194 FIncCam: Integer;
195 FSlopeOld: Integer;
196 FShellTimer: Integer;
197 FShellType: Byte;
198 FSawSound: TPlayableSound;
199 FSawSoundIdle: TPlayableSound;
200 FSawSoundHit: TPlayableSound;
201 FSawSoundSelect: TPlayableSound;
202 FFlameSoundOn: TPlayableSound;
203 FFlameSoundOff: TPlayableSound;
204 FFlameSoundWork: TPlayableSound;
205 FJetSoundOn: TPlayableSound;
206 FJetSoundOff: TPlayableSound;
207 FJetSoundFly: TPlayableSound;
208 FGodMode: Boolean;
209 FNoTarget: Boolean;
210 FNoReload: Boolean;
211 FJustTeleported: Boolean;
212 FNetTime: LongWord;
213 mEDamageType: Integer;
216 function CollideLevel(XInc, YInc: Integer): Boolean;
217 function StayOnStep(XInc, YInc: Integer): Boolean;
218 function HeadInLiquid(XInc, YInc: Integer): Boolean;
219 function BodyInLiquid(XInc, YInc: Integer): Boolean;
220 function BodyInAcid(XInc, YInc: Integer): Boolean;
221 function FullInLift(XInc, YInc: Integer): Integer;
222 {procedure CollideItem();}
223 procedure FlySmoke(Times: DWORD = 1);
224 procedure OnFireFlame(Times: DWORD = 1);
225 function GetAmmoByWeapon(Weapon: Byte): Word;
226 procedure SetAction(Action: Byte; Force: Boolean = False);
227 procedure OnDamage(Angle: SmallInt); virtual;
228 function firediry(): Integer;
229 procedure DoPunch();
231 procedure Run(Direction: TDirection);
232 procedure NextWeapon();
233 procedure PrevWeapon();
234 procedure SeeUp();
235 procedure SeeDown();
236 procedure Fire();
237 procedure Jump();
238 procedure Use();
240 function getNextWeaponIndex (): Byte; // return 255 for "no switch"
241 procedure resetWeaponQueue ();
242 function hasAmmoForWeapon (weapon: Byte): Boolean;
243 function hasAmmoForShooting (weapon: Byte): Boolean;
244 function shouldSwitch (weapon: Byte; hadWeapon: Boolean) : Boolean;
246 procedure doDamage (v: Integer);
248 function refreshCorpse(): Boolean;
250 public
251 FDamageBuffer: Integer;
253 FAmmo: Array [A_BULLETS..A_HIGH] of Word;
254 FMaxAmmo: Array [A_BULLETS..A_HIGH] of Word;
255 FWeapon: Array [WP_FIRST..WP_LAST] of Boolean;
256 FRulez: Set of R_ITEM_BACKPACK..R_BERSERK;
257 FBerserk: Integer;
258 FMegaRulez: Array [MR_SUIT..MR_MAX] of DWORD;
259 FReloading: Array [WP_FIRST..WP_LAST] of Word;
260 FTime: Array [T_RESPAWN..T_FLAGCAP] of DWORD;
261 FKeys: Array [KEY_LEFT..KEY_CHAT] of TKeyState;
262 FWeapSwitchMode: Byte;
263 FWeapPreferences: Array [WP_FIRST .. WP_LAST+1] of Byte;
264 FSwitchToEmpty: Byte;
265 FSkipFist: Byte;
266 FColor: TRGB;
267 FPreferredTeam: Byte;
268 FSpectator: Boolean;
269 FNoRespawn: Boolean;
270 FWantsInGame: Boolean;
271 FGhost: Boolean;
272 FPhysics: Boolean;
273 FFlaming: Boolean;
274 FJetpack: Boolean;
275 FActualModelName: string;
276 FClientID: SmallInt;
277 FPing: Word;
278 FLoss: Byte;
279 FReady: Boolean;
280 FDummy: Boolean;
281 FFireTime: Integer;
282 FSpawnInvul: Integer;
283 FHandicap: Integer;
284 FWaitForFirstSpawn: Boolean; // set to `true` in server, used to spawn a player on first full state request
285 FCorpse: Integer;
287 // debug: viewport offset
288 viewPortX, viewPortY, viewPortW, viewPortH: Integer;
290 function isValidViewPort (): Boolean; inline;
292 constructor Create(); virtual;
293 destructor Destroy(); override;
294 procedure Respawn(Silent: Boolean; Force: Boolean = False); virtual;
295 function GetRespawnPoint(): Byte;
296 procedure PressKey(Key: Byte; Time: Word = 1);
297 procedure ReleaseKeys();
298 procedure SetModel(ModelName: String);
299 procedure SetColor(Color: TRGB);
300 function GetColor(): TRGB;
301 procedure SetWeapon(W: Byte);
302 function IsKeyPressed(K: Byte): Boolean;
303 function GetKeys(): Byte;
304 function PickItem(ItemType: Byte; arespawn: Boolean; var remove: Boolean): Boolean; virtual;
305 procedure SetWeaponPrefs(Prefs: Array of Byte);
306 procedure SetWeaponPref(Weapon, Pref: Byte);
307 function GetWeaponPref(Weapon: Byte) : Byte;
308 function GetMorePrefered() : Byte;
309 function MaySwitch(Weapon: Byte) : Boolean;
310 function Collide(X, Y: Integer; Width, Height: Word): Boolean; overload;
311 function Collide(Panel: TPanel): Boolean; overload;
312 function Collide(X, Y: Integer): Boolean; overload;
313 procedure SetDirection(Direction: TDirection);
314 procedure GetSecret();
315 function TeleportTo(X, Y: Integer; silent: Boolean; dir: Byte): Boolean;
316 procedure Touch();
317 procedure Push(vx, vy: Integer);
318 procedure ChangeModel(ModelName: String);
319 procedure SwitchTeam;
320 procedure ChangeTeam(Team: Byte);
321 procedure BFGHit();
322 function GetFlag(Flag: Byte): Boolean;
323 procedure SetFlag(Flag: Byte);
324 function DropFlag(Silent: Boolean = True; DoThrow: Boolean = False): Boolean;
325 function TryDropFlag(): Boolean;
326 procedure AllRulez(Health: Boolean);
327 procedure RestoreHealthArmor();
328 procedure FragCombo();
329 procedure GiveItem(ItemType: Byte);
330 procedure Damage(value: Word; SpawnerUID: Word; vx, vy: Integer; t: Byte); virtual;
331 function Heal(value: Word; Soft: Boolean): Boolean; virtual;
332 procedure MakeBloodVector(Count: Word; VelX, VelY: Integer);
333 procedure MakeBloodSimple(Count: Word);
334 procedure Kill(KillType: Byte; SpawnerUID: Word; t: Byte);
335 procedure Reset(Force: Boolean);
336 procedure Spectate(NoMove: Boolean = False);
337 procedure SwitchNoClip;
338 procedure SoftReset();
339 procedure Draw(); virtual;
340 procedure DrawPain();
341 procedure DrawPickup();
342 procedure DrawRulez();
343 procedure DrawAim();
344 procedure DrawIndicator(Color: TRGB);
345 procedure DrawBubble();
346 procedure DrawGUI();
347 procedure PreUpdate();
348 procedure Update(); virtual;
349 procedure RememberState();
350 procedure RecallState();
351 procedure SaveState (st: TStream); virtual;
352 procedure LoadState (st: TStream); virtual;
353 procedure PauseSounds(Enable: Boolean);
354 procedure NetFire(Wpn: Byte; X, Y, AX, AY: Integer; WID: Integer = -1);
355 procedure DoLerp(Level: Integer = 2);
356 procedure SetLerp(XTo, YTo: Integer);
357 procedure ProcessWeaponAction(Action: Byte);
358 procedure QueueWeaponSwitch(Weapon: Byte);
359 procedure RealizeCurrentWeapon();
360 procedure FlamerOn;
361 procedure FlamerOff;
362 procedure JetpackOn;
363 procedure JetpackOff;
364 procedure CatchFire(Attacker: Word; Timeout: Integer = PLAYER_BURN_TIME);
366 //WARNING! this does nothing for now, but still call it!
367 procedure positionChanged (); //WARNING! call this after entity position was changed, or coldet will not work right!
369 procedure getMapBox (out x, y, w, h: Integer); inline;
370 procedure moveBy (dx, dy: Integer); inline;
372 function getCameraObj(): TObj;
374 public
375 property Vel: TPoint2i read FObj.Vel;
376 property Obj: TObj read FObj;
378 property Name: String read FName write FName;
379 property Model: TPlayerModel read FModel;
380 property Health: Integer read FHealth write FHealth;
381 property Lives: Byte read FLives write FLives;
382 property Armor: Integer read FArmor write FArmor;
383 property Air: Integer read FAir write FAir;
384 property JetFuel: Integer read FJetFuel write FJetFuel;
385 property Frags: Integer read FFrags write FFrags;
386 property Death: Integer read FDeath write FDeath;
387 property Kills: Integer read FKills write FKills;
388 property CurrWeap: Byte read FCurrWeap write FCurrWeap;
389 property WeapSwitchMode: Byte read FWeapSwitchMode write FWeapSwitchMode;
390 property SwitchToEmpty: Byte read FSwitchToEmpty write FSwitchToEmpty;
391 property SkipFist: Byte read FSkipFist write FSkipFist;
392 property MonsterKills: Integer read FMonsterKills write FMonsterKills;
393 property Secrets: Integer read FSecrets;
394 property GodMode: Boolean read FGodMode write FGodMode;
395 property NoTarget: Boolean read FNoTarget write FNoTarget;
396 property NoReload: Boolean read FNoReload write FNoReload;
397 property alive: Boolean read FAlive write FAlive;
398 property Flag: Byte read FFlag;
399 property Team: Byte read FTeam write FTeam;
400 property Direction: TDirection read FDirection;
401 property GameX: Integer read FObj.X write FObj.X;
402 property GameY: Integer read FObj.Y write FObj.Y;
403 property GameVelX: Integer read FObj.Vel.X write FObj.Vel.X;
404 property GameVelY: Integer read FObj.Vel.Y write FObj.Vel.Y;
405 property GameAccelX: Integer read FObj.Accel.X write FObj.Accel.X;
406 property GameAccelY: Integer read FObj.Accel.Y write FObj.Accel.Y;
407 property IncCam: Integer read FIncCam write FIncCam;
408 property IncCamOld: Integer read FIncCamOld write FIncCamOld;
409 property SlopeOld: Integer read FSlopeOld write FSlopeOld;
410 property UID: Word read FUID write FUID;
411 property JustTeleported: Boolean read FJustTeleported write FJustTeleported;
412 property NetTime: LongWord read FNetTime write FNetTime;
414 published
415 property eName: String read FName write FName;
416 property eHealth: Integer read FHealth write FHealth;
417 property eLives: Byte read FLives write FLives;
418 property eArmor: Integer read FArmor write FArmor;
419 property eAir: Integer read FAir write FAir;
420 property eJetFuel: Integer read FJetFuel write FJetFuel;
421 property eFrags: Integer read FFrags write FFrags;
422 property eDeath: Integer read FDeath write FDeath;
423 property eKills: Integer read FKills write FKills;
424 property eCurrWeap: Byte read FCurrWeap write FCurrWeap;
425 property eMonsterKills: Integer read FMonsterKills write FMonsterKills;
426 property eSecrets: Integer read FSecrets write FSecrets;
427 property eGodMode: Boolean read FGodMode write FGodMode;
428 property eNoTarget: Boolean read FNoTarget write FNoTarget;
429 property eNoReload: Boolean read FNoReload write FNoReload;
430 property eAlive: Boolean read FAlive write FAlive;
431 property eFlag: Byte read FFlag;
432 property eTeam: Byte read FTeam write FTeam;
433 property eDirection: TDirection read FDirection;
434 property eGameX: Integer read FObj.X write FObj.X;
435 property eGameY: Integer read FObj.Y write FObj.Y;
436 property eGameVelX: Integer read FObj.Vel.X write FObj.Vel.X;
437 property eGameVelY: Integer read FObj.Vel.Y write FObj.Vel.Y;
438 property eGameAccelX: Integer read FObj.Accel.X write FObj.Accel.X;
439 property eGameAccelY: Integer read FObj.Accel.Y write FObj.Accel.Y;
440 property eIncCam: Integer read FIncCam write FIncCam;
441 property eUID: Word read FUID;
442 property eJustTeleported: Boolean read FJustTeleported;
443 property eNetTime: LongWord read FNetTime;
445 // set this before assigning something to `eDamage`
446 property eDamageType: Integer read mEDamageType write mEDamageType;
447 property eDamage: Integer write doDamage;
448 end;
450 TDifficult = record
451 public
452 DiagFire: Byte;
453 InvisFire: Byte;
454 DiagPrecision: Byte;
455 FlyPrecision: Byte;
456 Cover: Byte;
457 CloseJump: Byte;
458 WeaponPrior: packed array [WP_FIRST..WP_LAST] of Byte;
459 CloseWeaponPrior: packed array [WP_FIRST..WP_LAST] of Byte;
460 //SafeWeaponPrior: Array [WP_FIRST..WP_LAST] of Byte;
462 public
463 procedure save (st: TStream);
464 procedure load (st: TStream);
465 end;
467 TAIFlag = record
468 Name: String;
469 Value: String;
470 end;
472 TBot = class(TPlayer)
473 private
474 FSelectedWeapon: Byte;
475 FTargetUID: Word;
476 FLastVisible: DWORD;
477 FAIFlags: Array of TAIFlag;
478 FDifficult: TDifficult;
480 function GetRnd(a: Byte): Boolean;
481 function GetInterval(a: Byte; radius: SmallInt): SmallInt;
482 function RunDirection(): TDirection;
483 function FullInStep(XInc, YInc: Integer): Boolean;
484 //function NeedItem(Item: Byte): Byte;
485 procedure SelectWeapon(Dist: Integer);
486 procedure SetAIFlag(aName, fValue: String20);
487 function GetAIFlag(aName: String20): String20;
488 procedure RemoveAIFlag(aName: String20);
489 function Healthy(): Byte;
490 procedure UpdateMove();
491 procedure UpdateCombat();
492 function KeyPressed(Key: Word): Boolean;
493 procedure ReleaseKey(Key: Byte);
494 function TargetOnScreen(TX, TY: Integer): Boolean;
495 procedure OnDamage(Angle: SmallInt); override;
497 public
498 procedure Respawn(Silent: Boolean; Force: Boolean = False); override;
499 constructor Create(); override;
500 destructor Destroy(); override;
501 procedure Draw(); override;
502 function PickItem(ItemType: Byte; force: Boolean; var remove: Boolean): Boolean; override;
503 function Heal(value: Word; Soft: Boolean): Boolean; override;
504 procedure Update(); override;
505 procedure SaveState (st: TStream); override;
506 procedure LoadState (st: TStream); override;
507 end;
509 PGib = ^TGib;
510 TGib = record
511 alive: Boolean;
512 ID: DWORD;
513 MaskID: DWORD;
514 RAngle: Integer;
515 Color: TRGB;
516 Obj: TObj;
518 procedure getMapBox (out x, y, w, h: Integer); inline;
519 procedure moveBy (dx, dy: Integer); inline;
521 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
522 end;
525 PShell = ^TShell;
526 TShell = record
527 SpriteID: DWORD;
528 alive: Boolean;
529 SType: Byte;
530 RAngle: Integer;
531 Timeout: Cardinal;
532 CX, CY: Integer;
533 Obj: TObj;
535 procedure getMapBox (out x, y, w, h: Integer); inline;
536 procedure moveBy (dx, dy: Integer); inline;
538 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
539 end;
541 TCorpse = class{$IFDEF USE_MEMPOOL}(TPoolObject){$ENDIF}
542 private
543 FModelName: String;
544 FMess: Boolean;
545 FState: Byte;
546 FDamage: Byte;
547 FColor: TRGB;
548 FObj: TObj;
549 FPlayerUID: Word;
550 FAnimation: TAnimation;
551 FAnimationMask: TAnimation;
553 public
554 constructor Create(X, Y: Integer; ModelName: String; aMess: Boolean);
555 destructor Destroy(); override;
556 procedure Damage(Value: Word; SpawnerUID: Word; vx, vy: Integer);
557 procedure Update();
558 procedure Draw();
559 procedure SaveState (st: TStream);
560 procedure LoadState (st: TStream);
562 procedure getMapBox (out x, y, w, h: Integer); inline;
563 procedure moveBy (dx, dy: Integer); inline;
565 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
567 function ObjPtr (): PObj; inline;
569 property Obj: TObj read FObj; // copies object
570 property State: Byte read FState;
571 property Mess: Boolean read FMess;
572 end;
574 TTeamStat = Array [TEAM_RED..TEAM_BLUE] of
575 record
576 Score: SmallInt;
577 end;
579 var
580 gPlayers: Array of TPlayer;
581 gCorpses: Array of TCorpse;
582 gGibs: Array of TGib;
583 gShells: Array of TShell;
584 gTeamStat: TTeamStat;
585 gFly: Boolean = False;
586 gAimLine: Boolean = False;
587 gChatBubble: Integer = 0;
588 gPlayerIndicator: Integer = 1;
589 gPlayerIndicatorStyle: Integer = 0;
590 gNumBots: Word = 0;
591 gSpectLatchPID1: Word = 0;
592 gSpectLatchPID2: Word = 0;
593 MAX_RUNVEL: Integer = 8;
594 VEL_JUMP: Integer = 10;
595 SHELL_TIMEOUT: Cardinal = 60000;
597 function Lerp(X, Y, Factor: Integer): Integer;
599 procedure g_Gibs_SetMax(Count: Word);
600 function g_Gibs_GetMax(): Word;
601 procedure g_Corpses_SetMax(Count: Word);
602 function g_Corpses_GetMax(): Word;
603 procedure g_Force_Model_Set(Mode: Word);
604 function g_Force_Model_Get(): Word;
605 procedure g_Forced_Model_SetName(Model: String);
606 function g_Forced_Model_GetName(): String;
607 procedure g_Shells_SetMax(Count: Word);
608 function g_Shells_GetMax(): Word;
610 procedure g_Player_Init();
611 procedure g_Player_Free();
612 function g_Player_Create(ModelName: String; Color: TRGB; Team: Byte; Bot: Boolean): Word;
613 function g_Player_CreateFromState (st: TStream): Word;
614 procedure g_Player_Remove(UID: Word);
615 procedure g_Player_ResetTeams();
616 procedure g_Player_PreUpdate();
617 procedure g_Player_UpdateAll();
618 procedure g_Player_DrawAll();
619 procedure g_Player_DrawDebug(p: TPlayer);
620 procedure g_Player_DrawHealth();
621 procedure g_Player_RememberAll();
622 procedure g_Player_ResetAll(Force, Silent: Boolean);
623 function g_Player_Get(UID: Word): TPlayer;
624 function g_Player_GetCount(): Byte;
625 function g_Player_GetStats(): TPlayerStatArray;
626 function g_Player_ValidName(Name: String): Boolean;
627 function g_Player_CreateCorpse(Player: TPlayer): Integer;
628 procedure g_Player_CreateGibs(fX, fY: Integer; ModelName: String; fColor: TRGB);
629 procedure g_Player_CreateShell(fX, fY, dX, dY: Integer; T: Byte);
630 procedure g_Player_UpdatePhysicalObjects();
631 procedure g_Player_DrawCorpses();
632 procedure g_Player_DrawShells();
633 procedure g_Player_RemoveAllCorpses();
634 procedure g_Player_Corpses_SaveState (st: TStream);
635 procedure g_Player_Corpses_LoadState (st: TStream);
636 procedure g_Player_ResetReady();
637 procedure g_Bot_Add(Team, Difficult: Byte; Handicap: Integer = 100);
638 procedure g_Bot_AddList(Team: Byte; lname: ShortString; num: Integer = -1; Handicap: Integer = 100);
639 procedure g_Bot_MixNames();
640 procedure g_Bot_RemoveAll();
641 function g_Bot_GetCount(): Integer;
643 implementation
645 uses
646 {$INCLUDE ../nogl/noGLuses.inc}
647 {$IFDEF ENABLE_HOLMES}
648 g_holmes,
649 {$ENDIF}
650 e_log, g_map, g_items, g_console, g_gfx, Math,
651 g_options, g_triggers, g_menu, g_game, g_grid, e_res,
652 wadreader, g_main, g_monsters, CONFIG, g_language,
653 g_net, g_netmsg, g_window,
654 utils, xstreams;
656 const PLR_SAVE_VERSION = 0;
658 type
659 TBotProfile = record
660 name: ShortString;
661 model: ShortString;
662 team: Byte;
663 color: TRGB;
664 diag_fire: Byte;
665 invis_fire: Byte;
666 diag_precision: Byte;
667 fly_precision: Byte;
668 cover: Byte;
669 close_jump: Byte;
670 w_prior1: Array [WP_FIRST..WP_LAST] of Byte;
671 w_prior2: Array [WP_FIRST..WP_LAST] of Byte;
672 w_prior3: Array [WP_FIRST..WP_LAST] of Byte;
673 end;
675 const
676 TIME_RESPAWN1 = 1500;
677 TIME_RESPAWN2 = 2000;
678 TIME_RESPAWN3 = 3000;
679 AIR_DEF = 360;
680 AIR_MAX = 1091;
681 JET_MAX = 540; // ~30 sec
682 PLAYER_SUIT_TIME = 30000;
683 PLAYER_INVUL_TIME = 30000;
684 PLAYER_INVIS_TIME = 35000;
685 FRAG_COMBO_TIME = 3000;
686 VEL_SW = 4;
687 VEL_FLY = 6;
688 ANGLE_RIGHTUP = 55;
689 ANGLE_RIGHTDOWN = -35;
690 ANGLE_LEFTUP = 125;
691 ANGLE_LEFTDOWN = -145;
692 PLAYER_HEADRECT: TRectWH = (X:24; Y:12; Width:20; Height:12);
693 WEAPONPOINT: Array [TDirection] of TDFPoint = ((X:16; Y:32), (X:47; Y:32));
694 BOT_MAXJUMP = 84;
695 BOT_LONGDIST = 300;
696 BOT_UNSAFEDIST = 128;
697 TEAMCOLOR: Array [TEAM_RED..TEAM_BLUE] of TRGB = ((R:255; G:0; B:0),
698 (R:0; G:0; B:255));
699 DIFFICULT_EASY: TDifficult = (DiagFire: 32; InvisFire: 32; DiagPrecision: 32;
700 FlyPrecision: 32; Cover: 32; CloseJump: 32;
701 WeaponPrior:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior:(0,0,0,0,0,0,0,0,0,0,0));
702 DIFFICULT_MEDIUM: TDifficult = (DiagFire: 127; InvisFire: 127; DiagPrecision: 127;
703 FlyPrecision: 127; Cover: 127; CloseJump: 127;
704 WeaponPrior:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior:(0,0,0,0,0,0,0,0,0,0,0));
705 DIFFICULT_HARD: TDifficult = (DiagFire: 255; InvisFire: 255; DiagPrecision: 255;
706 FlyPrecision: 255; Cover: 255; CloseJump: 255;
707 WeaponPrior:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior:(0,0,0,0,0,0,0,0,0,0,0));
708 WEAPON_PRIOR1: Array [WP_FIRST..WP_LAST] of Byte =
709 (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
710 WEAPON_SHOTGUN2, WEAPON_SHOTGUN1,
711 WEAPON_CHAINGUN, WEAPON_PLASMA, WEAPON_ROCKETLAUNCHER,
712 WEAPON_BFG, WEAPON_PISTOL, WEAPON_SAW, WEAPON_KASTET);
713 WEAPON_PRIOR2: Array [WP_FIRST..WP_LAST] of Byte =
714 (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
715 WEAPON_BFG, WEAPON_ROCKETLAUNCHER,
716 WEAPON_SHOTGUN2, WEAPON_PLASMA, WEAPON_SHOTGUN1,
717 WEAPON_CHAINGUN, WEAPON_PISTOL, WEAPON_SAW, WEAPON_KASTET);
718 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
719 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
720 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
721 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
722 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
723 WEAPON_RELOAD: Array [WP_FIRST..WP_LAST] of Byte =
724 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
726 PLAYER_SIGNATURE = $52594C50; // 'PLYR'
727 CORPSE_SIGNATURE = $50524F43; // 'CORP'
729 BOTNAMES_FILENAME = 'botnames.txt';
730 BOTLIST_FILENAME = 'botlist.txt';
732 var
733 MaxGibs: Word = 150;
734 MaxCorpses: Word = 20;
735 MaxShells: Word = 300;
736 ForceModel: Word = 0;
737 ForcedModelName: String = STD_PLAYER_MODEL;
738 CurrentGib: Integer = 0;
739 CurrentShell: Integer = 0;
740 BotNames: Array of String;
741 BotList: Array of TBotProfile;
742 SavedStates: Array of TPlayerSavedState;
745 function Lerp(X, Y, Factor: Integer): Integer;
746 begin
747 Result := X + ((Y - X) div Factor);
748 end;
750 function SameTeam(UID1, UID2: Word): Boolean;
751 begin
752 Result := False;
754 if (UID1 > UID_MAX_PLAYER) or (UID1 <= UID_MAX_GAME) or
755 (UID2 > UID_MAX_PLAYER) or (UID2 <= UID_MAX_GAME) then Exit;
757 if (g_Player_Get(UID1) = nil) or (g_Player_Get(UID2) = nil) then Exit;
759 if ((g_Player_Get(UID1).Team = TEAM_NONE) or
760 (g_Player_Get(UID2).Team = TEAM_NONE)) then Exit;
762 Result := g_Player_Get(UID1).FTeam = g_Player_Get(UID2).FTeam;
763 end;
765 procedure g_Gibs_SetMax(Count: Word);
766 begin
767 MaxGibs := Count;
768 SetLength(gGibs, Count);
770 if CurrentGib >= Count then
771 CurrentGib := 0;
772 end;
774 function g_Gibs_GetMax(): Word;
775 begin
776 Result := MaxGibs;
777 end;
779 procedure g_Shells_SetMax(Count: Word);
780 begin
781 MaxShells := Count;
782 SetLength(gShells, Count);
784 if CurrentShell >= Count then
785 CurrentShell := 0;
786 end;
788 function g_Shells_GetMax(): Word;
789 begin
790 Result := MaxShells;
791 end;
794 procedure g_Corpses_SetMax(Count: Word);
795 begin
796 MaxCorpses := Count;
797 SetLength(gCorpses, Count);
798 end;
800 function g_Corpses_GetMax(): Word;
801 begin
802 Result := MaxCorpses;
803 end;
805 procedure g_Force_Model_Set(Mode: Word);
806 begin
807 ForceModel := Mode;
808 end;
810 function g_Force_Model_Get(): Word;
811 begin
812 Result := ForceModel;
813 end;
815 procedure g_Forced_Model_SetName(Model: String);
816 begin
817 ForcedModelName := Model;
818 end;
820 function g_Forced_Model_GetName(): String;
821 begin
822 Result := ForcedModelName;
823 end;
825 function g_Player_Create(ModelName: String; Color: TRGB; Team: Byte; Bot: Boolean): Word;
826 var
827 a: Integer;
828 ok: Boolean;
829 begin
830 Result := 0;
832 ok := False;
833 a := 0;
835 // Åñòü ëè ìåñòî â gPlayers:
836 if gPlayers <> nil then
837 for a := 0 to High(gPlayers) do
838 if gPlayers[a] = nil then
839 begin
840 ok := True;
841 Break;
842 end;
844 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
845 if not ok then
846 begin
847 SetLength(gPlayers, Length(gPlayers)+1);
848 a := High(gPlayers);
849 end;
851 // Ñîçäàåì îáúåêò èãðîêà:
852 if Bot then
853 gPlayers[a] := TBot.Create()
854 else
855 gPlayers[a] := TPlayer.Create();
858 gPlayers[a].FActualModelName := ModelName;
859 gPlayers[a].SetModel(ModelName);
860 if Bot and (g_Force_Model_Get() <> 0) then
861 gPlayers[a].SetModel(g_Forced_Model_GetName());
863 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
864 if gPlayers[a].FModel = nil then
865 begin
866 gPlayers[a].Free();
867 gPlayers[a] := nil;
868 g_FatalError(Format(_lc[I_GAME_ERROR_MODEL], [ModelName]));
869 Exit;
870 end;
872 if not (Team in [TEAM_RED, TEAM_BLUE]) then
873 if Random(2) = 0 then
874 Team := TEAM_RED
875 else
876 Team := TEAM_BLUE;
877 gPlayers[a].FPreferredTeam := Team;
879 case gGameSettings.GameMode of
880 GM_DM: gPlayers[a].FTeam := TEAM_NONE;
881 GM_TDM,
882 GM_CTF: gPlayers[a].FTeam := gPlayers[a].FPreferredTeam;
883 GM_SINGLE,
884 GM_COOP: gPlayers[a].FTeam := TEAM_COOP;
885 end;
887 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
888 gPlayers[a].FColor := Color;
889 if gPlayers[a].FTeam in [TEAM_RED, TEAM_BLUE] then
890 gPlayers[a].FModel.Color := TEAMCOLOR[gPlayers[a].FTeam]
891 else
892 gPlayers[a].FModel.Color := Color;
894 gPlayers[a].FUID := g_CreateUID(UID_PLAYER);
895 gPlayers[a].FAlive := False;
897 Result := gPlayers[a].FUID;
898 end;
900 function g_Player_CreateFromState (st: TStream): Word;
901 var a: Integer; ok, Bot: Boolean; pos: Int64;
902 begin
903 assert(st <> nil);
905 // check signature and entity type
906 pos := st.Position;
907 if not utils.checkSign(st, 'PLYR') then raise XStreamError.Create('invalid player signature');
908 if (utils.readByte(st) <> PLR_SAVE_VERSION) then raise XStreamError.Create('invalid player version');
909 Bot := utils.readBool(st);
910 st.Position := pos;
912 // find free player slot
913 ok := false;
914 for a := 0 to High(gPlayers) do
915 if gPlayers[a] = nil then
916 begin
917 ok := true;
918 break;
919 end;
921 // allocate player slot
922 if not ok then
923 begin
924 SetLength(gPlayers, Length(gPlayers)+1);
925 a := High(gPlayers);
926 end;
928 // create entity and load state
929 if Bot then
930 begin
931 gPlayers[a] := TBot.Create();
932 if (g_Force_Model_Get() <> 0) then
933 gPlayers[a].SetModel(g_Forced_Model_GetName());
934 end
935 else
936 gPlayers[a] := TPlayer.Create();
937 gPlayers[a].FPhysics := True; // ???
938 gPlayers[a].LoadState(st);
940 result := gPlayers[a].FUID;
941 end;
944 procedure g_Player_ResetTeams();
945 var
946 a: Integer;
947 begin
948 if g_Game_IsClient then
949 Exit;
950 if gPlayers = nil then
951 Exit;
952 for a := Low(gPlayers) to High(gPlayers) do
953 if gPlayers[a] <> nil then
954 case gGameSettings.GameMode of
955 GM_DM:
956 gPlayers[a].ChangeTeam(TEAM_NONE);
957 GM_TDM, GM_CTF:
958 if not (gPlayers[a].Team in [TEAM_RED, TEAM_BLUE]) then
959 if gPlayers[a].FPreferredTeam in [TEAM_RED, TEAM_BLUE] then
960 gPlayers[a].ChangeTeam(gPlayers[a].FPreferredTeam)
961 else
962 if a mod 2 = 0 then
963 gPlayers[a].ChangeTeam(TEAM_RED)
964 else
965 gPlayers[a].ChangeTeam(TEAM_BLUE);
966 GM_SINGLE,
967 GM_COOP:
968 gPlayers[a].ChangeTeam(TEAM_COOP);
969 end;
970 end;
972 procedure g_Bot_Add(Team, Difficult: Byte; Handicap: Integer = 100);
973 var
974 m: SSArray;
975 _name, _model: String;
976 a, tr, tb: Integer;
977 begin
978 if not g_Game_IsServer then Exit;
980 // Íå äîáàâëÿåì áîòîâ åñëè ëèìèò óæå äîñòèãíóò
981 if (g_Bot_GetCount() >= gMaxBots) then Exit;
983 // Ñïèñîê íàçâàíèé ìîäåëåé:
984 m := g_PlayerModel_GetNames();
985 if m = nil then
986 Exit;
988 // Êîìàíäà:
989 if (gGameSettings.GameType = GT_SINGLE) or (gGameSettings.GameMode = GM_COOP) then
990 Team := TEAM_COOP // COOP
991 else
992 if gGameSettings.GameMode = GM_DM then
993 Team := TEAM_NONE // DM
994 else
995 if Team = TEAM_NONE then // CTF / TDM
996 begin
997 // Àâòîáàëàíñ êîìàíä:
998 tr := 0;
999 tb := 0;
1001 for a := 0 to High(gPlayers) do
1002 if gPlayers[a] <> nil then
1003 begin
1004 if gPlayers[a].Team = TEAM_RED then
1005 Inc(tr)
1006 else
1007 if gPlayers[a].Team = TEAM_BLUE then
1008 Inc(tb);
1009 end;
1011 if tr > tb then
1012 Team := TEAM_BLUE
1013 else
1014 if tb > tr then
1015 Team := TEAM_RED
1016 else // tr = tb
1017 if Random(2) = 0 then
1018 Team := TEAM_RED
1019 else
1020 Team := TEAM_BLUE;
1021 end;
1023 // Âûáèðàåì áîòó èìÿ:
1024 _name := '';
1025 if BotNames <> nil then
1026 for a := 0 to High(BotNames) do
1027 if g_Player_ValidName(BotNames[a]) then
1028 begin
1029 _name := BotNames[a];
1030 Break;
1031 end;
1033 // Âûáèðàåì ñëó÷àéíóþ ìîäåëü:
1034 _model := m[Random(Length(m))];
1036 // Ñîçäàåì áîòà:
1037 with g_Player_Get(g_Player_Create(_model,
1038 _RGB(Min(Random(9)*32, 255),
1039 Min(Random(9)*32, 255),
1040 Min(Random(9)*32, 255)),
1041 Team, True)) as TBot do
1042 begin
1043 // Åñëè èìåíè íåò, äåëàåì åãî èç UID áîòà
1044 if _name = '' then
1045 Name := Format('DFBOT%.5d', [UID])
1046 else
1047 Name := _name;
1049 case Difficult of
1050 1: FDifficult := DIFFICULT_EASY;
1051 2: FDifficult := DIFFICULT_MEDIUM;
1052 else FDifficult := DIFFICULT_HARD;
1053 end;
1055 for a := WP_FIRST to WP_LAST do
1056 begin
1057 FDifficult.WeaponPrior[a] := WEAPON_PRIOR1[a];
1058 FDifficult.CloseWeaponPrior[a] := WEAPON_PRIOR2[a];
1059 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1060 end;
1062 FHandicap := Handicap;
1064 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [Name]), True);
1066 if g_Game_IsNet then MH_SEND_PlayerCreate(UID);
1067 if g_Game_IsServer and (gGameSettings.MaxLives > 0) then
1068 Spectate();
1069 end;
1070 end;
1072 procedure g_Bot_AddList(Team: Byte; lName: ShortString; num: Integer = -1; Handicap: Integer = 100);
1073 var
1074 m: SSArray;
1075 _name, _model: String;
1076 a: Integer;
1077 begin
1078 if not g_Game_IsServer then Exit;
1080 // Íå äîáàâëÿåì áîòîâ åñëè ëèìèò óæå äîñòèãíóò
1081 if (g_Bot_GetCount() >= gMaxBots) then Exit;
1083 // Ñïèñîê íàçâàíèé ìîäåëåé:
1084 m := g_PlayerModel_GetNames();
1085 if m = nil then
1086 Exit;
1088 // Êîìàíäà:
1089 if (gGameSettings.GameType = GT_SINGLE) or (gGameSettings.GameMode = GM_COOP) then
1090 Team := TEAM_COOP // COOP
1091 else
1092 if gGameSettings.GameMode = GM_DM then
1093 Team := TEAM_NONE // DM
1094 else
1095 if Team = TEAM_NONE then
1096 Team := BotList[num].team; // CTF / TDM
1098 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1099 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 // Çàíÿòî - âûáèðàåì ñëó÷àéíîå:
1120 if not g_Player_ValidName(_name) then
1121 repeat
1122 _name := Format('DFBOT%.2d', [Random(100)]);
1123 until g_Player_ValidName(_name);
1125 // Ìîäåëü:
1126 _model := BotList[num].model;
1127 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1128 if not InSArray(_model, m) then
1129 _model := m[Random(Length(m))];
1131 // Ñîçäàåì áîòà:
1132 with g_Player_Get(g_Player_Create(_model, BotList[num].color, Team, True)) as TBot do
1133 begin
1134 Name := _name;
1136 FDifficult.DiagFire := BotList[num].diag_fire;
1137 FDifficult.InvisFire := BotList[num].invis_fire;
1138 FDifficult.DiagPrecision := BotList[num].diag_precision;
1139 FDifficult.FlyPrecision := BotList[num].fly_precision;
1140 FDifficult.Cover := BotList[num].cover;
1141 FDifficult.CloseJump := BotList[num].close_jump;
1143 FHandicap := Handicap;
1145 for a := WP_FIRST to WP_LAST do
1146 begin
1147 FDifficult.WeaponPrior[a] := BotList[num].w_prior1[a];
1148 FDifficult.CloseWeaponPrior[a] := BotList[num].w_prior2[a];
1149 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1150 end;
1152 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [Name]), True);
1154 if g_Game_IsNet then MH_SEND_PlayerCreate(UID);
1155 end;
1156 end;
1158 procedure g_Bot_RemoveAll();
1159 var
1160 a: Integer;
1161 begin
1162 if not g_Game_IsServer then Exit;
1163 if gPlayers = nil then Exit;
1165 for a := 0 to High(gPlayers) do
1166 if gPlayers[a] <> nil then
1167 if gPlayers[a] is TBot then
1168 begin
1169 gPlayers[a].Lives := 0;
1170 gPlayers[a].Kill(K_SIMPLEKILL, 0, HIT_DISCON);
1171 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [gPlayers[a].Name]), True);
1172 g_Player_Remove(gPlayers[a].FUID);
1173 end;
1175 g_Bot_MixNames();
1176 end;
1178 procedure g_Bot_MixNames();
1179 var
1180 s: String;
1181 a, b: Integer;
1182 begin
1183 if BotNames <> nil then
1184 for a := 0 to High(BotNames) do
1185 begin
1186 b := Random(Length(BotNames));
1187 s := BotNames[a];
1188 Botnames[a] := BotNames[b];
1189 BotNames[b] := s;
1190 end;
1191 end;
1193 procedure g_Player_Remove(UID: Word);
1194 var
1195 i: Integer;
1196 begin
1197 if gPlayers = nil then Exit;
1199 if g_Game_IsServer and g_Game_IsNet then
1200 MH_SEND_PlayerDelete(UID);
1202 for i := 0 to High(gPlayers) do
1203 if gPlayers[i] <> nil then
1204 if gPlayers[i].FUID = UID then
1205 begin
1206 if gPlayers[i] is TPlayer then
1207 TPlayer(gPlayers[i]).Free()
1208 else
1209 TBot(gPlayers[i]).Free();
1210 gPlayers[i] := nil;
1211 Exit;
1212 end;
1213 end;
1215 procedure g_Player_Init();
1216 var
1217 F: TextFile;
1218 s: String;
1219 a, b: Integer;
1220 config: TConfig;
1221 sa: SSArray;
1222 path: AnsiString;
1223 begin
1224 BotNames := nil;
1225 BotList := nil;
1227 path := BOTNAMES_FILENAME;
1228 if e_FindResource(DataDirs, path) then
1229 begin
1230 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1231 AssignFile(F, path);
1232 Reset(F);
1234 while not EOF(F) do
1235 begin
1236 ReadLn(F, s);
1238 s := Trim(s);
1239 if s = '' then
1240 Continue;
1242 SetLength(BotNames, Length(BotNames)+1);
1243 BotNames[High(BotNames)] := s;
1244 end;
1246 CloseFile(F);
1248 // Ïåðåìåøèâàåì èõ:
1249 g_Bot_MixNames();
1250 end;
1252 path := BOTLIST_FILENAME;
1253 if e_FindResource(DataDirs, path) then
1254 begin
1255 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1256 config := TConfig.CreateFile(path);
1257 a := 0;
1259 while config.SectionExists(IntToStr(a)) do
1260 begin
1261 SetLength(BotList, Length(BotList)+1);
1263 with BotList[High(BotList)] do
1264 begin
1265 name := config.ReadStr(IntToStr(a), 'name', ''); // Èìÿ áîòà
1266 model := config.ReadStr(IntToStr(a), 'model', ''); // Ìîäåëü
1268 // Êîìàíäà
1269 if config.ReadStr(IntToStr(a), 'team', 'red') = 'red'
1270 then team := TEAM_RED
1271 else team := TEAM_BLUE;
1273 // Öâåò ìîäåëè
1274 sa := parse(config.ReadStr(IntToStr(a), 'color', ''));
1275 color.R := StrToIntDef(sa[0], 0);
1276 color.G := StrToIntDef(sa[1], 0);
1277 color.B := StrToIntDef(sa[2], 0);
1279 diag_fire := config.ReadInt(IntToStr(a), 'diag_fire', 0); // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì
1280 invis_fire := config.ReadInt(IntToStr(a), 'invis_fire', 0); // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó
1281 diag_precision := config.ReadInt(IntToStr(a), 'diag_precision', 0); // Òî÷íîñòü ñòðåëüáû ïîä óãëîì
1282 fly_precision := config.ReadInt(IntToStr(a), 'fly_precision', 0); // Òî÷íîñòü ñòðåëüáû â ïîëåòå
1283 cover := config.ReadInt(IntToStr(a), 'cover', 0); // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ
1284 close_jump := config.ReadInt(IntToStr(a), 'close_jump', 0); // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà
1286 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ
1287 sa := parse(config.ReadStr(IntToStr(a), 'w_prior1', ''));
1288 if Length(sa) = 10 then
1289 for b := 0 to 9 do
1290 w_prior1[b] := EnsureRange(StrToInt(sa[b]), 0, 9);
1292 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ
1293 sa := parse(config.ReadStr(IntToStr(a), 'w_prior2', ''));
1294 if Length(sa) = 10 then
1295 for b := 0 to 9 do
1296 w_prior2[b] := EnsureRange(StrToInt(sa[b]), 0, 9);
1298 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1299 if Length(sa) = 10 then
1300 for b := 0 to 9 do
1301 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1302 end;
1304 a += 1;
1305 end;
1307 config.Free();
1308 end;
1310 SetLength(SavedStates, 0);
1311 end;
1313 procedure g_Player_Free();
1314 var
1315 i: Integer;
1316 begin
1317 if gPlayers <> nil then
1318 begin
1319 for i := 0 to High(gPlayers) do
1320 if gPlayers[i] <> nil then
1321 begin
1322 if gPlayers[i] is TPlayer then
1323 TPlayer(gPlayers[i]).Free()
1324 else
1325 TBot(gPlayers[i]).Free();
1326 gPlayers[i] := nil;
1327 end;
1329 gPlayers := nil;
1330 end;
1332 gPlayer1 := nil;
1333 gPlayer2 := nil;
1334 SetLength(SavedStates, 0);
1335 end;
1337 procedure g_Player_PreUpdate();
1338 var
1339 i: Integer;
1340 begin
1341 if gPlayers = nil then Exit;
1342 for i := 0 to High(gPlayers) do
1343 if gPlayers[i] <> nil then
1344 gPlayers[i].PreUpdate();
1345 end;
1347 procedure g_Player_UpdateAll();
1348 var
1349 i: Integer;
1350 begin
1351 if gPlayers = nil then Exit;
1353 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1354 for i := 0 to High(gPlayers) do
1355 begin
1356 if gPlayers[i] <> nil then
1357 begin
1358 if gPlayers[i] is TPlayer then
1359 begin
1360 gPlayers[i].Update();
1361 gPlayers[i].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1362 end
1363 else
1364 begin
1365 // bot updates weapons in `UpdateCombat()`
1366 TBot(gPlayers[i]).Update();
1367 end;
1368 end;
1369 end;
1370 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1371 end;
1373 procedure g_Player_DrawAll();
1374 var
1375 i: Integer;
1376 begin
1377 if gPlayers = nil then Exit;
1379 for i := 0 to High(gPlayers) do
1380 if gPlayers[i] <> nil then
1381 if gPlayers[i] is TPlayer then gPlayers[i].Draw()
1382 else TBot(gPlayers[i]).Draw();
1383 end;
1385 procedure g_Player_DrawDebug(p: TPlayer);
1386 var
1387 fW, fH: Byte;
1388 begin
1389 if p = nil then Exit;
1390 if (@p.FObj) = nil then Exit;
1392 e_TextureFontGetSize(gStdFont, fW, fH);
1394 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p.FObj.X), gStdFont);
1395 e_TextureFontPrint(0, fH , 'Pos Y: ' + IntToStr(p.FObj.Y), gStdFont);
1396 e_TextureFontPrint(0, fH * 2, 'Vel X: ' + IntToStr(p.FObj.Vel.X), gStdFont);
1397 e_TextureFontPrint(0, fH * 3, 'Vel Y: ' + IntToStr(p.FObj.Vel.Y), gStdFont);
1398 e_TextureFontPrint(0, fH * 4, 'Acc X: ' + IntToStr(p.FObj.Accel.X), gStdFont);
1399 e_TextureFontPrint(0, fH * 5, 'Acc Y: ' + IntToStr(p.FObj.Accel.Y), gStdFont);
1400 e_TextureFontPrint(0, fH * 6, 'Old X: ' + IntToStr(p.FObj.oldX), gStdFont);
1401 e_TextureFontPrint(0, fH * 7, 'Old Y: ' + IntToStr(p.FObj.oldY), gStdFont);
1402 end;
1404 procedure g_Player_DrawHealth();
1405 var
1406 i: Integer;
1407 fW, fH: Byte;
1408 begin
1409 if gPlayers = nil then Exit;
1410 e_TextureFontGetSize(gStdFont, fW, fH);
1412 for i := 0 to High(gPlayers) do
1413 if gPlayers[i] <> nil then
1414 begin
1415 e_TextureFontPrint(gPlayers[i].FObj.X + gPlayers[i].FObj.Rect.X,
1416 gPlayers[i].FObj.Y + gPlayers[i].FObj.Rect.Y + gPlayers[i].FObj.Rect.Height - fH * 2,
1417 IntToStr(gPlayers[i].FHealth), gStdFont);
1418 e_TextureFontPrint(gPlayers[i].FObj.X + gPlayers[i].FObj.Rect.X,
1419 gPlayers[i].FObj.Y + gPlayers[i].FObj.Rect.Y + gPlayers[i].FObj.Rect.Height - fH,
1420 IntToStr(gPlayers[i].FArmor), gStdFont);
1421 end;
1422 end;
1424 function g_Player_Get(UID: Word): TPlayer;
1425 var
1426 a: Integer;
1427 begin
1428 Result := nil;
1430 if gPlayers = nil then
1431 Exit;
1433 for a := 0 to High(gPlayers) do
1434 if gPlayers[a] <> nil then
1435 if gPlayers[a].FUID = UID then
1436 begin
1437 Result := gPlayers[a];
1438 Exit;
1439 end;
1440 end;
1442 function g_Player_GetCount(): Byte;
1443 var
1444 a: Integer;
1445 begin
1446 Result := 0;
1448 if gPlayers = nil then
1449 Exit;
1451 for a := 0 to High(gPlayers) do
1452 if gPlayers[a] <> nil then
1453 Result := Result + 1;
1454 end;
1456 function g_Bot_GetCount(): Integer;
1457 var
1458 a: Integer;
1459 begin
1460 Result := 0;
1462 if gPlayers = nil then
1463 Exit;
1465 for a := 0 to High(gPlayers) do
1466 if (gPlayers[a] <> nil) and (gPlayers[a] is TBot) then
1467 Result := Result + 1;
1468 end;
1470 function g_Player_GetStats(): TPlayerStatArray;
1471 var
1472 a: Integer;
1473 begin
1474 Result := nil;
1476 if gPlayers = nil then Exit;
1478 for a := 0 to High(gPlayers) do
1479 if gPlayers[a] <> nil then
1480 begin
1481 SetLength(Result, Length(Result)+1);
1482 with Result[High(Result)] do
1483 begin
1484 Num := a;
1485 Ping := gPlayers[a].FPing;
1486 Loss := gPlayers[a].FLoss;
1487 Name := gPlayers[a].FName;
1488 Team := gPlayers[a].FTeam;
1489 Frags := gPlayers[a].FFrags;
1490 Deaths := gPlayers[a].FDeath;
1491 Kills := gPlayers[a].FKills;
1492 Color := gPlayers[a].FModel.Color;
1493 Lives := gPlayers[a].FLives;
1494 Spectator := gPlayers[a].FSpectator;
1495 UID := gPlayers[a].FUID;
1496 end;
1497 end;
1498 end;
1500 procedure g_Player_ResetReady();
1501 var
1502 a: Integer;
1503 begin
1504 if not g_Game_IsServer then Exit;
1505 if gPlayers = nil then Exit;
1507 for a := 0 to High(gPlayers) do
1508 if gPlayers[a] <> nil then
1509 begin
1510 gPlayers[a].FReady := False;
1511 if g_Game_IsNet then
1512 MH_SEND_GameEvent(NET_EV_INTER_READY, gPlayers[a].UID, 'N');
1513 end;
1514 end;
1516 procedure g_Player_RememberAll;
1517 var
1518 i: Integer;
1519 begin
1520 for i := Low(gPlayers) to High(gPlayers) do
1521 if (gPlayers[i] <> nil) and gPlayers[i].alive then
1522 gPlayers[i].RememberState;
1523 end;
1525 procedure g_Player_ResetAll(Force, Silent: Boolean);
1526 var
1527 i: Integer;
1528 begin
1529 gTeamStat[TEAM_RED].Score := 0;
1530 gTeamStat[TEAM_BLUE].Score := 0;
1532 if gPlayers <> nil then
1533 for i := 0 to High(gPlayers) do
1534 if gPlayers[i] <> nil then
1535 begin
1536 gPlayers[i].Reset(Force);
1538 if gPlayers[i] is TPlayer then
1539 begin
1540 if (not gPlayers[i].FSpectator) or gPlayers[i].FWantsInGame then
1541 gPlayers[i].Respawn(Silent)
1542 else
1543 gPlayers[i].Spectate();
1544 end
1545 else
1546 TBot(gPlayers[i]).Respawn(Silent);
1547 end;
1548 end;
1550 function g_Player_CreateCorpse(Player: TPlayer): Integer;
1551 var
1552 i: Integer;
1553 find_id: DWORD;
1554 ok: Boolean;
1555 begin
1556 Result := -1;
1558 if Player.alive then
1559 Exit;
1561 // Ðàçðûâàåì ñâÿçü ñ ïðåæíèì òðóïîì:
1562 i := Player.FCorpse;
1563 if (i >= 0) and (i < Length(gCorpses)) then
1564 begin
1565 if (gCorpses[i] <> nil) and (gCorpses[i].FPlayerUID = Player.FUID) then
1566 gCorpses[i].FPlayerUID := 0;
1567 end;
1569 if Player.FObj.Y >= gMapInfo.Height+128 then
1570 Exit;
1572 with Player do
1573 begin
1574 if (FHealth >= -50) or (gGibsCount = 0) then
1575 begin
1576 if (gCorpses = nil) or (Length(gCorpses) = 0) then
1577 Exit;
1579 ok := False;
1580 for find_id := 0 to High(gCorpses) do
1581 if gCorpses[find_id] = nil then
1582 begin
1583 ok := True;
1584 Break;
1585 end;
1587 if not ok then
1588 find_id := Random(Length(gCorpses));
1590 gCorpses[find_id] := TCorpse.Create(FObj.X, FObj.Y, FModel.Name, FHealth < -20);
1591 gCorpses[find_id].FColor := FModel.Color;
1592 gCorpses[find_id].FObj.Vel := FObj.Vel;
1593 gCorpses[find_id].FObj.Accel := FObj.Accel;
1594 gCorpses[find_id].FPlayerUID := FUID;
1596 Result := find_id;
1597 end
1598 else
1599 g_Player_CreateGibs(FObj.X + PLAYER_RECT_CX,
1600 FObj.Y + PLAYER_RECT_CY,
1601 FModel.Name, FModel.Color);
1602 end;
1603 end;
1605 procedure g_Player_CreateShell(fX, fY, dX, dY: Integer; T: Byte);
1606 var
1607 SID: DWORD;
1608 begin
1609 if (gShells = nil) or (Length(gShells) = 0) then
1610 Exit;
1612 with gShells[CurrentShell] do
1613 begin
1614 SpriteID := 0;
1615 g_Obj_Init(@Obj);
1616 Obj.Rect.X := 0;
1617 Obj.Rect.Y := 0;
1618 if T = SHELL_BULLET then
1619 begin
1620 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID) then
1621 SpriteID := SID;
1622 CX := 2;
1623 CY := 1;
1624 Obj.Rect.Width := 4;
1625 Obj.Rect.Height := 2;
1626 end
1627 else
1628 begin
1629 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID) then
1630 SpriteID := SID;
1631 CX := 4;
1632 CY := 2;
1633 Obj.Rect.Width := 7;
1634 Obj.Rect.Height := 3;
1635 end;
1636 SType := T;
1637 alive := True;
1638 Obj.X := fX;
1639 Obj.Y := fY;
1640 g_Obj_Push(@Obj, dX + Random(4)-Random(4), dY-Random(4));
1641 positionChanged(); // this updates spatial accelerators
1642 RAngle := Random(360);
1643 Timeout := gTime + SHELL_TIMEOUT;
1645 if CurrentShell >= High(gShells) then
1646 CurrentShell := 0
1647 else
1648 Inc(CurrentShell);
1649 end;
1650 end;
1652 procedure g_Player_CreateGibs(fX, fY: Integer; ModelName: string; fColor: TRGB);
1653 var
1654 a: Integer;
1655 GibsArray: TGibsArray;
1656 Blood: TModelBlood;
1657 begin
1658 if (gGibs = nil) or (Length(gGibs) = 0) then
1659 Exit;
1660 if not g_PlayerModel_GetGibs(ModelName, GibsArray) then
1661 Exit;
1662 Blood := g_PlayerModel_GetBlood(ModelName);
1664 for a := 0 to High(GibsArray) do
1665 with gGibs[CurrentGib] do
1666 begin
1667 Color := fColor;
1668 ID := GibsArray[a].ID;
1669 MaskID := GibsArray[a].MaskID;
1670 alive := True;
1671 g_Obj_Init(@Obj);
1672 Obj.Rect := GibsArray[a].Rect;
1673 Obj.X := fX-GibsArray[a].Rect.X-(GibsArray[a].Rect.Width div 2);
1674 Obj.Y := fY-GibsArray[a].Rect.Y-(GibsArray[a].Rect.Height div 2);
1675 g_Obj_PushA(@Obj, 25 + Random(10), Random(361));
1676 positionChanged(); // this updates spatial accelerators
1677 RAngle := Random(360);
1679 if gBloodCount > 0 then
1680 g_GFX_Blood(fX, fY, 16*gBloodCount+Random(5*gBloodCount), -16+Random(33), -16+Random(33),
1681 Random(48), Random(48), Blood.R, Blood.G, Blood.B, Blood.Kind);
1683 if CurrentGib >= High(gGibs) then
1684 CurrentGib := 0
1685 else
1686 Inc(CurrentGib);
1687 end;
1688 end;
1690 procedure g_Player_UpdatePhysicalObjects();
1691 var
1692 i: Integer;
1693 vel: TPoint2i;
1694 mr: Word;
1696 procedure ShellSound_Bounce(X, Y: Integer; T: Byte);
1697 var
1698 k: Integer;
1699 begin
1700 k := 1 + Random(2);
1701 if T = SHELL_BULLET then
1702 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k), X, Y)
1703 else
1704 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k), X, Y);
1705 end;
1707 begin
1708 // Êóñêè ìÿñà:
1709 if gGibs <> nil then
1710 for i := 0 to High(gGibs) do
1711 if gGibs[i].alive then
1712 with gGibs[i] do
1713 begin
1714 Obj.oldX := Obj.X;
1715 Obj.oldY := Obj.Y;
1717 vel := Obj.Vel;
1718 mr := g_Obj_Move(@Obj, True, False, True);
1719 positionChanged(); // this updates spatial accelerators
1721 if WordBool(mr and MOVE_FALLOUT) then
1722 begin
1723 alive := False;
1724 Continue;
1725 end;
1727 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1728 if WordBool(mr and MOVE_HITWALL) then
1729 Obj.Vel.X := -(vel.X div 2);
1730 if WordBool(mr and (MOVE_HITCEIL or MOVE_HITLAND)) then
1731 Obj.Vel.Y := -(vel.Y div 2);
1733 if (Obj.Vel.X >= 0) then
1734 begin // Clockwise
1735 RAngle := RAngle + Abs(Obj.Vel.X)*6 + Abs(Obj.Vel.Y);
1736 if RAngle >= 360 then
1737 RAngle := RAngle mod 360;
1738 end else begin // Counter-clockwise
1739 RAngle := RAngle - Abs(Obj.Vel.X)*6 - Abs(Obj.Vel.Y);
1740 if RAngle < 0 then
1741 RAngle := (360 - (Abs(RAngle) mod 360)) mod 360;
1742 end;
1744 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1745 if gTime mod (GAME_TICK*3) = 0 then
1746 Obj.Vel.X := z_dec(Obj.Vel.X, 1);
1747 end;
1749 // Òðóïû:
1750 if gCorpses <> nil then
1751 for i := 0 to High(gCorpses) do
1752 if gCorpses[i] <> nil then
1753 if gCorpses[i].State = CORPSE_STATE_REMOVEME then
1754 begin
1755 gCorpses[i].Free();
1756 gCorpses[i] := nil;
1757 end
1758 else
1759 gCorpses[i].Update();
1761 // Ãèëüçû:
1762 if gShells <> nil then
1763 for i := 0 to High(gShells) do
1764 if gShells[i].alive then
1765 with gShells[i] do
1766 begin
1767 Obj.oldX := Obj.X;
1768 Obj.oldY := Obj.Y;
1770 vel := Obj.Vel;
1771 mr := g_Obj_Move(@Obj, True, False, True);
1772 positionChanged(); // this updates spatial accelerators
1774 if WordBool(mr and MOVE_FALLOUT) or (gShells[i].Timeout < gTime) then
1775 begin
1776 alive := False;
1777 Continue;
1778 end;
1780 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1781 if WordBool(mr and MOVE_HITWALL) then
1782 begin
1783 Obj.Vel.X := -(vel.X div 2);
1784 if not WordBool(mr and MOVE_INWATER) then
1785 ShellSound_Bounce(Obj.X, Obj.Y, SType);
1786 end;
1787 if WordBool(mr and (MOVE_HITCEIL or MOVE_HITLAND)) then
1788 begin
1789 Obj.Vel.Y := -(vel.Y div 2);
1790 if Obj.Vel.X <> 0 then Obj.Vel.X := Obj.Vel.X div 2;
1791 if (Obj.Vel.X = 0) and (Obj.Vel.Y = 0) then
1792 begin
1793 if RAngle mod 90 <> 0 then
1794 RAngle := (RAngle div 90) * 90;
1795 end
1796 else if not WordBool(mr and MOVE_INWATER) then
1797 ShellSound_Bounce(Obj.X, Obj.Y, SType);
1798 end;
1800 if (Obj.Vel.X >= 0) then
1801 begin // Clockwise
1802 RAngle := RAngle + Abs(Obj.Vel.X)*8 + Abs(Obj.Vel.Y);
1803 if RAngle >= 360 then
1804 RAngle := RAngle mod 360;
1805 end else begin // Counter-clockwise
1806 RAngle := RAngle - Abs(Obj.Vel.X)*8 - Abs(Obj.Vel.Y);
1807 if RAngle < 0 then
1808 RAngle := (360 - (Abs(RAngle) mod 360)) mod 360;
1809 end;
1810 end;
1811 end;
1814 procedure TGib.getMapBox (out x, y, w, h: Integer); inline;
1815 begin
1816 x := Obj.X+Obj.Rect.X;
1817 y := Obj.Y+Obj.Rect.Y;
1818 w := Obj.Rect.Width;
1819 h := Obj.Rect.Height;
1820 end;
1822 procedure TGib.moveBy (dx, dy: Integer); inline;
1823 begin
1824 if (dx <> 0) or (dy <> 0) then
1825 begin
1826 Obj.X += dx;
1827 Obj.Y += dy;
1828 positionChanged();
1829 end;
1830 end;
1833 procedure TShell.getMapBox (out x, y, w, h: Integer); inline;
1834 begin
1835 x := Obj.X;
1836 y := Obj.Y;
1837 w := Obj.Rect.Width;
1838 h := Obj.Rect.Height;
1839 end;
1841 procedure TShell.moveBy (dx, dy: Integer); inline;
1842 begin
1843 if (dx <> 0) or (dy <> 0) then
1844 begin
1845 Obj.X += dx;
1846 Obj.Y += dy;
1847 positionChanged();
1848 end;
1849 end;
1852 procedure TGib.positionChanged (); inline; begin end;
1853 procedure TShell.positionChanged (); inline; begin end;
1856 procedure g_Player_DrawCorpses();
1857 var
1858 i, fX, fY: Integer;
1859 a: TDFPoint;
1860 begin
1861 if gGibs <> nil then
1862 for i := 0 to High(gGibs) do
1863 if gGibs[i].alive then
1864 with gGibs[i] do
1865 begin
1866 if not g_Obj_Collide(sX, sY, sWidth, sHeight, @Obj) then
1867 Continue;
1869 Obj.lerp(gLerpFactor, fX, fY);
1871 a.X := Obj.Rect.X+(Obj.Rect.Width div 2);
1872 a.y := Obj.Rect.Y+(Obj.Rect.Height div 2);
1874 e_DrawAdv(ID, fX, fY, 0, True, False, RAngle, @a, TMirrorType.None);
1876 e_Colors := Color;
1877 e_DrawAdv(MaskID, fX, fY, 0, True, False, RAngle, @a, TMirrorType.None);
1878 e_Colors.R := 255;
1879 e_Colors.G := 255;
1880 e_Colors.B := 255;
1881 end;
1883 if gCorpses <> nil then
1884 for i := 0 to High(gCorpses) do
1885 if gCorpses[i] <> nil then
1886 gCorpses[i].Draw();
1887 end;
1889 procedure g_Player_DrawShells();
1890 var
1891 i, fX, fY: Integer;
1892 a: TDFPoint;
1893 begin
1894 if gShells <> nil then
1895 for i := 0 to High(gShells) do
1896 if gShells[i].alive then
1897 with gShells[i] do
1898 begin
1899 if not g_Obj_Collide(sX, sY, sWidth, sHeight, @Obj) then
1900 Continue;
1902 Obj.lerp(gLerpFactor, fX, fY);
1904 a.X := CX;
1905 a.Y := CY;
1907 e_DrawAdv(SpriteID, fX, fY, 0, True, False, RAngle, @a, TMirrorType.None);
1908 end;
1909 end;
1911 procedure g_Player_RemoveAllCorpses();
1912 var
1913 i: Integer;
1914 begin
1915 gGibs := nil;
1916 gShells := nil;
1917 SetLength(gGibs, MaxGibs);
1918 SetLength(gShells, MaxGibs);
1919 CurrentGib := 0;
1920 CurrentShell := 0;
1922 if gCorpses <> nil then
1923 for i := 0 to High(gCorpses) do
1924 gCorpses[i].Free();
1926 gCorpses := nil;
1927 SetLength(gCorpses, MaxCorpses);
1928 end;
1930 procedure g_Player_Corpses_SaveState (st: TStream);
1931 var
1932 count, i: Integer;
1933 begin
1934 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ
1935 count := 0;
1936 for i := 0 to High(gCorpses) do if (gCorpses[i] <> nil) then Inc(count);
1938 // Êîëè÷åñòâî òðóïîâ
1939 utils.writeInt(st, LongInt(count));
1941 if (count = 0) then exit;
1943 // Ñîõðàíÿåì òðóïû
1944 for i := 0 to High(gCorpses) do
1945 begin
1946 if gCorpses[i] <> nil then
1947 begin
1948 // Íàçâàíèå ìîäåëè
1949 utils.writeStr(st, gCorpses[i].FModelName);
1950 // Òèï ñìåðòè
1951 utils.writeBool(st, gCorpses[i].Mess);
1952 // Ñîõðàíÿåì äàííûå òðóïà:
1953 gCorpses[i].SaveState(st);
1954 end;
1955 end;
1956 end;
1959 procedure g_Player_Corpses_LoadState (st: TStream);
1960 var
1961 count, i: Integer;
1962 str: String;
1963 b: Boolean;
1964 begin
1965 assert(st <> nil);
1967 g_Player_RemoveAllCorpses();
1969 // Êîëè÷åñòâî òðóïîâ:
1970 count := utils.readLongInt(st);
1971 if (count < 0) or (count > Length(gCorpses)) then raise XStreamError.Create('invalid number of corpses');
1973 if (count = 0) then exit;
1975 // Çàãðóæàåì òðóïû
1976 for i := 0 to count-1 do
1977 begin
1978 // Íàçâàíèå ìîäåëè:
1979 str := utils.readStr(st);
1980 // Òèï ñìåðòè
1981 b := utils.readBool(st);
1982 // Ñîçäàåì òðóï
1983 gCorpses[i] := TCorpse.Create(0, 0, str, b);
1984 // Çàãðóæàåì äàííûå òðóïà
1985 gCorpses[i].LoadState(st);
1986 end;
1987 end;
1990 { T P l a y e r : }
1992 function TPlayer.isValidViewPort (): Boolean; inline; begin result := (viewPortW > 0) and (viewPortH > 0); end;
1994 procedure TPlayer.BFGHit();
1995 begin
1996 g_Weapon_BFGHit(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
1997 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2));
1998 if g_Game_IsServer and g_Game_IsNet then
1999 MH_SEND_Effect(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
2000 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
2001 0, NET_GFX_BFGHIT);
2002 end;
2004 procedure TPlayer.ChangeModel(ModelName: string);
2005 var
2006 locModel: TPlayerModel;
2007 begin
2008 locModel := g_PlayerModel_Get(ModelName);
2009 if locModel = nil then Exit;
2011 FModel.Free();
2012 FModel := locModel;
2013 end;
2015 procedure TPlayer.SetModel(ModelName: string);
2016 var
2017 m: TPlayerModel;
2018 begin
2019 m := g_PlayerModel_Get(ModelName);
2020 if m = nil then
2021 begin
2022 g_SimpleError(Format(_lc[I_GAME_ERROR_MODEL_FALLBACK], [ModelName]));
2023 m := g_PlayerModel_Get('doomer');
2024 if m = nil then
2025 begin
2026 g_FatalError(Format(_lc[I_GAME_ERROR_MODEL], ['doomer']));
2027 Exit;
2028 end;
2029 end;
2031 if FModel <> nil then
2032 FModel.Free();
2034 FModel := m;
2036 if not (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
2037 FModel.Color := FColor
2038 else
2039 FModel.Color := TEAMCOLOR[FTeam];
2040 FModel.SetWeapon(FCurrWeap);
2041 FModel.SetFlag(FFlag);
2042 SetDirection(FDirection);
2043 end;
2045 procedure TPlayer.SetColor(Color: TRGB);
2046 begin
2047 FColor := Color;
2048 if not (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
2049 if FModel <> nil then FModel.Color := Color;
2050 end;
2054 function TPlayer.GetColor(): TRGB;
2055 begin
2056 result := FModel.Color;
2057 end;
2059 procedure TPlayer.SetWeaponPrefs(Prefs: Array of Byte);
2060 var
2061 i: Integer;
2062 begin
2063 for i := WP_FIRST to WP_LAST + 1 do
2064 begin
2065 if (Prefs[i] > WP_LAST + 1) then
2066 FWeapPreferences[i] := 0
2067 else
2068 FWeapPreferences[i] := Prefs[i];
2069 end;
2070 end;
2072 procedure TPlayer.SetWeaponPref(Weapon, Pref: Byte);
2073 begin
2074 if (Weapon > WP_LAST + 1) then
2075 exit
2076 else if (Pref <= WP_LAST + 1) and (Weapon <= WP_LAST + 1) then
2077 FWeapPreferences[Weapon] := Pref
2078 else if (Weapon <= WP_LAST + 1) and (Pref > WP_LAST + 1) then
2079 FWeapPreferences[Weapon] := 0;
2080 end;
2082 function TPlayer.GetWeaponPref(Weapon: Byte) : Byte;
2083 begin
2084 if (Weapon > WP_LAST + 1) then
2085 result := 0
2086 else if (FWeapPreferences[Weapon] > WP_LAST + 1) then
2087 result := 0
2088 else
2089 result := FWeapPreferences[Weapon];
2090 end;
2092 function TPlayer.GetMorePrefered() : Byte;
2093 var
2094 testedWeap, i: Byte;
2095 begin
2096 testedWeap := FCurrWeap;
2097 for i := WP_FIRST to WP_LAST do
2098 if FWeapon[i] and maySwitch(i) and (FWeapPreferences[i] > FWeapPreferences[testedWeap]) then
2099 testedWeap := i;
2100 if (R_BERSERK in FRulez) and (FWeapPreferences[WP_LAST + 1] > FWeapPreferences[testedWeap]) then
2101 testedWeap := WEAPON_KASTET;
2102 result := testedWeap;
2103 end;
2105 function TPlayer.maySwitch(Weapon: Byte) : Boolean;
2106 begin
2107 result := true;
2108 if (Weapon = WEAPON_KASTET) and (FSkipFist <> 0) then
2109 begin
2110 if (FSkipFist = 1) and (not (R_BERSERK in FRulez)) then
2111 result := false;
2112 end
2113 else if (FSwitchToEmpty = 0) and (not hasAmmoForShooting(Weapon)) then
2114 result := false;
2115 end;
2117 procedure TPlayer.SwitchTeam;
2118 begin
2119 if g_Game_IsClient then
2120 Exit;
2121 if not (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then Exit;
2123 if gGameOn and FAlive then
2124 Kill(K_SIMPLEKILL, FUID, HIT_SELF);
2126 if FTeam = TEAM_RED then
2127 begin
2128 ChangeTeam(TEAM_BLUE);
2129 g_Console_Add(Format(_lc[I_PLAYER_CHTEAM_BLUE], [FName]), True);
2130 if g_Game_IsNet then
2131 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM, TEAM_BLUE, FName);
2132 end
2133 else
2134 begin
2135 ChangeTeam(TEAM_RED);
2136 g_Console_Add(Format(_lc[I_PLAYER_CHTEAM_RED], [FName]), True);
2137 if g_Game_IsNet then
2138 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM, TEAM_RED, FName);
2139 end;
2140 FPreferredTeam := FTeam;
2141 end;
2143 procedure TPlayer.ChangeTeam(Team: Byte);
2144 var
2145 OldTeam: Byte;
2146 begin
2147 OldTeam := FTeam;
2148 FTeam := Team;
2149 case Team of
2150 TEAM_RED, TEAM_BLUE:
2151 FModel.Color := TEAMCOLOR[Team];
2152 else
2153 FModel.Color := FColor;
2154 end;
2155 if (FTeam <> OldTeam) and g_Game_IsNet and g_Game_IsServer then
2156 MH_SEND_PlayerStats(FUID);
2157 end;
2160 procedure TPlayer.CollideItem();
2161 var
2162 i: Integer;
2163 r: Boolean;
2164 begin
2165 if gItems = nil then Exit;
2166 if not FAlive then Exit;
2168 for i := 0 to High(gItems) do
2169 with gItems[i] do
2170 begin
2171 if (ItemType <> ITEM_NONE) and alive then
2172 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
2173 PLAYER_RECT.Height, @Obj) then
2174 begin
2175 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
2177 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
2178 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
2179 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
2180 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
2181 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
2183 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
2184 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
2185 (gGameSettings.GameType = GT_SINGLE) and
2186 (g_Player_GetCount() > 1)) then
2187 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
2188 end;
2189 end;
2190 end;
2193 function TPlayer.CollideLevel(XInc, YInc: Integer): Boolean;
2194 begin
2195 Result := g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc,
2196 PLAYER_RECT.Width, PLAYER_RECT.Height, PANEL_WALL,
2197 False);
2198 end;
2200 constructor TPlayer.Create();
2201 begin
2202 viewPortX := 0;
2203 viewPortY := 0;
2204 viewPortW := 0;
2205 viewPortH := 0;
2206 mEDamageType := HIT_SOME;
2208 FIamBot := False;
2209 FDummy := False;
2210 FSpawned := False;
2212 FSawSound := TPlayableSound.Create();
2213 FSawSoundIdle := TPlayableSound.Create();
2214 FSawSoundHit := TPlayableSound.Create();
2215 FSawSoundSelect := TPlayableSound.Create();
2216 FFlameSoundOn := TPlayableSound.Create();
2217 FFlameSoundOff := TPlayableSound.Create();
2218 FFlameSoundWork := TPlayableSound.Create();
2219 FJetSoundFly := TPlayableSound.Create();
2220 FJetSoundOn := TPlayableSound.Create();
2221 FJetSoundOff := TPlayableSound.Create();
2223 FSawSound.SetByName('SOUND_WEAPON_FIRESAW');
2224 FSawSoundIdle.SetByName('SOUND_WEAPON_IDLESAW');
2225 FSawSoundHit.SetByName('SOUND_WEAPON_HITSAW');
2226 FSawSoundSelect.SetByName('SOUND_WEAPON_SELECTSAW');
2227 FFlameSoundOn.SetByName('SOUND_WEAPON_FLAMEON');
2228 FFlameSoundOff.SetByName('SOUND_WEAPON_FLAMEOFF');
2229 FFlameSoundWork.SetByName('SOUND_WEAPON_FLAMEWORK');
2230 FJetSoundFly.SetByName('SOUND_PLAYER_JETFLY');
2231 FJetSoundOn.SetByName('SOUND_PLAYER_JETON');
2232 FJetSoundOff.SetByName('SOUND_PLAYER_JETOFF');
2234 FSpectatePlayer := -1;
2235 FClientID := -1;
2236 FPing := 0;
2237 FLoss := 0;
2238 FSavedStateNum := -1;
2239 FShellTimer := -1;
2240 FFireTime := 0;
2241 FFirePainTime := 0;
2242 FFireAttacker := 0;
2243 FHandicap := 100;
2244 FCorpse := -1;
2246 FActualModelName := 'doomer';
2248 g_Obj_Init(@FObj);
2249 FObj.Rect := PLAYER_RECT;
2251 FBFGFireCounter := -1;
2252 FJustTeleported := False;
2253 FNetTime := 0;
2255 FWaitForFirstSpawn := false;
2257 resetWeaponQueue();
2258 end;
2260 procedure TPlayer.positionChanged (); inline;
2261 begin
2262 end;
2264 procedure TPlayer.doDamage (v: Integer);
2265 begin
2266 if (v <= 0) then exit;
2267 if (v > 32767) then v := 32767;
2268 Damage(v, 0, 0, 0, mEDamageType);
2269 end;
2271 procedure TPlayer.Damage(value: Word; SpawnerUID: Word; vx, vy: Integer; t: Byte);
2272 var
2273 c: Word;
2274 begin
2275 if (not g_Game_IsClient) and (not FAlive) then
2276 Exit;
2278 FLastHit := t;
2280 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2281 if ((t = HIT_TRAP) or (t = HIT_SELF)) and (not FGodMode) then
2282 begin
2283 if not g_Game_IsClient then
2284 begin
2285 FArmor := 0;
2286 if t = HIT_TRAP then
2287 begin
2288 // Ëîâóøêà óáèâàåò ñðàçó:
2289 FHealth := -100;
2290 Kill(K_EXTRAHARDKILL, SpawnerUID, t);
2291 end;
2292 if t = HIT_SELF then
2293 begin
2294 // Ñàìîóáèéñòâî:
2295 FHealth := 0;
2296 Kill(K_SIMPLEKILL, SpawnerUID, t);
2297 end;
2298 end;
2299 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2300 FMegaRulez[MR_SUIT] := 0;
2301 FMegaRulez[MR_INVUL] := 0;
2302 FMegaRulez[MR_INVIS] := 0;
2303 FSpawnInvul := 0;
2304 FBerserk := 0;
2305 end;
2307 // Íî îò îñòàëüíîãî ñïàñàåò:
2308 if FMegaRulez[MR_INVUL] >= gTime then
2309 Exit;
2311 // ×èò-êîä "ÃÎÐÅÖ":
2312 if FGodMode then
2313 Exit;
2315 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2316 if LongBool(gGameSettings.Options and GAME_OPTION_TEAMDAMAGE) or
2317 (SpawnerUID = FUID) or
2318 (not SameTeam(FUID, SpawnerUID)) then
2319 begin
2320 FLastSpawnerUID := SpawnerUID;
2322 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2323 if gBloodCount > 0 then
2324 begin
2325 c := Min(value, 200)*gBloodCount + Random(Min(value, 200) div 2);
2326 if value div 4 <= c then
2327 c := c - (value div 4)
2328 else
2329 c := 0;
2331 if (t = HIT_SOME) and (vx = 0) and (vy = 0) then
2332 MakeBloodSimple(c)
2333 else
2334 case t of
2335 HIT_TRAP, HIT_ACID, HIT_FLAME, HIT_SELF: MakeBloodSimple(c);
2336 HIT_BFG, HIT_ROCKET, HIT_SOME: MakeBloodVector(c, vx, vy);
2337 end;
2339 if t = HIT_WATER then
2340 begin
2341 g_GFX_Bubbles(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2),
2342 FObj.Y+PLAYER_RECT.Y-4, value div 2, 8, 4);
2343 if Random(2) = 0
2344 then g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj.X, FObj.Y)
2345 else g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj.X, FObj.Y);
2346 end;
2347 end;
2349 // Áóôåð óðîíà:
2350 if FAlive then
2351 Inc(FDamageBuffer, value);
2353 // Âñïûøêà áîëè:
2354 if gFlash <> 0 then
2355 FPain := FPain + value;
2356 end;
2358 if g_Game_IsServer and g_Game_IsNet then
2359 begin
2360 MH_SEND_PlayerDamage(FUID, t, SpawnerUID, value, vx, vy);
2361 MH_SEND_PlayerStats(FUID);
2362 MH_SEND_PlayerPos(False, FUID);
2363 end;
2364 end;
2366 function TPlayer.Heal(value: Word; Soft: Boolean): Boolean;
2367 begin
2368 Result := False;
2369 if g_Game_IsClient then
2370 Exit;
2371 if not FAlive then
2372 Exit;
2374 if Soft and (FHealth < PLAYER_HP_SOFT) then
2375 begin
2376 IncMax(FHealth, value, PLAYER_HP_SOFT);
2377 Result := True;
2378 end;
2379 if (not Soft) and (FHealth < PLAYER_HP_LIMIT) then
2380 begin
2381 IncMax(FHealth, value, PLAYER_HP_LIMIT);
2382 Result := True;
2383 end;
2385 if Result and g_Game_IsServer and g_Game_IsNet then
2386 MH_SEND_PlayerStats(FUID);
2387 end;
2389 destructor TPlayer.Destroy();
2390 begin
2391 if (gPlayer1 <> nil) and (gPlayer1.FUID = FUID) then
2392 gPlayer1 := nil;
2393 if (gPlayer2 <> nil) and (gPlayer2.FUID = FUID) then
2394 gPlayer2 := nil;
2396 FSawSound.Free();
2397 FSawSoundIdle.Free();
2398 FSawSoundHit.Free();
2399 FSawSoundSelect.Free();
2400 FFlameSoundOn.Free();
2401 FFlameSoundOff.Free();
2402 FFlameSoundWork.Free();
2403 FJetSoundFly.Free();
2404 FJetSoundOn.Free();
2405 FJetSoundOff.Free();
2406 FModel.Free();
2407 if FPunchAnim <> nil then
2408 FPunchAnim.Free();
2410 inherited;
2411 end;
2413 procedure TPlayer.DrawIndicator(Color: TRGB);
2414 var
2415 indX, indY, fX, fY, fSlope: Integer;
2416 indW, indH: Word;
2417 indA: Single;
2418 a: TDFPoint;
2419 nW, nH: Byte;
2420 ID: DWORD;
2421 c: TRGB;
2422 begin
2423 if FAlive then
2424 begin
2425 FObj.lerp(gLerpFactor, fX, fY);
2426 fSlope := nlerp(FSlopeOld, FObj.slopeUpLeft, gLerpFactor);
2428 case gPlayerIndicatorStyle of
2429 0:
2430 begin
2431 if g_Texture_Get('TEXTURE_PLAYER_INDICATOR', ID) then
2432 begin
2433 e_GetTextureSize(ID, @indW, @indH);
2434 a.X := indW div 2;
2435 a.Y := indH div 2;
2437 if (FObj.X + FObj.Rect.X) < 0 then
2438 begin
2439 indA := 90;
2440 indX := fX + FObj.Rect.X + FObj.Rect.Width;
2441 indY := fY + FObj.Rect.Y + (FObj.Rect.Height - indW) div 2;
2442 end
2444 else if (FObj.X + FObj.Rect.X + FObj.Rect.Width) > Max(gMapInfo.Width, gPlayerScreenSize.X) then
2445 begin
2446 indA := 270;
2447 indX := fX + FObj.Rect.X - indH;
2448 indY := fY + FObj.Rect.Y + (FObj.Rect.Height - indW) div 2;
2449 end
2451 else if (FObj.Y - indH) < 0 then
2452 begin
2453 indA := 180;
2454 indX := fX + FObj.Rect.X + (FObj.Rect.Width - indW) div 2;
2455 indY := fY + FObj.Rect.Y + FObj.Rect.Height;
2456 end
2458 else
2459 begin
2460 indA := 0;
2461 indX := fX + FObj.Rect.X + (FObj.Rect.Width - indW) div 2;
2462 indY := fY - indH;
2463 end;
2465 indY := indY + fSlope;
2466 indX := EnsureRange(indX, 0, Max(gMapInfo.Width, gPlayerScreenSize.X) - indW);
2467 indY := EnsureRange(indY, 0, Max(gMapInfo.Height, gPlayerScreenSize.Y) - indH);
2469 c := e_Colors;
2470 e_Colors := Color;
2471 e_DrawAdv(ID, indX, indY, 0, True, False, indA, @a);
2472 e_Colors := c;
2473 end;
2474 end;
2476 1:
2477 begin
2478 e_TextureFontGetSize(gStdFont, nW, nH);
2479 indX := fX + FObj.Rect.X + (FObj.Rect.Width - Length(FName) * nW) div 2;
2480 indY := fY - nH + fSlope;
2481 e_TextureFontPrintEx(indX, indY, FName, gStdFont, Color.R, Color.G, Color.B, 1.0, True);
2482 end;
2483 end;
2484 end;
2485 end;
2487 procedure TPlayer.DrawBubble();
2488 var
2489 bubX, bubY, fX, fY: Integer;
2490 ID: LongWord;
2491 Rb, Gb, Bb,
2492 Rw, Gw, Bw: SmallInt;
2493 Dot: Byte;
2494 CObj: TObj;
2495 begin
2496 CObj := getCameraObj();
2497 CObj.lerp(gLerpFactor, fX, fY);
2498 // NB: _F_Obj.Rect is used to keep the bubble higher; this is not a mistake
2499 bubX := fX+FObj.Rect.X + IfThen(FDirection = TDirection.D_LEFT, -4, 18);
2500 bubY := fY+FObj.Rect.Y - 18;
2501 Rb := 64;
2502 Gb := 64;
2503 Bb := 64;
2504 Rw := 240;
2505 Gw := 240;
2506 Bw := 240;
2507 case gChatBubble of
2508 1: // simple textual non-bubble
2509 begin
2510 bubX := fX+FObj.Rect.X - 11;
2511 bubY := fY+FObj.Rect.Y - 17;
2512 e_TextureFontPrint(bubX, bubY, '[...]', gStdFont);
2513 Exit;
2514 end;
2515 2: // advanced pixel-perfect bubble
2516 begin
2517 if FTeam = TEAM_RED then
2518 Rb := 255
2519 else
2520 if FTeam = TEAM_BLUE then
2521 Bb := 255;
2522 end;
2523 3: // colored bubble
2524 begin
2525 Rb := FModel.Color.R;
2526 Gb := FModel.Color.G;
2527 Bb := FModel.Color.B;
2528 Rw := Min(Rb * 2 + 64, 255);
2529 Gw := Min(Gb * 2 + 64, 255);
2530 Bw := Min(Bb * 2 + 64, 255);
2531 if (Abs(Rw - Rb) < 32)
2532 or (Abs(Gw - Gb) < 32)
2533 or (Abs(Bw - Bb) < 32) then
2534 begin
2535 Rb := Max(Rw div 2 - 16, 0);
2536 Gb := Max(Gw div 2 - 16, 0);
2537 Bb := Max(Bw div 2 - 16, 0);
2538 end;
2539 end;
2540 4: // custom textured bubble
2541 begin
2542 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID) then
2543 if FDirection = TDirection.D_RIGHT then
2544 e_Draw(ID, bubX - 6, bubY - 7, 0, True, False)
2545 else
2546 e_Draw(ID, bubX - 6, bubY - 7, 0, True, False, TMirrorType.Horizontal);
2547 Exit;
2548 end;
2549 end;
2551 // Outer borders
2552 e_DrawQuad(bubX + 1, bubY , bubX + 18, bubY + 13, Rb, Gb, Bb);
2553 e_DrawQuad(bubX , bubY + 1, bubX + 19, bubY + 12, Rb, Gb, Bb);
2554 // Inner box
2555 e_DrawFillQuad(bubX + 1, bubY + 1, bubX + 18, bubY + 12, Rw, Gw, Bw, 0);
2557 // Tail
2558 Dot := IfThen(FDirection = TDirection.D_LEFT, 14, 5);
2559 e_DrawLine(1, bubX + Dot, bubY + 14, bubX + Dot, bubY + 16, Rb, Gb, Bb);
2560 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);
2561 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);
2562 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);
2563 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);
2565 // Dots
2566 Dot := 6;
2567 e_DrawFillQuad(bubX + Dot, bubY + 8, bubX + Dot + 1, bubY + 9, Rb, Gb, Bb, 0);
2568 e_DrawFillQuad(bubX + Dot + 3, bubY + 8, bubX + Dot + 4, bubY + 9, Rb, Gb, Bb, 0);
2569 e_DrawFillQuad(bubX + Dot + 6, bubY + 8, bubX + Dot + 7, bubY + 9, Rb, Gb, Bb, 0);
2570 end;
2572 procedure TPlayer.Draw();
2573 var
2574 ID: DWORD;
2575 w, h: Word;
2576 dr: Boolean;
2577 Mirror: TMirrorType;
2578 fX, fY, fSlope: Integer;
2579 begin
2580 FObj.lerp(gLerpFactor, fX, fY);
2581 fSlope := nlerp(FSlopeOld, FObj.slopeUpLeft, gLerpFactor);
2583 if FAlive then
2584 begin
2585 if Direction = TDirection.D_RIGHT then
2586 Mirror := TMirrorType.None
2587 else
2588 Mirror := TMirrorType.Horizontal;
2590 if FPunchAnim <> nil then
2591 begin
2592 FPunchAnim.Draw(fX+IfThen(Direction = TDirection.D_LEFT, 15-FObj.Rect.X, FObj.Rect.X-15),
2593 fY+fSlope+FObj.Rect.Y-11, Mirror);
2594 if FPunchAnim.played then
2595 begin
2596 FPunchAnim.Free;
2597 FPunchAnim := nil;
2598 end;
2599 end;
2601 if (FMegaRulez[MR_INVUL] > gTime) and ((gPlayerDrawn <> Self) or (FSpawnInvul >= gTime)) then
2602 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID) then
2603 begin
2604 e_GetTextureSize(ID, @w, @h);
2605 if FDirection = TDirection.D_LEFT then
2606 e_Draw(ID, fX+FObj.Rect.X+(FObj.Rect.Width div 2)-(w div 2)+4,
2607 fY+FObj.Rect.Y+(FObj.Rect.Height div 2)-(h div 2)-7+fSlope, 0, True, False)
2608 else
2609 e_Draw(ID, fX+FObj.Rect.X+(FObj.Rect.Width div 2)-(w div 2)-2,
2610 fY+FObj.Rect.Y+(FObj.Rect.Height div 2)-(h div 2)-7+fSlope, 0, True, False);
2611 end;
2613 if FMegaRulez[MR_INVIS] > gTime then
2614 begin
2615 if (gPlayerDrawn <> nil) and ((Self = gPlayerDrawn) or
2616 ((FTeam = gPlayerDrawn.Team) and (gGameSettings.GameMode <> GM_DM))) then
2617 begin
2618 if (FMegaRulez[MR_INVIS] - gTime) <= 2100 then
2619 dr := not Odd((FMegaRulez[MR_INVIS] - gTime) div 300)
2620 else
2621 dr := True;
2622 if dr then
2623 FModel.Draw(fX, fY+fSlope, 200)
2624 else
2625 FModel.Draw(fX, fY+fSlope);
2626 end
2627 else
2628 FModel.Draw(fX, fY+fSlope, 254);
2629 end
2630 else
2631 FModel.Draw(fX, fY+fSlope);
2632 end;
2634 if g_debug_Frames then
2635 begin
2636 e_DrawQuad(FObj.X+FObj.Rect.X,
2637 FObj.Y+FObj.Rect.Y,
2638 FObj.X+FObj.Rect.X+FObj.Rect.Width-1,
2639 FObj.Y+FObj.Rect.Y+FObj.Rect.Height-1,
2640 0, 255, 0);
2641 end;
2643 if (gChatBubble > 0) and (FKeys[KEY_CHAT].Pressed) and not FGhost then
2644 if (FMegaRulez[MR_INVIS] <= gTime) or ((gPlayerDrawn <> nil) and ((Self = gPlayerDrawn) or
2645 ((FTeam = gPlayerDrawn.Team) and (gGameSettings.GameMode <> GM_DM)))) then
2646 DrawBubble();
2647 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2648 if gAimLine and alive and
2649 ((Self = gPlayer1) or (Self = gPlayer2)) then
2650 DrawAim();
2651 end;
2654 procedure TPlayer.DrawAim();
2655 procedure drawCast (sz: Integer; ax0, ay0, ax1, ay1: Integer);
2656 var
2657 ex, ey: Integer;
2658 begin
2660 {$IFDEF ENABLE_HOLMES}
2661 if isValidViewPort and (self = gPlayer1) then
2662 begin
2663 g_Holmes_plrLaser(ax0, ay0, ax1, ay1);
2664 end;
2665 {$ENDIF}
2667 e_DrawLine(sz, ax0, ay0, ax1, ay1, 255, 0, 0, 96);
2668 if (g_Map_traceToNearestWall(ax0, ay0, ax1, ay1, @ex, @ey) <> nil) then
2669 begin
2670 e_DrawLine(sz, ax0, ay0, ex, ey, 0, 255, 0, 96);
2671 end
2672 else
2673 begin
2674 e_DrawLine(sz, ax0, ay0, ex, ey, 0, 0, 255, 96);
2675 end;
2676 end;
2678 var
2679 wx, wy, xx, yy: Integer;
2680 angle: SmallInt;
2681 sz, len: Word;
2682 begin
2683 wx := FObj.X + WEAPONPOINT[FDirection].X + IfThen(FDirection = TDirection.D_LEFT, 7, -7);
2684 wy := FObj.Y + WEAPONPOINT[FDirection].Y;
2685 angle := FAngle;
2686 len := 1024;
2687 sz := 2;
2688 case FCurrWeap of
2689 0: begin // Punch
2690 len := 12;
2691 sz := 4;
2692 end;
2693 1: begin // Chainsaw
2694 len := 24;
2695 sz := 6;
2696 end;
2697 2: begin // Pistol
2698 len := 1024;
2699 sz := 2;
2700 if angle = ANGLE_RIGHTUP then Dec(angle, 2);
2701 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2702 if angle = ANGLE_LEFTUP then Inc(angle, 2);
2703 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2704 end;
2705 3: begin // Shotgun
2706 len := 1024;
2707 sz := 3;
2708 if angle = ANGLE_RIGHTUP then Dec(angle, 2);
2709 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2710 if angle = ANGLE_LEFTUP then Inc(angle, 2);
2711 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2712 end;
2713 4: begin // Double Shotgun
2714 len := 1024;
2715 sz := 4;
2716 if angle = ANGLE_RIGHTUP then Dec(angle, 2);
2717 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2718 if angle = ANGLE_LEFTUP then Inc(angle, 2);
2719 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2720 end;
2721 5: begin // Chaingun
2722 len := 1024;
2723 sz := 3;
2724 if angle = ANGLE_RIGHTUP then Dec(angle, 2);
2725 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2726 if angle = ANGLE_LEFTUP then Inc(angle, 2);
2727 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2728 end;
2729 6: begin // Rocket Launcher
2730 len := 1024;
2731 sz := 7;
2732 if angle = ANGLE_RIGHTUP then Inc(angle, 2);
2733 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2734 if angle = ANGLE_LEFTUP then Dec(angle, 2);
2735 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2736 end;
2737 7: begin // Plasmagun
2738 len := 1024;
2739 sz := 5;
2740 if angle = ANGLE_RIGHTUP then Inc(angle);
2741 if angle = ANGLE_RIGHTDOWN then Inc(angle, 3);
2742 if angle = ANGLE_LEFTUP then Dec(angle);
2743 if angle = ANGLE_LEFTDOWN then Dec(angle, 3);
2744 end;
2745 8: begin // BFG
2746 len := 1024;
2747 sz := 12;
2748 if angle = ANGLE_RIGHTUP then Inc(angle, 1);
2749 if angle = ANGLE_RIGHTDOWN then Inc(angle, 2);
2750 if angle = ANGLE_LEFTUP then Dec(angle, 1);
2751 if angle = ANGLE_LEFTDOWN then Dec(angle, 2);
2752 end;
2753 9: begin // Super Chaingun
2754 len := 1024;
2755 sz := 4;
2756 if angle = ANGLE_RIGHTUP then Dec(angle, 2);
2757 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2758 if angle = ANGLE_LEFTUP then Inc(angle, 2);
2759 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2760 end;
2761 end;
2762 xx := Trunc(Cos(-DegToRad(angle)) * len) + wx;
2763 yy := Trunc(Sin(-DegToRad(angle)) * len) + wy;
2764 {$IF DEFINED(D2F_DEBUG)}
2765 drawCast(sz, wx, wy, xx, yy);
2766 {$ELSE}
2767 e_DrawLine(sz, wx, wy, xx, yy, 255, 0, 0, 96);
2768 {$ENDIF}
2769 end;
2771 procedure TPlayer.DrawGUI();
2772 var
2773 ID: DWORD;
2774 X, Y, SY, a, p, m: Integer;
2775 tw, th: Word;
2776 cw, ch: Byte;
2777 s: string;
2778 stat: TPlayerStatArray;
2779 begin
2780 X := gPlayerScreenSize.X;
2781 SY := gPlayerScreenSize.Y;
2782 Y := 0;
2784 if gShowScore and (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
2785 begin
2786 if gGameSettings.GameMode = GM_CTF then
2787 a := 32 + 8
2788 else
2789 a := 0;
2790 if gGameSettings.GameMode = GM_CTF then
2791 begin
2792 s := 'TEXTURE_PLAYER_REDFLAG';
2793 if gFlags[FLAG_RED].State = FLAG_STATE_CAPTURED then
2794 s := 'TEXTURE_PLAYER_REDFLAG_S';
2795 if gFlags[FLAG_RED].State = FLAG_STATE_DROPPED then
2796 s := 'TEXTURE_PLAYER_REDFLAG_D';
2797 if g_Texture_Get(s, ID) then
2798 e_Draw(ID, X-16-32, 240-72-4, 0, True, False);
2799 end;
2801 s := IntToStr(gTeamStat[TEAM_RED].Score);
2802 e_CharFont_GetSize(gMenuFont, s, tw, th);
2803 e_CharFont_PrintEx(gMenuFont, X-16-a-tw, 240-72-4, s, TEAMCOLOR[TEAM_RED]);
2805 if gGameSettings.GameMode = GM_CTF then
2806 begin
2807 s := 'TEXTURE_PLAYER_BLUEFLAG';
2808 if gFlags[FLAG_BLUE].State = FLAG_STATE_CAPTURED then
2809 s := 'TEXTURE_PLAYER_BLUEFLAG_S';
2810 if gFlags[FLAG_BLUE].State = FLAG_STATE_DROPPED then
2811 s := 'TEXTURE_PLAYER_BLUEFLAG_D';
2812 if g_Texture_Get(s, ID) then
2813 e_Draw(ID, X-16-32, 240-32-4, 0, True, False);
2814 end;
2816 s := IntToStr(gTeamStat[TEAM_BLUE].Score);
2817 e_CharFont_GetSize(gMenuFont, s, tw, th);
2818 e_CharFont_PrintEx(gMenuFont, X-16-a-tw, 240-32-4, s, TEAMCOLOR[TEAM_BLUE]);
2819 end;
2821 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID) then
2822 e_DrawFill(ID, X, 0, 1, (gPlayerScreenSize.Y div 256)+IfThen(gPlayerScreenSize.Y mod 256 > 0, 1, 0),
2823 0, False, False);
2825 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID) then
2826 e_Draw(ID, X+2, Y, 0, True, False);
2828 if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
2829 begin
2830 if gShowStat then
2831 begin
2832 s := IntToStr(Frags);
2833 e_CharFont_GetSize(gMenuFont, s, tw, th);
2834 e_CharFont_PrintEx(gMenuFont, X-16-tw, Y, s, _RGB(255, 0, 0));
2836 s := '';
2837 p := 1;
2838 m := 0;
2839 stat := g_Player_GetStats();
2840 if stat <> nil then
2841 begin
2842 p := 1;
2844 for a := 0 to High(stat) do
2845 if stat[a].Name <> Name then
2846 begin
2847 if stat[a].Frags > m then m := stat[a].Frags;
2848 if stat[a].Frags > Frags then p := p+1;
2849 end;
2850 end;
2852 s := IntToStr(p)+' / '+IntToStr(Length(stat))+' ';
2853 if Frags >= m then s := s+'+' else s := s+'-';
2854 s := s+IntToStr(Abs(Frags-m));
2856 e_CharFont_GetSize(gMenuSmallFont, s, tw, th);
2857 e_CharFont_PrintEx(gMenuSmallFont, X-16-tw, Y+32, s, _RGB(255, 0, 0));
2858 end;
2860 if gLMSRespawn > LMS_RESPAWN_NONE then
2861 begin
2862 s := _lc[I_GAME_WARMUP];
2863 e_CharFont_GetSize(gMenuFont, s, tw, th);
2864 s := s + ': ' + IntToStr((gLMSRespawnTime - gTime) div 1000);
2865 e_CharFont_PrintEx(gMenuFont, X-64-tw, SY-32, s, _RGB(0, 255, 0));
2866 end
2867 else if gShowLives and (gGameSettings.MaxLives > 0) then
2868 begin
2869 s := IntToStr(Lives);
2870 e_CharFont_GetSize(gMenuFont, s, tw, th);
2871 e_CharFont_PrintEx(gMenuFont, X-16-tw, SY-32, s, _RGB(0, 255, 0));
2872 end;
2873 end;
2875 e_CharFont_GetSize(gMenuSmallFont, FName, tw, th);
2876 e_CharFont_PrintEx(gMenuSmallFont, X+98-(tw div 2), Y+8, FName, _RGB(255, 0, 0));
2878 if R_BERSERK in FRulez then
2879 e_Draw(gItemsTexturesID[ITEM_MEDKIT_BLACK], X+37, Y+45, 0, True, False)
2880 else
2881 e_Draw(gItemsTexturesID[ITEM_MEDKIT_LARGE], X+37, Y+45, 0, True, False);
2883 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID) then
2884 e_Draw(ID, X+36, Y+77, 0, True, False);
2886 s := IntToStr(IfThen(FHealth > 0, FHealth, 0));
2887 e_CharFont_GetSize(gMenuFont, s, tw, th);
2888 e_CharFont_PrintEx(gMenuFont, X+178-tw, Y+40, s, _RGB(255, 0, 0));
2890 s := IntToStr(FArmor);
2891 e_CharFont_GetSize(gMenuFont, s, tw, th);
2892 e_CharFont_PrintEx(gMenuFont, X+178-tw, Y+68, s, _RGB(255, 0, 0));
2894 s := IntToStr(GetAmmoByWeapon(FCurrWeap));
2896 case FCurrWeap of
2897 WEAPON_KASTET:
2898 begin
2899 s := '--';
2900 ID := gItemsTexturesID[ITEM_WEAPON_KASTET];
2901 end;
2902 WEAPON_SAW:
2903 begin
2904 s := '--';
2905 ID := gItemsTexturesID[ITEM_WEAPON_SAW];
2906 end;
2907 WEAPON_PISTOL: ID := gItemsTexturesID[ITEM_WEAPON_PISTOL];
2908 WEAPON_CHAINGUN: ID := gItemsTexturesID[ITEM_WEAPON_CHAINGUN];
2909 WEAPON_SHOTGUN1: ID := gItemsTexturesID[ITEM_WEAPON_SHOTGUN1];
2910 WEAPON_SHOTGUN2: ID := gItemsTexturesID[ITEM_WEAPON_SHOTGUN2];
2911 WEAPON_SUPERPULEMET: ID := gItemsTexturesID[ITEM_WEAPON_SUPERPULEMET];
2912 WEAPON_ROCKETLAUNCHER: ID := gItemsTexturesID[ITEM_WEAPON_ROCKETLAUNCHER];
2913 WEAPON_PLASMA: ID := gItemsTexturesID[ITEM_WEAPON_PLASMA];
2914 WEAPON_BFG: ID := gItemsTexturesID[ITEM_WEAPON_BFG];
2915 WEAPON_FLAMETHROWER: ID := gItemsTexturesID[ITEM_WEAPON_FLAMETHROWER];
2916 end;
2918 e_CharFont_GetSize(gMenuFont, s, tw, th);
2919 e_CharFont_PrintEx(gMenuFont, X+178-tw, Y+158, s, _RGB(255, 0, 0));
2920 e_Draw(ID, X+20, Y+160, 0, True, False);
2922 if R_KEY_RED in FRulez then
2923 e_Draw(gItemsTexturesID[ITEM_KEY_RED], X+78, Y+214, 0, True, False);
2925 if R_KEY_GREEN in FRulez then
2926 e_Draw(gItemsTexturesID[ITEM_KEY_GREEN], X+95, Y+214, 0, True, False);
2928 if R_KEY_BLUE in FRulez then
2929 e_Draw(gItemsTexturesID[ITEM_KEY_BLUE], X+112, Y+214, 0, True, False);
2931 if FJetFuel > 0 then
2932 begin
2933 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID) then
2934 e_Draw(ID, X+2, Y+116, 0, True, False);
2935 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID) then
2936 e_Draw(ID, X+2, Y+126, 0, True, False);
2937 e_DrawLine(4, X+16, Y+122, X+16+Trunc(168*IfThen(FAir > 0, FAir, 0)/AIR_MAX), Y+122, 0, 0, 196);
2938 e_DrawLine(4, X+16, Y+132, X+16+Trunc(168*FJetFuel/JET_MAX), Y+132, 208, 0, 0);
2939 end
2940 else
2941 begin
2942 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID) then
2943 e_Draw(ID, X+2, Y+124, 0, True, False);
2944 e_DrawLine(4, X+16, Y+130, X+16+Trunc(168*IfThen(FAir > 0, FAir, 0)/AIR_MAX), Y+130, 0, 0, 196);
2945 end;
2947 if gShowPing and g_Game_IsClient then
2948 begin
2949 s := _lc[I_GAME_PING_HUD] + IntToStr(NetPeer.lastRoundTripTime) + _lc[I_NET_SLIST_PING_MS];
2950 e_TextureFontPrint(X + 4, Y + 242, s, gStdFont);
2951 Y := Y + 16;
2952 end;
2954 if FSpectator then
2955 begin
2956 e_TextureFontPrint(X + 4, Y + 242, _lc[I_PLAYER_SPECT], gStdFont);
2957 e_TextureFontPrint(X + 4, Y + 258, _lc[I_PLAYER_SPECT2], gStdFont);
2958 e_TextureFontPrint(X + 4, Y + 274, _lc[I_PLAYER_SPECT1], gStdFont);
2959 if FNoRespawn then
2960 begin
2961 e_TextureFontGetSize(gStdFont, cw, ch);
2962 s := _lc[I_PLAYER_SPECT4];
2963 e_TextureFontPrintEx(gScreenWidth div 2 - cw*(Length(s) div 2),
2964 gScreenHeight-4-ch, s, gStdFont, 255, 255, 255, 1, True);
2965 e_TextureFontPrint(X + 4, Y + 290, _lc[I_PLAYER_SPECT1S], gStdFont);
2966 end;
2968 end;
2969 end;
2971 procedure TPlayer.DrawRulez();
2972 var
2973 dr: Boolean;
2974 begin
2975 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2976 if (FMegaRulez[MR_INVUL] >= gTime) and (FSpawnInvul < gTime) then
2977 begin
2978 if (FMegaRulez[MR_INVUL]-gTime) <= 2100 then
2979 dr := not Odd((FMegaRulez[MR_INVUL]-gTime) div 300)
2980 else
2981 dr := True;
2983 if dr then
2984 e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1,
2985 191, 191, 191, 0, TBlending.Invert);
2986 end;
2988 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2989 if FMegaRulez[MR_SUIT] >= gTime then
2990 begin
2991 if (FMegaRulez[MR_SUIT]-gTime) <= 2100 then
2992 dr := not Odd((FMegaRulez[MR_SUIT]-gTime) div 300)
2993 else
2994 dr := True;
2996 if dr then
2997 e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1,
2998 0, 96, 0, 200, TBlending.None);
2999 end;
3001 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
3002 if (FBerserk >= 0) and (LongWord(FBerserk) >= gTime) and (gFlash = 2) then
3003 begin
3004 e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1,
3005 255, 0, 0, 200, TBlending.None);
3006 end;
3007 end;
3009 procedure TPlayer.DrawPain();
3010 var
3011 a, h: Integer;
3012 begin
3013 if FPain = 0 then Exit;
3015 a := FPain;
3017 if a < 15 then h := 0
3018 else if a < 35 then h := 1
3019 else if a < 55 then h := 2
3020 else if a < 75 then h := 3
3021 else if a < 95 then h := 4
3022 else h := 5;
3024 //if a > 255 then a := 255;
3026 e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255, 0, 0, 255-h*50);
3027 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
3028 end;
3030 procedure TPlayer.DrawPickup();
3031 var
3032 a, h: Integer;
3033 begin
3034 if FPickup = 0 then Exit;
3036 a := FPickup;
3038 if a < 15 then h := 1
3039 else if a < 35 then h := 2
3040 else if a < 55 then h := 3
3041 else if a < 75 then h := 4
3042 else h := 5;
3044 e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 150, 200, 150, 255-h*50);
3045 end;
3047 procedure TPlayer.DoPunch();
3048 var
3049 id: DWORD;
3050 st: String;
3051 begin
3052 if FPunchAnim <> nil then begin
3053 FPunchAnim.reset();
3054 FPunchAnim.Free;
3055 FPunchAnim := nil;
3056 end;
3057 st := 'FRAMES_PUNCH';
3058 if R_BERSERK in FRulez then
3059 st := st + '_BERSERK';
3060 if FKeys[KEY_UP].Pressed then
3061 st := st + '_UP'
3062 else if FKeys[KEY_DOWN].Pressed then
3063 st := st + '_DN';
3064 g_Frames_Get(id, st);
3065 FPunchAnim := TAnimation.Create(id, False, 1);
3066 end;
3068 procedure TPlayer.Fire();
3069 var
3070 f, DidFire: Boolean;
3071 wx, wy, xd, yd: Integer;
3072 locobj: TObj;
3073 begin
3074 if g_Game_IsClient then Exit;
3075 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
3076 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
3078 if FSpectator then
3079 begin
3080 Respawn(False);
3081 Exit;
3082 end;
3084 if FReloading[FCurrWeap] <> 0 then Exit;
3086 DidFire := False;
3088 f := False;
3089 wx := FObj.X+WEAPONPOINT[FDirection].X;
3090 wy := FObj.Y+WEAPONPOINT[FDirection].Y;
3091 xd := wx+IfThen(FDirection = TDirection.D_LEFT, -30, 30);
3092 yd := wy+firediry();
3094 case FCurrWeap of
3095 WEAPON_KASTET:
3096 begin
3097 DoPunch();
3098 if R_BERSERK in FRulez then
3099 begin
3100 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
3101 locobj.X := FObj.X+FObj.Rect.X;
3102 locobj.Y := FObj.Y+FObj.Rect.Y;
3103 locobj.rect.X := 0;
3104 locobj.rect.Y := 0;
3105 locobj.rect.Width := 39;
3106 locobj.rect.Height := 52;
3107 locobj.Vel.X := (xd-wx) div 2;
3108 locobj.Vel.Y := (yd-wy) div 2;
3109 locobj.Accel.X := xd-wx;
3110 locobj.Accel.y := yd-wy;
3112 if g_Weapon_Hit(@locobj, 50, FUID, HIT_SOME) <> 0 then
3113 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj.X, FObj.Y)
3114 else
3115 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj.X, FObj.Y);
3117 if (gFlash = 1) and (FPain < 50) then FPain := min(FPain + 25, 50);
3118 end
3119 else
3120 begin
3121 g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 3, FUID);
3122 end;
3124 DidFire := True;
3125 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3126 end;
3128 WEAPON_SAW:
3129 begin
3130 if g_Weapon_chainsaw(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y,
3131 IfThen(gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF], 9, 3), FUID) <> 0 then
3132 begin
3133 FSawSoundSelect.Stop();
3134 FSawSound.Stop();
3135 FSawSoundHit.PlayAt(FObj.X, FObj.Y);
3136 end
3137 else if not FSawSoundHit.IsPlaying() then
3138 begin
3139 FSawSoundSelect.Stop();
3140 FSawSound.PlayAt(FObj.X, FObj.Y);
3141 end;
3143 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3144 DidFire := True;
3145 f := True;
3146 end;
3148 WEAPON_PISTOL:
3149 if FAmmo[A_BULLETS] > 0 then
3150 begin
3151 g_Weapon_pistol(wx, wy, xd, yd, FUID);
3152 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3153 Dec(FAmmo[A_BULLETS]);
3154 FFireAngle := FAngle;
3155 f := True;
3156 DidFire := True;
3157 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
3158 GameVelX, GameVelY-2, SHELL_BULLET);
3159 end;
3161 WEAPON_SHOTGUN1:
3162 if FAmmo[A_SHELLS] > 0 then
3163 begin
3164 g_Weapon_shotgun(wx, wy, xd, yd, FUID);
3165 if not gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx, wy);
3166 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3167 Dec(FAmmo[A_SHELLS]);
3168 FFireAngle := FAngle;
3169 f := True;
3170 DidFire := True;
3171 FShellTimer := 10;
3172 FShellType := SHELL_SHELL;
3173 end;
3175 WEAPON_SHOTGUN2:
3176 if FAmmo[A_SHELLS] >= 2 then
3177 begin
3178 g_Weapon_dshotgun(wx, wy, xd, yd, FUID);
3179 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3180 Dec(FAmmo[A_SHELLS], 2);
3181 FFireAngle := FAngle;
3182 f := True;
3183 DidFire := True;
3184 FShellTimer := 13;
3185 FShellType := SHELL_DBLSHELL;
3186 end;
3188 WEAPON_CHAINGUN:
3189 if FAmmo[A_BULLETS] > 0 then
3190 begin
3191 g_Weapon_mgun(wx, wy, xd, yd, FUID);
3192 if not gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx, wy);
3193 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3194 Dec(FAmmo[A_BULLETS]);
3195 FFireAngle := FAngle;
3196 f := True;
3197 DidFire := True;
3198 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
3199 GameVelX, GameVelY-2, SHELL_BULLET);
3200 end;
3202 WEAPON_ROCKETLAUNCHER:
3203 if FAmmo[A_ROCKETS] > 0 then
3204 begin
3205 g_Weapon_rocket(wx, wy, xd, yd, FUID);
3206 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3207 Dec(FAmmo[A_ROCKETS]);
3208 FFireAngle := FAngle;
3209 f := True;
3210 DidFire := True;
3211 end;
3213 WEAPON_PLASMA:
3214 if FAmmo[A_CELLS] > 0 then
3215 begin
3216 g_Weapon_plasma(wx, wy, xd, yd, FUID);
3217 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3218 Dec(FAmmo[A_CELLS]);
3219 FFireAngle := FAngle;
3220 f := True;
3221 DidFire := True;
3222 end;
3224 WEAPON_BFG:
3225 if (FAmmo[A_CELLS] >= 40) and (FBFGFireCounter = -1) then
3226 begin
3227 FBFGFireCounter := 17;
3228 if not FNoReload then
3229 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj.X, FObj.Y);
3230 Dec(FAmmo[A_CELLS], 40);
3231 DidFire := True;
3232 end;
3234 WEAPON_SUPERPULEMET:
3235 if FAmmo[A_SHELLS] > 0 then
3236 begin
3237 g_Weapon_shotgun(wx, wy, xd, yd, FUID);
3238 if not gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx, wy);
3239 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3240 Dec(FAmmo[A_SHELLS]);
3241 FFireAngle := FAngle;
3242 f := True;
3243 DidFire := True;
3244 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
3245 GameVelX, GameVelY-2, SHELL_SHELL);
3246 end;
3248 WEAPON_FLAMETHROWER:
3249 if FAmmo[A_FUEL] > 0 then
3250 begin
3251 g_Weapon_flame(wx, wy, xd, yd, FUID);
3252 FlamerOn;
3253 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3254 Dec(FAmmo[A_FUEL]);
3255 FFireAngle := FAngle;
3256 f := True;
3257 DidFire := True;
3258 end
3259 else
3260 begin
3261 FlamerOff;
3262 if g_Game_IsNet and g_Game_IsServer then MH_SEND_PlayerStats(FUID);
3263 end;
3264 end;
3266 if g_Game_IsNet then
3267 begin
3268 if DidFire then
3269 begin
3270 if FCurrWeap <> WEAPON_BFG then
3271 MH_SEND_PlayerFire(FUID, FCurrWeap, wx, wy, xd, yd, LastShotID)
3272 else
3273 if not FNoReload then
3274 MH_SEND_Sound(FObj.X, FObj.Y, 'SOUND_WEAPON_STARTFIREBFG');
3275 end;
3277 MH_SEND_PlayerStats(FUID);
3278 end;
3280 if not f then Exit;
3282 if (FAngle = 0) or (FAngle = 180) then SetAction(A_ATTACK)
3283 else if (FAngle = ANGLE_LEFTDOWN) or (FAngle = ANGLE_RIGHTDOWN) then SetAction(A_ATTACKDOWN)
3284 else if (FAngle = ANGLE_LEFTUP) or (FAngle = ANGLE_RIGHTUP) then SetAction(A_ATTACKUP);
3285 end;
3287 function TPlayer.GetAmmoByWeapon(Weapon: Byte): Word;
3288 begin
3289 case Weapon of
3290 WEAPON_PISTOL, WEAPON_CHAINGUN: Result := FAmmo[A_BULLETS];
3291 WEAPON_SHOTGUN1, WEAPON_SHOTGUN2, WEAPON_SUPERPULEMET: Result := FAmmo[A_SHELLS];
3292 WEAPON_ROCKETLAUNCHER: Result := FAmmo[A_ROCKETS];
3293 WEAPON_PLASMA, WEAPON_BFG: Result := FAmmo[A_CELLS];
3294 WEAPON_FLAMETHROWER: Result := FAmmo[A_FUEL];
3295 else Result := 0;
3296 end;
3297 end;
3299 function TPlayer.HeadInLiquid(XInc, YInc: Integer): Boolean;
3300 begin
3301 Result := g_Map_CollidePanel(FObj.X+PLAYER_HEADRECT.X+XInc, FObj.Y+PLAYER_HEADRECT.Y+YInc,
3302 PLAYER_HEADRECT.Width, PLAYER_HEADRECT.Height,
3303 PANEL_WATER or PANEL_ACID1 or PANEL_ACID2, True);
3304 end;
3306 procedure TPlayer.FlamerOn;
3307 begin
3308 FFlameSoundOff.Stop();
3309 FFlameSoundOff.SetPosition(0);
3310 if FFlaming then
3311 begin
3312 if (not FFlameSoundOn.IsPlaying()) and (not FFlameSoundWork.IsPlaying()) then
3313 FFlameSoundWork.PlayAt(FObj.X, FObj.Y);
3314 end
3315 else
3316 begin
3317 FFlameSoundOn.PlayAt(FObj.X, FObj.Y);
3318 FFlaming := True;
3319 end;
3320 end;
3322 procedure TPlayer.FlamerOff;
3323 begin
3324 if FFlaming then
3325 begin
3326 FFlameSoundOn.Stop();
3327 FFlameSoundOn.SetPosition(0);
3328 FFlameSoundWork.Stop();
3329 FFlameSoundWork.SetPosition(0);
3330 FFlameSoundOff.PlayAt(FObj.X, FObj.Y);
3331 FFlaming := False;
3332 end;
3333 end;
3335 procedure TPlayer.JetpackOn;
3336 begin
3337 FJetSoundFly.Stop;
3338 FJetSoundOff.Stop;
3339 FJetSoundOn.SetPosition(0);
3340 FJetSoundOn.PlayAt(FObj.X, FObj.Y);
3341 FlySmoke(8);
3342 end;
3344 procedure TPlayer.JetpackOff;
3345 begin
3346 FJetSoundFly.Stop;
3347 FJetSoundOn.Stop;
3348 FJetSoundOff.SetPosition(0);
3349 FJetSoundOff.PlayAt(FObj.X, FObj.Y);
3350 end;
3352 procedure TPlayer.CatchFire(Attacker: Word; Timeout: Integer = PLAYER_BURN_TIME);
3353 begin
3354 if Timeout <= 0 then
3355 exit;
3356 if (FMegaRulez[MR_SUIT] > gTime) or (FMegaRulez[MR_INVUL] > gTime) then
3357 exit; // Íå çàãîðàåìñÿ êîãäà åñòü çàùèòà
3358 if g_Obj_CollidePanel(@FObj, 0, 0, PANEL_WATER or PANEL_ACID1 or PANEL_ACID2) then
3359 exit; // Íå ïîäãîðàåì â âîäå íà âñÿêèé ñëó÷àé
3360 if FFireTime <= 0 then
3361 g_Sound_PlayExAt('SOUND_IGNITE', FObj.X, FObj.Y);
3362 FFireTime := Timeout;
3363 FFireAttacker := Attacker;
3364 if g_Game_IsNet and g_Game_IsServer then
3365 MH_SEND_PlayerStats(FUID);
3366 end;
3368 procedure TPlayer.Jump();
3369 begin
3370 if gFly or FJetpack then
3371 begin
3372 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
3373 if FObj.Vel.Y > -VEL_FLY then
3374 FObj.Vel.Y := FObj.Vel.Y - 3;
3375 if FJetpack then
3376 begin
3377 if FJetFuel > 0 then
3378 Dec(FJetFuel);
3379 if (FJetFuel < 1) and g_Game_IsServer then
3380 begin
3381 FJetpack := False;
3382 JetpackOff;
3383 if g_Game_IsNet then
3384 MH_SEND_PlayerStats(FUID);
3385 end;
3386 end;
3387 Exit;
3388 end;
3390 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
3391 if FGhost then
3392 FCanJetpack := False;
3394 // Ïðûãàåì èëè âñïëûâàåì:
3395 if (CollideLevel(0, 1) or
3396 g_Map_CollidePanel(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y+36, PLAYER_RECT.Width,
3397 PLAYER_RECT.Height-33, PANEL_STEP, False)
3398 ) and (FObj.Accel.Y = 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
3399 begin
3400 FObj.Vel.Y := -VEL_JUMP;
3401 FCanJetpack := False;
3402 end
3403 else
3404 begin
3405 if BodyInLiquid(0, 0) then
3406 FObj.Vel.Y := -VEL_SW
3407 else if (FJetFuel > 0) and FCanJetpack and
3408 g_Game_IsServer and (not g_Obj_CollideLiquid(@FObj, 0, 0)) then
3409 begin
3410 FJetpack := True;
3411 JetpackOn;
3412 if g_Game_IsNet then
3413 MH_SEND_PlayerStats(FUID);
3414 end;
3415 end;
3416 end;
3418 procedure TPlayer.Kill(KillType: Byte; SpawnerUID: Word; t: Byte);
3419 var
3420 a, i, k, ab, ar: Byte;
3421 s: String;
3422 mon: TMonster;
3423 plr: TPlayer;
3424 srv, netsrv: Boolean;
3425 DoFrags: Boolean;
3426 OldLR: Byte;
3427 KP: TPlayer;
3428 it: PItem;
3430 procedure PushItem(t: Byte);
3431 var
3432 id: DWORD;
3433 begin
3434 id := g_Items_Create(FObj.X, FObj.Y, t, True, False);
3435 it := g_Items_ByIdx(id);
3436 if KillType = K_EXTRAHARDKILL then // -7..+7; -8..0
3437 begin
3438 g_Obj_Push(@it.Obj, (FObj.Vel.X div 2)-7+Random(15),
3439 (FObj.Vel.Y div 2)-Random(9));
3440 it.positionChanged(); // this updates spatial accelerators
3441 end
3442 else
3443 begin
3444 if KillType = K_HARDKILL then // -5..+5; -5..0
3445 begin
3446 g_Obj_Push(@it.Obj, (FObj.Vel.X div 2)-5+Random(11),
3447 (FObj.Vel.Y div 2)-Random(6));
3448 end
3449 else // -3..+3; -3..0
3450 begin
3451 g_Obj_Push(@it.Obj, (FObj.Vel.X div 2)-3+Random(7),
3452 (FObj.Vel.Y div 2)-Random(4));
3453 end;
3454 it.positionChanged(); // this updates spatial accelerators
3455 end;
3457 if g_Game_IsNet and g_Game_IsServer then
3458 MH_SEND_ItemSpawn(True, id);
3459 end;
3461 begin
3462 DoFrags := (gGameSettings.MaxLives = 0) or (gGameSettings.GameMode = GM_COOP);
3463 Srv := g_Game_IsServer;
3464 Netsrv := g_Game_IsServer and g_Game_IsNet;
3465 if Srv then FDeath := FDeath + 1;
3466 if FAlive then
3467 begin
3468 if FGhost then
3469 FGhost := False;
3470 if not FPhysics then
3471 FPhysics := True;
3472 FAlive := False;
3473 end;
3474 FShellTimer := -1;
3476 if (gGameSettings.MaxLives > 0) and Srv and (gLMSRespawn = LMS_RESPAWN_NONE) then
3477 begin
3478 if FLives > 0 then FLives := FLives - 1;
3479 if FLives = 0 then FNoRespawn := True;
3480 end;
3482 // Íîìåð òèïà ñìåðòè:
3483 a := 1;
3484 case KillType of
3485 K_SIMPLEKILL: a := 1;
3486 K_HARDKILL: a := 2;
3487 K_EXTRAHARDKILL: a := 3;
3488 K_FALLKILL: a := 4;
3489 end;
3491 // Çâóê ñìåðòè:
3492 if not FModel.PlaySound(MODELSOUND_DIE, a, FObj.X, FObj.Y) then
3493 for i := 1 to 3 do
3494 if FModel.PlaySound(MODELSOUND_DIE, i, FObj.X, FObj.Y) then
3495 Break;
3497 // Âðåìÿ ðåñïàóíà:
3498 if Srv then
3499 case KillType of
3500 K_SIMPLEKILL:
3501 FTime[T_RESPAWN] := gTime + TIME_RESPAWN1;
3502 K_HARDKILL:
3503 FTime[T_RESPAWN] := gTime + TIME_RESPAWN2;
3504 K_EXTRAHARDKILL, K_FALLKILL:
3505 FTime[T_RESPAWN] := gTime + TIME_RESPAWN3;
3506 end;
3508 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3509 case KillType of
3510 K_SIMPLEKILL:
3511 SetAction(A_DIE1);
3512 K_HARDKILL, K_EXTRAHARDKILL:
3513 SetAction(A_DIE2);
3514 end;
3516 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3517 if (KillType <> K_FALLKILL) and (Srv) then
3518 g_Monsters_killedp();
3520 if SpawnerUID = FUID then
3521 begin // Ñàìîóáèëñÿ
3522 if Srv then
3523 begin
3524 if gGameSettings.GameMode = GM_TDM then
3525 Dec(gTeamStat[FTeam].Score);
3526 if DoFrags or (gGameSettings.GameMode = GM_TDM) then
3527 begin
3528 Dec(FFrags);
3529 FLastFrag := 0;
3530 end;
3531 end;
3532 g_Console_Add(Format(_lc[I_PLAYER_KILL_SELF], [FName]), True);
3533 end
3534 else
3535 if g_GetUIDType(SpawnerUID) = UID_PLAYER then
3536 begin // Óáèò äðóãèì èãðîêîì
3537 KP := g_Player_Get(SpawnerUID);
3538 if (KP <> nil) and Srv then
3539 begin
3540 if (DoFrags or (gGameSettings.GameMode = GM_TDM)) then
3541 if SameTeam(FUID, SpawnerUID) then
3542 begin
3543 Dec(KP.FFrags);
3544 KP.FLastFrag := 0;
3545 end else
3546 begin
3547 Inc(KP.FFrags);
3548 KP.FragCombo();
3549 end;
3551 if (gGameSettings.GameMode = GM_TDM) and DoFrags then
3552 Inc(gTeamStat[KP.Team].Score,
3553 IfThen(SameTeam(FUID, SpawnerUID), -1, 1));
3555 if netsrv then MH_SEND_PlayerStats(SpawnerUID);
3556 end;
3558 plr := g_Player_Get(SpawnerUID);
3559 if plr = nil then
3560 s := '?'
3561 else
3562 s := plr.FName;
3564 case KillType of
3565 K_HARDKILL:
3566 g_Console_Add(Format(_lc[I_PLAYER_KILL_EXTRAHARD_2],
3567 [FName, s]),
3568 gShowKillMsg);
3569 K_EXTRAHARDKILL:
3570 g_Console_Add(Format(_lc[I_PLAYER_KILL_EXTRAHARD_1],
3571 [FName, s]),
3572 gShowKillMsg);
3573 else
3574 g_Console_Add(Format(_lc[I_PLAYER_KILL],
3575 [FName, s]),
3576 gShowKillMsg);
3577 end;
3578 end
3579 else if g_GetUIDType(SpawnerUID) = UID_MONSTER then
3580 begin // Óáèò ìîíñòðîì
3581 mon := g_Monsters_ByUID(SpawnerUID);
3582 if mon = nil then
3583 s := '?'
3584 else
3585 s := g_Mons_GetKilledByTypeId(mon.MonsterType);
3587 case KillType of
3588 K_HARDKILL:
3589 g_Console_Add(Format(_lc[I_PLAYER_KILL_EXTRAHARD_2],
3590 [FName, s]),
3591 gShowKillMsg);
3592 K_EXTRAHARDKILL:
3593 g_Console_Add(Format(_lc[I_PLAYER_KILL_EXTRAHARD_1],
3594 [FName, s]),
3595 gShowKillMsg);
3596 else
3597 g_Console_Add(Format(_lc[I_PLAYER_KILL],
3598 [FName, s]),
3599 gShowKillMsg);
3600 end;
3601 end
3602 else // Îñîáûå òèïû ñìåðòè
3603 case t of
3604 HIT_DISCON: ;
3605 HIT_SELF: g_Console_Add(Format(_lc[I_PLAYER_KILL_SELF], [FName]), True);
3606 HIT_FALL: g_Console_Add(Format(_lc[I_PLAYER_KILL_FALL], [FName]), True);
3607 HIT_WATER: g_Console_Add(Format(_lc[I_PLAYER_KILL_WATER], [FName]), True);
3608 HIT_ACID: g_Console_Add(Format(_lc[I_PLAYER_KILL_ACID], [FName]), True);
3609 HIT_TRAP: g_Console_Add(Format(_lc[I_PLAYER_KILL_TRAP], [FName]), True);
3610 else g_Console_Add(Format(_lc[I_PLAYER_DIED], [FName]), True);
3611 end;
3613 if Srv then
3614 begin
3615 // Âûáðîñ îðóæèÿ:
3616 for a := WP_FIRST to WP_LAST do
3617 if FWeapon[a] then
3618 begin
3619 case a of
3620 WEAPON_SAW: i := ITEM_WEAPON_SAW;
3621 WEAPON_SHOTGUN1: i := ITEM_WEAPON_SHOTGUN1;
3622 WEAPON_SHOTGUN2: i := ITEM_WEAPON_SHOTGUN2;
3623 WEAPON_CHAINGUN: i := ITEM_WEAPON_CHAINGUN;
3624 WEAPON_ROCKETLAUNCHER: i := ITEM_WEAPON_ROCKETLAUNCHER;
3625 WEAPON_PLASMA: i := ITEM_WEAPON_PLASMA;
3626 WEAPON_BFG: i := ITEM_WEAPON_BFG;
3627 WEAPON_SUPERPULEMET: i := ITEM_WEAPON_SUPERPULEMET;
3628 WEAPON_FLAMETHROWER: i := ITEM_WEAPON_FLAMETHROWER;
3629 else i := 0;
3630 end;
3632 if i <> 0 then
3633 PushItem(i);
3634 end;
3636 // Âûáðîñ ðþêçàêà:
3637 if R_ITEM_BACKPACK in FRulez then
3638 PushItem(ITEM_AMMO_BACKPACK);
3640 // Âûáðîñ ðàêåòíîãî ðàíöà:
3641 if FJetFuel > 0 then
3642 PushItem(ITEM_JETPACK);
3644 // Âûáðîñ êëþ÷åé:
3645 if (not (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF])) or
3646 (not LongBool(gGameSettings.Options and GAME_OPTION_DMKEYS)) then
3647 begin
3648 if R_KEY_RED in FRulez then
3649 PushItem(ITEM_KEY_RED);
3651 if R_KEY_GREEN in FRulez then
3652 PushItem(ITEM_KEY_GREEN);
3654 if R_KEY_BLUE in FRulez then
3655 PushItem(ITEM_KEY_BLUE);
3656 end;
3658 // Âûáðîñ ôëàãà:
3659 DropFlag(KillType = K_FALLKILL);
3660 end;
3662 FCorpse := g_Player_CreateCorpse(Self);
3664 if Srv and (gGameSettings.MaxLives > 0) and FNoRespawn and
3665 (gLMSRespawn = LMS_RESPAWN_NONE) then
3666 begin
3667 a := 0;
3668 k := 0;
3669 ar := 0;
3670 ab := 0;
3671 for i := Low(gPlayers) to High(gPlayers) do
3672 begin
3673 if gPlayers[i] = nil then continue;
3674 if (not gPlayers[i].FNoRespawn) and (not gPlayers[i].FSpectator) then
3675 begin
3676 Inc(a);
3677 if gPlayers[i].FTeam = TEAM_RED then Inc(ar)
3678 else if gPlayers[i].FTeam = TEAM_BLUE then Inc(ab);
3679 k := i;
3680 end;
3681 end;
3683 OldLR := gLMSRespawn;
3684 if (gGameSettings.GameMode = GM_COOP) then
3685 begin
3686 if (a = 0) then
3687 begin
3688 // everyone is dead, restart the map
3689 g_Game_Message(_lc[I_MESSAGE_LMS_LOSE], 144);
3690 if Netsrv then
3691 MH_SEND_GameEvent(NET_EV_LMS_LOSE);
3692 gLMSRespawn := LMS_RESPAWN_FINAL;
3693 gLMSRespawnTime := gTime + 5000;
3694 end
3695 else if (a = 1) then
3696 begin
3697 if (gPlayers[k] <> nil) and not (gPlayers[k] is TBot) then
3698 if (gPlayers[k] = gPlayer1) or
3699 (gPlayers[k] = gPlayer2) then
3700 g_Console_Add('*** ' + _lc[I_MESSAGE_LMS_SURVIVOR] + ' ***', True)
3701 else if Netsrv and (gPlayers[k].FClientID >= 0) then
3702 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR, 0, 'N', gPlayers[k].FClientID);
3703 end;
3704 end
3705 else if (gGameSettings.GameMode = GM_TDM) then
3706 begin
3707 if (ab = 0) and (ar <> 0) then
3708 begin
3709 // blu team ded
3710 g_Game_Message(Format(_lc[I_MESSAGE_TLMS_WIN], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 144);
3711 if Netsrv then
3712 MH_SEND_GameEvent(NET_EV_TLMS_WIN, TEAM_RED);
3713 Inc(gTeamStat[TEAM_RED].Score);
3714 gLMSRespawn := LMS_RESPAWN_FINAL;
3715 gLMSRespawnTime := gTime + 5000;
3716 end
3717 else if (ar = 0) and (ab <> 0) then
3718 begin
3719 // red team ded
3720 g_Game_Message(Format(_lc[I_MESSAGE_TLMS_WIN], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 144);
3721 if Netsrv then
3722 MH_SEND_GameEvent(NET_EV_TLMS_WIN, TEAM_BLUE);
3723 Inc(gTeamStat[TEAM_BLUE].Score);
3724 gLMSRespawn := LMS_RESPAWN_FINAL;
3725 gLMSRespawnTime := gTime + 5000;
3726 end
3727 else if (ar = 0) and (ab = 0) then
3728 begin
3729 // everyone ded
3730 g_Game_Message(_lc[I_GAME_WIN_DRAW], 144);
3731 if Netsrv then
3732 MH_SEND_GameEvent(NET_EV_LMS_DRAW, 0, FName);
3733 gLMSRespawn := LMS_RESPAWN_FINAL;
3734 gLMSRespawnTime := gTime + 5000;
3735 end;
3736 end
3737 else if (gGameSettings.GameMode = GM_DM) then
3738 begin
3739 if (a = 1) then
3740 begin
3741 if gPlayers[k] <> nil then
3742 with gPlayers[k] do
3743 begin
3744 // survivor is the winner
3745 g_Game_Message(Format(_lc[I_MESSAGE_LMS_WIN], [AnsiUpperCase(FName)]), 144);
3746 if Netsrv then
3747 MH_SEND_GameEvent(NET_EV_LMS_WIN, 0, FName);
3748 Inc(FFrags);
3749 end;
3750 gLMSRespawn := LMS_RESPAWN_FINAL;
3751 gLMSRespawnTime := gTime + 5000;
3752 end
3753 else if (a = 0) then
3754 begin
3755 // everyone is dead, restart the map
3756 g_Game_Message(_lc[I_GAME_WIN_DRAW], 144);
3757 if Netsrv then
3758 MH_SEND_GameEvent(NET_EV_LMS_DRAW, 0, FName);
3759 gLMSRespawn := LMS_RESPAWN_FINAL;
3760 gLMSRespawnTime := gTime + 5000;
3761 end;
3762 end;
3763 if srv and (OldLR = LMS_RESPAWN_NONE) and (gLMSRespawn > LMS_RESPAWN_NONE) then
3764 begin
3765 if NetMode = NET_SERVER then
3766 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, gLMSRespawnTime - gTime)
3767 else
3768 g_Console_Add(Format(_lc[I_MSG_WARMUP_START], [(gLMSRespawnTime - gTime) div 1000]), True);
3769 end;
3770 end;
3772 if Netsrv then
3773 begin
3774 MH_SEND_PlayerStats(FUID);
3775 MH_SEND_PlayerDeath(FUID, KillType, t, SpawnerUID);
3776 if gGameSettings.GameMode = GM_TDM then MH_SEND_GameStats;
3777 end;
3779 if srv and FNoRespawn then Spectate(True);
3780 FWantsInGame := True;
3781 end;
3783 function TPlayer.BodyInLiquid(XInc, YInc: Integer): Boolean;
3784 begin
3785 Result := g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc, PLAYER_RECT.Width,
3786 PLAYER_RECT.Height-20, PANEL_WATER or PANEL_ACID1 or PANEL_ACID2, False);
3787 end;
3789 function TPlayer.BodyInAcid(XInc, YInc: Integer): Boolean;
3790 begin
3791 Result := g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc, PLAYER_RECT.Width,
3792 PLAYER_RECT.Height-20, PANEL_ACID1 or PANEL_ACID2, False);
3793 end;
3795 procedure TPlayer.MakeBloodSimple(Count: Word);
3796 begin
3797 g_GFX_Blood(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)+8,
3798 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2),
3799 Count div 2, 3, -1, 16, (PLAYER_RECT.Height*2 div 3),
3800 FModel.Blood.R, FModel.Blood.G, FModel.Blood.B, FModel.Blood.Kind);
3801 g_GFX_Blood(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-8,
3802 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2),
3803 Count div 2, -3, -1, 16, (PLAYER_RECT.Height*2) div 3,
3804 FModel.Blood.R, FModel.Blood.G, FModel.Blood.B, FModel.Blood.Kind);
3805 end;
3807 procedure TPlayer.MakeBloodVector(Count: Word; VelX, VelY: Integer);
3808 begin
3809 g_GFX_Blood(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2),
3810 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2),
3811 Count, VelX, VelY, 16, (PLAYER_RECT.Height*2) div 3,
3812 FModel.Blood.R, FModel.Blood.G, FModel.Blood.B, FModel.Blood.Kind);
3813 end;
3815 procedure TPlayer.ProcessWeaponAction(Action: Byte);
3816 begin
3817 if g_Game_IsClient then Exit;
3818 case Action of
3819 WP_PREV: PrevWeapon();
3820 WP_NEXT: NextWeapon();
3821 end;
3822 end;
3824 procedure TPlayer.QueueWeaponSwitch(Weapon: Byte);
3825 begin
3826 if g_Game_IsClient then Exit;
3827 if Weapon > High(FWeapon) then Exit;
3828 FNextWeap := FNextWeap or (1 shl Weapon);
3829 end;
3831 procedure TPlayer.resetWeaponQueue ();
3832 begin
3833 FNextWeap := 0;
3834 FNextWeapDelay := 0;
3835 end;
3837 function TPlayer.hasAmmoForWeapon (weapon: Byte): Boolean;
3838 begin
3839 result := false;
3840 case weapon of
3841 WEAPON_KASTET, WEAPON_SAW: result := true;
3842 WEAPON_SHOTGUN1, WEAPON_SHOTGUN2, WEAPON_SUPERPULEMET: result := (FAmmo[A_SHELLS] > 0);
3843 WEAPON_PISTOL, WEAPON_CHAINGUN: result := (FAmmo[A_BULLETS] > 0);
3844 WEAPON_ROCKETLAUNCHER: result := (FAmmo[A_ROCKETS] > 0);
3845 WEAPON_PLASMA, WEAPON_BFG: result := (FAmmo[A_CELLS] > 0);
3846 WEAPON_FLAMETHROWER: result := (FAmmo[A_FUEL] > 0);
3847 else result := (weapon < length(FWeapon));
3848 end;
3849 end;
3851 function TPlayer.hasAmmoForShooting (weapon: Byte): Boolean;
3852 begin
3853 result := false;
3854 case weapon of
3855 WEAPON_KASTET, WEAPON_SAW: result := true;
3856 WEAPON_SHOTGUN1, WEAPON_SUPERPULEMET: result := (FAmmo[A_SHELLS] > 0);
3857 WEAPON_SHOTGUN2: result := (FAmmo[A_SHELLS] > 1);
3858 WEAPON_PISTOL, WEAPON_CHAINGUN: result := (FAmmo[A_BULLETS] > 0);
3859 WEAPON_ROCKETLAUNCHER: result := (FAmmo[A_ROCKETS] > 0);
3860 WEAPON_PLASMA: result := (FAmmo[A_CELLS] > 0);
3861 WEAPON_BFG: result := (FAmmo[A_CELLS] >= 40);
3862 WEAPON_FLAMETHROWER: result := (FAmmo[A_FUEL] > 0);
3863 else result := (weapon < length(FWeapon));
3864 end;
3865 end;
3867 function TPlayer.shouldSwitch (weapon: Byte; hadWeapon: Boolean): Boolean;
3868 begin
3869 result := false;
3870 if (weapon > WP_LAST + 1) then
3871 begin
3872 result := false;
3873 exit;
3874 end;
3875 if (FWeapSwitchMode = 1) and not hadWeapon then
3876 result := true
3877 else if (FWeapSwitchMode = 2) then
3878 result := (FWeapPreferences[weapon] > FWeapPreferences[FCurrWeap]);
3879 end;
3881 // return 255 for "no switch"
3882 function TPlayer.getNextWeaponIndex (): Byte;
3883 var
3884 i: Word;
3885 wantThisWeapon: array[0..64] of Boolean;
3886 wwc: Integer = 0; //HACK!
3887 dir, cwi: Integer;
3888 begin
3889 result := 255; // default result: "no switch"
3890 //e_LogWriteFln('FSWITCHTOEMPTY: %s', [FSwitchToEmpty], TMsgType.Notify);
3891 // had weapon cycling on previous frame? remove that flag
3892 if (FNextWeap and $2000) <> 0 then
3893 begin
3894 FNextWeap := FNextWeap and $1FFF;
3895 FNextWeapDelay := 0;
3896 end;
3897 // cycling has priority
3898 if (FNextWeap and $C000) <> 0 then
3899 begin
3900 if (FNextWeap and $8000) <> 0 then
3901 dir := 1
3902 else
3903 dir := -1;
3904 FNextWeap := FNextWeap or $2000; // we need this
3905 if FNextWeapDelay > 0 then
3906 exit; // cooldown time
3907 cwi := FCurrWeap;
3908 for i := 0 to High(FWeapon) do
3909 begin
3910 cwi := (cwi+length(FWeapon)+dir) mod length(FWeapon);
3911 if FWeapon[cwi] and maySwitch(cwi) then
3912 begin
3913 //e_LogWriteFln(' SWITCH: cur=%d; new=%d %s %s', [FCurrWeap, cwi, FSwitchToEmpty, hasAmmoForWeapon(cwi)], TMsgType.Notify);
3914 result := Byte(cwi);
3915 FNextWeapDelay := WEAPON_DELAY;
3916 exit;
3917 end;
3918 end;
3919 resetWeaponQueue();
3920 exit;
3921 end;
3922 // no cycling
3923 for i := 0 to High(wantThisWeapon) do
3924 wantThisWeapon[i] := false;
3925 for i := 0 to High(FWeapon) do
3926 if (FNextWeap and (1 shl i)) <> 0 then
3927 begin
3928 wantThisWeapon[i] := true;
3929 Inc(wwc);
3930 end;
3932 // exclude currently selected weapon from the set
3933 wantThisWeapon[FCurrWeap] := false;
3934 // slow down alterations a little
3935 if wwc > 1 then
3936 begin
3937 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3938 // more than one weapon requested, assume "alteration" and check alteration delay
3939 if FNextWeapDelay > 0 then
3940 begin
3941 FNextWeap := 0;
3942 exit;
3943 end; // yeah
3944 end;
3945 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3946 // but clear all counters if no weapon should be switched
3947 if wwc < 1 then
3948 begin
3949 resetWeaponQueue();
3950 exit;
3951 end;
3952 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3953 // try weapons in descending order
3954 for i := High(FWeapon) downto 0 do
3955 begin
3956 if wantThisWeapon[i] and FWeapon[i] and ((wwc = 1) or hasAmmoForWeapon(i)) then
3957 begin
3958 // i found her!
3959 result := Byte(i);
3960 resetWeaponQueue();
3961 FNextWeapDelay := WEAPON_DELAY * 2; // anyway, 'cause why not
3962 //e_LogWriteFln('FOUND %s %s %s', [result, FSwitchToEmpty, hasAmmoForWeapon(i)], TMsgType.Notify);
3963 exit;
3964 end;
3965 end;
3966 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3967 resetWeaponQueue();
3968 end;
3970 procedure TPlayer.RealizeCurrentWeapon();
3971 function switchAllowed (): Boolean;
3972 var
3973 i: Byte;
3974 begin
3975 result := false;
3976 if FBFGFireCounter <> -1 then
3977 exit;
3978 if FTime[T_SWITCH] > gTime then
3979 exit;
3980 for i := WP_FIRST to WP_LAST do
3981 if FReloading[i] > 0 then
3982 exit;
3983 result := true;
3984 end;
3986 var
3987 nw: Byte;
3988 begin
3989 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3990 //FNextWeap := FNextWeap and $1FFF;
3991 if FNextWeapDelay > 0 then Dec(FNextWeapDelay); // "alteration delay"
3993 if not switchAllowed then
3994 begin
3995 //HACK for weapon cycling
3996 if (FNextWeap and $E000) <> 0 then FNextWeap := 0;
3997 exit;
3998 end;
4000 nw := getNextWeaponIndex();
4001 //
4002 if nw = 255 then exit; // don't reset anything here
4003 if nw > High(FWeapon) then
4004 begin
4005 // don't forget to reset queue here!
4006 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
4007 resetWeaponQueue();
4008 exit;
4009 end;
4011 if FWeapon[nw] then
4012 begin
4013 FCurrWeap := nw;
4014 FTime[T_SWITCH] := gTime+156;
4015 if FCurrWeap = WEAPON_SAW then FSawSoundSelect.PlayAt(FObj.X, FObj.Y);
4016 FModel.SetWeapon(FCurrWeap);
4017 if g_Game_IsNet then MH_SEND_PlayerStats(FUID);
4018 end;
4019 end;
4021 procedure TPlayer.NextWeapon();
4022 begin
4023 if g_Game_IsClient then Exit;
4024 FNextWeap := $8000;
4025 end;
4027 procedure TPlayer.PrevWeapon();
4028 begin
4029 if g_Game_IsClient then Exit;
4030 FNextWeap := $4000;
4031 end;
4033 procedure TPlayer.SetWeapon(W: Byte);
4034 begin
4035 if FCurrWeap <> W then
4036 if W = WEAPON_SAW then
4037 FSawSoundSelect.PlayAt(FObj.X, FObj.Y);
4039 FCurrWeap := W;
4040 FModel.SetWeapon(CurrWeap);
4041 resetWeaponQueue();
4042 end;
4044 function TPlayer.PickItem(ItemType: Byte; arespawn: Boolean; var remove: Boolean): Boolean;
4045 var
4046 a: Boolean;
4047 switchWeapon: Byte = 255;
4048 hadWeapon: Boolean = False;
4049 begin
4050 Result := False;
4051 if g_Game_IsClient then Exit;
4053 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
4054 a := LongBool(gGameSettings.Options and GAME_OPTION_WEAPONSTAY) and arespawn;
4055 remove := not a;
4056 case ItemType of
4057 ITEM_MEDKIT_SMALL:
4058 if (FHealth < PLAYER_HP_SOFT) or (FFireTime > 0) then
4059 begin
4060 if FHealth < PLAYER_HP_SOFT then IncMax(FHealth, 10, PLAYER_HP_SOFT);
4061 Result := True;
4062 remove := True;
4063 FFireTime := 0;
4064 if gFlash = 2 then Inc(FPickup, 5);
4065 end;
4067 ITEM_MEDKIT_LARGE:
4068 if (FHealth < PLAYER_HP_SOFT) or (FFireTime > 0) then
4069 begin
4070 if FHealth < PLAYER_HP_SOFT then IncMax(FHealth, 25, PLAYER_HP_SOFT);
4071 Result := True;
4072 remove := True;
4073 FFireTime := 0;
4074 if gFlash = 2 then Inc(FPickup, 5);
4075 end;
4077 ITEM_ARMOR_GREEN:
4078 if FArmor < PLAYER_AP_SOFT then
4079 begin
4080 FArmor := PLAYER_AP_SOFT;
4081 Result := True;
4082 remove := True;
4083 if gFlash = 2 then Inc(FPickup, 5);
4084 end;
4086 ITEM_ARMOR_BLUE:
4087 if FArmor < PLAYER_AP_LIMIT then
4088 begin
4089 FArmor := PLAYER_AP_LIMIT;
4090 Result := True;
4091 remove := True;
4092 if gFlash = 2 then Inc(FPickup, 5);
4093 end;
4095 ITEM_SPHERE_BLUE:
4096 if (FHealth < PLAYER_HP_LIMIT) or (FFireTime > 0) then
4097 begin
4098 if FHealth < PLAYER_HP_LIMIT then IncMax(FHealth, 100, PLAYER_HP_LIMIT);
4099 Result := True;
4100 remove := True;
4101 FFireTime := 0;
4102 if gFlash = 2 then Inc(FPickup, 5);
4103 end;
4105 ITEM_SPHERE_WHITE:
4106 if (FHealth < PLAYER_HP_LIMIT) or (FArmor < PLAYER_AP_LIMIT) or (FFireTime > 0) then
4107 begin
4108 if FHealth < PLAYER_HP_LIMIT then
4109 FHealth := PLAYER_HP_LIMIT;
4110 if FArmor < PLAYER_AP_LIMIT then
4111 FArmor := PLAYER_AP_LIMIT;
4112 Result := True;
4113 remove := True;
4114 FFireTime := 0;
4115 if gFlash = 2 then Inc(FPickup, 5);
4116 end;
4118 ITEM_WEAPON_SAW:
4119 if (not FWeapon[WEAPON_SAW]) or ((not arespawn) and (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF])) then
4120 begin
4121 hadWeapon := FWeapon[WEAPON_SAW];
4122 switchWeapon := WEAPON_SAW;
4123 FWeapon[WEAPON_SAW] := True;
4124 Result := True;
4125 if gFlash = 2 then Inc(FPickup, 5);
4126 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
4127 end;
4129 ITEM_WEAPON_SHOTGUN1:
4130 if (FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS]) or not FWeapon[WEAPON_SHOTGUN1] then
4131 begin
4132 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
4133 if a and FWeapon[WEAPON_SHOTGUN1] then Exit;
4134 hadWeapon := FWeapon[WEAPON_SHOTGUN1];
4135 switchWeapon := WEAPON_SHOTGUN1;
4136 IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
4137 FWeapon[WEAPON_SHOTGUN1] := True;
4138 Result := True;
4139 if gFlash = 2 then Inc(FPickup, 5);
4140 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
4141 end;
4143 ITEM_WEAPON_SHOTGUN2:
4144 if (FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS]) or not FWeapon[WEAPON_SHOTGUN2] then
4145 begin
4146 if a and FWeapon[WEAPON_SHOTGUN2] then Exit;
4147 hadWeapon := FWeapon[WEAPON_SHOTGUN2];
4148 switchWeapon := WEAPON_SHOTGUN2;
4149 IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
4150 FWeapon[WEAPON_SHOTGUN2] := True;
4151 Result := True;
4152 if gFlash = 2 then Inc(FPickup, 5);
4153 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
4154 end;
4156 ITEM_WEAPON_CHAINGUN:
4157 if (FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS]) or not FWeapon[WEAPON_CHAINGUN] then
4158 begin
4159 if a and FWeapon[WEAPON_CHAINGUN] then Exit;
4160 hadWeapon := FWeapon[WEAPON_CHAINGUN];
4161 switchWeapon := WEAPON_CHAINGUN;
4162 IncMax(FAmmo[A_BULLETS], 50, FMaxAmmo[A_BULLETS]);
4163 FWeapon[WEAPON_CHAINGUN] := True;
4164 Result := True;
4165 if gFlash = 2 then Inc(FPickup, 5);
4166 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
4167 end;
4169 ITEM_WEAPON_ROCKETLAUNCHER:
4170 if (FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS]) or not FWeapon[WEAPON_ROCKETLAUNCHER] then
4171 begin
4172 if a and FWeapon[WEAPON_ROCKETLAUNCHER] then Exit;
4173 switchWeapon := WEAPON_ROCKETLAUNCHER;
4174 hadWeapon := FWeapon[WEAPON_ROCKETLAUNCHER];
4175 IncMax(FAmmo[A_ROCKETS], 2, FMaxAmmo[A_ROCKETS]);
4176 FWeapon[WEAPON_ROCKETLAUNCHER] := True;
4177 Result := True;
4178 if gFlash = 2 then Inc(FPickup, 5);
4179 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
4180 end;
4182 ITEM_WEAPON_PLASMA:
4183 if (FAmmo[A_CELLS] < FMaxAmmo[A_CELLS]) or not FWeapon[WEAPON_PLASMA] then
4184 begin
4185 if a and FWeapon[WEAPON_PLASMA] then Exit;
4186 switchWeapon := WEAPON_PLASMA;
4187 hadWeapon := FWeapon[WEAPON_PLASMA];
4188 IncMax(FAmmo[A_CELLS], 40, FMaxAmmo[A_CELLS]);
4189 FWeapon[WEAPON_PLASMA] := True;
4190 Result := True;
4191 if gFlash = 2 then Inc(FPickup, 5);
4192 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
4193 end;
4195 ITEM_WEAPON_BFG:
4196 if (FAmmo[A_CELLS] < FMaxAmmo[A_CELLS]) or not FWeapon[WEAPON_BFG] then
4197 begin
4198 if a and FWeapon[WEAPON_BFG] then Exit;
4199 switchWeapon := WEAPON_BFG;
4200 hadWeapon := FWeapon[WEAPON_BFG];
4201 IncMax(FAmmo[A_CELLS], 40, FMaxAmmo[A_CELLS]);
4202 FWeapon[WEAPON_BFG] := True;
4203 Result := True;
4204 if gFlash = 2 then Inc(FPickup, 5);
4205 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
4206 end;
4208 ITEM_WEAPON_SUPERPULEMET:
4209 if (FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS]) or not FWeapon[WEAPON_SUPERPULEMET] then
4210 begin
4211 if a and FWeapon[WEAPON_SUPERPULEMET] then Exit;
4212 switchWeapon := WEAPON_SUPERPULEMET;
4213 hadWeapon := FWeapon[WEAPON_SUPERPULEMET];
4214 IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
4215 FWeapon[WEAPON_SUPERPULEMET] := True;
4216 Result := True;
4217 if gFlash = 2 then Inc(FPickup, 5);
4218 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
4219 end;
4221 ITEM_WEAPON_FLAMETHROWER:
4222 if (FAmmo[A_FUEL] < FMaxAmmo[A_FUEL]) or not FWeapon[WEAPON_FLAMETHROWER] then
4223 begin
4224 if a and FWeapon[WEAPON_FLAMETHROWER] then Exit;
4225 switchWeapon := WEAPON_FLAMETHROWER;
4226 hadWeapon := FWeapon[WEAPON_FLAMETHROWER];
4227 IncMax(FAmmo[A_FUEL], 100, FMaxAmmo[A_FUEL]);
4228 FWeapon[WEAPON_FLAMETHROWER] := True;
4229 Result := True;
4230 if gFlash = 2 then Inc(FPickup, 5);
4231 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
4232 end;
4234 ITEM_AMMO_BULLETS:
4235 if FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS] then
4236 begin
4237 IncMax(FAmmo[A_BULLETS], 10, FMaxAmmo[A_BULLETS]);
4238 Result := True;
4239 remove := True;
4240 if gFlash = 2 then Inc(FPickup, 5);
4241 end;
4243 ITEM_AMMO_BULLETS_BOX:
4244 if FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS] then
4245 begin
4246 IncMax(FAmmo[A_BULLETS], 50, FMaxAmmo[A_BULLETS]);
4247 Result := True;
4248 remove := True;
4249 if gFlash = 2 then Inc(FPickup, 5);
4250 end;
4252 ITEM_AMMO_SHELLS:
4253 if FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS] then
4254 begin
4255 IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
4256 Result := True;
4257 remove := True;
4258 if gFlash = 2 then Inc(FPickup, 5);
4259 end;
4261 ITEM_AMMO_SHELLS_BOX:
4262 if FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS] then
4263 begin
4264 IncMax(FAmmo[A_SHELLS], 25, FMaxAmmo[A_SHELLS]);
4265 Result := True;
4266 remove := True;
4267 if gFlash = 2 then Inc(FPickup, 5);
4268 end;
4270 ITEM_AMMO_ROCKET:
4271 if FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS] then
4272 begin
4273 IncMax(FAmmo[A_ROCKETS], 1, FMaxAmmo[A_ROCKETS]);
4274 Result := True;
4275 remove := True;
4276 if gFlash = 2 then Inc(FPickup, 5);
4277 end;
4279 ITEM_AMMO_ROCKET_BOX:
4280 if FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS] then
4281 begin
4282 IncMax(FAmmo[A_ROCKETS], 5, FMaxAmmo[A_ROCKETS]);
4283 Result := True;
4284 remove := True;
4285 if gFlash = 2 then Inc(FPickup, 5);
4286 end;
4288 ITEM_AMMO_CELL:
4289 if FAmmo[A_CELLS] < FMaxAmmo[A_CELLS] then
4290 begin
4291 IncMax(FAmmo[A_CELLS], 40, FMaxAmmo[A_CELLS]);
4292 Result := True;
4293 remove := True;
4294 if gFlash = 2 then Inc(FPickup, 5);
4295 end;
4297 ITEM_AMMO_CELL_BIG:
4298 if FAmmo[A_CELLS] < FMaxAmmo[A_CELLS] then
4299 begin
4300 IncMax(FAmmo[A_CELLS], 100, FMaxAmmo[A_CELLS]);
4301 Result := True;
4302 remove := True;
4303 if gFlash = 2 then Inc(FPickup, 5);
4304 end;
4306 ITEM_AMMO_FUELCAN:
4307 if FAmmo[A_FUEL] < FMaxAmmo[A_FUEL] then
4308 begin
4309 IncMax(FAmmo[A_FUEL], 100, FMaxAmmo[A_FUEL]);
4310 Result := True;
4311 remove := True;
4312 if gFlash = 2 then Inc(FPickup, 5);
4313 end;
4315 ITEM_AMMO_BACKPACK:
4316 if not(R_ITEM_BACKPACK in FRulez) or
4317 (FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS]) or
4318 (FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS]) or
4319 (FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS]) or
4320 (FAmmo[A_CELLS] < FMaxAmmo[A_CELLS]) or
4321 (FAmmo[A_FUEL] < FMaxAmmo[A_FUEL]) then
4322 begin
4323 FMaxAmmo[A_BULLETS] := AmmoLimits[1, A_BULLETS];
4324 FMaxAmmo[A_SHELLS] := AmmoLimits[1, A_SHELLS];
4325 FMaxAmmo[A_ROCKETS] := AmmoLimits[1, A_ROCKETS];
4326 FMaxAmmo[A_CELLS] := AmmoLimits[1, A_CELLS];
4327 FMaxAmmo[A_FUEL] := AmmoLimits[1, A_FUEL];
4329 if FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS] then
4330 IncMax(FAmmo[A_BULLETS], 10, FMaxAmmo[A_BULLETS]);
4331 if FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS] then
4332 IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
4333 if FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS] then
4334 IncMax(FAmmo[A_ROCKETS], 1, FMaxAmmo[A_ROCKETS]);
4335 if FAmmo[A_CELLS] < FMaxAmmo[A_CELLS] then
4336 IncMax(FAmmo[A_CELLS], 40, FMaxAmmo[A_CELLS]);
4337 if FAmmo[A_FUEL] < FMaxAmmo[A_FUEL] then
4338 IncMax(FAmmo[A_FUEL], 50, FMaxAmmo[A_FUEL]);
4340 FRulez := FRulez + [R_ITEM_BACKPACK];
4341 Result := True;
4342 remove := True;
4343 if gFlash = 2 then Inc(FPickup, 5);
4344 end;
4346 ITEM_KEY_RED:
4347 if not(R_KEY_RED in FRulez) then
4348 begin
4349 Include(FRulez, R_KEY_RED);
4350 Result := True;
4351 remove := (gGameSettings.GameMode <> GM_COOP) and (g_Player_GetCount() < 2);
4352 if gFlash = 2 then Inc(FPickup, 5);
4353 if (not remove) and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETITEM');
4354 end;
4356 ITEM_KEY_GREEN:
4357 if not(R_KEY_GREEN in FRulez) then
4358 begin
4359 Include(FRulez, R_KEY_GREEN);
4360 Result := True;
4361 remove := (gGameSettings.GameMode <> GM_COOP) and (g_Player_GetCount() < 2);
4362 if gFlash = 2 then Inc(FPickup, 5);
4363 if (not remove) and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETITEM');
4364 end;
4366 ITEM_KEY_BLUE:
4367 if not(R_KEY_BLUE in FRulez) then
4368 begin
4369 Include(FRulez, R_KEY_BLUE);
4370 Result := True;
4371 remove := (gGameSettings.GameMode <> GM_COOP) and (g_Player_GetCount() < 2);
4372 if gFlash = 2 then Inc(FPickup, 5);
4373 if (not remove) and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETITEM');
4374 end;
4376 ITEM_SUIT:
4377 if FMegaRulez[MR_SUIT] < gTime+PLAYER_SUIT_TIME then
4378 begin
4379 FMegaRulez[MR_SUIT] := gTime+PLAYER_SUIT_TIME;
4380 Result := True;
4381 remove := True;
4382 FFireTime := 0;
4383 if gFlash = 2 then Inc(FPickup, 5);
4384 end;
4386 ITEM_OXYGEN:
4387 if FAir < AIR_MAX then
4388 begin
4389 FAir := AIR_MAX;
4390 Result := True;
4391 remove := True;
4392 if gFlash = 2 then Inc(FPickup, 5);
4393 end;
4395 ITEM_MEDKIT_BLACK:
4396 begin
4397 if not (R_BERSERK in FRulez) then
4398 begin
4399 Include(FRulez, R_BERSERK);
4400 if (FBFGFireCounter = -1) then
4401 begin
4402 FCurrWeap := WEAPON_KASTET;
4403 resetWeaponQueue();
4404 FModel.SetWeapon(WEAPON_KASTET);
4405 end;
4406 if gFlash <> 0 then
4407 begin
4408 Inc(FPain, 100);
4409 if gFlash = 2 then Inc(FPickup, 5);
4410 end;
4411 FBerserk := gTime+30000;
4412 Result := True;
4413 remove := True;
4414 FFireTime := 0;
4415 end;
4416 if (FHealth < PLAYER_HP_SOFT) or (FFireTime > 0) then
4417 begin
4418 if FHealth < PLAYER_HP_SOFT then FHealth := PLAYER_HP_SOFT;
4419 FBerserk := gTime+30000;
4420 Result := True;
4421 remove := True;
4422 FFireTime := 0;
4423 end;
4424 end;
4426 ITEM_INVUL:
4427 if FMegaRulez[MR_INVUL] < gTime+PLAYER_INVUL_TIME then
4428 begin
4429 FMegaRulez[MR_INVUL] := gTime+PLAYER_INVUL_TIME;
4430 FSpawnInvul := 0;
4431 Result := True;
4432 remove := True;
4433 if gFlash = 2 then Inc(FPickup, 5);
4434 end;
4436 ITEM_BOTTLE:
4437 if (FHealth < PLAYER_HP_LIMIT) or (FFireTime > 0) then
4438 begin
4439 if FHealth < PLAYER_HP_LIMIT then IncMax(FHealth, 4, PLAYER_HP_LIMIT);
4440 Result := True;
4441 remove := True;
4442 FFireTime := 0;
4443 if gFlash = 2 then Inc(FPickup, 5);
4444 end;
4446 ITEM_HELMET:
4447 if FArmor < PLAYER_AP_LIMIT then
4448 begin
4449 IncMax(FArmor, 5, PLAYER_AP_LIMIT);
4450 Result := True;
4451 remove := True;
4452 if gFlash = 2 then Inc(FPickup, 5);
4453 end;
4455 ITEM_JETPACK:
4456 if FJetFuel < JET_MAX then
4457 begin
4458 FJetFuel := JET_MAX;
4459 Result := True;
4460 remove := True;
4461 if gFlash = 2 then Inc(FPickup, 5);
4462 end;
4464 ITEM_INVIS:
4465 if FMegaRulez[MR_INVIS] < gTime+PLAYER_INVIS_TIME then
4466 begin
4467 FMegaRulez[MR_INVIS] := gTime+PLAYER_INVIS_TIME;
4468 Result := True;
4469 remove := True;
4470 if gFlash = 2 then Inc(FPickup, 5);
4471 end;
4472 end;
4474 if (shouldSwitch(switchWeapon, hadWeapon)) then
4475 QueueWeaponSwitch(switchWeapon);
4476 end;
4478 procedure TPlayer.Touch();
4479 begin
4480 if not FAlive then
4481 Exit;
4482 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4483 if FIamBot then
4484 begin
4485 // Áðîñèòü ôëàã òîâàðèùó:
4486 if gGameSettings.GameMode = GM_CTF then
4487 DropFlag();
4488 end;
4489 end;
4491 procedure TPlayer.Push(vx, vy: Integer);
4492 begin
4493 if (not FPhysics) and FGhost then
4494 Exit;
4495 FObj.Accel.X := FObj.Accel.X + vx;
4496 FObj.Accel.Y := FObj.Accel.Y + vy;
4497 if g_Game_IsNet and g_Game_IsServer then
4498 MH_SEND_PlayerPos(True, FUID, NET_EVERYONE);
4499 end;
4501 procedure TPlayer.Reset(Force: Boolean);
4502 begin
4503 if Force then
4504 FAlive := False;
4506 FSpawned := False;
4507 FTime[T_RESPAWN] := 0;
4508 FTime[T_FLAGCAP] := 0;
4509 FGodMode := False;
4510 FNoTarget := False;
4511 FNoReload := False;
4512 FFrags := 0;
4513 FLastFrag := 0;
4514 FComboEvnt := -1;
4515 FKills := 0;
4516 FMonsterKills := 0;
4517 FDeath := 0;
4518 FSecrets := 0;
4519 FSpawnInvul := 0;
4520 FCorpse := -1;
4521 FReady := False;
4522 if FNoRespawn then
4523 begin
4524 FSpectator := False;
4525 FGhost := False;
4526 FPhysics := True;
4527 FSpectatePlayer := -1;
4528 FNoRespawn := False;
4529 end;
4530 FLives := gGameSettings.MaxLives;
4532 SetFlag(FLAG_NONE);
4533 end;
4535 procedure TPlayer.SoftReset();
4536 begin
4537 ReleaseKeys();
4539 FDamageBuffer := 0;
4540 FSlopeOld := 0;
4541 FIncCamOld := 0;
4542 FIncCam := 0;
4543 FBFGFireCounter := -1;
4544 FShellTimer := -1;
4545 FPain := 0;
4546 FLastHit := 0;
4547 FLastFrag := 0;
4548 FComboEvnt := -1;
4550 SetFlag(FLAG_NONE);
4551 SetAction(A_STAND, True);
4552 end;
4554 function TPlayer.GetRespawnPoint(): Byte;
4555 var
4556 c: Byte;
4557 begin
4558 Result := 255;
4559 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4561 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4562 if gGameSettings.GameMode in [GM_COOP, GM_SINGLE] then
4563 begin
4564 if Self = gPlayer1 then
4565 begin
4566 // player 1 should try to spawn on the player 1 point
4567 if g_Map_GetPointCount(RESPAWNPOINT_PLAYER1) > 0 then
4568 Exit(RESPAWNPOINT_PLAYER1)
4569 else if g_Map_GetPointCount(RESPAWNPOINT_PLAYER2) > 0 then
4570 Exit(RESPAWNPOINT_PLAYER2);
4571 end
4572 else if Self = gPlayer2 then
4573 begin
4574 // player 2 should try to spawn on the player 2 point
4575 if g_Map_GetPointCount(RESPAWNPOINT_PLAYER2) > 0 then
4576 Exit(RESPAWNPOINT_PLAYER2)
4577 else if g_Map_GetPointCount(RESPAWNPOINT_PLAYER1) > 0 then
4578 Exit(RESPAWNPOINT_PLAYER1);
4579 end
4580 else
4581 begin
4582 // other players randomly pick either the first or the second point
4583 c := IfThen((Random(2) = 0), RESPAWNPOINT_PLAYER1, RESPAWNPOINT_PLAYER2);
4584 if g_Map_GetPointCount(c) > 0 then
4585 Exit(c);
4586 // try the other one
4587 c := IfThen((c = RESPAWNPOINT_PLAYER1), RESPAWNPOINT_PLAYER2, RESPAWNPOINT_PLAYER1);
4588 if g_Map_GetPointCount(c) > 0 then
4589 Exit(c);
4590 end;
4591 end;
4593 // Ìÿñîïîâàë
4594 if gGameSettings.GameMode = GM_DM then
4595 begin
4596 // try DM points first
4597 if g_Map_GetPointCount(RESPAWNPOINT_DM) > 0 then
4598 Exit(RESPAWNPOINT_DM);
4599 end;
4601 // Êîìàíäíûå
4602 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
4603 begin
4604 // try team points first
4605 c := RESPAWNPOINT_DM;
4606 if FTeam = TEAM_RED then
4607 c := RESPAWNPOINT_RED
4608 else if FTeam = TEAM_BLUE then
4609 c := RESPAWNPOINT_BLUE;
4610 if g_Map_GetPointCount(c) > 0 then
4611 Exit(c);
4612 end;
4614 // still haven't found a spawnpoint, try random shit
4615 Result := g_Map_GetRandomPointType();
4616 end;
4618 procedure TPlayer.Respawn(Silent: Boolean; Force: Boolean = False);
4619 var
4620 RespawnPoint: TRespawnPoint;
4621 a, b, c: Byte;
4622 Anim: TAnimation;
4623 ID: DWORD;
4624 begin
4625 FSlopeOld := 0;
4626 FIncCamOld := 0;
4627 FIncCam := 0;
4628 FBFGFireCounter := -1;
4629 FShellTimer := -1;
4630 FPain := 0;
4631 FLastHit := 0;
4632 FSpawnInvul := 0;
4633 FCorpse := -1;
4635 if not g_Game_IsServer then
4636 Exit;
4637 if FDummy then
4638 Exit;
4639 FWantsInGame := True;
4640 FJustTeleported := True;
4641 if Force then
4642 begin
4643 FTime[T_RESPAWN] := 0;
4644 FAlive := False;
4645 end;
4646 FNetTime := 0;
4647 // if server changes MaxLives we gotta be ready
4648 if gGameSettings.MaxLives = 0 then FNoRespawn := False;
4650 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4651 if FTime[T_RESPAWN] > gTime then
4652 Exit;
4654 // Ïðîñðàë âñå æèçíè:
4655 if FNoRespawn then
4656 begin
4657 if not FSpectator then Spectate(True);
4658 FWantsInGame := True;
4659 Exit;
4660 end;
4662 if (gGameSettings.GameType <> GT_SINGLE) and (gGameSettings.GameMode <> GM_COOP) then
4663 begin // "Ñâîÿ èãðà"
4664 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4665 FRulez := FRulez-[R_BERSERK];
4666 end
4667 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4668 begin
4669 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4670 FRulez := FRulez-[R_KEY_RED, R_KEY_GREEN, R_KEY_BLUE, R_BERSERK];
4671 end;
4673 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4674 c := GetRespawnPoint();
4676 ReleaseKeys();
4677 SetFlag(FLAG_NONE);
4679 // Âîñêðåøåíèå áåç îðóæèÿ:
4680 if not FAlive then
4681 begin
4682 FHealth := Round(PLAYER_HP_SOFT * (FHandicap / 100));
4683 FArmor := 0;
4684 FAlive := True;
4685 FAir := AIR_DEF;
4686 FJetFuel := 0;
4688 for a := WP_FIRST to WP_LAST do
4689 begin
4690 FWeapon[a] := False;
4691 FReloading[a] := 0;
4692 end;
4694 FWeapon[WEAPON_PISTOL] := True;
4695 FWeapon[WEAPON_KASTET] := True;
4696 FCurrWeap := WEAPON_PISTOL;
4697 resetWeaponQueue();
4699 FModel.SetWeapon(FCurrWeap);
4701 for b := A_BULLETS to A_HIGH do
4702 FAmmo[b] := 0;
4704 FAmmo[A_BULLETS] := 50;
4706 FMaxAmmo[A_BULLETS] := AmmoLimits[0, A_BULLETS];
4707 FMaxAmmo[A_SHELLS] := AmmoLimits[0, A_SHELLS];
4708 FMaxAmmo[A_ROCKETS] := AmmoLimits[0, A_SHELLS];
4709 FMaxAmmo[A_CELLS] := AmmoLimits[0, A_CELLS];
4710 FMaxAmmo[A_FUEL] := AmmoLimits[0, A_FUEL];
4712 if (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF]) and
4713 LongBool(gGameSettings.Options and GAME_OPTION_DMKEYS) then
4714 FRulez := [R_KEY_RED, R_KEY_GREEN, R_KEY_BLUE]
4715 else
4716 FRulez := [];
4717 end;
4719 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4720 if not g_Map_GetPoint(c, RespawnPoint) then
4721 begin
4722 g_FatalError(_lc[I_GAME_ERROR_GET_SPAWN]);
4723 Exit;
4724 end;
4726 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4727 FObj.X := RespawnPoint.X-PLAYER_RECT.X;
4728 FObj.Y := RespawnPoint.Y-PLAYER_RECT.Y;
4729 FObj.oldX := FObj.X; // don't interpolate after respawn
4730 FObj.oldY := FObj.Y;
4731 FObj.Vel.X := 0;
4732 FObj.Vel.Y := 0;
4733 FObj.Accel.X := 0;
4734 FObj.Accel.Y := 0;
4736 FDirection := RespawnPoint.Direction;
4737 if FDirection = TDirection.D_LEFT then
4738 FAngle := 180
4739 else
4740 FAngle := 0;
4742 SetAction(A_STAND, True);
4743 FModel.Direction := FDirection;
4745 for a := Low(FTime) to High(FTime) do
4746 FTime[a] := 0;
4748 for a := Low(FMegaRulez) to High(FMegaRulez) do
4749 FMegaRulez[a] := 0;
4751 // Respawn invulnerability
4752 if (gGameSettings.GameType <> GT_SINGLE) and (gGameSettings.SpawnInvul > 0) then
4753 begin
4754 FMegaRulez[MR_INVUL] := gTime + gGameSettings.SpawnInvul * 1000;
4755 FSpawnInvul := FMegaRulez[MR_INVUL];
4756 end;
4758 FDamageBuffer := 0;
4759 FJetpack := False;
4760 FCanJetpack := False;
4761 FFlaming := False;
4762 FFireTime := 0;
4763 FFirePainTime := 0;
4764 FFireAttacker := 0;
4766 // Àíèìàöèÿ âîçðîæäåíèÿ:
4767 if (not gLoadGameMode) and (not Silent) then
4768 if g_Frames_Get(ID, 'FRAMES_TELEPORT') then
4769 begin
4770 Anim := TAnimation.Create(ID, False, 3);
4771 g_GFX_OnceAnim(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
4772 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32, Anim);
4773 Anim.Free();
4774 end;
4776 FSpectator := False;
4777 FGhost := False;
4778 FPhysics := True;
4779 FSpectatePlayer := -1;
4780 FSpawned := True;
4782 if (gPlayer1 = nil) and (gSpectLatchPID1 = FUID) then
4783 gPlayer1 := self;
4784 if (gPlayer2 = nil) and (gSpectLatchPID2 = FUID) then
4785 gPlayer2 := self;
4787 if g_Game_IsNet then
4788 begin
4789 MH_SEND_PlayerPos(True, FUID, NET_EVERYONE);
4790 MH_SEND_PlayerStats(FUID, NET_EVERYONE);
4791 if not Silent then
4792 MH_SEND_Effect(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
4793 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32,
4794 0, NET_GFX_TELE);
4795 end;
4796 end;
4798 procedure TPlayer.Spectate(NoMove: Boolean = False);
4799 begin
4800 if FAlive then
4801 Kill(K_EXTRAHARDKILL, FUID, HIT_SOME)
4802 else if (not NoMove) then
4803 begin
4804 GameX := gMapInfo.Width div 2;
4805 GameY := gMapInfo.Height div 2;
4806 end;
4807 FXTo := GameX;
4808 FYTo := GameY;
4810 FAlive := False;
4811 FSpectator := True;
4812 FGhost := True;
4813 FPhysics := False;
4814 FWantsInGame := False;
4815 FSpawned := False;
4816 FCorpse := -1;
4818 if FNoRespawn then
4819 begin
4820 if Self = gPlayer1 then
4821 begin
4822 gSpectLatchPID1 := FUID;
4823 gPlayer1 := nil;
4824 end
4825 else if Self = gPlayer2 then
4826 begin
4827 gSpectLatchPID2 := FUID;
4828 gPlayer2 := nil;
4829 end;
4830 end;
4832 if g_Game_IsNet then
4833 MH_SEND_PlayerStats(FUID);
4834 end;
4836 procedure TPlayer.SwitchNoClip;
4837 begin
4838 if not FAlive then
4839 Exit;
4840 FGhost := not FGhost;
4841 FPhysics := not FGhost;
4842 if FGhost then
4843 begin
4844 FXTo := FObj.X;
4845 FYTo := FObj.Y;
4846 end else
4847 begin
4848 FObj.Accel.X := 0;
4849 FObj.Accel.Y := 0;
4850 end;
4851 end;
4853 procedure TPlayer.Run(Direction: TDirection);
4854 var
4855 a, b: Integer;
4856 begin
4857 if MAX_RUNVEL > 8 then
4858 FlySmoke();
4860 // Áåæèì:
4861 if Direction = TDirection.D_LEFT then
4862 begin
4863 if FObj.Vel.X > -MAX_RUNVEL then
4864 FObj.Vel.X := FObj.Vel.X - (MAX_RUNVEL shr 3);
4865 end
4866 else
4867 if FObj.Vel.X < MAX_RUNVEL then
4868 FObj.Vel.X := FObj.Vel.X + (MAX_RUNVEL shr 3);
4870 // Âîçìîæíî, ïèíàåì êóñêè:
4871 if (FObj.Vel.X <> 0) and (gGibs <> nil) then
4872 begin
4873 b := Abs(FObj.Vel.X);
4874 if b > 1 then b := b * (Random(8 div b) + 1);
4875 for a := 0 to High(gGibs) do
4876 begin
4877 if gGibs[a].alive and
4878 g_Obj_Collide(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y+FObj.Rect.Height-4,
4879 FObj.Rect.Width, 8, @gGibs[a].Obj) and (Random(3) = 0) then
4880 begin
4881 // Ïèíàåì êóñêè
4882 if FObj.Vel.X < 0 then
4883 begin
4884 g_Obj_PushA(@gGibs[a].Obj, b, Random(61)+120) // íàëåâî
4885 end
4886 else
4887 begin
4888 g_Obj_PushA(@gGibs[a].Obj, b, Random(61)); // íàïðàâî
4889 end;
4890 gGibs[a].positionChanged(); // this updates spatial accelerators
4891 end;
4892 end;
4893 end;
4895 SetAction(A_WALK);
4896 end;
4898 procedure TPlayer.SeeDown();
4899 begin
4900 SetAction(A_SEEDOWN);
4902 if FDirection = TDirection.D_LEFT then FAngle := ANGLE_LEFTDOWN else FAngle := ANGLE_RIGHTDOWN;
4904 if FIncCam > -120 then DecMin(FIncCam, 5, -120);
4905 end;
4907 procedure TPlayer.SeeUp();
4908 begin
4909 SetAction(A_SEEUP);
4911 if FDirection = TDirection.D_LEFT then FAngle := ANGLE_LEFTUP else FAngle := ANGLE_RIGHTUP;
4913 if FIncCam < 120 then IncMax(FIncCam, 5, 120);
4914 end;
4916 procedure TPlayer.SetAction(Action: Byte; Force: Boolean = False);
4917 var
4918 Prior: Byte;
4919 begin
4920 case Action of
4921 A_WALK: Prior := 3;
4922 A_DIE1: Prior := 5;
4923 A_DIE2: Prior := 5;
4924 A_ATTACK: Prior := 2;
4925 A_SEEUP: Prior := 1;
4926 A_SEEDOWN: Prior := 1;
4927 A_ATTACKUP: Prior := 2;
4928 A_ATTACKDOWN: Prior := 2;
4929 A_PAIN: Prior := 4;
4930 else Prior := 0;
4931 end;
4933 if (Prior > FActionPrior) or Force then
4934 if not ((Prior = 2) and (FCurrWeap = WEAPON_SAW)) then
4935 begin
4936 FActionPrior := Prior;
4937 FActionAnim := Action;
4938 FActionForce := Force;
4939 FActionChanged := True;
4940 end;
4942 if Action in [A_ATTACK, A_ATTACKUP, A_ATTACKDOWN] then FModel.SetFire(True);
4943 end;
4945 function TPlayer.StayOnStep(XInc, YInc: Integer): Boolean;
4946 begin
4947 Result := not g_Map_CollidePanel(FObj.X+PLAYER_RECT.X, FObj.Y+YInc+PLAYER_RECT.Y+PLAYER_RECT.Height-1,
4948 PLAYER_RECT.Width, 1, PANEL_STEP, False)
4949 and g_Map_CollidePanel(FObj.X+PLAYER_RECT.X, FObj.Y+YInc+PLAYER_RECT.Y+PLAYER_RECT.Height,
4950 PLAYER_RECT.Width, 1, PANEL_STEP, False);
4951 end;
4953 function TPlayer.TeleportTo(X, Y: Integer; silent: Boolean; dir: Byte): Boolean;
4954 var
4955 Anim: TAnimation;
4956 ID: DWORD;
4957 begin
4958 Result := False;
4960 if g_CollideLevel(X, Y, PLAYER_RECT.Width, PLAYER_RECT.Height) then
4961 begin
4962 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj.X, FObj.Y);
4963 if g_Game_IsServer and g_Game_IsNet then
4964 MH_SEND_Sound(FObj.X, FObj.Y, 'SOUND_GAME_NOTELEPORT');
4965 Exit;
4966 end;
4968 FJustTeleported := True;
4970 Anim := nil;
4971 if not silent then
4972 begin
4973 if g_Frames_Get(ID, 'FRAMES_TELEPORT') then
4974 begin
4975 Anim := TAnimation.Create(ID, False, 3);
4976 end;
4978 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj.X, FObj.Y);
4979 g_GFX_OnceAnim(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
4980 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32, Anim);
4981 if g_Game_IsServer and g_Game_IsNet then
4982 MH_SEND_Effect(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
4983 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32, 1,
4984 NET_GFX_TELE);
4985 end;
4987 FObj.X := X-PLAYER_RECT.X;
4988 FObj.Y := Y-PLAYER_RECT.Y;
4989 FObj.oldX := FObj.X; // don't interpolate after respawn
4990 FObj.oldY := FObj.Y;
4991 if FAlive and FGhost then
4992 begin
4993 FXTo := FObj.X;
4994 FYTo := FObj.Y;
4995 end;
4997 if not g_Game_IsNet then
4998 begin
4999 if dir = 1 then
5000 begin
5001 SetDirection(TDirection.D_LEFT);
5002 FAngle := 180;
5003 end
5004 else
5005 if dir = 2 then
5006 begin
5007 SetDirection(TDirection.D_RIGHT);
5008 FAngle := 0;
5009 end
5010 else
5011 if dir = 3 then
5012 begin // îáðàòíîå
5013 if FDirection = TDirection.D_RIGHT then
5014 begin
5015 SetDirection(TDirection.D_LEFT);
5016 FAngle := 180;
5017 end
5018 else
5019 begin
5020 SetDirection(TDirection.D_RIGHT);
5021 FAngle := 0;
5022 end;
5023 end;
5024 end;
5026 if not silent and (Anim <> nil) then
5027 begin
5028 g_GFX_OnceAnim(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
5029 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32, Anim);
5030 Anim.Free();
5032 if g_Game_IsServer and g_Game_IsNet then
5033 MH_SEND_Effect(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
5034 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32, 0,
5035 NET_GFX_TELE);
5036 end;
5038 Result := True;
5039 end;
5041 function nonz(a: Single): Single;
5042 begin
5043 if a <> 0 then
5044 Result := a
5045 else
5046 Result := 1;
5047 end;
5049 function TPlayer.refreshCorpse(): Boolean;
5050 var
5051 i: Integer;
5052 begin
5053 Result := False;
5054 FCorpse := -1;
5055 if FAlive or FSpectator then
5056 Exit;
5057 if (gCorpses = nil) or (Length(gCorpses) = 0) then
5058 Exit;
5059 for i := 0 to High(gCorpses) do
5060 if gCorpses[i] <> nil then
5061 if gCorpses[i].FPlayerUID = FUID then
5062 begin
5063 Result := True;
5064 FCorpse := i;
5065 break;
5066 end;
5067 end;
5069 function TPlayer.getCameraObj(): TObj;
5070 begin
5071 if (not FAlive) and (not FSpectator) and
5072 (FCorpse >= 0) and (FCorpse < Length(gCorpses)) and
5073 (gCorpses[FCorpse] <> nil) and (gCorpses[FCorpse].FPlayerUID = FUID) then
5074 begin
5075 gCorpses[FCorpse].FObj.slopeUpLeft := FObj.slopeUpLeft;
5076 Result := gCorpses[FCorpse].FObj;
5077 end
5078 else
5079 begin
5080 Result := FObj;
5081 end;
5082 end;
5084 procedure TPlayer.PreUpdate();
5085 begin
5086 FSlopeOld := FObj.slopeUpLeft;
5087 FIncCamOld := FIncCam;
5088 FObj.oldX := FObj.X;
5089 FObj.oldY := FObj.Y;
5090 end;
5092 procedure TPlayer.Update();
5093 var
5094 b: Byte;
5095 i, ii, wx, wy, xd, yd, k: Integer;
5096 blockmon, headwater, dospawn: Boolean;
5097 NetServer: Boolean;
5098 AnyServer: Boolean;
5099 SetSpect: Boolean;
5100 begin
5101 NetServer := g_Game_IsNet and g_Game_IsServer;
5102 AnyServer := g_Game_IsServer;
5104 if g_Game_IsClient and (NetInterpLevel > 0) then
5105 DoLerp(NetInterpLevel + 1)
5106 else
5107 if FGhost then
5108 DoLerp(4);
5110 if NetServer then
5111 if (FClientID >= 0) and (NetClients[FClientID].Peer <> nil) then
5112 begin
5113 FPing := NetClients[FClientID].Peer^.lastRoundTripTime;
5114 if NetClients[FClientID].Peer^.packetsSent > 0 then
5115 FLoss := Round(100*NetClients[FClientID].Peer^.packetsLost/NetClients[FClientID].Peer^.packetsSent)
5116 else
5117 FLoss := 0;
5118 end else
5119 begin
5120 FPing := 0;
5121 FLoss := 0;
5122 end;
5124 if FAlive and (FPunchAnim <> nil) then
5125 FPunchAnim.Update();
5127 if FAlive and (gFly or FJetpack) then
5128 FlySmoke();
5130 if FDirection = TDirection.D_LEFT then
5131 FAngle := 180
5132 else
5133 FAngle := 0;
5135 if FAlive and (not FGhost) then
5136 begin
5137 if FKeys[KEY_UP].Pressed then
5138 SeeUp();
5139 if FKeys[KEY_DOWN].Pressed then
5140 SeeDown();
5141 end;
5143 if (not (FKeys[KEY_UP].Pressed or FKeys[KEY_DOWN].Pressed)) and
5144 (FIncCam <> 0) then
5145 begin
5146 i := g_basic.Sign(FIncCam);
5147 FIncCam := Abs(FIncCam);
5148 DecMin(FIncCam, 5, 0);
5149 FIncCam := FIncCam*i;
5150 end;
5152 if gTime mod (GAME_TICK*2) <> 0 then
5153 begin
5154 if (FObj.Vel.X = 0) and FAlive then
5155 begin
5156 if FKeys[KEY_LEFT].Pressed then
5157 Run(TDirection.D_LEFT);
5158 if FKeys[KEY_RIGHT].Pressed then
5159 Run(TDirection.D_RIGHT);
5160 end;
5162 if FPhysics then
5163 begin
5164 g_Obj_Move(@FObj, True, True, True);
5165 positionChanged(); // this updates spatial accelerators
5166 end;
5168 Exit;
5169 end;
5171 FActionChanged := False;
5173 if FAlive then
5174 begin
5175 // Let alive player do some actions
5176 if FKeys[KEY_LEFT].Pressed then Run(TDirection.D_LEFT);
5177 if FKeys[KEY_RIGHT].Pressed then Run(TDirection.D_RIGHT);
5178 if FKeys[KEY_FIRE].Pressed and AnyServer then Fire()
5179 else
5180 begin
5181 if AnyServer then
5182 begin
5183 FlamerOff;
5184 if NetServer then MH_SEND_PlayerStats(FUID);
5185 end;
5186 end;
5187 if FKeys[KEY_OPEN].Pressed and AnyServer then Use();
5188 if FKeys[KEY_JUMP].Pressed then Jump()
5189 else
5190 begin
5191 if AnyServer and FJetpack then
5192 begin
5193 FJetpack := False;
5194 JetpackOff;
5195 if NetServer then MH_SEND_PlayerStats(FUID);
5196 end;
5197 FCanJetpack := True;
5198 end;
5199 end
5200 else // Dead
5201 begin
5202 dospawn := False;
5203 if not FGhost then
5204 for k := Low(FKeys) to KEY_CHAT-1 do
5205 begin
5206 if FKeys[k].Pressed then
5207 begin
5208 dospawn := True;
5209 break;
5210 end;
5211 end;
5212 if dospawn then
5213 begin
5214 if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
5215 Respawn(False)
5216 else // Single
5217 if (FTime[T_RESPAWN] <= gTime) and
5218 gGameOn and (not FAlive) then
5219 begin
5220 if (g_Player_GetCount() > 1) then
5221 Respawn(False)
5222 else
5223 begin
5224 gExit := EXIT_RESTART;
5225 Exit;
5226 end;
5227 end;
5228 end;
5229 // Dead spectator actions
5230 if FGhost then
5231 begin
5232 if FKeys[KEY_OPEN].Pressed and AnyServer then Fire();
5233 if FKeys[KEY_FIRE].Pressed and AnyServer then
5234 begin
5235 if FSpectator then
5236 begin
5237 if (FSpectatePlayer >= High(gPlayers)) then
5238 FSpectatePlayer := -1
5239 else
5240 begin
5241 SetSpect := False;
5242 for I := FSpectatePlayer + 1 to High(gPlayers) do
5243 if gPlayers[I] <> nil then
5244 if gPlayers[I].alive then
5245 if gPlayers[I].UID <> FUID then
5246 begin
5247 FSpectatePlayer := I;
5248 SetSpect := True;
5249 break;
5250 end;
5252 if not SetSpect then FSpectatePlayer := -1;
5253 end;
5255 ReleaseKeys;
5256 end;
5257 end;
5258 end;
5259 end;
5260 // No clipping
5261 if FGhost then
5262 begin
5263 if FKeys[KEY_UP].Pressed or FKeys[KEY_JUMP].Pressed then
5264 begin
5265 FYTo := FObj.Y - 32;
5266 FSpectatePlayer := -1;
5267 end;
5268 if FKeys[KEY_DOWN].Pressed then
5269 begin
5270 FYTo := FObj.Y + 32;
5271 FSpectatePlayer := -1;
5272 end;
5273 if FKeys[KEY_LEFT].Pressed then
5274 begin
5275 FXTo := FObj.X - 32;
5276 FSpectatePlayer := -1;
5277 end;
5278 if FKeys[KEY_RIGHT].Pressed then
5279 begin
5280 FXTo := FObj.X + 32;
5281 FSpectatePlayer := -1;
5282 end;
5284 if (FXTo < -64) then
5285 FXTo := -64
5286 else if (FXTo > gMapInfo.Width + 32) then
5287 FXTo := gMapInfo.Width + 32;
5288 if (FYTo < -72) then
5289 FYTo := -72
5290 else if (FYTo > gMapInfo.Height + 32) then
5291 FYTo := gMapInfo.Height + 32;
5292 end;
5294 if FPhysics then
5295 begin
5296 g_Obj_Move(@FObj, True, True, True);
5297 positionChanged(); // this updates spatial accelerators
5298 end
5299 else
5300 begin
5301 FObj.Vel.X := 0;
5302 FObj.Vel.Y := 0;
5303 if FSpectator then
5304 if (FSpectatePlayer <= High(gPlayers)) and (FSpectatePlayer >= 0) then
5305 if gPlayers[FSpectatePlayer] <> nil then
5306 if gPlayers[FSpectatePlayer].alive then
5307 begin
5308 FXTo := gPlayers[FSpectatePlayer].GameX;
5309 FYTo := gPlayers[FSpectatePlayer].GameY;
5310 end;
5311 end;
5313 blockmon := g_Map_CollidePanel(FObj.X+PLAYER_HEADRECT.X, FObj.Y+PLAYER_HEADRECT.Y,
5314 PLAYER_HEADRECT.Width, PLAYER_HEADRECT.Height,
5315 PANEL_BLOCKMON, True);
5316 headwater := HeadInLiquid(0, 0);
5318 // Ñîïðîòèâëåíèå âîçäóõà:
5319 if (not FAlive) or not (FKeys[KEY_LEFT].Pressed or FKeys[KEY_RIGHT].Pressed) then
5320 if FObj.Vel.X <> 0 then
5321 FObj.Vel.X := z_dec(FObj.Vel.X, 1);
5323 if (FLastHit = HIT_TRAP) and (FPain > 90) then FPain := 90;
5324 DecMin(FPain, 5, 0);
5325 DecMin(FPickup, 1, 0);
5327 if FAlive and (FObj.Y > Integer(gMapInfo.Height)+128) and AnyServer then
5328 begin
5329 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
5330 FMegaRulez[MR_SUIT] := 0;
5331 FMegaRulez[MR_INVUL] := 0;
5332 FMegaRulez[MR_INVIS] := 0;
5333 Kill(K_FALLKILL, 0, HIT_FALL);
5334 end;
5336 i := 9;
5338 if FAlive then
5339 begin
5340 if FCurrWeap = WEAPON_SAW then
5341 if not (FSawSound.IsPlaying() or FSawSoundHit.IsPlaying() or
5342 FSawSoundSelect.IsPlaying()) then
5343 FSawSoundIdle.PlayAt(FObj.X, FObj.Y);
5345 if FJetpack then
5346 if (not FJetSoundFly.IsPlaying()) and (not FJetSoundOn.IsPlaying()) and
5347 (not FJetSoundOff.IsPlaying()) then
5348 begin
5349 FJetSoundFly.SetPosition(0);
5350 FJetSoundFly.PlayAt(FObj.X, FObj.Y);
5351 end;
5353 for b := WP_FIRST to WP_LAST do
5354 if FReloading[b] > 0 then
5355 if FNoReload then
5356 FReloading[b] := 0
5357 else
5358 Dec(FReloading[b]);
5360 if FShellTimer > -1 then
5361 if FShellTimer = 0 then
5362 begin
5363 if FShellType = SHELL_SHELL then
5364 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
5365 GameVelX, GameVelY-2, SHELL_SHELL)
5366 else if FShellType = SHELL_DBLSHELL then
5367 begin
5368 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
5369 GameVelX+1, GameVelY-2, SHELL_SHELL);
5370 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
5371 GameVelX-1, GameVelY-2, SHELL_SHELL);
5372 end;
5373 FShellTimer := -1;
5374 end else Dec(FShellTimer);
5376 if (FBFGFireCounter > -1) then
5377 if FBFGFireCounter = 0 then
5378 begin
5379 if AnyServer then
5380 begin
5381 wx := FObj.X+WEAPONPOINT[FDirection].X;
5382 wy := FObj.Y+WEAPONPOINT[FDirection].Y;
5383 xd := wx+IfThen(FDirection = TDirection.D_LEFT, -30, 30);
5384 yd := wy+firediry();
5385 g_Weapon_bfgshot(wx, wy, xd, yd, FUID);
5386 if NetServer then MH_SEND_PlayerFire(FUID, WEAPON_BFG, wx, wy, xd, yd);
5387 if (FAngle = 0) or (FAngle = 180) then SetAction(A_ATTACK)
5388 else if (FAngle = ANGLE_LEFTDOWN) or (FAngle = ANGLE_RIGHTDOWN) then SetAction(A_ATTACKDOWN)
5389 else if (FAngle = ANGLE_LEFTUP) or (FAngle = ANGLE_RIGHTUP) then SetAction(A_ATTACKUP);
5390 end;
5392 FReloading[WEAPON_BFG] := WEAPON_RELOAD[WEAPON_BFG];
5393 FBFGFireCounter := -1;
5394 end else
5395 if FNoReload then
5396 FBFGFireCounter := 0
5397 else
5398 Dec(FBFGFireCounter);
5400 if (FMegaRulez[MR_SUIT] < gTime) and AnyServer then
5401 begin
5402 b := g_GetAcidHit(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width, PLAYER_RECT.Height);
5404 if (b > 0) and (gTime mod (15*GAME_TICK) = 0) then Damage(b, 0, 0, 0, HIT_ACID);
5405 end;
5407 if (headwater or blockmon) then
5408 begin
5409 Dec(FAir);
5411 if FAir < -9 then
5412 begin
5413 if AnyServer then Damage(10, 0, 0, 0, HIT_WATER);
5414 FAir := 0;
5415 end
5416 else if (FAir mod 31 = 0) and not blockmon then
5417 begin
5418 g_GFX_Bubbles(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2), FObj.Y+PLAYER_RECT.Y-4, 5+Random(6), 8, 4);
5419 if Random(2) = 0
5420 then g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj.X, FObj.Y)
5421 else g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj.X, FObj.Y);
5422 end;
5423 end else if FAir < AIR_DEF then
5424 FAir := AIR_DEF;
5426 if FFireTime > 0 then
5427 begin
5428 if BodyInLiquid(0, 0) then
5429 begin
5430 FFireTime := 0;
5431 FFirePainTime := 0;
5432 end
5433 else if FMegaRulez[MR_SUIT] >= gTime then
5434 begin
5435 if FMegaRulez[MR_SUIT] = gTime then
5436 FFireTime := 1;
5437 FFirePainTime := 0;
5438 end
5439 else
5440 begin
5441 OnFireFlame(1);
5442 if FFirePainTime <= 0 then
5443 begin
5444 if g_Game_IsServer then
5445 Damage(2, FFireAttacker, 0, 0, HIT_FLAME);
5446 FFirePainTime := 12 - FFireTime div 12;
5447 end;
5448 FFirePainTime := FFirePainTime - 1;
5449 FFireTime := FFireTime - 1;
5450 if ((FFireTime mod 33) = 0) and (FMegaRulez[MR_INVUL] < gTime) then
5451 FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
5452 if (FFireTime = 0) and g_Game_IsNet and g_Game_IsServer then
5453 MH_SEND_PlayerStats(FUID);
5454 end;
5455 end;
5457 if FDamageBuffer > 0 then
5458 begin
5459 if FDamageBuffer >= 9 then
5460 begin
5461 SetAction(A_PAIN);
5463 if FDamageBuffer < 30 then i := 9
5464 else if FDamageBuffer < 100 then i := 18
5465 else i := 27;
5466 end;
5468 ii := Round(FDamageBuffer*FHealth / nonz(FArmor*(3/4)+FHealth));
5469 FArmor := FArmor-(FDamageBuffer-ii);
5470 FHealth := FHealth-ii;
5471 if FArmor < 0 then
5472 begin
5473 FHealth := FHealth+FArmor;
5474 FArmor := 0;
5475 end;
5477 if AnyServer then
5478 if FHealth <= 0 then
5479 if FHealth > -30 then Kill(K_SIMPLEKILL, FLastSpawnerUID, FLastHit)
5480 else if FHealth > -50 then Kill(K_HARDKILL, FLastSpawnerUID, FLastHit)
5481 else Kill(K_EXTRAHARDKILL, FLastSpawnerUID, FLastHit);
5483 if FAlive and ((FLastHit <> HIT_FLAME) or (FFireTime <= 0)) then
5484 begin
5485 if FDamageBuffer <= 20 then FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y)
5486 else if FDamageBuffer <= 55 then FModel.PlaySound(MODELSOUND_PAIN, 2, FObj.X, FObj.Y)
5487 else if FDamageBuffer <= 120 then FModel.PlaySound(MODELSOUND_PAIN, 3, FObj.X, FObj.Y)
5488 else FModel.PlaySound(MODELSOUND_PAIN, 4, FObj.X, FObj.Y);
5489 end;
5491 FDamageBuffer := 0;
5492 end;
5494 {CollideItem();}
5495 end; // if FAlive then ...
5497 if (FActionAnim = A_PAIN) and (FModel.Animation <> A_PAIN) then
5498 begin
5499 FModel.ChangeAnimation(FActionAnim, FActionForce);
5500 FModel.GetCurrentAnimation.MinLength := i;
5501 FModel.GetCurrentAnimationMask.MinLength := i;
5502 end else FModel.ChangeAnimation(FActionAnim, FActionForce and (FModel.Animation <> A_STAND));
5504 if (FModel.GetCurrentAnimation.Played or ((not FActionChanged) and (FModel.Animation = A_WALK)))
5505 then SetAction(A_STAND, True);
5507 if not ((FModel.Animation = A_WALK) and (Abs(FObj.Vel.X) < 4) and not FModel.Fire) then FModel.Update;
5509 for b := Low(FKeys) to High(FKeys) do
5510 if FKeys[b].Time = 0 then FKeys[b].Pressed := False else Dec(FKeys[b].Time);
5511 end;
5514 procedure TPlayer.getMapBox (out x, y, w, h: Integer); inline;
5515 begin
5516 x := FObj.X+PLAYER_RECT.X;
5517 y := FObj.Y+PLAYER_RECT.Y;
5518 w := PLAYER_RECT.Width;
5519 h := PLAYER_RECT.Height;
5520 end;
5523 procedure TPlayer.moveBy (dx, dy: Integer); inline;
5524 begin
5525 if (dx <> 0) or (dy <> 0) then
5526 begin
5527 FObj.X += dx;
5528 FObj.Y += dy;
5529 positionChanged();
5530 end;
5531 end;
5534 function TPlayer.Collide(X, Y: Integer; Width, Height: Word): Boolean;
5535 begin
5536 Result := g_Collide(FObj.X+PLAYER_RECT.X,
5537 FObj.Y+PLAYER_RECT.Y,
5538 PLAYER_RECT.Width,
5539 PLAYER_RECT.Height,
5540 X, Y,
5541 Width, Height);
5542 end;
5544 function TPlayer.Collide(Panel: TPanel): Boolean;
5545 begin
5546 Result := g_Collide(FObj.X+PLAYER_RECT.X,
5547 FObj.Y+PLAYER_RECT.Y,
5548 PLAYER_RECT.Width,
5549 PLAYER_RECT.Height,
5550 Panel.X, Panel.Y,
5551 Panel.Width, Panel.Height);
5552 end;
5554 function TPlayer.Collide(X, Y: Integer): Boolean;
5555 begin
5556 X := X-FObj.X-PLAYER_RECT.X;
5557 Y := Y-FObj.Y-PLAYER_RECT.Y;
5558 Result := (x >= 0) and (x <= PLAYER_RECT.Width) and
5559 (y >= 0) and (y <= PLAYER_RECT.Height);
5560 end;
5562 function g_Player_ValidName(Name: string): Boolean;
5563 var
5564 a: Integer;
5565 begin
5566 Result := True;
5568 if gPlayers = nil then Exit;
5570 for a := 0 to High(gPlayers) do
5571 if gPlayers[a] <> nil then
5572 if LowerCase(Name) = LowerCase(gPlayers[a].FName) then
5573 begin
5574 Result := False;
5575 Exit;
5576 end;
5577 end;
5579 procedure TPlayer.SetDirection(Direction: TDirection);
5580 var
5581 d: TDirection;
5582 begin
5583 d := FModel.Direction;
5585 FModel.Direction := Direction;
5586 if d <> Direction then FModel.ChangeAnimation(FModel.Animation, True);
5588 FDirection := Direction;
5589 end;
5591 function TPlayer.GetKeys(): Byte;
5592 begin
5593 Result := 0;
5595 if R_KEY_RED in FRulez then Result := KEY_RED;
5596 if R_KEY_GREEN in FRulez then Result := Result or KEY_GREEN;
5597 if R_KEY_BLUE in FRulez then Result := Result or KEY_BLUE;
5599 if FTeam = TEAM_RED then Result := Result or KEY_REDTEAM;
5600 if FTeam = TEAM_BLUE then Result := Result or KEY_BLUETEAM;
5601 end;
5603 procedure TPlayer.Use();
5604 var
5605 a: Integer;
5606 begin
5607 if FTime[T_USE] > gTime then Exit;
5609 g_Triggers_PressR(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
5610 PLAYER_RECT.Height, FUID, ACTIVATE_PLAYERPRESS);
5612 for a := 0 to High(gPlayers) do
5613 if (gPlayers[a] <> nil) and (gPlayers[a] <> Self) and
5614 gPlayers[a].alive and SameTeam(FUID, gPlayers[a].FUID) and
5615 g_Obj_Collide(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y,
5616 FObj.Rect.Width, FObj.Rect.Height, @gPlayers[a].FObj) then
5617 begin
5618 gPlayers[a].Touch();
5619 if g_Game_IsNet and g_Game_IsServer then
5620 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH, gPlayers[a].FUID);
5621 end;
5623 FTime[T_USE] := gTime+120;
5624 end;
5626 procedure TPlayer.NetFire(Wpn: Byte; X, Y, AX, AY: Integer; WID: Integer = -1);
5627 var
5628 locObj: TObj;
5629 visible: Boolean = True;
5630 WX, WY, XD, YD: Integer;
5631 begin
5632 WX := X;
5633 WY := Y;
5634 XD := AX;
5635 YD := AY;
5637 case FCurrWeap of
5638 WEAPON_KASTET:
5639 begin
5640 visible := False;
5641 DoPunch();
5642 if R_BERSERK in FRulez then
5643 begin
5644 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5645 locobj.X := FObj.X+FObj.Rect.X;
5646 locobj.Y := FObj.Y+FObj.Rect.Y;
5647 locobj.rect.X := 0;
5648 locobj.rect.Y := 0;
5649 locobj.rect.Width := 39;
5650 locobj.rect.Height := 52;
5651 locobj.Vel.X := (xd-wx) div 2;
5652 locobj.Vel.Y := (yd-wy) div 2;
5653 locobj.Accel.X := xd-wx;
5654 locobj.Accel.y := yd-wy;
5656 if g_Weapon_Hit(@locobj, 50, FUID, HIT_SOME) <> 0 then
5657 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj.X, FObj.Y)
5658 else
5659 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj.X, FObj.Y);
5661 if gFlash = 1 then
5662 if FPain < 50 then
5663 FPain := min(FPain + 25, 50);
5664 end else
5665 g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 3, FUID);
5666 end;
5668 WEAPON_SAW:
5669 begin
5670 if g_Weapon_chainsaw(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y,
5671 IfThen(gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF], 9, 3), FUID) <> 0 then
5672 begin
5673 FSawSoundSelect.Stop();
5674 FSawSound.Stop();
5675 FSawSoundHit.PlayAt(FObj.X, FObj.Y);
5676 end
5677 else if not FSawSoundHit.IsPlaying() then
5678 begin
5679 FSawSoundSelect.Stop();
5680 FSawSound.PlayAt(FObj.X, FObj.Y);
5681 end;
5682 end;
5684 WEAPON_PISTOL:
5685 begin
5686 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX, Gamey);
5687 FFireAngle := FAngle;
5688 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
5689 GameVelX, GameVelY-2, SHELL_BULLET);
5690 end;
5692 WEAPON_SHOTGUN1:
5693 begin
5694 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex, Gamey);
5695 FFireAngle := FAngle;
5696 FShellTimer := 10;
5697 FShellType := SHELL_SHELL;
5698 end;
5700 WEAPON_SHOTGUN2:
5701 begin
5702 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex, Gamey);
5703 FFireAngle := FAngle;
5704 FShellTimer := 13;
5705 FShellType := SHELL_DBLSHELL;
5706 end;
5708 WEAPON_CHAINGUN:
5709 begin
5710 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex, Gamey);
5711 FFireAngle := FAngle;
5712 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
5713 GameVelX, GameVelY-2, SHELL_BULLET);
5714 end;
5716 WEAPON_ROCKETLAUNCHER:
5717 begin
5718 g_Weapon_Rocket(wx, wy, xd, yd, FUID, WID);
5719 FFireAngle := FAngle;
5720 end;
5722 WEAPON_PLASMA:
5723 begin
5724 g_Weapon_Plasma(wx, wy, xd, yd, FUID, WID);
5725 FFireAngle := FAngle;
5726 end;
5728 WEAPON_BFG:
5729 begin
5730 g_Weapon_BFGShot(wx, wy, xd, yd, FUID, WID);
5731 FFireAngle := FAngle;
5732 end;
5734 WEAPON_SUPERPULEMET:
5735 begin
5736 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex, Gamey);
5737 FFireAngle := FAngle;
5738 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
5739 GameVelX, GameVelY-2, SHELL_SHELL);
5740 end;
5742 WEAPON_FLAMETHROWER:
5743 begin
5744 g_Weapon_flame(wx, wy, xd, yd, FUID, WID);
5745 FlamerOn;
5746 FFireAngle := FAngle;
5747 end;
5748 end;
5750 if not visible then Exit;
5752 if (FAngle = 0) or (FAngle = 180) then SetAction(A_ATTACK)
5753 else if (FAngle = ANGLE_LEFTDOWN) or (FAngle = ANGLE_RIGHTDOWN) then SetAction(A_ATTACKDOWN)
5754 else if (FAngle = ANGLE_LEFTUP) or (FAngle = ANGLE_RIGHTUP) then SetAction(A_ATTACKUP);
5755 end;
5757 procedure TPlayer.DoLerp(Level: Integer = 2);
5758 begin
5759 if FObj.X <> FXTo then FObj.X := Lerp(FObj.X, FXTo, Level);
5760 if FObj.Y <> FYTo then FObj.Y := Lerp(FObj.Y, FYTo, Level);
5761 end;
5763 procedure TPlayer.SetLerp(XTo, YTo: Integer);
5764 var
5765 AX, AY: Integer;
5766 begin
5767 FXTo := XTo;
5768 FYTo := YTo;
5769 if FJustTeleported or (NetInterpLevel < 1) then
5770 begin
5771 FObj.X := XTo;
5772 FObj.Y := YTo;
5773 if FJustTeleported then
5774 begin
5775 FObj.oldX := FObj.X;
5776 FObj.oldY := FObj.Y;
5777 end;
5778 end
5779 else
5780 begin
5781 AX := Abs(FXTo - FObj.X);
5782 AY := Abs(FYTo - FObj.Y);
5783 if (AX > 32) or (AX <= NetInterpLevel) then
5784 FObj.X := FXTo;
5785 if (AY > 32) or (AY <= NetInterpLevel) then
5786 FObj.Y := FYTo;
5787 end;
5788 end;
5790 function TPlayer.FullInLift(XInc, YInc: Integer): Integer;
5791 begin
5792 if g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc,
5793 PLAYER_RECT.Width, PLAYER_RECT.Height-8,
5794 PANEL_LIFTUP, False) then Result := -1
5795 else
5796 if g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc,
5797 PLAYER_RECT.Width, PLAYER_RECT.Height-8,
5798 PANEL_LIFTDOWN, False) then Result := 1
5799 else Result := 0;
5800 end;
5802 function TPlayer.GetFlag(Flag: Byte): Boolean;
5803 var
5804 s, ts: String;
5805 evtype, a: Byte;
5806 begin
5807 Result := False;
5809 if Flag = FLAG_NONE then
5810 Exit;
5812 if not g_Game_IsServer then Exit;
5814 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5815 if (Flag = FTeam) and
5816 (gFlags[Flag].State = FLAG_STATE_NORMAL) and
5817 (FFlag <> FLAG_NONE) then
5818 begin
5819 if FFlag = FLAG_RED then
5820 s := _lc[I_PLAYER_FLAG_RED]
5821 else
5822 s := _lc[I_PLAYER_FLAG_BLUE];
5824 evtype := FLAG_STATE_SCORED;
5826 ts := Format('%.4d', [gFlags[FFlag].CaptureTime]);
5827 Insert('.', ts, Length(ts) + 1 - 3);
5828 g_Console_Add(Format(_lc[I_PLAYER_FLAG_CAPTURE], [FName, s, ts]), True);
5830 g_Map_ResetFlag(FFlag);
5831 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_CAPTURE], [AnsiUpperCase(s)]), 144);
5833 if ((Self = gPlayer1) or (Self = gPlayer2)
5834 or ((gPlayer1 <> nil) and (gPlayer1.Team = FTeam))
5835 or ((gPlayer2 <> nil) and (gPlayer2.Team = FTeam))) then
5836 a := 0
5837 else
5838 a := 1;
5840 if not sound_cap_flag[a].IsPlaying() then
5841 sound_cap_flag[a].Play();
5843 gTeamStat[FTeam].Score += 1;
5845 Result := True;
5846 if g_Game_IsNet then
5847 begin
5848 MH_SEND_FlagEvent(evtype, FFlag, FUID, False);
5849 MH_SEND_GameStats;
5850 end;
5852 gFlags[FFlag].CaptureTime := 0;
5853 SetFlag(FLAG_NONE);
5854 Exit;
5855 end;
5857 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5858 if (Flag = FTeam) and
5859 (gFlags[Flag].State = FLAG_STATE_DROPPED) then
5860 begin
5861 if Flag = FLAG_RED then
5862 s := _lc[I_PLAYER_FLAG_RED]
5863 else
5864 s := _lc[I_PLAYER_FLAG_BLUE];
5866 evtype := FLAG_STATE_RETURNED;
5867 gFlags[Flag].CaptureTime := 0;
5869 g_Console_Add(Format(_lc[I_PLAYER_FLAG_RETURN], [FName, s]), True);
5871 g_Map_ResetFlag(Flag);
5872 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_RETURN], [AnsiUpperCase(s)]), 144);
5874 if ((Self = gPlayer1) or (Self = gPlayer2)
5875 or ((gPlayer1 <> nil) and (gPlayer1.Team = FTeam))
5876 or ((gPlayer2 <> nil) and (gPlayer2.Team = FTeam))) then
5877 a := 0
5878 else
5879 a := 1;
5881 if not sound_ret_flag[a].IsPlaying() then
5882 sound_ret_flag[a].Play();
5884 Result := True;
5885 if g_Game_IsNet then
5886 begin
5887 MH_SEND_FlagEvent(evtype, Flag, FUID, False);
5888 MH_SEND_GameStats;
5889 end;
5890 Exit;
5891 end;
5893 // Ïîäîáðàë ÷óæîé ôëàã:
5894 if (Flag <> FTeam) and (FTime[T_FLAGCAP] <= gTime) then
5895 begin
5896 SetFlag(Flag);
5898 if Flag = FLAG_RED then
5899 s := _lc[I_PLAYER_FLAG_RED]
5900 else
5901 s := _lc[I_PLAYER_FLAG_BLUE];
5903 evtype := FLAG_STATE_CAPTURED;
5905 g_Console_Add(Format(_lc[I_PLAYER_FLAG_GET], [FName, s]), True);
5907 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_GET], [AnsiUpperCase(s)]), 144);
5909 gFlags[Flag].State := FLAG_STATE_CAPTURED;
5911 if ((Self = gPlayer1) or (Self = gPlayer2)
5912 or ((gPlayer1 <> nil) and (gPlayer1.Team = FTeam))
5913 or ((gPlayer2 <> nil) and (gPlayer2.Team = FTeam))) then
5914 a := 0
5915 else
5916 a := 1;
5918 if not sound_get_flag[a].IsPlaying() then
5919 sound_get_flag[a].Play();
5921 Result := True;
5922 if g_Game_IsNet then
5923 begin
5924 MH_SEND_FlagEvent(evtype, Flag, FUID, False);
5925 MH_SEND_GameStats;
5926 end;
5927 end;
5928 end;
5930 procedure TPlayer.SetFlag(Flag: Byte);
5931 begin
5932 FFlag := Flag;
5933 if FModel <> nil then
5934 FModel.SetFlag(FFlag);
5935 end;
5937 function TPlayer.TryDropFlag(): Boolean;
5938 begin
5939 if LongBool(gGameSettings.Options and GAME_OPTION_ALLOWDROPFLAG) then
5940 Result := DropFlag(False, LongBool(gGameSettings.Options and GAME_OPTION_THROWFLAG))
5941 else
5942 Result := False;
5943 end;
5945 function TPlayer.DropFlag(Silent: Boolean = True; DoThrow: Boolean = False): Boolean;
5946 var
5947 s: String;
5948 a: Byte;
5949 xv, yv: Integer;
5950 begin
5951 Result := False;
5952 if (not g_Game_IsServer) or (FFlag = FLAG_NONE) then
5953 Exit;
5954 FTime[T_FLAGCAP] := gTime + 2000;
5955 with gFlags[FFlag] do
5956 begin
5957 Obj.X := FObj.X;
5958 Obj.Y := FObj.Y;
5959 Direction := FDirection;
5960 State := FLAG_STATE_DROPPED;
5961 Count := FLAG_TIME;
5962 if DoThrow then
5963 begin
5964 xv := FObj.Vel.X + IfThen(Direction = TDirection.D_RIGHT, 10, -10);
5965 yv := FObj.Vel.Y - 2;
5966 end
5967 else
5968 begin
5969 xv := (FObj.Vel.X div 2);
5970 yv := (FObj.Vel.Y div 2) - 2;
5971 end;
5972 g_Obj_Push(@Obj, xv, yv);
5974 positionChanged(); // this updates spatial accelerators
5976 if FFlag = FLAG_RED then
5977 s := _lc[I_PLAYER_FLAG_RED]
5978 else
5979 s := _lc[I_PLAYER_FLAG_BLUE];
5981 g_Console_Add(Format(_lc[I_PLAYER_FLAG_DROP], [FName, s]), True);
5982 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_DROP], [AnsiUpperCase(s)]), 144);
5984 if ((Self = gPlayer1) or (Self = gPlayer2)
5985 or ((gPlayer1 <> nil) and (gPlayer1.Team = FTeam))
5986 or ((gPlayer2 <> nil) and (gPlayer2.Team = FTeam))) then
5987 a := 0
5988 else
5989 a := 1;
5991 if (not Silent) and (not sound_lost_flag[a].IsPlaying()) then
5992 sound_lost_flag[a].Play();
5994 if g_Game_IsNet then
5995 MH_SEND_FlagEvent(FLAG_STATE_DROPPED, Flag, FUID, False);
5996 end;
5997 SetFlag(FLAG_NONE);
5998 Result := True;
5999 end;
6001 procedure TPlayer.GetSecret();
6002 begin
6003 if (self = gPlayer1) or (self = gPlayer2) then
6004 begin
6005 g_Console_Add(Format(_lc[I_PLAYER_SECRET], [FName]), True);
6006 g_Sound_PlayEx('SOUND_GAME_SECRET');
6007 end;
6008 Inc(FSecrets);
6009 end;
6011 procedure TPlayer.PressKey(Key: Byte; Time: Word = 1);
6012 begin
6013 Assert(Key <= High(FKeys));
6015 FKeys[Key].Pressed := True;
6016 FKeys[Key].Time := Time;
6017 end;
6019 function TPlayer.IsKeyPressed(K: Byte): Boolean;
6020 begin
6021 Result := FKeys[K].Pressed;
6022 end;
6024 procedure TPlayer.ReleaseKeys();
6025 var
6026 a: Integer;
6027 begin
6028 for a := Low(FKeys) to High(FKeys) do
6029 begin
6030 FKeys[a].Pressed := False;
6031 FKeys[a].Time := 0;
6032 end;
6033 end;
6035 procedure TPlayer.OnDamage(Angle: SmallInt);
6036 begin
6037 end;
6039 function TPlayer.firediry(): Integer;
6040 begin
6041 if FKeys[KEY_UP].Pressed then Result := -42
6042 else if FKeys[KEY_DOWN].Pressed then Result := 19
6043 else Result := 0;
6044 end;
6046 procedure TPlayer.RememberState();
6047 var
6048 i: Integer;
6049 SavedState: TPlayerSavedState;
6050 begin
6051 SavedState.Health := FHealth;
6052 SavedState.Armor := FArmor;
6053 SavedState.Air := FAir;
6054 SavedState.JetFuel := FJetFuel;
6055 SavedState.CurrWeap := FCurrWeap;
6056 SavedState.NextWeap := FNextWeap;
6057 SavedState.NextWeapDelay := FNextWeapDelay;
6058 for i := Low(FWeapon) to High(FWeapon) do
6059 SavedState.Weapon[i] := FWeapon[i];
6060 for i := Low(FAmmo) to High(FAmmo) do
6061 SavedState.Ammo[i] := FAmmo[i];
6062 for i := Low(FMaxAmmo) to High(FMaxAmmo) do
6063 SavedState.MaxAmmo[i] := FMaxAmmo[i];
6064 SavedState.Rulez := FRulez - [R_KEY_RED, R_KEY_GREEN, R_KEY_BLUE];
6066 FSavedStateNum := -1;
6067 for i := Low(SavedStates) to High(SavedStates) do
6068 if not SavedStates[i].Used then
6069 begin
6070 FSavedStateNum := i;
6071 break;
6072 end;
6073 if FSavedStateNum < 0 then
6074 begin
6075 SetLength(SavedStates, Length(SavedStates) + 1);
6076 FSavedStateNum := High(SavedStates);
6077 end;
6079 SavedState.Used := True;
6080 SavedStates[FSavedStateNum] := SavedState;
6081 end;
6083 procedure TPlayer.RecallState();
6084 var
6085 i: Integer;
6086 SavedState: TPlayerSavedState;
6087 begin
6088 if(FSavedStateNum < 0) or (FSavedStateNum > High(SavedStates)) then
6089 Exit;
6091 SavedState := SavedStates[FSavedStateNum];
6092 SavedStates[FSavedStateNum].Used := False;
6093 FSavedStateNum := -1;
6095 FHealth := SavedState.Health;
6096 FArmor := SavedState.Armor;
6097 FAir := SavedState.Air;
6098 FJetFuel := SavedState.JetFuel;
6099 FCurrWeap := SavedState.CurrWeap;
6100 FNextWeap := SavedState.NextWeap;
6101 FNextWeapDelay := SavedState.NextWeapDelay;
6102 for i := Low(FWeapon) to High(FWeapon) do
6103 FWeapon[i] := SavedState.Weapon[i];
6104 for i := Low(FAmmo) to High(FAmmo) do
6105 FAmmo[i] := SavedState.Ammo[i];
6106 for i := Low(FMaxAmmo) to High(FMaxAmmo) do
6107 FMaxAmmo[i] := SavedState.MaxAmmo[i];
6108 FRulez := SavedState.Rulez;
6110 if gGameSettings.GameType = GT_SERVER then
6111 MH_SEND_PlayerStats(FUID);
6112 end;
6114 procedure TPlayer.SaveState (st: TStream);
6115 var
6116 i: Integer;
6117 b: Byte;
6118 begin
6119 // Ñèãíàòóðà èãðîêà
6120 utils.writeSign(st, 'PLYR');
6121 utils.writeInt(st, Byte(PLR_SAVE_VERSION)); // version
6122 // Áîò èëè ÷åëîâåê
6123 utils.writeBool(st, FIamBot);
6124 // UID èãðîêà
6125 utils.writeInt(st, Word(FUID));
6126 // Èìÿ èãðîêà
6127 utils.writeStr(st, FName);
6128 // Êîìàíäà
6129 utils.writeInt(st, Byte(FTeam));
6130 // Æèâ ëè
6131 utils.writeBool(st, FAlive);
6132 // Èçðàñõîäîâàë ëè âñå æèçíè
6133 utils.writeBool(st, FNoRespawn);
6134 // Íàïðàâëåíèå
6135 if FDirection = TDirection.D_LEFT then b := 1 else b := 2; // D_RIGHT
6136 utils.writeInt(st, Byte(b));
6137 // Çäîðîâüå
6138 utils.writeInt(st, LongInt(FHealth));
6139 // Êîýôôèöèåíò èíâàëèäíîñòè
6140 utils.writeInt(st, LongInt(FHandicap));
6141 // Æèçíè
6142 utils.writeInt(st, Byte(FLives));
6143 // Áðîíÿ
6144 utils.writeInt(st, LongInt(FArmor));
6145 // Çàïàñ âîçäóõà
6146 utils.writeInt(st, LongInt(FAir));
6147 // Çàïàñ ãîðþ÷åãî
6148 utils.writeInt(st, LongInt(FJetFuel));
6149 // Áîëü
6150 utils.writeInt(st, LongInt(FPain));
6151 // Óáèë
6152 utils.writeInt(st, LongInt(FKills));
6153 // Óáèë ìîíñòðîâ
6154 utils.writeInt(st, LongInt(FMonsterKills));
6155 // Ôðàãîâ
6156 utils.writeInt(st, LongInt(FFrags));
6157 // Ôðàãîâ ïîäðÿä
6158 utils.writeInt(st, Byte(FFragCombo));
6159 // Âðåìÿ ïîñëåäíåãî ôðàãà
6160 utils.writeInt(st, LongWord(FLastFrag));
6161 // Ñìåðòåé
6162 utils.writeInt(st, LongInt(FDeath));
6163 // Êàêîé ôëàã íåñåò
6164 utils.writeInt(st, Byte(FFlag));
6165 // Íàøåë ñåêðåòîâ
6166 utils.writeInt(st, LongInt(FSecrets));
6167 // Òåêóùåå îðóæèå
6168 utils.writeInt(st, Byte(FCurrWeap));
6169 // Æåëàåìîå îðóæèå
6170 utils.writeInt(st, Word(FNextWeap));
6171 // ...è ïàóçà
6172 utils.writeInt(st, Byte(FNextWeapDelay));
6173 // Âðåìÿ çàðÿäêè BFG
6174 utils.writeInt(st, SmallInt(FBFGFireCounter));
6175 // Áóôåð óðîíà
6176 utils.writeInt(st, LongInt(FDamageBuffer));
6177 // Ïîñëåäíèé óäàðèâøèé
6178 utils.writeInt(st, Word(FLastSpawnerUID));
6179 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6180 utils.writeInt(st, Byte(FLastHit));
6181 // Îáúåêò èãðîêà
6182 Obj_SaveState(st, @FObj);
6183 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6184 for i := A_BULLETS to A_HIGH do utils.writeInt(st, Word(FAmmo[i]));
6185 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6186 for i := A_BULLETS to A_HIGH do utils.writeInt(st, Word(FMaxAmmo[i]));
6187 // Íàëè÷èå îðóæèÿ
6188 for i := WP_FIRST to WP_LAST do utils.writeBool(st, FWeapon[i]);
6189 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6190 for i := WP_FIRST to WP_LAST do utils.writeInt(st, Word(FReloading[i]));
6191 // Íàëè÷èå ðþêçàêà
6192 utils.writeBool(st, (R_ITEM_BACKPACK in FRulez));
6193 // Íàëè÷èå êðàñíîãî êëþ÷à
6194 utils.writeBool(st, (R_KEY_RED in FRulez));
6195 // Íàëè÷èå çåëåíîãî êëþ÷à
6196 utils.writeBool(st, (R_KEY_GREEN in FRulez));
6197 // Íàëè÷èå ñèíåãî êëþ÷à
6198 utils.writeBool(st, (R_KEY_BLUE in FRulez));
6199 // Íàëè÷èå áåðñåðêà
6200 utils.writeBool(st, (R_BERSERK in FRulez));
6201 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6202 for i := MR_SUIT to MR_MAX do utils.writeInt(st, LongWord(FMegaRulez[i]));
6203 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6204 for i := T_RESPAWN to T_FLAGCAP do utils.writeInt(st, LongWord(FTime[i]));
6205 // Íàçâàíèå ìîäåëè
6206 utils.writeStr(st, FModel.Name);
6207 // Öâåò ìîäåëè
6208 utils.writeInt(st, Byte(FColor.R));
6209 utils.writeInt(st, Byte(FColor.G));
6210 utils.writeInt(st, Byte(FColor.B));
6211 end;
6214 procedure TPlayer.LoadState (st: TStream);
6215 var
6216 i: Integer;
6217 str: String;
6218 b: Byte;
6219 begin
6220 assert(st <> nil);
6222 // Ñèãíàòóðà èãðîêà
6223 if not utils.checkSign(st, 'PLYR') then raise XStreamError.Create('invalid player signature');
6224 if (utils.readByte(st) <> PLR_SAVE_VERSION) then raise XStreamError.Create('invalid player version');
6225 // Áîò èëè ÷åëîâåê:
6226 FIamBot := utils.readBool(st);
6227 // UID èãðîêà
6228 FUID := utils.readWord(st);
6229 // Èìÿ èãðîêà
6230 str := utils.readStr(st);
6231 if (self <> gPlayer1) and (self <> gPlayer2) then FName := str;
6232 // Êîìàíäà
6233 FTeam := utils.readByte(st);
6234 // Æèâ ëè
6235 FAlive := utils.readBool(st);
6236 // Èçðàñõîäîâàë ëè âñå æèçíè
6237 FNoRespawn := utils.readBool(st);
6238 // Íàïðàâëåíèå
6239 b := utils.readByte(st);
6240 if b = 1 then FDirection := TDirection.D_LEFT else FDirection := TDirection.D_RIGHT; // b = 2
6241 // Çäîðîâüå
6242 FHealth := utils.readLongInt(st);
6243 // Êîýôôèöèåíò èíâàëèäíîñòè
6244 FHandicap := utils.readLongInt(st);
6245 // Æèçíè
6246 FLives := utils.readByte(st);
6247 // Áðîíÿ
6248 FArmor := utils.readLongInt(st);
6249 // Çàïàñ âîçäóõà
6250 FAir := utils.readLongInt(st);
6251 // Çàïàñ ãîðþ÷åãî
6252 FJetFuel := utils.readLongInt(st);
6253 // Áîëü
6254 FPain := utils.readLongInt(st);
6255 // Óáèë
6256 FKills := utils.readLongInt(st);
6257 // Óáèë ìîíñòðîâ
6258 FMonsterKills := utils.readLongInt(st);
6259 // Ôðàãîâ
6260 FFrags := utils.readLongInt(st);
6261 // Ôðàãîâ ïîäðÿä
6262 FFragCombo := utils.readByte(st);
6263 // Âðåìÿ ïîñëåäíåãî ôðàãà
6264 FLastFrag := utils.readLongWord(st);
6265 // Ñìåðòåé
6266 FDeath := utils.readLongInt(st);
6267 // Êàêîé ôëàã íåñåò
6268 FFlag := utils.readByte(st);
6269 // Íàøåë ñåêðåòîâ
6270 FSecrets := utils.readLongInt(st);
6271 // Òåêóùåå îðóæèå
6272 FCurrWeap := utils.readByte(st);
6273 // Æåëàåìîå îðóæèå
6274 FNextWeap := utils.readWord(st);
6275 // ...è ïàóçà
6276 FNextWeapDelay := utils.readByte(st);
6277 // Âðåìÿ çàðÿäêè BFG
6278 FBFGFireCounter := utils.readSmallInt(st);
6279 // Áóôåð óðîíà
6280 FDamageBuffer := utils.readLongInt(st);
6281 // Ïîñëåäíèé óäàðèâøèé
6282 FLastSpawnerUID := utils.readWord(st);
6283 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6284 FLastHit := utils.readByte(st);
6285 // Îáúåêò èãðîêà
6286 Obj_LoadState(@FObj, st);
6287 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6288 for i := A_BULLETS to A_HIGH do FAmmo[i] := utils.readWord(st);
6289 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6290 for i := A_BULLETS to A_HIGH do FMaxAmmo[i] := utils.readWord(st);
6291 // Íàëè÷èå îðóæèÿ
6292 for i := WP_FIRST to WP_LAST do FWeapon[i] := utils.readBool(st);
6293 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6294 for i := WP_FIRST to WP_LAST do FReloading[i] := utils.readWord(st);
6295 // Íàëè÷èå ðþêçàêà
6296 if utils.readBool(st) then Include(FRulez, R_ITEM_BACKPACK);
6297 // Íàëè÷èå êðàñíîãî êëþ÷à
6298 if utils.readBool(st) then Include(FRulez, R_KEY_RED);
6299 // Íàëè÷èå çåëåíîãî êëþ÷à
6300 if utils.readBool(st) then Include(FRulez, R_KEY_GREEN);
6301 // Íàëè÷èå ñèíåãî êëþ÷à
6302 if utils.readBool(st) then Include(FRulez, R_KEY_BLUE);
6303 // Íàëè÷èå áåðñåðêà
6304 if utils.readBool(st) then Include(FRulez, R_BERSERK);
6305 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6306 for i := MR_SUIT to MR_MAX do FMegaRulez[i] := utils.readLongWord(st);
6307 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6308 for i := T_RESPAWN to T_FLAGCAP do FTime[i] := utils.readLongWord(st);
6309 // Íàçâàíèå ìîäåëè
6310 str := utils.readStr(st);
6311 // Öâåò ìîäåëè
6312 FColor.R := utils.readByte(st);
6313 FColor.G := utils.readByte(st);
6314 FColor.B := utils.readByte(st);
6315 if (self = gPlayer1) then
6316 begin
6317 str := gPlayer1Settings.Model;
6318 FColor := gPlayer1Settings.Color;
6319 end
6320 else if (self = gPlayer2) then
6321 begin
6322 str := gPlayer2Settings.Model;
6323 FColor := gPlayer2Settings.Color;
6324 end;
6325 // Îáíîâëÿåì ìîäåëü èãðîêà
6326 SetModel(str);
6327 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
6328 FModel.Color := TEAMCOLOR[FTeam]
6329 else
6330 FModel.Color := FColor;
6331 end;
6334 procedure TPlayer.AllRulez(Health: Boolean);
6335 var
6336 a: Integer;
6337 begin
6338 if Health then
6339 begin
6340 FHealth := PLAYER_HP_LIMIT;
6341 FArmor := PLAYER_AP_LIMIT;
6342 Exit;
6343 end;
6345 for a := WP_FIRST to WP_LAST do FWeapon[a] := True;
6346 for a := A_BULLETS to A_HIGH do FAmmo[a] := 30000;
6347 FRulez := FRulez+[R_KEY_RED, R_KEY_GREEN, R_KEY_BLUE];
6348 end;
6350 procedure TPlayer.RestoreHealthArmor();
6351 begin
6352 FHealth := PLAYER_HP_LIMIT;
6353 FArmor := PLAYER_AP_LIMIT;
6354 end;
6356 procedure TPlayer.FragCombo();
6357 var
6358 Param: Integer;
6359 begin
6360 if (gGameSettings.GameMode in [GM_COOP, GM_SINGLE]) or g_Game_IsClient then
6361 Exit;
6362 if gTime - FLastFrag < FRAG_COMBO_TIME then
6363 begin
6364 if FFragCombo < 5 then
6365 Inc(FFragCombo);
6366 Param := FUID or (FFragCombo shl 16);
6367 if (FComboEvnt >= Low(gDelayedEvents)) and
6368 (FComboEvnt <= High(gDelayedEvents)) and
6369 gDelayedEvents[FComboEvnt].Pending and
6370 (gDelayedEvents[FComboEvnt].DEType = DE_KILLCOMBO) and
6371 (gDelayedEvents[FComboEvnt].DENum and $FFFF = FUID) then
6372 begin
6373 gDelayedEvents[FComboEvnt].Time := gTime + 500;
6374 gDelayedEvents[FComboEvnt].DENum := Param;
6375 end
6376 else
6377 FComboEvnt := g_Game_DelayEvent(DE_KILLCOMBO, 500, Param);
6378 end
6379 else
6380 FFragCombo := 1;
6382 FLastFrag := gTime;
6383 end;
6385 procedure TPlayer.GiveItem(ItemType: Byte);
6386 begin
6387 case ItemType of
6388 ITEM_SUIT:
6389 if FMegaRulez[MR_SUIT] < gTime+PLAYER_SUIT_TIME then
6390 begin
6391 FMegaRulez[MR_SUIT] := gTime+PLAYER_SUIT_TIME;
6392 end;
6394 ITEM_OXYGEN:
6395 if FAir < AIR_MAX then
6396 begin
6397 FAir := AIR_MAX;
6398 end;
6400 ITEM_MEDKIT_BLACK:
6401 begin
6402 if not (R_BERSERK in FRulez) then
6403 begin
6404 Include(FRulez, R_BERSERK);
6405 if FBFGFireCounter < 1 then
6406 begin
6407 FCurrWeap := WEAPON_KASTET;
6408 resetWeaponQueue();
6409 FModel.SetWeapon(WEAPON_KASTET);
6410 end;
6411 if gFlash <> 0 then
6412 Inc(FPain, 100);
6413 FBerserk := gTime+30000;
6414 end;
6415 if FHealth < PLAYER_HP_SOFT then
6416 begin
6417 FHealth := PLAYER_HP_SOFT;
6418 FBerserk := gTime+30000;
6419 end;
6420 end;
6422 ITEM_INVUL:
6423 if FMegaRulez[MR_INVUL] < gTime+PLAYER_INVUL_TIME then
6424 begin
6425 FMegaRulez[MR_INVUL] := gTime+PLAYER_INVUL_TIME;
6426 FSpawnInvul := 0;
6427 end;
6429 ITEM_INVIS:
6430 if FMegaRulez[MR_INVIS] < gTime+PLAYER_INVIS_TIME then
6431 begin
6432 FMegaRulez[MR_INVIS] := gTime+PLAYER_INVIS_TIME;
6433 end;
6435 ITEM_JETPACK:
6436 if FJetFuel < JET_MAX then
6437 begin
6438 FJetFuel := JET_MAX;
6439 end;
6441 ITEM_MEDKIT_SMALL: if FHealth < PLAYER_HP_SOFT then IncMax(FHealth, 10, PLAYER_HP_SOFT);
6442 ITEM_MEDKIT_LARGE: if FHealth < PLAYER_HP_SOFT then IncMax(FHealth, 25, PLAYER_HP_SOFT);
6444 ITEM_ARMOR_GREEN: if FArmor < PLAYER_AP_SOFT then FArmor := PLAYER_AP_SOFT;
6445 ITEM_ARMOR_BLUE: if FArmor < PLAYER_AP_LIMIT then FArmor := PLAYER_AP_LIMIT;
6447 ITEM_SPHERE_BLUE: if FHealth < PLAYER_HP_LIMIT then IncMax(FHealth, 100, PLAYER_HP_LIMIT);
6448 ITEM_SPHERE_WHITE:
6449 if (FHealth < PLAYER_HP_LIMIT) or (FArmor < PLAYER_AP_LIMIT) then
6450 begin
6451 if FHealth < PLAYER_HP_LIMIT then FHealth := PLAYER_HP_LIMIT;
6452 if FArmor < PLAYER_AP_LIMIT then FArmor := PLAYER_AP_LIMIT;
6453 end;
6455 ITEM_WEAPON_SAW: FWeapon[WEAPON_SAW] := True;
6456 ITEM_WEAPON_SHOTGUN1: FWeapon[WEAPON_SHOTGUN1] := True;
6457 ITEM_WEAPON_SHOTGUN2: FWeapon[WEAPON_SHOTGUN2] := True;
6458 ITEM_WEAPON_CHAINGUN: FWeapon[WEAPON_CHAINGUN] := True;
6459 ITEM_WEAPON_ROCKETLAUNCHER: FWeapon[WEAPON_ROCKETLAUNCHER] := True;
6460 ITEM_WEAPON_PLASMA: FWeapon[WEAPON_PLASMA] := True;
6461 ITEM_WEAPON_BFG: FWeapon[WEAPON_BFG] := True;
6462 ITEM_WEAPON_SUPERPULEMET: FWeapon[WEAPON_SUPERPULEMET] := True;
6463 ITEM_WEAPON_FLAMETHROWER: FWeapon[WEAPON_FLAMETHROWER] := True;
6465 ITEM_AMMO_BULLETS: if FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS] then IncMax(FAmmo[A_BULLETS], 10, FMaxAmmo[A_BULLETS]);
6466 ITEM_AMMO_BULLETS_BOX: if FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS] then IncMax(FAmmo[A_BULLETS], 50, FMaxAmmo[A_BULLETS]);
6467 ITEM_AMMO_SHELLS: if FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS] then IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
6468 ITEM_AMMO_SHELLS_BOX: if FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS] then IncMax(FAmmo[A_SHELLS], 25, FMaxAmmo[A_SHELLS]);
6469 ITEM_AMMO_ROCKET: if FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS] then IncMax(FAmmo[A_ROCKETS], 1, FMaxAmmo[A_ROCKETS]);
6470 ITEM_AMMO_ROCKET_BOX: if FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS] then IncMax(FAmmo[A_ROCKETS], 5, FMaxAmmo[A_ROCKETS]);
6471 ITEM_AMMO_CELL: if FAmmo[A_CELLS] < FMaxAmmo[A_CELLS] then IncMax(FAmmo[A_CELLS], 40, FMaxAmmo[A_CELLS]);
6472 ITEM_AMMO_CELL_BIG: if FAmmo[A_CELLS] < FMaxAmmo[A_CELLS] then IncMax(FAmmo[A_CELLS], 100, FMaxAmmo[A_CELLS]);
6473 ITEM_AMMO_FUELCAN: if FAmmo[A_FUEL] < FMaxAmmo[A_FUEL] then IncMax(FAmmo[A_FUEL], 100, FMaxAmmo[A_FUEL]);
6475 ITEM_AMMO_BACKPACK:
6476 if (FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS]) or
6477 (FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS]) or
6478 (FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS]) or
6479 (FAmmo[A_CELLS] < FMaxAmmo[A_CELLS]) or
6480 (FMaxAmmo[A_FUEL] < AmmoLimits[1, A_FUEL]) then
6481 begin
6482 FMaxAmmo[A_BULLETS] := AmmoLimits[1, A_BULLETS];
6483 FMaxAmmo[A_SHELLS] := AmmoLimits[1, A_SHELLS];
6484 FMaxAmmo[A_ROCKETS] := AmmoLimits[1, A_ROCKETS];
6485 FMaxAmmo[A_CELLS] := AmmoLimits[1, A_CELLS];
6486 FMaxAmmo[A_FUEL] := AmmoLimits[1, A_FUEL];
6488 if FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS] then IncMax(FAmmo[A_BULLETS], 10, FMaxAmmo[A_BULLETS]);
6489 if FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS] then IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
6490 if FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS] then IncMax(FAmmo[A_ROCKETS], 1, FMaxAmmo[A_ROCKETS]);
6491 if FAmmo[A_CELLS] < FMaxAmmo[A_CELLS] then IncMax(FAmmo[A_CELLS], 40, FMaxAmmo[A_CELLS]);
6493 FRulez := FRulez + [R_ITEM_BACKPACK];
6494 end;
6496 ITEM_KEY_RED: if not (R_KEY_RED in FRulez) then Include(FRulez, R_KEY_RED);
6497 ITEM_KEY_GREEN: if not (R_KEY_GREEN in FRulez) then Include(FRulez, R_KEY_GREEN);
6498 ITEM_KEY_BLUE: if not (R_KEY_BLUE in FRulez) then Include(FRulez, R_KEY_BLUE);
6500 ITEM_BOTTLE: if FHealth < PLAYER_HP_LIMIT then IncMax(FHealth, 4, PLAYER_HP_LIMIT);
6501 ITEM_HELMET: if FArmor < PLAYER_AP_LIMIT then IncMax(FArmor, 5, PLAYER_AP_LIMIT);
6503 else
6504 Exit;
6505 end;
6506 if g_Game_IsNet and g_Game_IsServer then
6507 MH_SEND_PlayerStats(FUID);
6508 end;
6510 procedure TPlayer.FlySmoke(Times: DWORD = 1);
6511 var
6512 id, i: DWORD;
6513 Anim: TAnimation;
6514 begin
6515 if (Random(5) = 1) and (Times = 1) then
6516 Exit;
6518 if BodyInLiquid(0, 0) then
6519 begin
6520 g_GFX_Bubbles(Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2)+Random(3)-1,
6521 Obj.Y+Obj.Rect.Height+8, 1, 8, 4);
6522 if Random(2) = 0
6523 then g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj.X, FObj.Y)
6524 else g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj.X, FObj.Y);
6525 Exit;
6526 end;
6528 if g_Frames_Get(id, 'FRAMES_SMOKE') then
6529 begin
6530 for i := 1 to Times do
6531 begin
6532 Anim := TAnimation.Create(id, False, 3);
6533 Anim.Alpha := 150;
6534 g_GFX_OnceAnim(Obj.X+Obj.Rect.X+Random(Obj.Rect.Width+Times*2)-(Anim.Width div 2),
6535 Obj.Y+Obj.Rect.Height-4+Random(8+Times*2), Anim, ONCEANIM_SMOKE);
6536 Anim.Free();
6537 end;
6538 end;
6539 end;
6541 procedure TPlayer.OnFireFlame(Times: DWORD = 1);
6542 var
6543 id, i: DWORD;
6544 Anim: TAnimation;
6545 begin
6546 if (Random(10) = 1) and (Times = 1) then
6547 Exit;
6549 if g_Frames_Get(id, 'FRAMES_FLAME') then
6550 begin
6551 for i := 1 to Times do
6552 begin
6553 Anim := TAnimation.Create(id, False, 3);
6554 Anim.Alpha := 0;
6555 g_GFX_OnceAnim(Obj.X+Obj.Rect.X+Random(Obj.Rect.Width+Times*2)-(Anim.Width div 2),
6556 Obj.Y+8+Random(8+Times*2), Anim, ONCEANIM_SMOKE);
6557 Anim.Free();
6558 end;
6559 end;
6560 end;
6562 procedure TPlayer.PauseSounds(Enable: Boolean);
6563 begin
6564 FSawSound.Pause(Enable);
6565 FSawSoundIdle.Pause(Enable);
6566 FSawSoundHit.Pause(Enable);
6567 FSawSoundSelect.Pause(Enable);
6568 FFlameSoundOn.Pause(Enable);
6569 FFlameSoundOff.Pause(Enable);
6570 FFlameSoundWork.Pause(Enable);
6571 FJetSoundFly.Pause(Enable);
6572 FJetSoundOn.Pause(Enable);
6573 FJetSoundOff.Pause(Enable);
6574 end;
6576 { T C o r p s e : }
6578 constructor TCorpse.Create(X, Y: Integer; ModelName: String; aMess: Boolean);
6579 begin
6580 g_Obj_Init(@FObj);
6581 FObj.X := X;
6582 FObj.Y := Y;
6583 FObj.Rect := PLAYER_CORPSERECT;
6584 FModelName := ModelName;
6585 FMess := aMess;
6587 if FMess then
6588 begin
6589 FState := CORPSE_STATE_MESS;
6590 g_PlayerModel_GetAnim(ModelName, A_DIE2, FAnimation, FAnimationMask);
6591 end
6592 else
6593 begin
6594 FState := CORPSE_STATE_NORMAL;
6595 g_PlayerModel_GetAnim(ModelName, A_DIE1, FAnimation, FAnimationMask);
6596 end;
6597 end;
6599 destructor TCorpse.Destroy();
6600 begin
6601 FAnimation.Free();
6603 inherited;
6604 end;
6606 function TCorpse.ObjPtr (): PObj; inline; begin result := @FObj; end;
6608 procedure TCorpse.positionChanged (); inline; begin end;
6610 procedure TCorpse.moveBy (dx, dy: Integer); inline;
6611 begin
6612 if (dx <> 0) or (dy <> 0) then
6613 begin
6614 FObj.X += dx;
6615 FObj.Y += dy;
6616 positionChanged();
6617 end;
6618 end;
6621 procedure TCorpse.getMapBox (out x, y, w, h: Integer); inline;
6622 begin
6623 x := FObj.X+PLAYER_CORPSERECT.X;
6624 y := FObj.Y+PLAYER_CORPSERECT.Y;
6625 w := PLAYER_CORPSERECT.Width;
6626 h := PLAYER_CORPSERECT.Height;
6627 end;
6630 procedure TCorpse.Damage(Value: Word; SpawnerUID: Word; vx, vy: Integer);
6631 var
6632 pm: TPlayerModel;
6633 Blood: TModelBlood;
6634 begin
6635 if FState = CORPSE_STATE_REMOVEME then
6636 Exit;
6638 FDamage := FDamage + Value;
6640 if FDamage > 150 then
6641 begin
6642 if FAnimation <> nil then
6643 begin
6644 FAnimation.Free();
6645 FAnimation := nil;
6647 FState := CORPSE_STATE_REMOVEME;
6649 g_Player_CreateGibs(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
6650 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
6651 FModelName, FColor);
6652 // Çâóê ìÿñà îò òðóïà:
6653 pm := g_PlayerModel_Get(FModelName);
6654 pm.PlaySound(MODELSOUND_DIE, 5, FObj.X, FObj.Y);
6655 pm.Free;
6657 // Çëîâåùèé ñìåõ:
6658 if (gBodyKillEvent <> -1)
6659 and gDelayedEvents[gBodyKillEvent].Pending then
6660 gDelayedEvents[gBodyKillEvent].Pending := False;
6661 gBodyKillEvent := g_Game_DelayEvent(DE_BODYKILL, 1050, SpawnerUID);
6662 end;
6663 end
6664 else
6665 begin
6666 Blood := g_PlayerModel_GetBlood(FModelName);
6667 FObj.Vel.X := FObj.Vel.X + vx;
6668 FObj.Vel.Y := FObj.Vel.Y + vy;
6669 g_GFX_Blood(FObj.X+PLAYER_CORPSERECT.X+(PLAYER_CORPSERECT.Width div 2),
6670 FObj.Y+PLAYER_CORPSERECT.Y+(PLAYER_CORPSERECT.Height div 2),
6671 Value, vx, vy, 16, (PLAYER_CORPSERECT.Height*2) div 3,
6672 Blood.R, Blood.G, Blood.B, Blood.Kind);
6673 end;
6674 end;
6676 procedure TCorpse.Draw();
6677 var
6678 fX, fY: Integer;
6679 begin
6680 if FState = CORPSE_STATE_REMOVEME then
6681 Exit;
6683 FObj.lerp(gLerpFactor, fX, fY);
6685 if FAnimation <> nil then
6686 FAnimation.Draw(fX, fY, TMirrorType.None);
6688 if FAnimationMask <> nil then
6689 begin
6690 e_Colors := FColor;
6691 FAnimationMask.Draw(fX, fY, TMirrorType.None);
6692 e_Colors.R := 255;
6693 e_Colors.G := 255;
6694 e_Colors.B := 255;
6695 end;
6696 end;
6698 procedure TCorpse.Update();
6699 var
6700 st: Word;
6701 begin
6702 if FState = CORPSE_STATE_REMOVEME then
6703 Exit;
6705 FObj.oldX := FObj.X;
6706 FObj.oldY := FObj.Y;
6708 if gTime mod (GAME_TICK*2) <> 0 then
6709 begin
6710 g_Obj_Move(@FObj, True, True, True);
6711 positionChanged(); // this updates spatial accelerators
6712 Exit;
6713 end;
6715 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6716 FObj.Vel.X := z_dec(FObj.Vel.X, 1);
6718 st := g_Obj_Move(@FObj, True, True, True);
6719 positionChanged(); // this updates spatial accelerators
6721 if WordBool(st and MOVE_FALLOUT) then
6722 begin
6723 FState := CORPSE_STATE_REMOVEME;
6724 Exit;
6725 end;
6727 if FAnimation <> nil then
6728 FAnimation.Update();
6729 if FAnimationMask <> nil then
6730 FAnimationMask.Update();
6731 end;
6734 procedure TCorpse.SaveState (st: TStream);
6735 var
6736 anim: Boolean;
6737 begin
6738 assert(st <> nil);
6740 // Ñèãíàòóðà òðóïà
6741 utils.writeSign(st, 'CORP');
6742 utils.writeInt(st, Byte(0));
6743 // Ñîñòîÿíèå
6744 utils.writeInt(st, Byte(FState));
6745 // Íàêîïëåííûé óðîí
6746 utils.writeInt(st, Byte(FDamage));
6747 // Öâåò
6748 utils.writeInt(st, Byte(FColor.R));
6749 utils.writeInt(st, Byte(FColor.G));
6750 utils.writeInt(st, Byte(FColor.B));
6751 // Îáúåêò òðóïà
6752 Obj_SaveState(st, @FObj);
6753 utils.writeInt(st, Word(FPlayerUID));
6754 // Åñòü ëè àíèìàöèÿ
6755 anim := (FAnimation <> nil);
6756 utils.writeBool(st, anim);
6757 // Åñëè åñòü - ñîõðàíÿåì
6758 if anim then FAnimation.SaveState(st);
6759 // Åñòü ëè ìàñêà àíèìàöèè
6760 anim := (FAnimationMask <> nil);
6761 utils.writeBool(st, anim);
6762 // Åñëè åñòü - ñîõðàíÿåì
6763 if anim then FAnimationMask.SaveState(st);
6764 end;
6767 procedure TCorpse.LoadState (st: TStream);
6768 var
6769 anim: Boolean;
6770 begin
6771 assert(st <> nil);
6773 // Ñèãíàòóðà òðóïà
6774 if not utils.checkSign(st, 'CORP') then raise XStreamError.Create('invalid corpse signature');
6775 if (utils.readByte(st) <> 0) then raise XStreamError.Create('invalid corpse version');
6776 // Ñîñòîÿíèå
6777 FState := utils.readByte(st);
6778 // Íàêîïëåííûé óðîí
6779 FDamage := utils.readByte(st);
6780 // Öâåò
6781 FColor.R := utils.readByte(st);
6782 FColor.G := utils.readByte(st);
6783 FColor.B := utils.readByte(st);
6784 // Îáúåêò òðóïà
6785 Obj_LoadState(@FObj, st);
6786 FPlayerUID := utils.readWord(st);
6787 // Åñòü ëè àíèìàöèÿ
6788 anim := utils.readBool(st);
6789 // Åñëè åñòü - çàãðóæàåì
6790 if anim then
6791 begin
6792 Assert(FAnimation <> nil, 'TCorpse.LoadState: no FAnimation');
6793 FAnimation.LoadState(st);
6794 end;
6795 // Åñòü ëè ìàñêà àíèìàöèè
6796 anim := utils.readBool(st);
6797 // Åñëè åñòü - çàãðóæàåì
6798 if anim then
6799 begin
6800 Assert(FAnimationMask <> nil, 'TCorpse.LoadState: no FAnimationMask');
6801 FAnimationMask.LoadState(st);
6802 end;
6803 end;
6805 { T B o t : }
6807 constructor TBot.Create();
6808 var
6809 a: Integer;
6810 begin
6811 inherited Create();
6813 FPhysics := True;
6814 FSpectator := False;
6815 FGhost := False;
6817 FIamBot := True;
6819 Inc(gNumBots);
6821 for a := WP_FIRST to WP_LAST do
6822 begin
6823 FDifficult.WeaponPrior[a] := WEAPON_PRIOR1[a];
6824 FDifficult.CloseWeaponPrior[a] := WEAPON_PRIOR2[a];
6825 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6826 end;
6827 end;
6829 destructor TBot.Destroy();
6830 begin
6831 Dec(gNumBots);
6832 inherited Destroy();
6833 end;
6835 procedure TBot.Draw();
6836 begin
6837 inherited Draw();
6839 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6840 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6841 end;
6843 procedure TBot.Respawn(Silent: Boolean; Force: Boolean = False);
6844 begin
6845 inherited Respawn(Silent, Force);
6847 FAIFlags := nil;
6848 FSelectedWeapon := FCurrWeap;
6849 resetWeaponQueue();
6850 FTargetUID := 0;
6851 end;
6853 procedure TBot.UpdateCombat();
6854 type
6855 TTarget = record
6856 UID: Word;
6857 X, Y: Integer;
6858 Rect: TRectWH;
6859 cX, cY: Integer;
6860 Dist: Word;
6861 Line: Boolean;
6862 Visible: Boolean;
6863 IsPlayer: Boolean;
6864 end;
6866 TTargetRecord = array of TTarget;
6868 function Compare(a, b: TTarget): Integer;
6869 begin
6870 if a.Line and not b.Line then // A íà ëèíèè îãíÿ
6871 Result := -1
6872 else
6873 if not a.Line and b.Line then // B íà ëèíèè îãíÿ
6874 Result := 1
6875 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6876 if (a.Line and b.Line) or ((not a.Line) and (not b.Line)) then
6877 begin
6878 if a.Dist > b.Dist then // B áëèæå
6879 Result := 1
6880 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6881 Result := -1;
6882 end
6883 else // Ñòðàííî -> A
6884 Result := -1;
6885 end;
6887 var
6888 a, x1, y1, x2, y2: Integer;
6889 targets: TTargetRecord;
6890 ammo: Word;
6891 Target, BestTarget: TTarget;
6892 firew, fireh: Integer;
6893 angle: SmallInt;
6894 mon: TMonster;
6895 pla, tpla: TPlayer;
6896 vsPlayer, vsMonster, ok: Boolean;
6899 function monsUpdate (mon: TMonster): Boolean;
6900 begin
6901 result := false; // don't stop
6902 if mon.alive and (mon.MonsterType <> MONSTER_BARREL) then
6903 begin
6904 if not TargetOnScreen(mon.Obj.X+mon.Obj.Rect.X, mon.Obj.Y+mon.Obj.Rect.Y) then exit;
6906 x2 := mon.Obj.X+mon.Obj.Rect.X+(mon.Obj.Rect.Width div 2);
6907 y2 := mon.Obj.Y+mon.Obj.Rect.Y+(mon.Obj.Rect.Height div 2);
6909 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6910 if g_TraceVector(x1, y1, x2, y2) then
6911 begin
6912 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6913 SetLength(targets, Length(targets)+1);
6914 with targets[High(targets)] do
6915 begin
6916 UID := mon.UID;
6917 X := mon.Obj.X;
6918 Y := mon.Obj.Y;
6919 cX := x2;
6920 cY := y2;
6921 Rect := mon.Obj.Rect;
6922 Dist := g_PatchLength(x1, y1, x2, y2);
6923 Line := (y1+4 < Target.Y + mon.Obj.Rect.Y + mon.Obj.Rect.Height) and
6924 (y1-4 > Target.Y + mon.Obj.Rect.Y);
6925 Visible := True;
6926 IsPlayer := False;
6927 end;
6928 end;
6929 end;
6930 end;
6932 begin
6933 vsPlayer := LongBool(gGameSettings.Options and GAME_OPTION_BOTVSPLAYER);
6934 vsMonster := LongBool(gGameSettings.Options and GAME_OPTION_BOTVSMONSTER);
6936 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6937 if FCurrWeap <> FSelectedWeapon then
6938 NextWeapon();
6940 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6941 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap = FSelectedWeapon) then
6942 begin
6943 RemoveAIFlag('NEEDFIRE');
6945 case FCurrWeap of
6946 WEAPON_PLASMA, WEAPON_SUPERPULEMET, WEAPON_CHAINGUN: PressKey(KEY_FIRE, 20);
6947 WEAPON_SAW, WEAPON_KASTET, WEAPON_FLAMETHROWER: PressKey(KEY_FIRE, 40);
6948 else PressKey(KEY_FIRE);
6949 end;
6950 end;
6952 // Êîîðäèíàòû ñòâîëà:
6953 x1 := FObj.X + WEAPONPOINT[FDirection].X;
6954 y1 := FObj.Y + WEAPONPOINT[FDirection].Y;
6956 Target.UID := FTargetUID;
6958 ok := False;
6959 if Target.UID <> 0 then
6960 begin // Öåëü åñòü - íàñòðàèâàåì
6961 if (g_GetUIDType(Target.UID) = UID_PLAYER) and
6962 vsPlayer then
6963 begin // Èãðîê
6964 tpla := g_Player_Get(Target.UID);
6965 if tpla <> nil then
6966 with tpla do
6967 begin
6968 if (@FObj) <> nil then
6969 begin
6970 Target.X := FObj.X;
6971 Target.Y := FObj.Y;
6972 end;
6973 end;
6975 Target.cX := Target.X + PLAYER_RECT_CX;
6976 Target.cY := Target.Y + PLAYER_RECT_CY;
6977 Target.Rect := PLAYER_RECT;
6978 Target.Visible := g_TraceVector(x1, y1, Target.cX, Target.cY);
6979 Target.Line := (y1+4 < Target.Y+PLAYER_RECT.Y+PLAYER_RECT.Height) and
6980 (y1-4 > Target.Y+PLAYER_RECT.Y);
6981 Target.IsPlayer := True;
6982 ok := True;
6983 end
6984 else
6985 if (g_GetUIDType(Target.UID) = UID_MONSTER) and
6986 vsMonster then
6987 begin // Ìîíñòð
6988 mon := g_Monsters_ByUID(Target.UID);
6989 if mon <> nil then
6990 begin
6991 Target.X := mon.Obj.X;
6992 Target.Y := mon.Obj.Y;
6994 Target.cX := Target.X + mon.Obj.Rect.X + (mon.Obj.Rect.Width div 2);
6995 Target.cY := Target.Y + mon.Obj.Rect.Y + (mon.Obj.Rect.Height div 2);
6996 Target.Rect := mon.Obj.Rect;
6997 Target.Visible := g_TraceVector(x1, y1, Target.cX, Target.cY);
6998 Target.Line := (y1+4 < Target.Y + mon.Obj.Rect.Y + mon.Obj.Rect.Height) and
6999 (y1-4 > Target.Y + mon.Obj.Rect.Y);
7000 Target.IsPlayer := False;
7001 ok := True;
7002 end;
7003 end;
7004 end;
7006 if not ok then
7007 begin // Öåëè íåò - îáíóëÿåì
7008 Target.X := 0;
7009 Target.Y := 0;
7010 Target.cX := 0;
7011 Target.cY := 0;
7012 Target.Visible := False;
7013 Target.Line := False;
7014 Target.IsPlayer := False;
7015 end;
7017 targets := nil;
7019 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
7020 if (not Target.Line) or (not Target.Visible) then
7021 begin
7022 // Èãðîêè:
7023 if vsPlayer then
7024 for a := 0 to High(gPlayers) do
7025 if (gPlayers[a] <> nil) and (gPlayers[a].alive) and
7026 (gPlayers[a].FUID <> FUID) and
7027 (not SameTeam(FUID, gPlayers[a].FUID)) and
7028 (not gPlayers[a].NoTarget) and
7029 (gPlayers[a].FMegaRulez[MR_INVIS] < gTime) then
7030 begin
7031 if not TargetOnScreen(gPlayers[a].FObj.X + PLAYER_RECT.X,
7032 gPlayers[a].FObj.Y + PLAYER_RECT.Y) then
7033 Continue;
7035 x2 := gPlayers[a].FObj.X + PLAYER_RECT_CX;
7036 y2 := gPlayers[a].FObj.Y + PLAYER_RECT_CY;
7038 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
7039 if g_TraceVector(x1, y1, x2, y2) then
7040 begin
7041 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
7042 SetLength(targets, Length(targets)+1);
7043 with targets[High(targets)] do
7044 begin
7045 UID := gPlayers[a].FUID;
7046 X := gPlayers[a].FObj.X;
7047 Y := gPlayers[a].FObj.Y;
7048 cX := x2;
7049 cY := y2;
7050 Rect := PLAYER_RECT;
7051 Dist := g_PatchLength(x1, y1, x2, y2);
7052 Line := (y1+4 < Target.Y+PLAYER_RECT.Y+PLAYER_RECT.Height) and
7053 (y1-4 > Target.Y+PLAYER_RECT.Y);
7054 Visible := True;
7055 IsPlayer := True;
7056 end;
7057 end;
7058 end;
7060 // Ìîíñòðû:
7061 if vsMonster then g_Mons_ForEach(monsUpdate);
7062 end;
7064 // Åñëè åñòü âîçìîæíûå öåëè:
7065 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
7066 if targets <> nil then
7067 begin
7068 // Âûáèðàåì íàèëó÷øóþ öåëü:
7069 BestTarget := targets[0];
7070 if Length(targets) > 1 then
7071 for a := 1 to High(targets) do
7072 if Compare(BestTarget, targets[a]) = 1 then
7073 BestTarget := targets[a];
7075 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
7076 if ((not Target.Visible) and BestTarget.Visible and (Target.UID <> BestTarget.UID)) or
7077 ((not Target.Line) and BestTarget.Line and BestTarget.Visible) then
7078 begin
7079 Target := BestTarget;
7081 if (Healthy() = 3) or ((Healthy() = 2)) then
7082 begin // Åñëè çäîðîâû - äîãîíÿåì
7083 if ((RunDirection() = TDirection.D_LEFT) and (Target.X > FObj.X)) then
7084 SetAIFlag('GORIGHT', '1');
7085 if ((RunDirection() = TDirection.D_RIGHT) and (Target.X < FObj.X)) then
7086 SetAIFlag('GOLEFT', '1');
7087 end
7088 else
7089 begin // Åñëè ïîáèòû - óáåãàåì
7090 if ((RunDirection() = TDirection.D_LEFT) and (Target.X < FObj.X)) then
7091 SetAIFlag('GORIGHT', '1');
7092 if ((RunDirection() = TDirection.D_RIGHT) and (Target.X > FObj.X)) then
7093 SetAIFlag('GOLEFT', '1');
7094 end;
7096 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
7097 SelectWeapon(Abs(x1-Target.cX));
7098 end;
7099 end;
7101 // Åñëè åñòü öåëü:
7102 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
7103 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
7104 if Target.UID <> 0 then
7105 begin
7106 if not TargetOnScreen(Target.X + Target.Rect.X,
7107 Target.Y + Target.Rect.Y) then
7108 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
7109 if (Healthy() = 3) or ((Healthy() = 2)) then
7110 begin // Åñëè çäîðîâû - äîãîíÿåì
7111 if ((RunDirection() = TDirection.D_LEFT) and (Target.X > FObj.X)) then
7112 SetAIFlag('GORIGHT', '1');
7113 if ((RunDirection() = TDirection.D_RIGHT) and (Target.X < FObj.X)) then
7114 SetAIFlag('GOLEFT', '1');
7115 end
7116 else
7117 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
7118 Target.UID := 0;
7119 if ((RunDirection() = TDirection.D_LEFT) and (Target.X < FObj.X)) then
7120 SetAIFlag('GORIGHT', '1');
7121 if ((RunDirection() = TDirection.D_RIGHT) and (Target.X > FObj.X)) then
7122 SetAIFlag('GOLEFT', '1');
7123 end;
7124 end
7125 else
7126 begin // Öåëü ïîêà íà "ýêðàíå"
7127 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
7128 if g_TraceVector(x1, y1, Target.cX, Target.cY) then
7129 FLastVisible := gTime;
7130 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
7131 if (Abs(FObj.Y-Target.Y) <= 128) then
7132 begin
7133 if ((RunDirection() = TDirection.D_LEFT) and (Target.X > FObj.X)) then
7134 SetAIFlag('GORIGHT', '1');
7135 if ((RunDirection() = TDirection.D_RIGHT) and (Target.X < FObj.X)) then
7136 SetAIFlag('GOLEFT', '1');
7137 end;
7138 end;
7140 // Âûáèðàåì óãîë ââåðõ:
7141 if FDirection = TDirection.D_LEFT then
7142 angle := ANGLE_LEFTUP
7143 else
7144 angle := ANGLE_RIGHTUP;
7146 firew := Trunc(Cos(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
7147 fireh := Trunc(Sin(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
7149 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
7150 if g_CollideLine(x1, y1, x1+firew, y1+fireh,
7151 Target.X+Target.Rect.X+GetInterval(FDifficult.DiagPrecision, 128), //96
7152 Target.Y+Target.Rect.Y+GetInterval(FDifficult.DiagPrecision, 128),
7153 Target.Rect.Width, Target.Rect.Height) and
7154 g_TraceVector(x1, y1, Target.cX, Target.cY) then
7155 begin // òî íóæíî ñòðåëÿòü ââåðõ
7156 SetAIFlag('NEEDFIRE', '1');
7157 SetAIFlag('NEEDSEEUP', '1');
7158 end;
7160 // Âûáèðàåì óãîë âíèç:
7161 if FDirection = TDirection.D_LEFT then
7162 angle := ANGLE_LEFTDOWN
7163 else
7164 angle := ANGLE_RIGHTDOWN;
7166 firew := Trunc(Cos(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
7167 fireh := Trunc(Sin(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
7169 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
7170 if g_CollideLine(x1, y1, x1+firew, y1+fireh,
7171 Target.X+Target.Rect.X+GetInterval(FDifficult.DiagPrecision, 128),
7172 Target.Y+Target.Rect.Y+GetInterval(FDifficult.DiagPrecision, 128),
7173 Target.Rect.Width, Target.Rect.Height) and
7174 g_TraceVector(x1, y1, Target.cX, Target.cY) then
7175 begin // òî íóæíî ñòðåëÿòü âíèç
7176 SetAIFlag('NEEDFIRE', '1');
7177 SetAIFlag('NEEDSEEDOWN', '1');
7178 end;
7180 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
7181 if Target.Visible and
7182 (y1+4 < Target.Y+Target.Rect.Y+Target.Rect.Height) and
7183 (y1-4 > Target.Y+Target.Rect.Y) then
7184 begin
7185 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
7186 if ((FDirection = TDirection.D_LEFT) and (Target.X < FObj.X)) or
7187 ((FDirection = TDirection.D_RIGHT) and (Target.X > FObj.X)) then
7188 begin // òî íóæíî ñòðåëÿòü âïåðåä
7189 SetAIFlag('NEEDFIRE', '1');
7190 SetAIFlag('NEEDSEEDOWN', '');
7191 SetAIFlag('NEEDSEEUP', '');
7192 end;
7193 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
7194 if Abs(FObj.X-Target.X) < Trunc(gPlayerScreenSize.X*0.75) then
7195 if GetRnd(FDifficult.CloseJump) then
7196 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
7197 if Abs(FObj.X-Target.X) < 128 then
7198 a := 4
7199 else
7200 a := 30;
7201 if Random(a) = 0 then
7202 SetAIFlag('NEEDJUMP', '1');
7203 end;
7204 end;
7206 // Åñëè öåëü âñå åùå åñòü:
7207 if Target.UID <> 0 then
7208 if gTime-FLastVisible > 2000 then // Åñëè âèäåëè äàâíî
7209 Target.UID := 0 // òî çàáûòü öåëü
7210 else // Åñëè âèäåëè íåäàâíî
7211 begin // íî öåëü óáèëè
7212 if Target.IsPlayer then
7213 begin // Öåëü - èãðîê
7214 pla := g_Player_Get(Target.UID);
7215 if (pla = nil) or (not pla.alive) or pla.NoTarget or
7216 (pla.FMegaRulez[MR_INVIS] >= gTime) then
7217 Target.UID := 0; // òî çàáûòü öåëü
7218 end
7219 else
7220 begin // Öåëü - ìîíñòð
7221 mon := g_Monsters_ByUID(Target.UID);
7222 if (mon = nil) or (not mon.alive) then
7223 Target.UID := 0; // òî çàáûòü öåëü
7224 end;
7225 end;
7226 end; // if Target.UID <> 0
7228 FTargetUID := Target.UID;
7230 // Åñëè âîçìîæíûõ öåëåé íåò:
7231 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
7232 if targets = nil then
7233 if GetAIFlag('ATTACKLEFT') <> '' then
7234 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
7235 RemoveAIFlag('ATTACKLEFT');
7237 SetAIFlag('NEEDJUMP', '1');
7239 if RunDirection() = TDirection.D_RIGHT then
7240 begin // Èäåì íå â òó ñòîðîíó
7241 if (Healthy() > 1) and GetRnd(FDifficult.InvisFire) then
7242 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
7243 SetAIFlag('NEEDFIRE', '1');
7244 SetAIFlag('GOLEFT', '1');
7245 end;
7246 end
7247 else
7248 begin // Èäåì â íóæíóþ ñòîðîíó
7249 if GetRnd(FDifficult.InvisFire) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7250 SetAIFlag('NEEDFIRE', '1');
7251 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7252 SetAIFlag('GORIGHT', '1');
7253 end;
7254 end
7255 else
7256 if GetAIFlag('ATTACKRIGHT') <> '' then
7257 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
7258 RemoveAIFlag('ATTACKRIGHT');
7260 SetAIFlag('NEEDJUMP', '1');
7262 if RunDirection() = TDirection.D_LEFT then
7263 begin // Èäåì íå â òó ñòîðîíó
7264 if (Healthy() > 1) and GetRnd(FDifficult.InvisFire) then
7265 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
7266 SetAIFlag('NEEDFIRE', '1');
7267 SetAIFlag('GORIGHT', '1');
7268 end;
7269 end
7270 else
7271 begin
7272 if GetRnd(FDifficult.InvisFire) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7273 SetAIFlag('NEEDFIRE', '1');
7274 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7275 SetAIFlag('GOLEFT', '1');
7276 end;
7277 end;
7279 //HACK! (does it belongs there?)
7280 RealizeCurrentWeapon();
7282 // Åñëè åñòü âîçìîæíûå öåëè:
7283 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
7284 if (targets <> nil) and (GetAIFlag('NEEDFIRE') <> '') then
7285 for a := 0 to High(targets) do
7286 begin
7287 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
7288 if GetRnd(FDifficult.DiagFire) then
7289 begin
7290 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
7291 if FDirection = TDirection.D_LEFT then
7292 angle := ANGLE_LEFTUP
7293 else
7294 angle := ANGLE_RIGHTUP;
7296 firew := Trunc(Cos(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
7297 fireh := Trunc(Sin(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
7299 if g_CollideLine(x1, y1, x1+firew, y1+fireh,
7300 targets[a].X+targets[a].Rect.X+GetInterval(FDifficult.DiagPrecision, 128),
7301 targets[a].Y+targets[a].Rect.Y+GetInterval(FDifficult.DiagPrecision, 128),
7302 targets[a].Rect.Width, targets[a].Rect.Height) and
7303 g_TraceVector(x1, y1, targets[a].cX, targets[a].cY) then
7304 begin
7305 SetAIFlag('NEEDFIRE', '1');
7306 SetAIFlag('NEEDSEEUP', '1');
7307 end;
7309 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
7310 if FDirection = TDirection.D_LEFT then
7311 angle := ANGLE_LEFTDOWN
7312 else
7313 angle := ANGLE_RIGHTDOWN;
7315 firew := Trunc(Cos(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
7316 fireh := Trunc(Sin(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
7318 if g_CollideLine(x1, y1, x1+firew, y1+fireh,
7319 targets[a].X+targets[a].Rect.X+GetInterval(FDifficult.DiagPrecision, 128),
7320 targets[a].Y+targets[a].Rect.Y+GetInterval(FDifficult.DiagPrecision, 128),
7321 targets[a].Rect.Width, targets[a].Rect.Height) and
7322 g_TraceVector(x1, y1, targets[a].cX, targets[a].cY) then
7323 begin
7324 SetAIFlag('NEEDFIRE', '1');
7325 SetAIFlag('NEEDSEEDOWN', '1');
7326 end;
7327 end;
7329 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
7330 if targets[a].Line and targets[a].Visible and
7331 (((FDirection = TDirection.D_LEFT) and (targets[a].X < FObj.X)) or
7332 ((FDirection = TDirection.D_RIGHT) and (targets[a].X > FObj.X))) then
7333 begin
7334 SetAIFlag('NEEDFIRE', '1');
7335 Break;
7336 end;
7337 end;
7339 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
7340 if g_Weapon_Danger(FUID, FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y,
7341 PLAYER_RECT.Width, PLAYER_RECT.Height,
7342 40+GetInterval(FDifficult.Cover, 40)) then
7343 SetAIFlag('NEEDJUMP', '1');
7345 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
7346 ammo := GetAmmoByWeapon(FCurrWeap);
7347 if ((FCurrWeap = WEAPON_SHOTGUN2) and (ammo < 2)) or
7348 ((FCurrWeap = WEAPON_BFG) and (ammo < 40)) or
7349 (ammo = 0) then
7350 SetAIFlag('SELECTWEAPON', '1');
7352 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
7353 if GetAIFlag('SELECTWEAPON') = '1' then
7354 begin
7355 SelectWeapon(-1);
7356 RemoveAIFlag('SELECTWEAPON');
7357 end;
7358 end;
7360 procedure TBot.Update();
7361 var
7362 EnableAI: Boolean;
7363 begin
7364 if not FAlive then
7365 begin // Respawn
7366 ReleaseKeys();
7367 PressKey(KEY_UP);
7368 end
7369 else
7370 begin
7371 EnableAI := True;
7373 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
7374 if (g_debug_BotAIOff = 1) and (Team = TEAM_RED) then
7375 EnableAI := False;
7376 if (g_debug_BotAIOff = 2) and (Team = TEAM_BLUE) then
7377 EnableAI := False;
7378 if g_debug_BotAIOff = 3 then
7379 EnableAI := False;
7381 if EnableAI then
7382 begin
7383 UpdateMove();
7384 UpdateCombat();
7385 end
7386 else
7387 begin
7388 RealizeCurrentWeapon();
7389 end;
7390 end;
7392 inherited Update();
7393 end;
7395 procedure TBot.ReleaseKey(Key: Byte);
7396 begin
7397 with FKeys[Key] do
7398 begin
7399 Pressed := False;
7400 Time := 0;
7401 end;
7402 end;
7404 function TBot.KeyPressed(Key: Word): Boolean;
7405 begin
7406 Result := FKeys[Key].Pressed;
7407 end;
7409 function TBot.GetAIFlag(aName: String20): String20;
7410 var
7411 a: Integer;
7412 begin
7413 Result := '';
7415 aName := LowerCase(aName);
7417 if FAIFlags <> nil then
7418 for a := 0 to High(FAIFlags) do
7419 if LowerCase(FAIFlags[a].Name) = aName then
7420 begin
7421 Result := FAIFlags[a].Value;
7422 Break;
7423 end;
7424 end;
7426 procedure TBot.RemoveAIFlag(aName: String20);
7427 var
7428 a, b: Integer;
7429 begin
7430 if FAIFlags = nil then Exit;
7432 aName := LowerCase(aName);
7434 for a := 0 to High(FAIFlags) do
7435 if LowerCase(FAIFlags[a].Name) = aName then
7436 begin
7437 if a <> High(FAIFlags) then
7438 for b := a to High(FAIFlags)-1 do
7439 FAIFlags[b] := FAIFlags[b+1];
7441 SetLength(FAIFlags, Length(FAIFlags)-1);
7442 Break;
7443 end;
7444 end;
7446 procedure TBot.SetAIFlag(aName, fValue: String20);
7447 var
7448 a: Integer;
7449 ok: Boolean;
7450 begin
7451 a := 0;
7452 ok := False;
7454 aName := LowerCase(aName);
7456 if FAIFlags <> nil then
7457 for a := 0 to High(FAIFlags) do
7458 if LowerCase(FAIFlags[a].Name) = aName then
7459 begin
7460 ok := True;
7461 Break;
7462 end;
7464 if ok then FAIFlags[a].Value := fValue
7465 else
7466 begin
7467 SetLength(FAIFlags, Length(FAIFlags)+1);
7468 with FAIFlags[High(FAIFlags)] do
7469 begin
7470 Name := aName;
7471 Value := fValue;
7472 end;
7473 end;
7474 end;
7476 procedure TBot.UpdateMove;
7478 procedure GoLeft(Time: Word = 1);
7479 begin
7480 ReleaseKey(KEY_LEFT);
7481 ReleaseKey(KEY_RIGHT);
7482 PressKey(KEY_LEFT, Time);
7483 SetDirection(TDirection.D_LEFT);
7484 end;
7486 procedure GoRight(Time: Word = 1);
7487 begin
7488 ReleaseKey(KEY_LEFT);
7489 ReleaseKey(KEY_RIGHT);
7490 PressKey(KEY_RIGHT, Time);
7491 SetDirection(TDirection.D_RIGHT);
7492 end;
7494 function Rnd(a: Word): Boolean;
7495 begin
7496 Result := Random(a) = 0;
7497 end;
7499 procedure Turn(Time: Word = 1200);
7500 begin
7501 if RunDirection() = TDirection.D_LEFT then GoRight(Time) else GoLeft(Time);
7502 end;
7504 procedure Stop();
7505 begin
7506 ReleaseKey(KEY_LEFT);
7507 ReleaseKey(KEY_RIGHT);
7508 end;
7510 function CanRunLeft(): Boolean;
7511 begin
7512 Result := not CollideLevel(-1, 0);
7513 end;
7515 function CanRunRight(): Boolean;
7516 begin
7517 Result := not CollideLevel(1, 0);
7518 end;
7520 function CanRun(): Boolean;
7521 begin
7522 if RunDirection() = TDirection.D_LEFT then Result := CanRunLeft() else Result := CanRunRight();
7523 end;
7525 procedure Jump(Time: Word = 30);
7526 begin
7527 PressKey(KEY_JUMP, Time);
7528 end;
7530 function NearHole(): Boolean;
7531 var
7532 x, sx: Integer;
7533 begin
7534 { TODO 5 : Ëåñòíèöû }
7535 sx := IfThen(RunDirection() = TDirection.D_LEFT, -1, 1);
7536 for x := 1 to PLAYER_RECT.Width do
7537 if (not StayOnStep(x*sx, 0)) and
7538 (not CollideLevel(x*sx, PLAYER_RECT.Height)) and
7539 (not CollideLevel(x*sx, PLAYER_RECT.Height*2)) then
7540 begin
7541 Result := True;
7542 Exit;
7543 end;
7545 Result := False;
7546 end;
7548 function BorderHole(): Boolean;
7549 var
7550 x, sx, xx: Integer;
7551 begin
7552 { TODO 5 : Ëåñòíèöû }
7553 sx := IfThen(RunDirection() = TDirection.D_LEFT, -1, 1);
7554 for x := 1 to PLAYER_RECT.Width do
7555 if (not StayOnStep(x*sx, 0)) and
7556 (not CollideLevel(x*sx, PLAYER_RECT.Height)) and
7557 (not CollideLevel(x*sx, PLAYER_RECT.Height*2)) then
7558 begin
7559 for xx := x to x+32 do
7560 if CollideLevel(xx*sx, PLAYER_RECT.Height) then
7561 begin
7562 Result := True;
7563 Exit;
7564 end;
7565 end;
7567 Result := False;
7568 end;
7570 function NearDeepHole(): Boolean;
7571 var
7572 x, sx, y: Integer;
7573 begin
7574 Result := False;
7576 sx := IfThen(RunDirection() = TDirection.D_LEFT, -1, 1);
7577 y := 3;
7579 for x := 1 to PLAYER_RECT.Width do
7580 if (not StayOnStep(x*sx, 0)) and
7581 (not CollideLevel(x*sx, PLAYER_RECT.Height)) and
7582 (not CollideLevel(x*sx, PLAYER_RECT.Height*2)) then
7583 begin
7584 while FObj.Y+y*PLAYER_RECT.Height < gMapInfo.Height do
7585 begin
7586 if CollideLevel(x*sx, PLAYER_RECT.Height*y) then Exit;
7587 y := y+1;
7588 end;
7590 Result := True;
7591 end else Result := False;
7592 end;
7594 function OverDeepHole(): Boolean;
7595 var
7596 y: Integer;
7597 begin
7598 Result := False;
7600 y := 1;
7601 while FObj.Y+y*PLAYER_RECT.Height < gMapInfo.Height do
7602 begin
7603 if CollideLevel(0, PLAYER_RECT.Height*y) then Exit;
7604 y := y+1;
7605 end;
7607 Result := True;
7608 end;
7610 function OnGround(): Boolean;
7611 begin
7612 Result := StayOnStep(0, 0) or CollideLevel(0, 1);
7613 end;
7615 function OnLadder(): Boolean;
7616 begin
7617 Result := FullInStep(0, 0);
7618 end;
7620 function BelowLadder(): Boolean;
7621 begin
7622 Result := (FullInStep(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -PLAYER_RECT.Height) and
7623 not CollideLevel(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -PLAYER_RECT.Height)) or
7624 (FullInStep(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -BOT_MAXJUMP) and
7625 not CollideLevel(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -BOT_MAXJUMP));
7626 end;
7628 function BelowLiftUp(): Boolean;
7629 begin
7630 Result := ((FullInLift(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -PLAYER_RECT.Height) = -1) and
7631 not CollideLevel(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -PLAYER_RECT.Height)) or
7632 ((FullInLift(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -BOT_MAXJUMP) = -1) and
7633 not CollideLevel(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -BOT_MAXJUMP));
7634 end;
7636 function OnTopLift(): Boolean;
7637 begin
7638 Result := (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7639 end;
7641 function CanJumpOver(): Boolean;
7642 var
7643 sx, y: Integer;
7644 begin
7645 sx := IfThen(RunDirection() = TDirection.D_LEFT, -1, 1);
7647 Result := False;
7649 if not CollideLevel(sx, 0) then Exit;
7651 for y := 1 to BOT_MAXJUMP do
7652 if CollideLevel(0, -y) then Exit else
7653 if not CollideLevel(sx, -y) then
7654 begin
7655 Result := True;
7656 Exit;
7657 end;
7658 end;
7660 function CanJumpUp(Dist: ShortInt): Boolean;
7661 var
7662 y, yy: Integer;
7663 c: Boolean;
7664 begin
7665 Result := False;
7667 if CollideLevel(Dist, 0) then Exit;
7669 c := False;
7670 for y := 0 to BOT_MAXJUMP do
7671 if CollideLevel(Dist, -y) then
7672 begin
7673 c := True;
7674 Break;
7675 end;
7677 if not c then Exit;
7679 c := False;
7680 for yy := y+1 to BOT_MAXJUMP do
7681 if not CollideLevel(Dist, -yy) then
7682 begin
7683 c := True;
7684 Break;
7685 end;
7687 if not c then Exit;
7689 c := False;
7690 for y := 0 to BOT_MAXJUMP do
7691 if CollideLevel(0, -y) then
7692 begin
7693 c := True;
7694 Break;
7695 end;
7697 if c then Exit;
7699 if y < yy then Exit;
7701 Result := True;
7702 end;
7704 function IsSafeTrigger(): Boolean;
7705 var
7706 a: Integer;
7707 begin
7708 Result := True;
7709 if gTriggers = nil then
7710 Exit;
7711 for a := 0 to High(gTriggers) do
7712 if Collide(gTriggers[a].X,
7713 gTriggers[a].Y,
7714 gTriggers[a].Width,
7715 gTriggers[a].Height) and
7716 (gTriggers[a].TriggerType in [TRIGGER_EXIT, TRIGGER_CLOSEDOOR,
7717 TRIGGER_CLOSETRAP, TRIGGER_TRAP,
7718 TRIGGER_PRESS, TRIGGER_ON, TRIGGER_OFF,
7719 TRIGGER_ONOFF, TRIGGER_SPAWNMONSTER,
7720 TRIGGER_DAMAGE, TRIGGER_SHOT]) then
7721 Result := False;
7722 end;
7724 begin
7725 // Âîçìîæíî, íàæèìàåì êíîïêó:
7726 if Rnd(16) and IsSafeTrigger() then
7727 PressKey(KEY_OPEN);
7729 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7730 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7731 begin
7732 ReleaseKey(KEY_LEFT);
7733 ReleaseKey(KEY_RIGHT);
7734 Jump();
7735 end;
7737 // Èäåì âëåâî, åñëè íàäî áûëî:
7738 if GetAIFlag('GOLEFT') <> '' then
7739 begin
7740 RemoveAIFlag('GOLEFT');
7741 if CanRunLeft() then
7742 GoLeft(360);
7743 end;
7745 // Èäåì âïðàâî, åñëè íàäî áûëî:
7746 if GetAIFlag('GORIGHT') <> '' then
7747 begin
7748 RemoveAIFlag('GORIGHT');
7749 if CanRunRight() then
7750 GoRight(360);
7751 end;
7753 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7754 if FObj.X < -32 then
7755 GoRight(360)
7756 else
7757 if FObj.X+32 > gMapInfo.Width then
7758 GoLeft(360);
7760 // Ïðûãàåì, åñëè íàäî áûëî:
7761 if GetAIFlag('NEEDJUMP') <> '' then
7762 begin
7763 Jump(0);
7764 RemoveAIFlag('NEEDJUMP');
7765 end;
7767 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7768 if GetAIFlag('NEEDSEEUP') <> '' then
7769 begin
7770 ReleaseKey(KEY_UP);
7771 ReleaseKey(KEY_DOWN);
7772 PressKey(KEY_UP, 20);
7773 RemoveAIFlag('NEEDSEEUP');
7774 end;
7776 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7777 if GetAIFlag('NEEDSEEDOWN') <> '' then
7778 begin
7779 ReleaseKey(KEY_UP);
7780 ReleaseKey(KEY_DOWN);
7781 PressKey(KEY_DOWN, 20);
7782 RemoveAIFlag('NEEDSEEDOWN');
7783 end;
7785 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7786 if GetAIFlag('GOINHOLE') <> '' then
7787 if not OnGround() then
7788 begin
7789 ReleaseKey(KEY_LEFT);
7790 ReleaseKey(KEY_RIGHT);
7791 RemoveAIFlag('GOINHOLE');
7792 SetAIFlag('FALLINHOLE', '1');
7793 end;
7795 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7796 if GetAIFlag('FALLINHOLE') <> '' then
7797 if OnGround() then
7798 RemoveAIFlag('FALLINHOLE');
7800 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7801 if not (KeyPressed(KEY_LEFT) or KeyPressed(KEY_RIGHT)) then
7802 if GetAIFlag('FALLINHOLE') = '' then
7803 if (not OnLadder()) or (FObj.Vel.Y >= 0) or (OnTopLift()) then
7804 if Rnd(2) then
7805 GoLeft(360)
7806 else
7807 GoRight(360);
7809 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7810 if OnGround() and
7811 CanJumpUp(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*32) and
7812 Rnd(8) then
7813 Jump();
7815 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7816 if OnGround() and NearHole() then
7817 if NearDeepHole() then // Åñëè ýòî áåçäíà
7818 case Random(6) of
7819 0..3: Turn(); // Áåæèì îáðàòíî
7820 4: Jump(); // Ïðûãàåì
7821 5: begin // Ïðûãàåì îáðàòíî
7822 Turn();
7823 Jump();
7824 end;
7825 end
7826 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7827 if GetAIFlag('GOINHOLE') = '' then
7828 case Random(6) of
7829 0: Turn(); // Íå íóæíî òóäà
7830 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7831 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7832 if BorderHole() then
7833 SetAIFlag('GOINHOLE', '1');
7834 end;
7836 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7837 if (not CanRun()) and OnGround() then
7838 begin
7839 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7840 if CanJumpOver() or OnLadder() then
7841 Jump()
7842 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7843 if Random(2) = 0 then
7844 begin
7845 if IsSafeTrigger() then
7846 PressKey(KEY_OPEN);
7847 end else
7848 Turn();
7849 end;
7851 // Îñòàëîñü ìàëî âîçäóõà:
7852 if FAir < 36 * 2 then
7853 Jump(20);
7855 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7856 if (FMegaRulez[MR_SUIT] < gTime) and ((FLastHit = HIT_ACID) or (Healthy() <= 1)) then
7857 if BodyInAcid(0, 0) then
7858 Jump();
7859 end;
7861 function TBot.FullInStep(XInc, YInc: Integer): Boolean;
7862 begin
7863 Result := g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc,
7864 PLAYER_RECT.Width, PLAYER_RECT.Height, PANEL_STEP, False);
7865 end;
7867 {function TBot.NeedItem(Item: Byte): Byte;
7868 begin
7869 Result := 4;
7870 end;}
7872 procedure TBot.SelectWeapon(Dist: Integer);
7873 var
7874 a: Integer;
7876 function HaveAmmo(weapon: Byte): Boolean;
7877 begin
7878 case weapon of
7879 WEAPON_PISTOL: Result := FAmmo[A_BULLETS] >= 1;
7880 WEAPON_SHOTGUN1: Result := FAmmo[A_SHELLS] >= 1;
7881 WEAPON_SHOTGUN2: Result := FAmmo[A_SHELLS] >= 2;
7882 WEAPON_CHAINGUN: Result := FAmmo[A_BULLETS] >= 10;
7883 WEAPON_ROCKETLAUNCHER: Result := FAmmo[A_ROCKETS] >= 1;
7884 WEAPON_PLASMA: Result := FAmmo[A_CELLS] >= 10;
7885 WEAPON_BFG: Result := FAmmo[A_CELLS] >= 40;
7886 WEAPON_SUPERPULEMET: Result := FAmmo[A_SHELLS] >= 1;
7887 WEAPON_FLAMETHROWER: Result := FAmmo[A_FUEL] >= 1;
7888 else Result := True;
7889 end;
7890 end;
7892 begin
7893 if Dist = -1 then Dist := BOT_LONGDIST;
7895 if Dist > BOT_LONGDIST then
7896 begin // Äàëüíèé áîé
7897 for a := 0 to 9 do
7898 if FWeapon[FDifficult.WeaponPrior[a]] and HaveAmmo(FDifficult.WeaponPrior[a]) then
7899 begin
7900 FSelectedWeapon := FDifficult.WeaponPrior[a];
7901 Break;
7902 end;
7903 end
7904 else //if Dist > BOT_UNSAFEDIST then
7905 begin // Áëèæíèé áîé
7906 for a := 0 to 9 do
7907 if FWeapon[FDifficult.CloseWeaponPrior[a]] and HaveAmmo(FDifficult.CloseWeaponPrior[a]) then
7908 begin
7909 FSelectedWeapon := FDifficult.CloseWeaponPrior[a];
7910 Break;
7911 end;
7912 end;
7913 { else
7914 begin
7915 for a := 0 to 9 do
7916 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7917 begin
7918 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7919 Break;
7920 end;
7921 end;}
7922 end;
7924 function TBot.PickItem(ItemType: Byte; force: Boolean; var remove: Boolean): Boolean;
7925 begin
7926 Result := inherited PickItem(ItemType, force, remove);
7928 if Result then SetAIFlag('SELECTWEAPON', '1');
7929 end;
7931 function TBot.Heal(value: Word; Soft: Boolean): Boolean;
7932 begin
7933 Result := inherited Heal(value, Soft);
7934 end;
7936 function TBot.Healthy(): Byte;
7937 begin
7938 if FMegaRulez[MR_INVUL] >= gTime then Result := 3
7939 else if (FHealth > 80) or ((FHealth > 50) and (FArmor > 20)) then Result := 3
7940 else if (FHealth > 50) then Result := 2
7941 else if (FHealth > 20) then Result := 1
7942 else Result := 0;
7943 end;
7945 function TBot.TargetOnScreen(TX, TY: Integer): Boolean;
7946 begin
7947 Result := (Abs(FObj.X-TX) <= Trunc(gPlayerScreenSize.X*0.6)) and
7948 (Abs(FObj.Y-TY) <= Trunc(gPlayerScreenSize.Y*0.6));
7949 end;
7951 procedure TBot.OnDamage(Angle: SmallInt);
7952 var
7953 pla: TPlayer;
7954 mon: TMonster;
7955 ok: Boolean;
7956 begin
7957 inherited;
7959 if (Angle = 0) or (Angle = 180) then
7960 begin
7961 ok := False;
7962 if (g_GetUIDType(FLastSpawnerUID) = UID_PLAYER) and
7963 LongBool(gGameSettings.Options and GAME_OPTION_BOTVSPLAYER) then
7964 begin // Èãðîê
7965 pla := g_Player_Get(FLastSpawnerUID);
7966 ok := not TargetOnScreen(pla.FObj.X + PLAYER_RECT.X,
7967 pla.FObj.Y + PLAYER_RECT.Y);
7968 end
7969 else
7970 if (g_GetUIDType(FLastSpawnerUID) = UID_MONSTER) and
7971 LongBool(gGameSettings.Options and GAME_OPTION_BOTVSMONSTER) then
7972 begin // Ìîíñòð
7973 mon := g_Monsters_ByUID(FLastSpawnerUID);
7974 ok := not TargetOnScreen(mon.Obj.X + mon.Obj.Rect.X,
7975 mon.Obj.Y + mon.Obj.Rect.Y);
7976 end;
7978 if ok then
7979 if Angle = 0 then
7980 SetAIFlag('ATTACKLEFT', '1')
7981 else
7982 SetAIFlag('ATTACKRIGHT', '1');
7983 end;
7984 end;
7986 function TBot.RunDirection(): TDirection;
7987 begin
7988 if Abs(Vel.X) >= 1 then
7989 begin
7990 if Vel.X > 0 then Result := TDirection.D_RIGHT else Result := TDirection.D_LEFT;
7991 end else
7992 Result := FDirection;
7993 end;
7995 function TBot.GetRnd(a: Byte): Boolean;
7996 begin
7997 if a = 0 then Result := False
7998 else if a = 255 then Result := True
7999 else Result := Random(256) > 255-a;
8000 end;
8002 function TBot.GetInterval(a: Byte; radius: SmallInt): SmallInt;
8003 begin
8004 Result := Round((255-a)/255*radius*(Random(2)-1));
8005 end;
8008 procedure TDifficult.save (st: TStream);
8009 begin
8010 utils.writeInt(st, Byte(DiagFire));
8011 utils.writeInt(st, Byte(InvisFire));
8012 utils.writeInt(st, Byte(DiagPrecision));
8013 utils.writeInt(st, Byte(FlyPrecision));
8014 utils.writeInt(st, Byte(Cover));
8015 utils.writeInt(st, Byte(CloseJump));
8016 st.WriteBuffer(WeaponPrior[Low(WeaponPrior)], sizeof(WeaponPrior));
8017 st.WriteBuffer(CloseWeaponPrior[Low(CloseWeaponPrior)], sizeof(CloseWeaponPrior));
8018 end;
8020 procedure TDifficult.load (st: TStream);
8021 begin
8022 DiagFire := utils.readByte(st);
8023 InvisFire := utils.readByte(st);
8024 DiagPrecision := utils.readByte(st);
8025 FlyPrecision := utils.readByte(st);
8026 Cover := utils.readByte(st);
8027 CloseJump := utils.readByte(st);
8028 st.ReadBuffer(WeaponPrior[Low(WeaponPrior)], sizeof(WeaponPrior));
8029 st.ReadBuffer(CloseWeaponPrior[Low(CloseWeaponPrior)], sizeof(CloseWeaponPrior));
8030 end;
8033 procedure TBot.SaveState (st: TStream);
8034 var
8035 i: Integer;
8036 dw: Integer;
8037 begin
8038 inherited SaveState(st);
8039 utils.writeSign(st, 'BOT0');
8040 // Âûáðàííîå îðóæèå
8041 utils.writeInt(st, Byte(FSelectedWeapon));
8042 // UID öåëè
8043 utils.writeInt(st, Word(FTargetUID));
8044 // Âðåìÿ ïîòåðè öåëè
8045 utils.writeInt(st, LongWord(FLastVisible));
8046 // Êîëè÷åñòâî ôëàãîâ ÈÈ
8047 dw := Length(FAIFlags);
8048 utils.writeInt(st, LongInt(dw));
8049 // Ôëàãè ÈÈ
8050 for i := 0 to dw-1 do
8051 begin
8052 utils.writeStr(st, FAIFlags[i].Name, 20);
8053 utils.writeStr(st, FAIFlags[i].Value, 20);
8054 end;
8055 // Íàñòðîéêè ñëîæíîñòè
8056 FDifficult.save(st);
8057 end;
8060 procedure TBot.LoadState (st: TStream);
8061 var
8062 i: Integer;
8063 dw: Integer;
8064 begin
8065 inherited LoadState(st);
8066 if not utils.checkSign(st, 'BOT0') then raise XStreamError.Create('invalid bot signature');
8067 // Âûáðàííîå îðóæèå
8068 FSelectedWeapon := utils.readByte(st);
8069 // UID öåëè
8070 FTargetUID := utils.readWord(st);
8071 // Âðåìÿ ïîòåðè öåëè
8072 FLastVisible := utils.readLongWord(st);
8073 // Êîëè÷åñòâî ôëàãîâ ÈÈ
8074 dw := utils.readLongInt(st);
8075 if (dw < 0) or (dw > 16384) then raise XStreamError.Create('invalid number of bot AI flags');
8076 SetLength(FAIFlags, dw);
8077 // Ôëàãè ÈÈ
8078 for i := 0 to dw-1 do
8079 begin
8080 FAIFlags[i].Name := utils.readStr(st, 20);
8081 FAIFlags[i].Value := utils.readStr(st, 20);
8082 end;
8083 // Íàñòðîéêè ñëîæíîñòè
8084 FDifficult.load(st);
8085 end;
8088 begin
8089 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');
8090 conRegVar('player_indicator_style', @gPlayerIndicatorStyle, 'Visual appearance of indicator', 'Visual appearance of indicator');
8091 end.