Fix friendly-fire issues; rename its options and constants in code to clarify them
[d2df-sdl.git] / src / game / g_player.pas
blobfea3cd5f28cde736b149814d30b22282f0221b81
1 (* Copyright (C) 2016 - The Doom2D.org team & involved community members <http://www.doom2d.org>.
2 * This file is part of Doom2D Forever.
4 * This program is free software: you can redistribute it and/or modify it under the terms of
5 * the GNU General Public License as published by the Free Software Foundation, version 3 of
6 * the License ONLY.
8 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 * See the GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License along with this program.
13 * If not, see <http://www.gnu.org/licenses/>.
16 {$INCLUDE ../shared/a_modes.inc}
17 {$M+}
18 unit g_player;
20 interface
22 uses
23 SysUtils, Classes,
24 {$IFDEF USE_MEMPOOL}mempool,{$ENDIF}
25 {$IFDEF ENABLE_SOUND}
26 g_sound,
27 {$ENDIF}
28 e_graphics, g_playermodel, g_basic, g_textures,
29 g_weapons, g_phys, g_saveload, MAPDEF,
30 g_panel;
32 const
33 KEY_LEFT = 1;
34 KEY_RIGHT = 2;
35 KEY_UP = 3;
36 KEY_DOWN = 4;
37 KEY_FIRE = 5;
38 KEY_OPEN = 6;
39 KEY_JUMP = 7;
40 KEY_CHAT = 8;
42 WP_PREV = 0;
43 WP_NEXT = 1;
44 WP_FACT = WP_PREV;
45 WP_LACT = WP_NEXT;
47 R_ITEM_BACKPACK = 0;
48 R_KEY_RED = 1;
49 R_KEY_GREEN = 2;
50 R_KEY_BLUE = 3;
51 R_BERSERK = 4;
53 MR_SUIT = 0;
54 MR_INVUL = 1;
55 MR_INVIS = 2;
56 MR_MAX = 2;
58 A_BULLETS = 0;
59 A_SHELLS = 1;
60 A_ROCKETS = 2;
61 A_CELLS = 3;
62 A_FUEL = 4;
63 A_HIGH = 4;
65 AmmoLimits: Array [0..1] of Array [A_BULLETS..A_HIGH] of Word =
66 ((200, 50, 50, 300, 100),
67 (400, 100, 100, 600, 200));
69 K_SIMPLEKILL = 0;
70 K_HARDKILL = 1;
71 K_EXTRAHARDKILL = 2;
72 K_FALLKILL = 3;
74 T_RESPAWN = 0;
75 T_SWITCH = 1;
76 T_USE = 2;
77 T_FLAGCAP = 3;
79 TEAM_NONE = 0;
80 TEAM_RED = 1;
81 TEAM_BLUE = 2;
82 TEAM_COOP = 3;
84 SHELL_BULLET = 0;
85 SHELL_SHELL = 1;
86 SHELL_DBLSHELL = 2;
88 ANGLE_NONE = Low(SmallInt);
90 CORPSE_STATE_REMOVEME = 0;
91 CORPSE_STATE_NORMAL = 1;
92 CORPSE_STATE_MESS = 2;
94 PLAYER_RECT: TRectWH = (X:15; Y:12; Width:34; Height:52);
95 PLAYER_RECT_CX = 15+(34 div 2);
96 PLAYER_RECT_CY = 12+(52 div 2);
97 PLAYER_CORPSERECT: TRectWH = (X:15; Y:48; Width:34; Height:16);
99 PLAYER_HP_SOFT = 100;
100 PLAYER_HP_LIMIT = 200;
101 PLAYER_AP_SOFT = 100;
102 PLAYER_AP_LIMIT = 200;
103 SUICIDE_DAMAGE = 112;
104 WEAPON_DELAY = 5;
106 PLAYER_BURN_TIME = 110;
108 PLAYER1_DEF_COLOR: TRGB = (R:64; G:175; B:48);
109 PLAYER2_DEF_COLOR: TRGB = (R:96; G:96; B:96);
111 type
112 TPlayerStat = record
113 Num: Integer;
114 Ping: Word;
115 Loss: Byte;
116 Name: String;
117 Team: Byte;
118 Frags: SmallInt;
119 Deaths: SmallInt;
120 Lives: Byte;
121 Kills: Word;
122 Color: TRGB;
123 Spectator: Boolean;
124 UID: Word;
125 end;
127 TPlayerStatArray = Array of TPlayerStat;
129 TPlayerSavedState = record
130 Health: Integer;
131 Armor: Integer;
132 Air: Integer;
133 JetFuel: Integer;
134 CurrWeap: Byte;
135 NextWeap: WORD;
136 NextWeapDelay: Byte;
137 Ammo: Array [A_BULLETS..A_HIGH] of Word;
138 MaxAmmo: Array [A_BULLETS..A_HIGH] of Word;
139 Weapon: Array [WP_FIRST..WP_LAST] of Boolean;
140 Inventory: Set of R_ITEM_BACKPACK..R_BERSERK;
141 Used: Boolean;
142 end;
144 TKeyState = record
145 Pressed: Boolean;
146 Time: Word;
147 end;
149 TPlayer = class{$IFDEF USE_MEMPOOL}(TPoolObject){$ENDIF}
150 private
151 FIamBot: Boolean;
152 FUID: Word;
153 FName: String;
154 FTeam: Byte;
155 FAlive: Boolean;
156 FSpawned: Boolean;
157 FDirection: TDirection;
158 FHealth: Integer;
159 FLives: Byte;
160 FArmor: Integer;
161 FAir: Integer;
162 FPain: Integer;
163 FPickup: Integer;
164 FKills: Integer;
165 FMonsterKills: Integer;
166 FFrags: Integer;
167 FFragCombo: Byte;
168 FLastFrag: LongWord;
169 FComboEvnt: Integer;
170 FDeath: Integer;
171 FCanJetpack: Boolean;
172 FJetFuel: Integer;
173 FFlag: Byte;
174 FSecrets: Integer;
175 FCurrWeap: Byte;
176 FNextWeap: WORD;
177 FNextWeapDelay: Byte; // frames
178 FBFGFireCounter: SmallInt;
179 FLastSpawnerUID: Word;
180 FLastHit: Byte;
181 FObj: TObj;
182 FXTo, FYTo: Integer;
183 FSpectatePlayer: Integer;
184 FFirePainTime: Integer;
185 FFireAttacker: Word;
187 FSavedStateNum: Integer;
189 FModel: TPlayerModel;
190 FPunchAnim: TAnimation;
191 FActionPrior: Byte;
192 FActionAnim: Byte;
193 FActionForce: Boolean;
194 FActionChanged: Boolean;
195 FAngle: SmallInt;
196 FFireAngle: SmallInt;
197 FIncCamOld: Integer;
198 FIncCam: Integer;
199 FSlopeOld: Integer;
200 FShellTimer: Integer;
201 FShellType: Byte;
202 {$IFDEF ENABLE_SOUND}
203 FSawSound: TPlayableSound;
204 FSawSoundIdle: TPlayableSound;
205 FSawSoundHit: TPlayableSound;
206 FSawSoundSelect: TPlayableSound;
207 FFlameSoundOn: TPlayableSound;
208 FFlameSoundOff: TPlayableSound;
209 FFlameSoundWork: TPlayableSound;
210 FJetSoundOn: TPlayableSound;
211 FJetSoundOff: TPlayableSound;
212 FJetSoundFly: TPlayableSound;
213 {$ENDIF}
214 FGodMode: Boolean;
215 FNoTarget: Boolean;
216 FNoReload: Boolean;
217 FJustTeleported: Boolean;
218 FNetTime: LongWord;
219 mEDamageType: Integer;
222 function CollideLevel(XInc, YInc: Integer): Boolean;
223 function StayOnStep(XInc, YInc: Integer): Boolean;
224 function HeadInLiquid(XInc, YInc: Integer): Boolean;
225 function BodyInLiquid(XInc, YInc: Integer): Boolean;
226 function BodyInAcid(XInc, YInc: Integer): Boolean;
227 function FullInLift(XInc, YInc: Integer): Integer;
228 {procedure CollideItem();}
229 procedure FlySmoke(Times: DWORD = 1);
230 procedure OnFireFlame(Times: DWORD = 1);
231 function GetAmmoByWeapon(Weapon: Byte): Word;
232 procedure SetAction(Action: Byte; Force: Boolean = False);
233 procedure OnDamage(Angle: SmallInt); virtual;
234 function firediry(): Integer;
235 procedure DoPunch();
237 procedure Run(Direction: TDirection);
238 procedure NextWeapon();
239 procedure PrevWeapon();
240 procedure SeeUp();
241 procedure SeeDown();
242 procedure Fire();
243 procedure Jump();
244 procedure Use();
246 function getNextWeaponIndex (): Byte; // returns 255 for "no switch"
247 procedure resetWeaponQueue ();
248 function hasAmmoForWeapon (weapon: Byte): Boolean;
249 function hasAmmoForShooting (weapon: Byte): Boolean;
250 function shouldSwitch (weapon: Byte; hadWeapon: Boolean) : Boolean;
252 procedure doDamage (v: Integer);
254 function refreshCorpse(): Boolean;
256 public
257 FDamageBuffer: Integer;
259 FAmmo: Array [A_BULLETS..A_HIGH] of Word;
260 FMaxAmmo: Array [A_BULLETS..A_HIGH] of Word;
261 FWeapon: Array [WP_FIRST..WP_LAST] of Boolean;
262 FInventory: Set of R_ITEM_BACKPACK..R_BERSERK;
263 FBerserk: Integer;
264 FPowerups: Array [MR_SUIT..MR_MAX] of DWORD;
265 FReloading: Array [WP_FIRST..WP_LAST] of Word;
266 FTime: Array [T_RESPAWN..T_FLAGCAP] of DWORD;
267 FKeys: Array [KEY_LEFT..KEY_CHAT] of TKeyState;
268 FWeapSwitchMode: Byte;
269 FWeapPreferences: Array [WP_FIRST .. WP_LAST+1] of Byte;
270 FSwitchToEmpty: Byte;
271 FSkipIronFist: Byte;
272 FColor: TRGB;
273 FPreferredTeam: Byte;
274 FSpectator: Boolean;
275 FNoRespawn: Boolean;
276 FWantsInGame: Boolean;
277 FGhost: Boolean;
278 FPhysics: Boolean;
279 FFlaming: Boolean;
280 FJetpack: Boolean;
281 FActualModelName: string;
282 FClientID: SmallInt;
283 FPing: Word;
284 FLoss: Byte;
285 FReady: Boolean;
286 FDummy: Boolean;
287 FFireTime: Integer;
288 FSpawnInvul: Integer;
289 FHandicap: Integer;
290 FWaitForFirstSpawn: Boolean; // set to `true` in server, used to spawn a player on first full state request
291 FCorpse: Integer;
293 // debug: viewport offset
294 viewPortX, viewPortY, viewPortW, viewPortH: Integer;
296 function isValidViewPort (): Boolean; inline;
298 constructor Create(); virtual;
299 destructor Destroy(); override;
300 procedure Respawn(Silent: Boolean; Force: Boolean = False); virtual;
301 function GetRespawnPoint(): Byte;
302 procedure PressKey(Key: Byte; Time: Word = 1);
303 procedure ReleaseKeys();
304 procedure SetModel(ModelName: String);
305 procedure SetColor(Color: TRGB);
306 function GetColor(): TRGB;
307 procedure SetWeapon(W: Byte);
308 function IsKeyPressed(K: Byte): Boolean;
309 function GetKeys(): Byte;
310 function PickItem(ItemType: Byte; arespawn: Boolean; var remove: Boolean): Boolean; virtual;
311 procedure SetWeaponPrefs(Prefs: Array of Byte);
312 procedure SetWeaponPref(Weapon, Pref: Byte);
313 function GetWeaponPref(Weapon: Byte) : Byte;
314 function GetMorePrefered() : Byte;
315 function MaySwitch(Weapon: Byte) : Boolean;
316 function Collide(X, Y: Integer; Width, Height: Word): Boolean; overload;
317 function Collide(Panel: TPanel): Boolean; overload;
318 function Collide(X, Y: Integer): Boolean; overload;
319 procedure SetDirection(Direction: TDirection);
320 procedure GetSecret();
321 function TeleportTo(X, Y: Integer; silent: Boolean; dir: Byte): Boolean;
322 procedure Touch();
323 procedure Push(vx, vy: Integer);
324 procedure ChangeModel(ModelName: String);
325 procedure SwitchTeam;
326 procedure ChangeTeam(Team: Byte);
327 procedure BFGHit();
328 function GetFlag(Flag: Byte): Boolean;
329 procedure SetFlag(Flag: Byte);
330 function DropFlag(Silent: Boolean = True; DoThrow: Boolean = False): Boolean;
331 function TryDropFlag(): Boolean;
332 procedure TankRamboCheats(Health: Boolean);
333 procedure RestoreHealthArmor();
334 procedure FragCombo();
335 procedure GiveItem(ItemType: Byte);
336 procedure Damage(value: Word; SpawnerUID: Word; vx, vy: Integer; t: Byte); virtual;
337 function Heal(value: Word; Soft: Boolean): Boolean; virtual;
338 procedure MakeBloodVector(Count: Word; VelX, VelY: Integer);
339 procedure MakeBloodSimple(Count: Word);
340 procedure Kill(KillType: Byte; SpawnerUID: Word; t: Byte);
341 procedure Reset(Force: Boolean);
342 procedure Spectate(NoMove: Boolean = False);
343 procedure SwitchNoClip;
344 procedure SoftReset();
345 procedure Draw(); virtual;
346 procedure DrawPain();
347 procedure DrawPickup();
348 procedure DrawOverlay();
349 procedure DrawAim();
350 procedure DrawIndicator(Color: TRGB);
351 procedure DrawBubble();
352 procedure DrawGUI();
353 procedure PreUpdate();
354 procedure Update(); virtual;
355 procedure PreserveState();
356 procedure RestoreState();
357 procedure SaveState (st: TStream); virtual;
358 procedure LoadState (st: TStream); virtual;
359 {$IFDEF ENABLE_SOUND}
360 procedure PauseSounds(Enable: Boolean);
361 {$ENDIF}
362 procedure NetFire(Wpn: Byte; X, Y, AX, AY: Integer; WID: Integer = -1);
363 procedure DoLerp(Level: Integer = 2);
364 procedure SetLerp(XTo, YTo: Integer);
365 procedure ProcessWeaponAction(Action: Byte);
366 procedure QueueWeaponSwitch(Weapon: Byte);
367 procedure RealizeCurrentWeapon();
368 procedure FlamerOn;
369 procedure FlamerOff;
370 procedure JetpackOn;
371 procedure JetpackOff;
372 procedure CatchFire(Attacker: Word; Timeout: Integer = PLAYER_BURN_TIME);
374 //WARNING! this does nothing for now, but still call it!
375 procedure positionChanged (); //WARNING! call this after entity position was changed, or coldet will not work right!
377 procedure getMapBox (out x, y, w, h: Integer); inline;
378 procedure moveBy (dx, dy: Integer); inline;
380 function getCameraObj(): TObj;
382 public
383 property Vel: TPoint2i read FObj.Vel;
384 property Obj: TObj read FObj;
386 property Name: String read FName write FName;
387 property Model: TPlayerModel read FModel;
388 property Health: Integer read FHealth write FHealth;
389 property Lives: Byte read FLives write FLives;
390 property Armor: Integer read FArmor write FArmor;
391 property Air: Integer read FAir write FAir;
392 property JetFuel: Integer read FJetFuel write FJetFuel;
393 property Frags: Integer read FFrags write FFrags;
394 property Death: Integer read FDeath write FDeath;
395 property Kills: Integer read FKills write FKills;
396 property CurrWeap: Byte read FCurrWeap write FCurrWeap;
397 property WeapSwitchMode: Byte read FWeapSwitchMode write FWeapSwitchMode;
398 property SwitchToEmpty: Byte read FSwitchToEmpty write FSwitchToEmpty;
399 property SkipIronFist: Byte read FSkipIronFist write FSkipIronFist;
400 property MonsterKills: Integer read FMonsterKills write FMonsterKills;
401 property Secrets: Integer read FSecrets;
402 property GodMode: Boolean read FGodMode write FGodMode;
403 property NoTarget: Boolean read FNoTarget write FNoTarget;
404 property NoReload: Boolean read FNoReload write FNoReload;
405 property alive: Boolean read FAlive write FAlive;
406 property Flag: Byte read FFlag;
407 property Team: Byte read FTeam write FTeam;
408 property Direction: TDirection read FDirection;
409 property GameX: Integer read FObj.X write FObj.X;
410 property GameY: Integer read FObj.Y write FObj.Y;
411 property GameVelX: Integer read FObj.Vel.X write FObj.Vel.X;
412 property GameVelY: Integer read FObj.Vel.Y write FObj.Vel.Y;
413 property GameAccelX: Integer read FObj.Accel.X write FObj.Accel.X;
414 property GameAccelY: Integer read FObj.Accel.Y write FObj.Accel.Y;
415 property IncCam: Integer read FIncCam write FIncCam;
416 property IncCamOld: Integer read FIncCamOld write FIncCamOld;
417 property SlopeOld: Integer read FSlopeOld write FSlopeOld;
418 property UID: Word read FUID write FUID;
419 property JustTeleported: Boolean read FJustTeleported write FJustTeleported;
420 property NetTime: LongWord read FNetTime write FNetTime;
422 published
423 property eName: String read FName write FName;
424 property eHealth: Integer read FHealth write FHealth;
425 property eLives: Byte read FLives write FLives;
426 property eArmor: Integer read FArmor write FArmor;
427 property eAir: Integer read FAir write FAir;
428 property eJetFuel: Integer read FJetFuel write FJetFuel;
429 property eFrags: Integer read FFrags write FFrags;
430 property eDeath: Integer read FDeath write FDeath;
431 property eKills: Integer read FKills write FKills;
432 property eCurrWeap: Byte read FCurrWeap write FCurrWeap;
433 property eMonsterKills: Integer read FMonsterKills write FMonsterKills;
434 property eSecrets: Integer read FSecrets write FSecrets;
435 property eGodMode: Boolean read FGodMode write FGodMode;
436 property eNoTarget: Boolean read FNoTarget write FNoTarget;
437 property eNoReload: Boolean read FNoReload write FNoReload;
438 property eAlive: Boolean read FAlive write FAlive;
439 property eFlag: Byte read FFlag;
440 property eTeam: Byte read FTeam write FTeam;
441 property eDirection: TDirection read FDirection;
442 property eGameX: Integer read FObj.X write FObj.X;
443 property eGameY: Integer read FObj.Y write FObj.Y;
444 property eGameVelX: Integer read FObj.Vel.X write FObj.Vel.X;
445 property eGameVelY: Integer read FObj.Vel.Y write FObj.Vel.Y;
446 property eGameAccelX: Integer read FObj.Accel.X write FObj.Accel.X;
447 property eGameAccelY: Integer read FObj.Accel.Y write FObj.Accel.Y;
448 property eIncCam: Integer read FIncCam write FIncCam;
449 property eUID: Word read FUID;
450 property eJustTeleported: Boolean read FJustTeleported;
451 property eNetTime: LongWord read FNetTime;
453 // set this before assigning something to `eDamage`
454 property eDamageType: Integer read mEDamageType write mEDamageType;
455 property eDamage: Integer write doDamage;
456 end;
458 TDifficult = record
459 public
460 DiagFire: Byte;
461 InvisFire: Byte;
462 DiagPrecision: Byte;
463 FlyPrecision: Byte;
464 Cover: Byte;
465 CloseJump: Byte;
466 WeaponPrior: packed array [WP_FIRST..WP_LAST] of Byte;
467 CloseWeaponPrior: packed array [WP_FIRST..WP_LAST] of Byte;
468 //SafeWeaponPrior: Array [WP_FIRST..WP_LAST] of Byte;
470 public
471 procedure save (st: TStream);
472 procedure load (st: TStream);
473 end;
475 TAIFlag = record
476 Name: String;
477 Value: String;
478 end;
480 TBot = class(TPlayer)
481 private
482 FSelectedWeapon: Byte;
483 FTargetUID: Word;
484 FLastVisible: DWORD;
485 FAIFlags: Array of TAIFlag;
486 FDifficult: TDifficult;
488 function GetRnd(a: Byte): Boolean;
489 function GetInterval(a: Byte; radius: SmallInt): SmallInt;
490 function RunDirection(): TDirection;
491 function FullInStep(XInc, YInc: Integer): Boolean;
492 //function NeedItem(Item: Byte): Byte;
493 procedure SelectWeapon(Dist: Integer);
494 procedure SetAIFlag(const aName, fValue: String);
495 function GetAIFlag(const aName: String): String;
496 procedure RemoveAIFlag(const aName: String);
497 function Healthy(): Byte;
498 procedure UpdateMove();
499 procedure UpdateCombat();
500 function KeyPressed(Key: Word): Boolean;
501 procedure ReleaseKey(Key: Byte);
502 function TargetOnScreen(TX, TY: Integer): Boolean;
503 procedure OnDamage(Angle: SmallInt); override;
505 public
506 procedure Respawn(Silent: Boolean; Force: Boolean = False); override;
507 constructor Create(); override;
508 destructor Destroy(); override;
509 procedure Draw(); override;
510 function PickItem(ItemType: Byte; force: Boolean; var remove: Boolean): Boolean; override;
511 function Heal(value: Word; Soft: Boolean): Boolean; override;
512 procedure Update(); override;
513 procedure SaveState (st: TStream); override;
514 procedure LoadState (st: TStream); override;
515 end;
517 PGib = ^TGib;
518 TGib = record
519 alive: Boolean;
520 ID: DWORD;
521 MaskID: DWORD;
522 RAngle: Integer;
523 Color: TRGB;
524 Obj: TObj;
526 procedure getMapBox (out x, y, w, h: Integer); inline;
527 procedure moveBy (dx, dy: Integer); inline;
529 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
530 end;
533 PShell = ^TShell;
534 TShell = record
535 SpriteID: DWORD;
536 alive: Boolean;
537 SType: Byte;
538 RAngle: Integer;
539 Timeout: Cardinal;
540 CX, CY: Integer;
541 Obj: TObj;
543 procedure getMapBox (out x, y, w, h: Integer); inline;
544 procedure moveBy (dx, dy: Integer); inline;
546 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
547 end;
549 TCorpse = class{$IFDEF USE_MEMPOOL}(TPoolObject){$ENDIF}
550 private
551 FModelName: String;
552 FMess: Boolean;
553 FState: Byte;
554 FDamage: Byte;
555 FColor: TRGB;
556 FObj: TObj;
557 FPlayerUID: Word;
558 FAnimation: TAnimation;
559 FAnimationMask: TAnimation;
561 public
562 constructor Create(X, Y: Integer; ModelName: String; aMess: Boolean);
563 destructor Destroy(); override;
564 procedure Damage(Value: Word; SpawnerUID: Word; vx, vy: Integer);
565 procedure Update();
566 procedure Draw();
567 procedure SaveState (st: TStream);
568 procedure LoadState (st: TStream);
570 procedure getMapBox (out x, y, w, h: Integer); inline;
571 procedure moveBy (dx, dy: Integer); inline;
573 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
575 function ObjPtr (): PObj; inline;
577 property Obj: TObj read FObj; // copies object
578 property State: Byte read FState;
579 property Mess: Boolean read FMess;
580 end;
582 TTeamStat = Array [TEAM_RED..TEAM_BLUE] of
583 record
584 Score: SmallInt;
585 end;
588 gPlayers: Array of TPlayer;
589 gCorpses: Array of TCorpse;
590 gGibs: Array of TGib;
591 gShells: Array of TShell;
592 gTeamStat: TTeamStat;
593 gFly: Boolean;
594 gAimLine: Boolean;
595 gChatBubble: Integer;
596 gPlayerIndicator: Integer = 1;
597 gPlayerIndicatorStyle: Integer;
598 gNumBots: Word;
599 gSpectLatchPID1: Word;
600 gSpectLatchPID2: Word;
601 MAX_RUNVEL: Integer = 8;
602 VEL_JUMP: Integer = 10;
603 SHELL_TIMEOUT: Cardinal = 60000;
605 function Lerp(X, Y, Factor: Integer): Integer;
607 procedure g_Gibs_SetMax(Count: Word);
608 function g_Gibs_GetMax(): Word;
609 procedure g_Corpses_SetMax(Count: Word);
610 function g_Corpses_GetMax(): Word;
611 procedure g_Force_Model_Set(Mode: Word);
612 function g_Force_Model_Get(): Word;
613 procedure g_Forced_Model_SetName(Model: String);
614 function g_Forced_Model_GetName(): String;
615 procedure g_Shells_SetMax(Count: Word);
616 function g_Shells_GetMax(): Word;
618 procedure g_Player_Init();
619 procedure g_Player_Free();
620 function g_Player_Create(ModelName: String; Color: TRGB; Team: Byte; Bot: Boolean): Word;
621 function g_Player_CreateFromState (st: TStream): Word;
622 procedure g_Player_Remove(UID: Word);
623 procedure g_Player_ResetTeams();
624 procedure g_Player_PreUpdate();
625 procedure g_Player_UpdateAll();
626 procedure g_Player_DrawAll();
627 procedure g_Player_DrawDebug(p: TPlayer);
628 procedure g_Player_DrawHealth();
629 procedure g_Player_RememberAll();
630 procedure g_Player_ResetAll(Force, Silent: Boolean);
631 function g_Player_Get(UID: Word): TPlayer;
632 function g_Player_GetCount(): Byte;
633 function g_Player_GetStats(): TPlayerStatArray;
634 function g_Player_ExistingName(Name: String): Boolean;
635 function g_Player_CreateCorpse(Player: TPlayer): Integer;
636 procedure g_Player_CreateGibs(fX, fY: Integer; ModelName: String; fColor: TRGB);
637 procedure g_Player_CreateShell(fX, fY, dX, dY: Integer; T: Byte);
638 procedure g_Player_UpdatePhysicalObjects();
639 procedure g_Player_DrawCorpses();
640 procedure g_Player_DrawShells();
641 procedure g_Player_RemoveAllCorpses();
642 procedure g_Player_Corpses_SaveState (st: TStream);
643 procedure g_Player_Corpses_LoadState (st: TStream);
644 procedure g_Player_ResetReady();
645 procedure g_Bot_Add(Team, Difficult: Byte; Handicap: Integer = 100);
646 procedure g_Bot_AddList(Team: Byte; lname: ShortString; num: Integer = -1; Handicap: Integer = 100);
647 procedure g_Bot_MixNames();
648 procedure g_Bot_RemoveAll();
649 function g_Bot_GetCount(): Integer;
651 implementation
653 uses
654 {$INCLUDE ../nogl/noGLuses.inc}
655 {$IFDEF ENABLE_HOLMES}
656 g_holmes,
657 {$ENDIF}
658 e_log, g_map, g_items, g_console, g_gfx, Math,
659 g_options, g_triggers, g_menu, g_game, g_grid, e_res,
660 wadreader, g_main, g_monsters, CONFIG, g_language,
661 g_net, g_netmsg, g_window,
662 utils, xstreams;
664 const PLR_SAVE_VERSION = 0;
666 type
667 TBotProfile = record
668 name: ShortString;
669 model: ShortString;
670 team: Byte;
671 color: TRGB;
672 diag_fire: Byte;
673 invis_fire: Byte;
674 diag_precision: Byte;
675 fly_precision: Byte;
676 cover: Byte;
677 close_jump: Byte;
678 w_prior1: Array [WP_FIRST..WP_LAST] of Byte;
679 w_prior2: Array [WP_FIRST..WP_LAST] of Byte;
680 w_prior3: Array [WP_FIRST..WP_LAST] of Byte;
681 end;
683 const
684 TIME_RESPAWN1 = 1500;
685 TIME_RESPAWN2 = 2000;
686 TIME_RESPAWN3 = 3000;
687 AIR_DEF = 360;
688 AIR_MAX = 1091;
689 JET_MAX = 540; // ~30 sec
690 PLAYER_SUIT_TIME = 30000;
691 PLAYER_INVUL_TIME = 30000;
692 PLAYER_INVIS_TIME = 35000;
693 FRAG_COMBO_TIME = 3000;
694 VEL_SW = 4;
695 VEL_FLY = 6;
696 ANGLE_RIGHTUP = 55;
697 ANGLE_RIGHTDOWN = -35;
698 ANGLE_LEFTUP = 125;
699 ANGLE_LEFTDOWN = -145;
700 PLAYER_HEADRECT: TRectWH = (X:24; Y:12; Width:20; Height:12);
701 WEAPONPOINT: Array [TDirection] of TDFPoint = ((X:16; Y:32), (X:47; Y:32));
702 BOT_MAXJUMP = 84;
703 BOT_LONGDIST = 300;
704 BOT_UNSAFEDIST = 128;
705 TEAMCOLOR: Array [TEAM_RED..TEAM_BLUE] of TRGB = ((R:255; G:0; B:0),
706 (R:0; G:0; B:255));
707 DIFFICULT_EASY: TDifficult = (DiagFire: 32; InvisFire: 32; DiagPrecision: 32;
708 FlyPrecision: 32; Cover: 32; CloseJump: 32;
709 WeaponPrior:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior:(0,0,0,0,0,0,0,0,0,0,0));
710 DIFFICULT_MEDIUM: TDifficult = (DiagFire: 127; InvisFire: 127; DiagPrecision: 127;
711 FlyPrecision: 127; Cover: 127; CloseJump: 127;
712 WeaponPrior:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior:(0,0,0,0,0,0,0,0,0,0,0));
713 DIFFICULT_HARD: TDifficult = (DiagFire: 255; InvisFire: 255; DiagPrecision: 255;
714 FlyPrecision: 255; Cover: 255; CloseJump: 255;
715 WeaponPrior:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior:(0,0,0,0,0,0,0,0,0,0,0));
716 WEAPON_PRIOR1: Array [WP_FIRST..WP_LAST] of Byte =
717 (WEAPON_FLAMETHROWER, WEAPON_SUPERCHAINGUN,
718 WEAPON_SHOTGUN2, WEAPON_SHOTGUN1,
719 WEAPON_CHAINGUN, WEAPON_PLASMA, WEAPON_ROCKETLAUNCHER,
720 WEAPON_BFG, WEAPON_PISTOL, WEAPON_SAW, WEAPON_IRONFIST);
721 WEAPON_PRIOR2: Array [WP_FIRST..WP_LAST] of Byte =
722 (WEAPON_FLAMETHROWER, WEAPON_SUPERCHAINGUN,
723 WEAPON_BFG, WEAPON_ROCKETLAUNCHER,
724 WEAPON_SHOTGUN2, WEAPON_PLASMA, WEAPON_SHOTGUN1,
725 WEAPON_CHAINGUN, WEAPON_PISTOL, WEAPON_SAW, WEAPON_IRONFIST);
726 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
727 // (WEAPON_FLAMETHROWER, WEAPON_SUPERCHAINGUN,
728 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
729 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
730 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_IRONFIST);
731 WEAPON_RELOAD: Array [WP_FIRST..WP_LAST] of Byte =
732 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
734 PLAYER_SIGNATURE = $52594C50; // 'PLYR'
735 CORPSE_SIGNATURE = $50524F43; // 'CORP'
737 BOTNAMES_FILENAME = 'botnames.txt';
738 BOTLIST_FILENAME = 'botlist.txt';
741 MaxGibs: Word = 150;
742 MaxCorpses: Word = 20;
743 MaxShells: Word = 300;
744 ForceModel: Word = 0;
745 ForcedModelName: String = STD_PLAYER_MODEL;
746 CurrentGib: Integer = 0;
747 CurrentShell: Integer = 0;
748 BotNames: Array of String;
749 BotList: Array of TBotProfile;
750 SavedStates: Array of TPlayerSavedState;
753 function Lerp(X, Y, Factor: Integer): Integer;
754 begin
755 Result := X + ((Y - X) div Factor);
756 end;
758 function SameTeam(UID1, UID2: Word): Boolean;
759 begin
760 Result := False;
762 if (UID1 > UID_MAX_PLAYER) or (UID1 <= UID_MAX_GAME) or
763 (UID2 > UID_MAX_PLAYER) or (UID2 <= UID_MAX_GAME) then Exit;
765 if (g_Player_Get(UID1) = nil) or (g_Player_Get(UID2) = nil) then Exit;
767 if ((g_Player_Get(UID1).Team = TEAM_NONE) or
768 (g_Player_Get(UID2).Team = TEAM_NONE)) then Exit;
770 Result := g_Player_Get(UID1).FTeam = g_Player_Get(UID2).FTeam;
771 end;
773 procedure g_Gibs_SetMax(Count: Word);
774 begin
775 MaxGibs := Count;
776 SetLength(gGibs, Count);
778 if CurrentGib >= Count then
779 CurrentGib := 0;
780 end;
782 function g_Gibs_GetMax(): Word;
783 begin
784 Result := MaxGibs;
785 end;
787 procedure g_Shells_SetMax(Count: Word);
788 begin
789 MaxShells := Count;
790 SetLength(gShells, Count);
792 if CurrentShell >= Count then
793 CurrentShell := 0;
794 end;
796 function g_Shells_GetMax(): Word;
797 begin
798 Result := MaxShells;
799 end;
802 procedure g_Corpses_SetMax(Count: Word);
803 begin
804 MaxCorpses := Count;
805 SetLength(gCorpses, Count);
806 end;
808 function g_Corpses_GetMax(): Word;
809 begin
810 Result := MaxCorpses;
811 end;
813 procedure g_Force_Model_Set(Mode: Word);
814 begin
815 ForceModel := Mode;
816 end;
818 function g_Force_Model_Get(): Word;
819 begin
820 Result := ForceModel;
821 end;
823 procedure g_Forced_Model_SetName(Model: String);
824 begin
825 ForcedModelName := Model;
826 end;
828 function g_Forced_Model_GetName(): String;
829 begin
830 Result := ForcedModelName;
831 end;
833 function g_Player_Create(ModelName: String; Color: TRGB; Team: Byte; Bot: Boolean): Word;
835 a: Integer;
836 ok: Boolean = False;
837 begin
838 Result := 0;
840 // Åñòü ëè ìåñòî â gPlayers:
841 for a := 0 to High(gPlayers) do
842 if gPlayers[a] = nil then
843 begin
844 ok := True;
845 Break;
846 end;
848 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
849 if not ok then
850 begin
851 SetLength(gPlayers, Length(gPlayers)+1);
852 a := High(gPlayers);
853 end;
855 // Ñîçäàåì îáúåêò èãðîêà:
856 if Bot
857 then gPlayers[a] := TBot.Create()
858 else gPlayers[a] := TPlayer.Create();
860 gPlayers[a].FActualModelName := ModelName;
861 gPlayers[a].SetModel(ModelName);
862 if Bot and (g_Force_Model_Get() <> 0) then
863 gPlayers[a].SetModel(g_Forced_Model_GetName());
865 // Íåò ìîäåëè - ñîçäàíèå íåâîçìîæíî:
866 if gPlayers[a].FModel = nil then
867 begin
868 FreeAndNil(gPlayers[a]);
869 g_FatalError(Format(_lc[I_GAME_ERROR_MODEL], [ModelName]));
870 Exit;
871 end;
873 if not (Team in [TEAM_RED, TEAM_BLUE]) then
874 if Random(2) = 0
875 then Team := TEAM_RED
876 else Team := TEAM_BLUE;
877 gPlayers[a].FPreferredTeam := Team;
879 case gGameSettings.GameMode of
880 GM_DM: gPlayers[a].FTeam := TEAM_NONE;
881 GM_TDM, GM_CTF: gPlayers[a].FTeam := gPlayers[a].FPreferredTeam;
882 GM_SINGLE, GM_COOP: gPlayers[a].FTeam := TEAM_COOP;
883 end;
885 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
886 gPlayers[a].FColor := Color;
887 if gPlayers[a].FTeam in [TEAM_RED, TEAM_BLUE]
888 then gPlayers[a].FModel.Color := TEAMCOLOR[gPlayers[a].FTeam]
889 else gPlayers[a].FModel.Color := Color;
891 gPlayers[a].FUID := g_CreateUID(UID_PLAYER);
892 gPlayers[a].FAlive := False;
894 Result := gPlayers[a].FUID;
895 end;
897 function g_Player_CreateFromState (st: TStream): Word;
899 i: SizeInt;
900 ok, Bot: Boolean;
901 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
908 Raise XStreamError.Create('invalid player signature');
909 if st.ReadByte() <> PLR_SAVE_VERSION then
910 Raise XStreamError.Create('invalid player version');
912 Bot := st.ReadBool();
913 st.Position := pos;
915 // find free player slot
916 ok := False;
917 for i := 0 to High(gPlayers) do
918 if gPlayers[i] = nil then
919 begin
920 ok := True;
921 break;
922 end;
924 // allocate player slot
925 if not ok then
926 begin
927 SetLength(gPlayers, Length(gPlayers)+1);
928 i := High(gPlayers);
929 end;
931 // create entity and load state
932 if Bot then
933 begin
934 gPlayers[i] := TBot.Create();
935 if g_Force_Model_Get() <> 0 then
936 gPlayers[i].SetModel(g_Forced_Model_GetName());
938 else
939 gPlayers[i] := TPlayer.Create();
941 gPlayers[i].FPhysics := True; // ???
942 gPlayers[i].LoadState(st);
944 Result := gPlayers[i].FUID;
945 end;
948 procedure g_Player_ResetTeams();
950 a: Integer;
951 begin
952 if g_Game_IsClient then
953 Exit;
954 if gPlayers = nil then
955 Exit;
956 for a := Low(gPlayers) to High(gPlayers) do
957 if gPlayers[a] <> nil then
958 case gGameSettings.GameMode of
959 GM_DM:
960 gPlayers[a].ChangeTeam(TEAM_NONE);
961 GM_TDM, GM_CTF:
962 if not (gPlayers[a].Team in [TEAM_RED, TEAM_BLUE]) then
963 if gPlayers[a].FPreferredTeam in [TEAM_RED, TEAM_BLUE] then
964 gPlayers[a].ChangeTeam(gPlayers[a].FPreferredTeam)
965 else
966 if a mod 2 = 0
967 then gPlayers[a].ChangeTeam(TEAM_RED)
968 else gPlayers[a].ChangeTeam(TEAM_BLUE);
969 GM_SINGLE,
970 GM_COOP:
971 gPlayers[a].ChangeTeam(TEAM_COOP);
972 end;
973 end;
975 procedure g_Bot_Add(Team, Difficult: Byte; Handicap: Integer = 100);
977 m: SSArray;
978 _name, _model: String;
979 a, tr, tb: Integer;
980 begin
981 if not g_Game_IsServer then Exit;
983 // Íå äîáàâëÿåì áîòîâ åñëè ëèìèò óæå äîñòèãíóò
984 if (g_Bot_GetCount() >= gMaxBots) then Exit;
986 // Ñïèñîê íàçâàíèé ìîäåëåé:
987 m := g_PlayerModel_GetNames();
988 if m = nil then
989 Exit;
991 // Êîìàíäà:
992 if (gGameSettings.GameType = GT_SINGLE) or (gGameSettings.GameMode = GM_COOP) then
993 Team := TEAM_COOP // COOP
994 else
995 if gGameSettings.GameMode = GM_DM then
996 Team := TEAM_NONE // DM
997 else
998 if Team = TEAM_NONE then // CTF / TDM
999 begin
1000 // Àâòîáàëàíñ êîìàíä:
1001 tr := 0;
1002 tb := 0;
1004 for a := 0 to High(gPlayers) do
1005 if gPlayers[a] <> nil then
1006 begin
1007 if gPlayers[a].Team = TEAM_RED then
1008 Inc(tr)
1009 else
1010 if gPlayers[a].Team = TEAM_BLUE then
1011 Inc(tb);
1012 end;
1014 if tr > tb then
1015 Team := TEAM_BLUE
1016 else
1017 if tb > tr then
1018 Team := TEAM_RED
1019 else // tr = tb
1020 if Random(2) = 0 then
1021 Team := TEAM_RED
1022 else
1023 Team := TEAM_BLUE;
1024 end;
1026 // Âûáèðàåì áîòó èìÿ:
1027 _name := '';
1028 if BotNames <> nil then
1029 for a := 0 to High(BotNames) do
1030 if g_Player_ExistingName(BotNames[a]) then
1031 begin
1032 _name := BotNames[a];
1033 Break;
1034 end;
1036 // Âûáèðàåì ñëó÷àéíóþ ìîäåëü:
1037 _model := m[Random(Length(m))];
1039 // Ñîçäàåì áîòà:
1040 with g_Player_Get(g_Player_Create(_model,
1041 _RGB(Min(Random(9)*32, 255),
1042 Min(Random(9)*32, 255),
1043 Min(Random(9)*32, 255)),
1044 Team, True)) as TBot do
1045 begin
1046 // Åñëè èìåíè íåò, äåëàåì åãî èç UID áîòà
1047 if _name = '' then
1048 Name := Format('DFBOT%.5d', [UID])
1049 else
1050 Name := _name;
1052 case Difficult of
1053 1: FDifficult := DIFFICULT_EASY;
1054 2: FDifficult := DIFFICULT_MEDIUM;
1055 else FDifficult := DIFFICULT_HARD;
1056 end;
1058 for a := WP_FIRST to WP_LAST do
1059 begin
1060 FDifficult.WeaponPrior[a] := WEAPON_PRIOR1[a];
1061 FDifficult.CloseWeaponPrior[a] := WEAPON_PRIOR2[a];
1062 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1063 end;
1065 FHandicap := Handicap;
1067 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [Name]), True);
1069 if g_Game_IsNet then MH_SEND_PlayerCreate(UID);
1070 if g_Game_IsServer and (gGameSettings.MaxLives > 0) then
1071 Spectate();
1072 end;
1073 end;
1075 procedure g_Bot_AddList(Team: Byte; lName: ShortString; num: Integer = -1; Handicap: Integer = 100);
1077 m: SSArray;
1078 _name, _model: String;
1079 a: Integer;
1080 begin
1081 if not g_Game_IsServer then Exit;
1083 // Íå äîáàâëÿåì áîòîâ åñëè ëèìèò óæå äîñòèãíóò
1084 if (g_Bot_GetCount() >= gMaxBots) then Exit;
1086 // Ñïèñîê íàçâàíèé ìîäåëåé:
1087 m := g_PlayerModel_GetNames();
1088 if m = nil then
1089 Exit;
1091 // Êîìàíäà:
1092 if (gGameSettings.GameType = GT_SINGLE) or (gGameSettings.GameMode = GM_COOP) then
1093 Team := TEAM_COOP // COOP
1094 else
1095 if gGameSettings.GameMode = GM_DM then
1096 Team := TEAM_NONE // DM
1097 else
1098 if Team = TEAM_NONE then
1099 Team := BotList[num].team; // CTF / TDM
1101 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1102 if lName = '' then
1103 num := Random(Length(BotList))
1104 else
1105 begin
1106 if (num < 0) or (num > Length(BotList)-1) then
1107 num := -1;
1108 if (num = -1) and (BotList <> nil) then
1109 lName := AnsiLowerCase(lName);
1110 for a := 0 to High(BotList) do
1111 if AnsiLowerCase(BotList[a].name) = lName then
1112 begin
1113 num := a;
1114 Break;
1115 end;
1116 if num = -1 then
1117 Exit;
1118 end;
1120 // Èìÿ áîòà:
1121 _name := BotList[num].name;
1122 if (_name = '') and (BotNames <> nil) then
1123 for a := 0 to High(BotNames) do
1124 if g_Player_ExistingName(BotNames[a]) then
1125 begin
1126 _name := BotNames[a];
1127 Break;
1128 end;
1130 // Ìîäåëü:
1131 _model := BotList[num].model;
1132 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1133 if not InSArray(_model, m) then
1134 _model := m[Random(Length(m))];
1136 // Ñîçäàåì áîòà:
1137 with g_Player_Get(g_Player_Create(_model, BotList[num].color, Team, True)) as TBot do
1138 begin
1139 // Åñëè èìåíè íåò, äåëàåì åãî èç UID áîòà
1140 if _name = ''
1141 then Name := Format('DFBOT%.5d', [UID])
1142 else Name := _name;
1144 FDifficult.DiagFire := BotList[num].diag_fire;
1145 FDifficult.InvisFire := BotList[num].invis_fire;
1146 FDifficult.DiagPrecision := BotList[num].diag_precision;
1147 FDifficult.FlyPrecision := BotList[num].fly_precision;
1148 FDifficult.Cover := BotList[num].cover;
1149 FDifficult.CloseJump := BotList[num].close_jump;
1151 FHandicap := Handicap;
1153 for a := WP_FIRST to WP_LAST do
1154 begin
1155 FDifficult.WeaponPrior[a] := BotList[num].w_prior1[a];
1156 FDifficult.CloseWeaponPrior[a] := BotList[num].w_prior2[a];
1157 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1158 end;
1160 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [Name]), True);
1162 if g_Game_IsNet then MH_SEND_PlayerCreate(UID);
1163 end;
1164 end;
1166 procedure g_Bot_RemoveAll();
1168 a: Integer;
1169 begin
1170 if not g_Game_IsServer then Exit;
1171 if gPlayers = nil then Exit;
1173 for a := 0 to High(gPlayers) do
1174 if gPlayers[a] <> nil then
1175 if gPlayers[a] is TBot then
1176 begin
1177 gPlayers[a].Lives := 0;
1178 gPlayers[a].Kill(K_SIMPLEKILL, 0, HIT_DISCON);
1179 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [gPlayers[a].Name]), True);
1180 g_Player_Remove(gPlayers[a].FUID);
1181 end;
1183 g_Bot_MixNames();
1184 end;
1186 procedure g_Bot_MixNames();
1188 s: String;
1189 a, b: Integer;
1190 begin
1191 if BotNames <> nil then
1192 for a := 0 to High(BotNames) do
1193 begin
1194 b := Random(Length(BotNames));
1195 s := BotNames[a];
1196 Botnames[a] := BotNames[b];
1197 BotNames[b] := s;
1198 end;
1199 end;
1201 procedure g_Player_Remove(UID: Word);
1203 i: Integer;
1204 begin
1205 if gPlayers = nil then Exit;
1207 if g_Game_IsServer and g_Game_IsNet then
1208 MH_SEND_PlayerDelete(UID);
1210 for i := 0 to High(gPlayers) do
1211 if gPlayers[i] <> nil then
1212 if gPlayers[i].FUID = UID then
1213 begin
1214 if gPlayers[i] is TPlayer then
1215 TPlayer(gPlayers[i]).Free()
1216 else
1217 TBot(gPlayers[i]).Free();
1218 gPlayers[i] := nil;
1219 Exit;
1220 end;
1221 end;
1223 procedure g_Player_Init();
1225 F: TextFile;
1226 s: String;
1227 a, b: Integer;
1228 config: TConfig;
1229 sa: SSArray;
1230 path: AnsiString;
1231 begin
1232 BotNames := nil;
1233 BotList := nil;
1235 path := BOTNAMES_FILENAME;
1236 if e_FindResource(DataDirs, path) then
1237 begin
1238 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1239 AssignFile(F, path);
1240 Reset(F);
1242 while not EOF(F) do
1243 begin
1244 ReadLn(F, s);
1246 s := Trim(s);
1247 if s = '' then
1248 Continue;
1250 SetLength(BotNames, Length(BotNames)+1);
1251 BotNames[High(BotNames)] := s;
1252 end;
1254 CloseFile(F);
1256 // Ïåðåìåøèâàåì èõ:
1257 g_Bot_MixNames();
1258 end;
1260 path := BOTLIST_FILENAME;
1261 if e_FindResource(DataDirs, path) then
1262 begin
1263 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1264 config := TConfig.CreateFile(path);
1265 a := 0;
1267 while config.SectionExists(IntToStr(a)) do
1268 begin
1269 SetLength(BotList, Length(BotList)+1);
1271 with BotList[High(BotList)] do
1272 begin
1273 name := config.ReadStr(IntToStr(a), 'name', ''); // Èìÿ áîòà
1274 model := config.ReadStr(IntToStr(a), 'model', ''); // Ìîäåëü
1276 // Êîìàíäà
1277 s := config.ReadStr(IntToStr(a), 'team', '');
1278 if s = 'red' then
1279 team := TEAM_RED
1280 else if s = 'blue' then
1281 team := TEAM_BLUE
1282 else
1283 team := TEAM_NONE;
1285 // Öâåò ìîäåëè
1286 sa := parse(config.ReadStr(IntToStr(a), 'color', ''));
1287 SetLength(sa, 3);
1288 color.R := StrToIntDef(sa[0], 0);
1289 color.G := StrToIntDef(sa[1], 0);
1290 color.B := StrToIntDef(sa[2], 0);
1292 diag_fire := config.ReadInt(IntToStr(a), 'diag_fire', 0); // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì
1293 invis_fire := config.ReadInt(IntToStr(a), 'invis_fire', 0); // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó
1294 diag_precision := config.ReadInt(IntToStr(a), 'diag_precision', 0); // Òî÷íîñòü ñòðåëüáû ïîä óãëîì
1295 fly_precision := config.ReadInt(IntToStr(a), 'fly_precision', 0); // Òî÷íîñòü ñòðåëüáû â ïîëåòå
1296 cover := config.ReadInt(IntToStr(a), 'cover', 0); // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ
1297 close_jump := config.ReadInt(IntToStr(a), 'close_jump', 0); // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà
1299 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ
1300 sa := parse(config.ReadStr(IntToStr(a), 'w_prior1', ''));
1301 if Length(sa) = 10 then
1302 for b := 0 to 9 do
1303 w_prior1[b] := EnsureRange(StrToInt(sa[b]), 0, 9);
1305 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ
1306 sa := parse(config.ReadStr(IntToStr(a), 'w_prior2', ''));
1307 if Length(sa) = 10 then
1308 for b := 0 to 9 do
1309 w_prior2[b] := EnsureRange(StrToInt(sa[b]), 0, 9);
1311 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1312 if Length(sa) = 10 then
1313 for b := 0 to 9 do
1314 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1315 end;
1317 a += 1;
1318 end;
1320 config.Free();
1321 end;
1323 SetLength(SavedStates, 0);
1324 end;
1326 procedure g_Player_Free();
1328 i: Integer;
1329 begin
1330 if gPlayers <> nil then
1331 begin
1332 for i := 0 to High(gPlayers) do
1333 if gPlayers[i] <> nil then
1334 begin
1335 if gPlayers[i] is TPlayer then
1336 TPlayer(gPlayers[i]).Free()
1337 else
1338 TBot(gPlayers[i]).Free();
1339 gPlayers[i] := nil;
1340 end;
1342 gPlayers := nil;
1343 end;
1345 gPlayer1 := nil;
1346 gPlayer2 := nil;
1347 SetLength(SavedStates, 0);
1348 end;
1350 procedure g_Player_PreUpdate();
1352 i: Integer;
1353 begin
1354 if gPlayers = nil then Exit;
1355 for i := 0 to High(gPlayers) do
1356 if gPlayers[i] <> nil then
1357 gPlayers[i].PreUpdate();
1358 end;
1360 procedure g_Player_UpdateAll();
1362 i: Integer;
1363 begin
1364 if gPlayers = nil then Exit;
1366 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1367 for i := 0 to High(gPlayers) do
1368 begin
1369 if gPlayers[i] <> nil then
1370 begin
1371 if gPlayers[i] is TPlayer then
1372 begin
1373 gPlayers[i].Update();
1374 gPlayers[i].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1376 else
1377 begin
1378 // bot updates weapons in `UpdateCombat()`
1379 TBot(gPlayers[i]).Update();
1380 end;
1381 end;
1382 end;
1383 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1384 end;
1386 procedure g_Player_DrawAll();
1388 i: Integer;
1389 begin
1390 if gPlayers = nil then Exit;
1392 for i := 0 to High(gPlayers) do
1393 if gPlayers[i] <> nil then
1394 if gPlayers[i] is TPlayer then gPlayers[i].Draw()
1395 else TBot(gPlayers[i]).Draw();
1396 end;
1398 procedure g_Player_DrawDebug(p: TPlayer);
1400 fW, fH: Byte;
1401 begin
1402 if p = nil then Exit;
1403 if (@p.FObj) = nil then Exit;
1405 e_TextureFontGetSize(gStdFont, fW, fH);
1407 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p.FObj.X), gStdFont);
1408 e_TextureFontPrint(0, fH , 'Pos Y: ' + IntToStr(p.FObj.Y), gStdFont);
1409 e_TextureFontPrint(0, fH * 2, 'Vel X: ' + IntToStr(p.FObj.Vel.X), gStdFont);
1410 e_TextureFontPrint(0, fH * 3, 'Vel Y: ' + IntToStr(p.FObj.Vel.Y), gStdFont);
1411 e_TextureFontPrint(0, fH * 4, 'Acc X: ' + IntToStr(p.FObj.Accel.X), gStdFont);
1412 e_TextureFontPrint(0, fH * 5, 'Acc Y: ' + IntToStr(p.FObj.Accel.Y), gStdFont);
1413 e_TextureFontPrint(0, fH * 6, 'Old X: ' + IntToStr(p.FObj.oldX), gStdFont);
1414 e_TextureFontPrint(0, fH * 7, 'Old Y: ' + IntToStr(p.FObj.oldY), gStdFont);
1415 end;
1417 procedure g_Player_DrawHealth();
1419 i: Integer;
1420 fW, fH: Byte;
1421 begin
1422 if gPlayers = nil then Exit;
1423 e_TextureFontGetSize(gStdFont, fW, fH);
1425 for i := 0 to High(gPlayers) do
1426 if gPlayers[i] <> nil then
1427 begin
1428 e_TextureFontPrint(gPlayers[i].FObj.X + gPlayers[i].FObj.Rect.X,
1429 gPlayers[i].FObj.Y + gPlayers[i].FObj.Rect.Y + gPlayers[i].FObj.Rect.Height - fH * 2,
1430 IntToStr(gPlayers[i].FHealth), gStdFont);
1431 e_TextureFontPrint(gPlayers[i].FObj.X + gPlayers[i].FObj.Rect.X,
1432 gPlayers[i].FObj.Y + gPlayers[i].FObj.Rect.Y + gPlayers[i].FObj.Rect.Height - fH,
1433 IntToStr(gPlayers[i].FArmor), gStdFont);
1434 end;
1435 end;
1437 function g_Player_Get(UID: Word): TPlayer;
1439 a: Integer;
1440 begin
1441 Result := nil;
1443 if gPlayers = nil then
1444 Exit;
1446 for a := 0 to High(gPlayers) do
1447 if gPlayers[a] <> nil then
1448 if gPlayers[a].FUID = UID then
1449 begin
1450 Result := gPlayers[a];
1451 Exit;
1452 end;
1453 end;
1455 function g_Player_GetCount(): Byte;
1457 a: Integer;
1458 begin
1459 Result := 0;
1461 if gPlayers = nil then
1462 Exit;
1464 for a := 0 to High(gPlayers) do
1465 if gPlayers[a] <> nil then
1466 Result := Result + 1;
1467 end;
1469 function g_Bot_GetCount(): Integer;
1471 a: Integer;
1472 begin
1473 Result := 0;
1475 if gPlayers = nil then
1476 Exit;
1478 for a := 0 to High(gPlayers) do
1479 if (gPlayers[a] <> nil) and (gPlayers[a] is TBot) then
1480 Result := Result + 1;
1481 end;
1483 function g_Player_GetStats(): TPlayerStatArray;
1485 a: Integer;
1486 begin
1487 Result := nil;
1489 if gPlayers = nil then Exit;
1491 for a := 0 to High(gPlayers) do
1492 if gPlayers[a] <> nil then
1493 begin
1494 SetLength(Result, Length(Result)+1);
1495 with Result[High(Result)] do
1496 begin
1497 Num := a;
1498 Ping := gPlayers[a].FPing;
1499 Loss := gPlayers[a].FLoss;
1500 Name := gPlayers[a].FName;
1501 Team := gPlayers[a].FTeam;
1502 Frags := gPlayers[a].FFrags;
1503 Deaths := gPlayers[a].FDeath;
1504 Kills := gPlayers[a].FKills;
1505 Color := gPlayers[a].FModel.Color;
1506 Lives := gPlayers[a].FLives;
1507 Spectator := gPlayers[a].FSpectator;
1508 UID := gPlayers[a].FUID;
1509 end;
1510 end;
1511 end;
1513 procedure g_Player_ResetReady();
1515 a: Integer;
1516 begin
1517 if not g_Game_IsServer then Exit;
1518 if gPlayers = nil then Exit;
1520 for a := 0 to High(gPlayers) do
1521 if gPlayers[a] <> nil then
1522 begin
1523 gPlayers[a].FReady := False;
1524 if g_Game_IsNet then
1525 MH_SEND_GameEvent(NET_EV_INTER_READY, gPlayers[a].UID, 'N');
1526 end;
1527 end;
1529 procedure g_Player_RememberAll;
1531 i: Integer;
1532 begin
1533 for i := Low(gPlayers) to High(gPlayers) do
1534 if (gPlayers[i] <> nil) and gPlayers[i].alive then
1535 gPlayers[i].PreserveState;
1536 end;
1538 procedure g_Player_ResetAll(Force, Silent: Boolean);
1540 i: Integer;
1541 begin
1542 gTeamStat[TEAM_RED].Score := 0;
1543 gTeamStat[TEAM_BLUE].Score := 0;
1545 if gPlayers <> nil then
1546 for i := 0 to High(gPlayers) do
1547 if gPlayers[i] <> nil then
1548 begin
1549 gPlayers[i].Reset(Force);
1551 if gPlayers[i] is TPlayer then
1552 begin
1553 if (not gPlayers[i].FSpectator) or gPlayers[i].FWantsInGame then
1554 gPlayers[i].Respawn(Silent)
1555 else
1556 gPlayers[i].Spectate();
1558 else
1559 TBot(gPlayers[i]).Respawn(Silent);
1560 end;
1561 end;
1563 function g_Player_CreateCorpse(Player: TPlayer): Integer;
1565 i: Integer;
1566 find_id: DWORD;
1567 ok: Boolean;
1568 begin
1569 Result := -1;
1571 if Player.alive then
1572 Exit;
1574 // Ðàçðûâàåì ñâÿçü ñ ïðåæíèì òðóïîì:
1575 i := Player.FCorpse;
1576 if (Low(gCorpses) <= i) and (High(gCorpses) >= i) then
1577 begin
1578 if (gCorpses[i] <> nil) and (gCorpses[i].FPlayerUID = Player.FUID) then
1579 gCorpses[i].FPlayerUID := 0;
1580 end;
1582 if Player.FObj.Y >= gMapInfo.Height+128 then
1583 Exit;
1585 with Player do
1586 begin
1587 if (FHealth >= -50) or (gGibsCount = 0) then
1588 begin
1589 if Length(gCorpses) = 0 then
1590 Exit;
1592 ok := False;
1593 for find_id := 0 to High(gCorpses) do
1594 if gCorpses[find_id] = nil then
1595 begin
1596 ok := True;
1597 Break;
1598 end;
1600 if not ok then
1601 begin
1602 find_id := Random(Length(gCorpses));
1603 gCorpses[find_id].Destroy();
1604 end;
1606 gCorpses[find_id] := TCorpse.Create(FObj.X, FObj.Y, FModel.Name, FHealth < -20);
1607 gCorpses[find_id].FColor := FModel.Color;
1608 gCorpses[find_id].FObj.Vel := FObj.Vel;
1609 gCorpses[find_id].FObj.Accel := FObj.Accel;
1610 gCorpses[find_id].FPlayerUID := FUID;
1612 Result := find_id;
1614 else
1615 g_Player_CreateGibs(FObj.X + PLAYER_RECT_CX,
1616 FObj.Y + PLAYER_RECT_CY,
1617 FModel.Name, FModel.Color);
1618 end;
1619 end;
1621 procedure g_Player_CreateShell(fX, fY, dX, dY: Integer; T: Byte);
1623 SID: DWORD;
1624 begin
1625 if (gShells = nil) or (Length(gShells) = 0) then
1626 Exit;
1628 with gShells[CurrentShell] do
1629 begin
1630 SpriteID := 0;
1631 g_Obj_Init(@Obj);
1632 Obj.Rect.X := 0;
1633 Obj.Rect.Y := 0;
1634 if T = SHELL_BULLET then
1635 begin
1636 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID) then
1637 SpriteID := SID;
1638 CX := 2;
1639 CY := 1;
1640 Obj.Rect.Width := 4;
1641 Obj.Rect.Height := 2;
1643 else
1644 begin
1645 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID) then
1646 SpriteID := SID;
1647 CX := 4;
1648 CY := 2;
1649 Obj.Rect.Width := 7;
1650 Obj.Rect.Height := 3;
1651 end;
1652 SType := T;
1653 alive := True;
1654 Obj.X := fX;
1655 Obj.Y := fY;
1656 g_Obj_Push(@Obj, dX + Random(4)-Random(4), dY-Random(4));
1657 positionChanged(); // this updates spatial accelerators
1658 RAngle := Random(360);
1659 Timeout := gTime + SHELL_TIMEOUT;
1661 if CurrentShell >= High(gShells) then
1662 CurrentShell := 0
1663 else
1664 Inc(CurrentShell);
1665 end;
1666 end;
1668 procedure g_Player_CreateGibs(fX, fY: Integer; ModelName: string; fColor: TRGB);
1670 a: Integer;
1671 GibsArray: TGibsArray;
1672 Blood: TModelBlood;
1673 begin
1674 if (gGibs = nil) or (Length(gGibs) = 0) then
1675 Exit;
1676 if not g_PlayerModel_GetGibs(ModelName, GibsArray) then
1677 Exit;
1678 Blood := g_PlayerModel_GetBlood(ModelName);
1680 for a := 0 to High(GibsArray) do
1681 with gGibs[CurrentGib] do
1682 begin
1683 Color := fColor;
1684 ID := GibsArray[a].ID;
1685 MaskID := GibsArray[a].MaskID;
1686 alive := True;
1687 g_Obj_Init(@Obj);
1688 Obj.Rect := GibsArray[a].Rect;
1689 Obj.X := fX-GibsArray[a].Rect.X-(GibsArray[a].Rect.Width div 2);
1690 Obj.Y := fY-GibsArray[a].Rect.Y-(GibsArray[a].Rect.Height div 2);
1691 g_Obj_PushA(@Obj, 25 + Random(10), Random(361));
1692 positionChanged(); // this updates spatial accelerators
1693 RAngle := Random(360);
1695 if gBloodCount > 0 then
1696 g_GFX_Blood(fX, fY, 16*gBloodCount+Random(5*gBloodCount), -16+Random(33), -16+Random(33),
1697 Random(48), Random(48), Blood.R, Blood.G, Blood.B, Blood.Kind);
1699 if CurrentGib >= High(gGibs) then
1700 CurrentGib := 0
1701 else
1702 Inc(CurrentGib);
1703 end;
1704 end;
1706 procedure g_Player_UpdatePhysicalObjects();
1708 i: Integer;
1709 vel: TPoint2i;
1710 mr: Word;
1712 procedure ShellSound_Bounce(X, Y: Integer; T: Byte);
1714 k: Integer;
1715 begin
1716 k := 1 + Random(2);
1717 {$IFDEF ENABLE_SOUND}
1718 if T = SHELL_BULLET
1719 then g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k), X, Y)
1720 else g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k), X, Y);
1721 {$ENDIF}
1722 end;
1724 begin
1725 // Êóñêè ìÿñà:
1726 for i := 0 to High(gGibs) do
1727 if gGibs[i].alive then
1728 with gGibs[i] do
1729 begin
1730 Obj.oldX := Obj.X;
1731 Obj.oldY := Obj.Y;
1733 vel := Obj.Vel;
1734 mr := g_Obj_Move(@Obj, True, False, True);
1735 positionChanged(); // this updates spatial accelerators
1737 if WordBool(mr and MOVE_FALLOUT) then
1738 begin
1739 alive := False;
1740 Continue;
1741 end;
1743 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1744 if WordBool(mr and MOVE_HITWALL) then
1745 Obj.Vel.X := -(vel.X div 2);
1746 if WordBool(mr and (MOVE_HITCEIL or MOVE_HITLAND)) then
1747 Obj.Vel.Y := -(vel.Y div 2);
1749 if (Obj.Vel.X >= 0) then
1750 begin // Clockwise
1751 RAngle := RAngle + Abs(Obj.Vel.X)*6 + Abs(Obj.Vel.Y);
1752 if RAngle >= 360 then
1753 RAngle := RAngle mod 360;
1755 else
1756 begin // Counter-clockwise
1757 RAngle := RAngle - Abs(Obj.Vel.X)*6 - Abs(Obj.Vel.Y);
1758 if RAngle < 0 then
1759 RAngle := (360 - (Abs(RAngle) mod 360)) mod 360;
1760 end;
1762 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1763 if gTime mod (GAME_TICK*3) = 0 then
1764 Obj.Vel.X := z_dec(Obj.Vel.X, 1);
1765 end;
1767 // Òðóïû:
1768 for i := 0 to High(gCorpses) do
1769 if gCorpses[i] <> nil then
1770 if gCorpses[i].State = CORPSE_STATE_REMOVEME
1771 then FreeAndNil(gCorpses[i])
1772 else gCorpses[i].Update();
1774 // Ãèëüçû:
1775 for i := 0 to High(gShells) do
1776 if gShells[i].alive then
1777 with gShells[i] do
1778 begin
1779 Obj.oldX := Obj.X;
1780 Obj.oldY := Obj.Y;
1782 vel := Obj.Vel;
1783 mr := g_Obj_Move(@Obj, True, False, True);
1784 positionChanged(); // this updates spatial accelerators
1786 if WordBool(mr and MOVE_FALLOUT) or (gShells[i].Timeout < gTime) then
1787 begin
1788 alive := False;
1789 Continue;
1790 end;
1792 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1793 if WordBool(mr and MOVE_HITWALL) then
1794 begin
1795 Obj.Vel.X := -(vel.X div 2);
1796 if not WordBool(mr and MOVE_INWATER) then
1797 ShellSound_Bounce(Obj.X, Obj.Y, SType);
1798 end;
1799 if WordBool(mr and (MOVE_HITCEIL or MOVE_HITLAND)) then
1800 begin
1801 Obj.Vel.Y := -(vel.Y div 2);
1802 if Obj.Vel.X <> 0 then Obj.Vel.X := Obj.Vel.X div 2;
1803 if (Obj.Vel.X = 0) and (Obj.Vel.Y = 0) then
1804 begin
1805 if RAngle mod 90 <> 0 then
1806 RAngle := (RAngle div 90) * 90;
1808 else if not WordBool(mr and MOVE_INWATER) then
1809 ShellSound_Bounce(Obj.X, Obj.Y, SType);
1810 end;
1812 if (Obj.Vel.X >= 0) then
1813 begin // Clockwise
1814 RAngle := RAngle + Abs(Obj.Vel.X)*8 + Abs(Obj.Vel.Y);
1815 if RAngle >= 360 then
1816 RAngle := RAngle mod 360;
1818 else
1819 begin // Counter-clockwise
1820 RAngle := RAngle - Abs(Obj.Vel.X)*8 - Abs(Obj.Vel.Y);
1821 if RAngle < 0 then
1822 RAngle := (360 - (Abs(RAngle) mod 360)) mod 360;
1823 end;
1824 end;
1825 end;
1828 procedure TGib.getMapBox (out x, y, w, h: Integer); inline;
1829 begin
1830 x := Obj.X+Obj.Rect.X;
1831 y := Obj.Y+Obj.Rect.Y;
1832 w := Obj.Rect.Width;
1833 h := Obj.Rect.Height;
1834 end;
1836 procedure TGib.moveBy (dx, dy: Integer); inline;
1837 begin
1838 if (dx <> 0) or (dy <> 0) then
1839 begin
1840 Obj.X += dx;
1841 Obj.Y += dy;
1842 positionChanged();
1843 end;
1844 end;
1847 procedure TShell.getMapBox (out x, y, w, h: Integer); inline;
1848 begin
1849 x := Obj.X;
1850 y := Obj.Y;
1851 w := Obj.Rect.Width;
1852 h := Obj.Rect.Height;
1853 end;
1855 procedure TShell.moveBy (dx, dy: Integer); inline;
1856 begin
1857 if (dx <> 0) or (dy <> 0) then
1858 begin
1859 Obj.X += dx;
1860 Obj.Y += dy;
1861 positionChanged();
1862 end;
1863 end;
1866 procedure TGib.positionChanged (); inline; begin end;
1867 procedure TShell.positionChanged (); inline; begin end;
1870 procedure g_Player_DrawCorpses();
1872 i, fX, fY: Integer;
1873 a: TDFPoint;
1874 begin
1875 for i := 0 to High(gGibs) do
1876 if gGibs[i].alive then
1877 with gGibs[i] do
1878 begin
1879 if not g_Obj_Collide(sX, sY, sWidth, sHeight, @Obj) then
1880 Continue;
1882 Obj.lerp(gLerpFactor, fX, fY);
1884 a.X := Obj.Rect.X+(Obj.Rect.Width div 2);
1885 a.y := Obj.Rect.Y+(Obj.Rect.Height div 2);
1887 e_DrawAdv(ID, fX, fY, 0, True, False, RAngle, @a, TMirrorType.None);
1889 e_Colors := Color;
1890 e_DrawAdv(MaskID, fX, fY, 0, True, False, RAngle, @a, TMirrorType.None);
1891 e_Colors.R := 255;
1892 e_Colors.G := 255;
1893 e_Colors.B := 255;
1894 end;
1896 for i := 0 to High(gCorpses) do
1897 if gCorpses[i] <> nil then
1898 gCorpses[i].Draw();
1899 end;
1901 procedure g_Player_DrawShells();
1903 i, fX, fY: Integer;
1904 a: TDFPoint;
1905 begin
1906 for i := 0 to High(gShells) do
1907 if gShells[i].alive then
1908 with gShells[i] do
1909 begin
1910 if not g_Obj_Collide(sX, sY, sWidth, sHeight, @Obj) then
1911 Continue;
1913 Obj.lerp(gLerpFactor, fX, fY);
1915 a.X := CX;
1916 a.Y := CY;
1918 e_DrawAdv(SpriteID, fX, fY, 0, True, False, RAngle, @a, TMirrorType.None);
1919 end;
1920 end;
1922 procedure g_Player_RemoveAllCorpses();
1924 i: Integer;
1925 begin
1926 gGibs := nil;
1927 SetLength(gGibs, MaxGibs);
1929 gShells := nil;
1930 SetLength(gShells, MaxGibs);
1932 CurrentGib := 0;
1933 CurrentShell := 0;
1935 for i := 0 to High(gCorpses) do
1936 FreeAndNil(gCorpses[i]);
1937 SetLength(gCorpses, MaxCorpses);
1938 end;
1940 procedure g_Player_Corpses_SaveState (st: TStream);
1942 count: SizeUInt;
1943 i: SizeInt;
1944 begin
1945 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ
1946 count := 0;
1947 for i := 0 to High(gCorpses) do
1948 if gCorpses[i] <> nil then
1949 count += 1;
1951 // Êîëè÷åñòâî òðóïîâ
1952 st.WriteDWordLE(count);
1953 if count = 0 then Exit;
1955 // Ñîõðàíÿåì òðóïû
1956 for i := 0 to High(gCorpses) do
1957 begin
1958 if gCorpses[i] <> nil then
1959 begin
1960 utils.writeStr(st, gCorpses[i].FModelName); // Íàçâàíèå ìîäåëè
1961 st.WriteBool(gCorpses[i].Mess); // Òèï ñìåðòè
1962 gCorpses[i].SaveState(st); // Ñîõðàíÿåì äàííûå òðóïà:
1963 end;
1964 end;
1965 end;
1968 procedure g_Player_Corpses_LoadState (st: TStream);
1970 count, i: SizeUInt;
1971 str: String;
1972 b: Boolean;
1973 begin
1974 Assert(st <> nil);
1975 g_Player_RemoveAllCorpses();
1977 // Êîëè÷åñòâî òðóïîâ:
1978 count := st.ReadDWordLE();
1979 if count = 0 then Exit;
1980 if Length(gCorpses) < count then
1981 raise XStreamError.Create('invalid number of corpses');
1983 // Çàãðóæàåì òðóïû
1984 for i := 0 to count-1 do
1985 begin
1986 str := utils.readStr(st); // Íàçâàíèå ìîäåëè:
1987 b := st.ReadBool(); // Òèï ñìåðòè
1989 // Ñîçäàåì òðóï
1990 gCorpses[i] := TCorpse.Create(0, 0, str, b);
1991 gCorpses[i].LoadState(st); // Çàãðóæàåì äàííûå òðóïà
1992 end;
1993 end;
1996 { TPlayer: }
1998 function TPlayer.isValidViewPort (): Boolean; inline;
1999 begin
2000 Result := (viewPortW > 0) and (viewPortH > 0);
2001 end;
2003 procedure TPlayer.BFGHit();
2004 begin
2005 g_Weapon_BFGHit(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
2006 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2));
2007 if g_Game_IsServer and g_Game_IsNet then
2008 MH_SEND_Effect(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
2009 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
2010 0, NET_GFX_BFGHIT);
2011 end;
2013 procedure TPlayer.ChangeModel(ModelName: string);
2015 locModel: TPlayerModel;
2016 begin
2017 locModel := g_PlayerModel_Get(ModelName);
2018 if locModel = nil then Exit;
2020 FModel.Free();
2021 FModel := locModel;
2022 end;
2024 procedure TPlayer.SetModel(ModelName: string);
2026 m: TPlayerModel;
2027 begin
2028 m := g_PlayerModel_Get(ModelName);
2029 if m = nil then
2030 begin
2031 g_SimpleError(Format(_lc[I_GAME_ERROR_MODEL_FALLBACK], [ModelName]));
2032 m := g_PlayerModel_Get('doomer');
2033 if m = nil then
2034 begin
2035 g_FatalError(Format(_lc[I_GAME_ERROR_MODEL], ['doomer']));
2036 Exit;
2037 end;
2038 end;
2040 if FModel <> nil then
2041 FModel.Free();
2043 FModel := m;
2045 if not (gGameSettings.GameMode in [GM_TDM, GM_CTF])
2046 then FModel.Color := FColor
2047 else FModel.Color := TEAMCOLOR[FTeam];
2049 FModel.SetWeapon(FCurrWeap);
2050 FModel.SetFlag(FFlag);
2051 SetDirection(FDirection);
2052 end;
2054 procedure TPlayer.SetColor(Color: TRGB);
2055 begin
2056 FColor := Color;
2057 if not (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
2058 if FModel <> nil then FModel.Color := Color;
2059 end;
2063 function TPlayer.GetColor(): TRGB;
2064 begin
2065 result := FModel.Color;
2066 end;
2068 procedure TPlayer.SetWeaponPrefs(Prefs: Array of Byte);
2070 i: Integer;
2071 begin
2072 for i := WP_FIRST to WP_LAST + 1 do
2073 begin
2074 if (Prefs[i] > WP_LAST + 1) then
2075 FWeapPreferences[i] := 0
2076 else
2077 FWeapPreferences[i] := Prefs[i];
2078 end;
2079 end;
2081 procedure TPlayer.SetWeaponPref(Weapon, Pref: Byte);
2082 begin
2083 if (Weapon > WP_LAST + 1) then
2084 exit
2085 else if (Pref <= WP_LAST + 1) and (Weapon <= WP_LAST + 1) then
2086 FWeapPreferences[Weapon] := Pref
2087 else if (Weapon <= WP_LAST + 1) and (Pref > WP_LAST + 1) then
2088 FWeapPreferences[Weapon] := 0;
2089 end;
2091 function TPlayer.GetWeaponPref(Weapon: Byte) : Byte;
2092 begin
2093 if (Weapon > WP_LAST + 1) then
2094 result := 0
2095 else if (FWeapPreferences[Weapon] > WP_LAST + 1) then
2096 result := 0
2097 else
2098 result := FWeapPreferences[Weapon];
2099 end;
2101 function TPlayer.GetMorePrefered() : Byte;
2103 testedWeap, i: Byte;
2104 begin
2105 testedWeap := FCurrWeap;
2106 for i := WP_FIRST to WP_LAST do
2107 if FWeapon[i] and maySwitch(i) and (FWeapPreferences[i] > FWeapPreferences[testedWeap]) then
2108 testedWeap := i;
2109 if (R_BERSERK in FInventory) and (FWeapPreferences[WP_LAST + 1] > FWeapPreferences[testedWeap]) then
2110 testedWeap := WEAPON_IRONFIST;
2111 result := testedWeap;
2112 end;
2114 function TPlayer.maySwitch(Weapon: Byte) : Boolean;
2115 begin
2116 result := true;
2117 if (Weapon = WEAPON_IRONFIST) and (FSkipIronFist <> 0) then
2118 begin
2119 if (FSkipIronFist = 1) and (not (R_BERSERK in FInventory)) then
2120 result := false;
2122 else if (FSwitchToEmpty = 0) and (not hasAmmoForShooting(Weapon)) then
2123 result := false;
2124 end;
2126 procedure TPlayer.SwitchTeam;
2127 begin
2128 if g_Game_IsClient then
2129 Exit;
2130 if not (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then Exit;
2132 if gGameOn and FAlive then
2133 Kill(K_SIMPLEKILL, FUID, HIT_SELF);
2135 if FTeam = TEAM_RED then
2136 begin
2137 ChangeTeam(TEAM_BLUE);
2138 g_Console_Add(Format(_lc[I_PLAYER_CHTEAM_BLUE], [FName]), True);
2139 if g_Game_IsNet then
2140 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM, TEAM_BLUE, FName);
2142 else
2143 begin
2144 ChangeTeam(TEAM_RED);
2145 g_Console_Add(Format(_lc[I_PLAYER_CHTEAM_RED], [FName]), True);
2146 if g_Game_IsNet then
2147 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM, TEAM_RED, FName);
2148 end;
2149 FPreferredTeam := FTeam;
2150 end;
2152 procedure TPlayer.ChangeTeam(Team: Byte);
2154 OldTeam: Byte;
2155 begin
2156 OldTeam := FTeam;
2157 FTeam := Team;
2158 case Team of
2159 TEAM_RED, TEAM_BLUE:
2160 FModel.Color := TEAMCOLOR[Team];
2161 else
2162 FModel.Color := FColor;
2163 end;
2164 if (FTeam <> OldTeam) and g_Game_IsNet and g_Game_IsServer then
2165 MH_SEND_PlayerStats(FUID);
2166 end;
2169 procedure TPlayer.CollideItem();
2171 i: Integer;
2172 r: Boolean;
2173 begin
2174 if gItems = nil then Exit;
2175 if not FAlive then Exit;
2177 for i := 0 to High(gItems) do
2178 with gItems[i] do
2179 begin
2180 if (ItemType <> ITEM_NONE) and alive then
2181 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
2182 PLAYER_RECT.Height, @Obj) then
2183 begin
2184 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
2186 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
2187 g_Sound_PlayExAt('SOUND_ITEM_GETPOWERUP', FObj.X, FObj.Y)
2188 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
2189 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
2190 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
2192 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòüñÿ ñ äðóãèì èãðîêîì:
2193 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
2194 (gGameSettings.GameType = GT_SINGLE) and
2195 (g_Player_GetCount() > 1)) then
2196 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
2197 end;
2198 end;
2199 end;
2202 function TPlayer.CollideLevel(XInc, YInc: Integer): Boolean;
2203 begin
2204 Result := g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc,
2205 PLAYER_RECT.Width, PLAYER_RECT.Height, PANEL_WALL,
2206 False);
2207 end;
2209 constructor TPlayer.Create();
2210 begin
2211 viewPortX := 0;
2212 viewPortY := 0;
2213 viewPortW := 0;
2214 viewPortH := 0;
2215 mEDamageType := HIT_SOME;
2217 FIamBot := False;
2218 FDummy := False;
2219 FSpawned := False;
2221 {$IFDEF ENABLE_SOUND}
2222 FSawSound := TPlayableSound.Create();
2223 FSawSoundIdle := TPlayableSound.Create();
2224 FSawSoundHit := TPlayableSound.Create();
2225 FSawSoundSelect := TPlayableSound.Create();
2226 FFlameSoundOn := TPlayableSound.Create();
2227 FFlameSoundOff := TPlayableSound.Create();
2228 FFlameSoundWork := TPlayableSound.Create();
2229 FJetSoundFly := TPlayableSound.Create();
2230 FJetSoundOn := TPlayableSound.Create();
2231 FJetSoundOff := TPlayableSound.Create();
2233 FSawSound.SetByName('SOUND_WEAPON_FIRESAW');
2234 FSawSoundIdle.SetByName('SOUND_WEAPON_IDLESAW');
2235 FSawSoundHit.SetByName('SOUND_WEAPON_HITSAW');
2236 FSawSoundSelect.SetByName('SOUND_WEAPON_SELECTSAW');
2237 FFlameSoundOn.SetByName('SOUND_WEAPON_FLAMEON');
2238 FFlameSoundOff.SetByName('SOUND_WEAPON_FLAMEOFF');
2239 FFlameSoundWork.SetByName('SOUND_WEAPON_FLAMEWORK');
2240 FJetSoundFly.SetByName('SOUND_PLAYER_JETFLY');
2241 FJetSoundOn.SetByName('SOUND_PLAYER_JETON');
2242 FJetSoundOff.SetByName('SOUND_PLAYER_JETOFF');
2243 {$ENDIF}
2245 FSpectatePlayer := -1;
2246 FClientID := -1;
2247 FPing := 0;
2248 FLoss := 0;
2249 FSavedStateNum := -1;
2250 FShellTimer := -1;
2251 FFireTime := 0;
2252 FFirePainTime := 0;
2253 FFireAttacker := 0;
2254 FHandicap := 100;
2255 FCorpse := -1;
2257 FActualModelName := 'doomer';
2259 g_Obj_Init(@FObj);
2260 FObj.Rect := PLAYER_RECT;
2262 FBFGFireCounter := -1;
2263 FJustTeleported := False;
2264 FNetTime := 0;
2266 FWaitForFirstSpawn := false;
2268 resetWeaponQueue();
2269 end;
2271 procedure TPlayer.positionChanged (); inline;
2272 begin
2273 end;
2275 procedure TPlayer.doDamage (v: Integer);
2276 begin
2277 if (v <= 0) then exit;
2278 if (v > 32767) then v := 32767;
2279 Damage(v, 0, 0, 0, mEDamageType);
2280 end;
2282 procedure TPlayer.Damage(value: Word; SpawnerUID: Word; vx, vy: Integer; t: Byte);
2284 c: Word;
2285 begin
2286 if (not g_Game_IsClient) and (not FAlive) then
2287 Exit;
2289 FLastHit := t;
2291 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2292 if ((t = HIT_TRAP) or (t = HIT_SELF)) and (not FGodMode) then
2293 begin
2294 if not g_Game_IsClient then
2295 begin
2296 FArmor := 0;
2297 if t = HIT_TRAP then
2298 begin
2299 // Ëîâóøêà óáèâàåò ñðàçó:
2300 FHealth := -100;
2301 Kill(K_EXTRAHARDKILL, SpawnerUID, t);
2302 end;
2303 if t = HIT_SELF then
2304 begin
2305 // Ñàìîóáèéñòâî:
2306 FHealth := 0;
2307 Kill(K_SIMPLEKILL, SpawnerUID, t);
2308 end;
2309 end;
2310 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2311 FPowerups[MR_SUIT] := 0;
2312 FPowerups[MR_INVUL] := 0;
2313 FPowerups[MR_INVIS] := 0;
2314 FSpawnInvul := 0;
2315 FBerserk := 0;
2316 end;
2318 // Íî îò îñòàëüíîãî ñïàñàåò:
2319 if FPowerups[MR_INVUL] >= gTime then
2320 Exit;
2322 // ×èò-êîä "ÃÎÐÅÖ":
2323 if FGodMode then
2324 Exit;
2326 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2327 if (TGameOption.FRIENDLY_FIRE in gGameSettings.Options) or
2328 (SpawnerUID = FUID) or
2329 (not SameTeam(FUID, SpawnerUID)) then
2330 begin
2331 FLastSpawnerUID := SpawnerUID;
2333 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2334 if gBloodCount > 0 then
2335 begin
2336 c := Min(value, 200)*gBloodCount + Random(Min(value, 200) div 2);
2337 if value div 4 <= c then
2338 c := c - (value div 4)
2339 else
2340 c := 0;
2342 if (t = HIT_SOME) and (vx = 0) and (vy = 0) then
2343 MakeBloodSimple(c)
2344 else
2345 case t of
2346 HIT_TRAP, HIT_ACID, HIT_FLAME, HIT_SELF: MakeBloodSimple(c);
2347 HIT_BFG, HIT_ROCKET, HIT_SOME: MakeBloodVector(c, vx, vy);
2348 end;
2350 if t = HIT_WATER then
2351 g_Game_Effect_Bubbles(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2),
2352 FObj.Y+PLAYER_RECT.Y-4, value div 2, 8, 4);
2353 end;
2355 // Áóôåð óðîíà:
2356 if FAlive then
2357 Inc(FDamageBuffer, value);
2359 // Âñïûøêà áîëè:
2360 if gFlash <> 0 then
2361 FPain := FPain + value;
2362 end;
2364 if g_Game_IsServer and g_Game_IsNet then
2365 begin
2366 MH_SEND_PlayerDamage(FUID, t, SpawnerUID, value, vx, vy);
2367 MH_SEND_PlayerStats(FUID);
2368 MH_SEND_PlayerPos(False, FUID);
2369 end;
2370 end;
2372 function TPlayer.Heal(value: Word; Soft: Boolean): Boolean;
2373 begin
2374 Result := False;
2375 if g_Game_IsClient then
2376 Exit;
2377 if not FAlive then
2378 Exit;
2380 if Soft and (FHealth < PLAYER_HP_SOFT) then
2381 begin
2382 IncMax(FHealth, value, PLAYER_HP_SOFT);
2383 Result := True;
2384 end;
2385 if (not Soft) and (FHealth < PLAYER_HP_LIMIT) then
2386 begin
2387 IncMax(FHealth, value, PLAYER_HP_LIMIT);
2388 Result := True;
2389 end;
2391 if Result and g_Game_IsServer and g_Game_IsNet then
2392 MH_SEND_PlayerStats(FUID);
2393 end;
2395 destructor TPlayer.Destroy();
2396 begin
2397 if (gPlayer1 <> nil) and (gPlayer1.FUID = FUID) then
2398 gPlayer1 := nil;
2399 if (gPlayer2 <> nil) and (gPlayer2.FUID = FUID) then
2400 gPlayer2 := nil;
2402 {$IFDEF ENABLE_SOUND}
2403 FSawSound.Free();
2404 FSawSoundIdle.Free();
2405 FSawSoundHit.Free();
2406 FSawSoundSelect.Free();
2407 FFlameSoundOn.Free();
2408 FFlameSoundOff.Free();
2409 FFlameSoundWork.Free();
2410 FJetSoundFly.Free();
2411 FJetSoundOn.Free();
2412 FJetSoundOff.Free();
2413 {$ENDIF}
2415 FModel.Free();
2416 FPunchAnim.Free();
2418 inherited;
2419 end;
2421 procedure TPlayer.DrawIndicator(Color: TRGB);
2423 indX, indY, fX, fY, fSlope: Integer;
2424 indW, indH: Word;
2425 indA: Single;
2426 a: TDFPoint;
2427 nW, nH: Byte;
2428 ID: DWORD;
2429 c: TRGB;
2430 begin
2431 if FAlive then
2432 begin
2433 FObj.lerp(gLerpFactor, fX, fY);
2434 fSlope := nlerp(FSlopeOld, FObj.slopeUpLeft, gLerpFactor);
2436 case gPlayerIndicatorStyle of
2438 begin
2439 if g_Texture_Get('TEXTURE_PLAYER_INDICATOR', ID) then
2440 begin
2441 e_GetTextureSize(ID, @indW, @indH);
2442 a.X := indW div 2;
2443 a.Y := indH div 2;
2445 if (FObj.X + FObj.Rect.X) < 0 then
2446 begin
2447 indA := 90;
2448 indX := fX + FObj.Rect.X + FObj.Rect.Width;
2449 indY := fY + FObj.Rect.Y + (FObj.Rect.Height - indW) div 2;
2452 else if (FObj.X + FObj.Rect.X + FObj.Rect.Width) > Max(gMapInfo.Width, gPlayerScreenSize.X) then
2453 begin
2454 indA := 270;
2455 indX := fX + FObj.Rect.X - indH;
2456 indY := fY + FObj.Rect.Y + (FObj.Rect.Height - indW) div 2;
2459 else if (FObj.Y - indH) < 0 then
2460 begin
2461 indA := 180;
2462 indX := fX + FObj.Rect.X + (FObj.Rect.Width - indW) div 2;
2463 indY := fY + FObj.Rect.Y + FObj.Rect.Height;
2466 else
2467 begin
2468 indA := 0;
2469 indX := fX + FObj.Rect.X + (FObj.Rect.Width - indW) div 2;
2470 indY := fY - indH;
2471 end;
2473 indY := indY + fSlope;
2474 indX := EnsureRange(indX, 0, Max(gMapInfo.Width, gPlayerScreenSize.X) - indW);
2475 indY := EnsureRange(indY, 0, Max(gMapInfo.Height, gPlayerScreenSize.Y) - indH);
2477 c := e_Colors;
2478 e_Colors := Color;
2479 e_DrawAdv(ID, indX, indY, 0, True, False, indA, @a);
2480 e_Colors := c;
2481 end;
2482 end;
2485 begin
2486 e_TextureFontGetSize(gStdFont, nW, nH);
2487 indX := fX + FObj.Rect.X + (FObj.Rect.Width - Length(FName) * nW) div 2;
2488 indY := fY - nH + fSlope;
2489 e_TextureFontPrintEx(indX, indY, FName, gStdFont, Color.R, Color.G, Color.B, 1.0, True);
2490 end;
2491 end;
2492 end;
2493 end;
2495 procedure TPlayer.DrawBubble();
2497 bubX, bubY, fX, fY: Integer;
2498 ID: LongWord;
2499 Rb, Gb, Bb,
2500 Rw, Gw, Bw: SmallInt;
2501 Dot: Byte;
2502 CObj: TObj;
2503 begin
2504 CObj := getCameraObj();
2505 CObj.lerp(gLerpFactor, fX, fY);
2506 // NB: _F_Obj.Rect is used to keep the bubble higher; this is not a mistake
2507 bubX := fX+FObj.Rect.X + IfThen(FDirection = TDirection.D_LEFT, -4, 18);
2508 bubY := fY+FObj.Rect.Y - 18;
2509 Rb := 64;
2510 Gb := 64;
2511 Bb := 64;
2512 Rw := 240;
2513 Gw := 240;
2514 Bw := 240;
2515 case gChatBubble of
2516 1: // simple textual non-bubble
2517 begin
2518 bubX := fX+FObj.Rect.X - 11;
2519 bubY := fY+FObj.Rect.Y - 17;
2520 e_TextureFontPrint(bubX, bubY, '[...]', gStdFont);
2521 Exit;
2522 end;
2523 2: // advanced pixel-perfect bubble
2524 begin
2525 if FTeam = TEAM_RED then
2526 Rb := 255
2527 else
2528 if FTeam = TEAM_BLUE then
2529 Bb := 255;
2530 end;
2531 3: // colored bubble
2532 begin
2533 Rb := FModel.Color.R;
2534 Gb := FModel.Color.G;
2535 Bb := FModel.Color.B;
2536 Rw := Min(Rb * 2 + 64, 255);
2537 Gw := Min(Gb * 2 + 64, 255);
2538 Bw := Min(Bb * 2 + 64, 255);
2539 if (Abs(Rw - Rb) < 32)
2540 or (Abs(Gw - Gb) < 32)
2541 or (Abs(Bw - Bb) < 32) then
2542 begin
2543 Rb := Max(Rw div 2 - 16, 0);
2544 Gb := Max(Gw div 2 - 16, 0);
2545 Bb := Max(Bw div 2 - 16, 0);
2546 end;
2547 end;
2548 4: // custom textured bubble
2549 begin
2550 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID) then
2551 if FDirection = TDirection.D_RIGHT then
2552 e_Draw(ID, bubX - 6, bubY - 7, 0, True, False)
2553 else
2554 e_Draw(ID, bubX - 6, bubY - 7, 0, True, False, TMirrorType.Horizontal);
2555 Exit;
2556 end;
2557 end;
2559 // Outer borders
2560 e_DrawQuad(bubX + 1, bubY , bubX + 18, bubY + 13, Rb, Gb, Bb);
2561 e_DrawQuad(bubX , bubY + 1, bubX + 19, bubY + 12, Rb, Gb, Bb);
2562 // Inner box
2563 e_DrawFillQuad(bubX + 1, bubY + 1, bubX + 18, bubY + 12, Rw, Gw, Bw, 0);
2565 // Tail
2566 Dot := IfThen(FDirection = TDirection.D_LEFT, 14, 5);
2567 e_DrawLine(1, bubX + Dot, bubY + 14, bubX + Dot, bubY + 16, Rb, Gb, Bb);
2568 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);
2569 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);
2570 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);
2571 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);
2573 // Dots
2574 Dot := 6;
2575 e_DrawFillQuad(bubX + Dot, bubY + 8, bubX + Dot + 1, bubY + 9, Rb, Gb, Bb, 0);
2576 e_DrawFillQuad(bubX + Dot + 3, bubY + 8, bubX + Dot + 4, bubY + 9, Rb, Gb, Bb, 0);
2577 e_DrawFillQuad(bubX + Dot + 6, bubY + 8, bubX + Dot + 7, bubY + 9, Rb, Gb, Bb, 0);
2578 end;
2580 procedure TPlayer.Draw();
2582 ID: DWORD;
2583 w, h: Word;
2584 dr: Boolean;
2585 Mirror: TMirrorType;
2586 fX, fY, fSlope: Integer;
2587 begin
2588 FObj.lerp(gLerpFactor, fX, fY);
2589 fSlope := nlerp(FSlopeOld, FObj.slopeUpLeft, gLerpFactor);
2591 if FAlive then
2592 begin
2593 if Direction = TDirection.D_RIGHT then
2594 Mirror := TMirrorType.None
2595 else
2596 Mirror := TMirrorType.Horizontal;
2598 if FPunchAnim <> nil then
2599 begin
2600 FPunchAnim.Draw(fX+IfThen(Direction = TDirection.D_LEFT, 15-FObj.Rect.X, FObj.Rect.X-15),
2601 fY+fSlope+FObj.Rect.Y-11, Mirror);
2602 if FPunchAnim.played then
2603 FreeAndNil(FPunchAnim);
2604 end;
2606 if (FPowerups[MR_INVUL] > gTime) and ((gPlayerDrawn <> Self) or (FSpawnInvul >= gTime)) then
2607 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID) then
2608 begin
2609 e_GetTextureSize(ID, @w, @h);
2610 if FDirection = TDirection.D_LEFT then
2611 e_Draw(ID, fX+FObj.Rect.X+(FObj.Rect.Width div 2)-(w div 2)+4,
2612 fY+FObj.Rect.Y+(FObj.Rect.Height div 2)-(h div 2)-7+fSlope, 0, True, False)
2613 else
2614 e_Draw(ID, fX+FObj.Rect.X+(FObj.Rect.Width div 2)-(w div 2)-2,
2615 fY+FObj.Rect.Y+(FObj.Rect.Height div 2)-(h div 2)-7+fSlope, 0, True, False);
2616 end;
2618 if FPowerups[MR_INVIS] > gTime then
2619 begin
2620 if (gPlayerDrawn <> nil) and ((Self = gPlayerDrawn) or
2621 ((FTeam = gPlayerDrawn.Team) and (gGameSettings.GameMode <> GM_DM))) then
2622 begin
2623 if (FPowerups[MR_INVIS] - gTime) <= 2100
2624 then dr := not Odd((FPowerups[MR_INVIS] - gTime) div 300)
2625 else dr := True;
2626 if dr
2627 then FModel.Draw(fX, fY+fSlope, 200)
2628 else FModel.Draw(fX, fY+fSlope);
2630 else
2631 FModel.Draw(fX, fY+fSlope, 255);
2633 else
2634 FModel.Draw(fX, fY+fSlope);
2635 end;
2637 if g_debug_Frames then
2638 begin
2639 e_DrawQuad(FObj.X+FObj.Rect.X,
2640 FObj.Y+FObj.Rect.Y,
2641 FObj.X+FObj.Rect.X+FObj.Rect.Width-1,
2642 FObj.Y+FObj.Rect.Y+FObj.Rect.Height-1,
2643 0, 255, 0);
2644 end;
2646 if (gChatBubble > 0) and (FKeys[KEY_CHAT].Pressed) and not FGhost then
2647 if (FPowerups[MR_INVIS] <= gTime) or ((gPlayerDrawn <> nil) and ((Self = gPlayerDrawn) or
2648 ((FTeam = gPlayerDrawn.Team) and (gGameSettings.GameMode <> GM_DM)))) then
2649 DrawBubble();
2650 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2651 if gAimLine and alive and
2652 ((Self = gPlayer1) or (Self = gPlayer2)) then
2653 DrawAim();
2654 end;
2657 procedure TPlayer.DrawAim();
2658 procedure drawCast (sz: Integer; ax0, ay0, ax1, ay1: Integer);
2660 ex, ey: Integer;
2661 begin
2663 {$IFDEF ENABLE_HOLMES}
2664 if isValidViewPort and (self = gPlayer1) then
2665 begin
2666 g_Holmes_plrLaser(ax0, ay0, ax1, ay1);
2667 end;
2668 {$ENDIF}
2670 e_DrawLine(sz, ax0, ay0, ax1, ay1, 255, 0, 0, 96);
2671 if (g_Map_traceToNearestWall(ax0, ay0, ax1, ay1, @ex, @ey) <> nil) then
2672 begin
2673 e_DrawLine(sz, ax0, ay0, ex, ey, 0, 255, 0, 96);
2675 else
2676 begin
2677 e_DrawLine(sz, ax0, ay0, ex, ey, 0, 0, 255, 96);
2678 end;
2679 end;
2682 wx, wy, xx, yy: Integer;
2683 angle: SmallInt;
2684 sz, len: Word;
2685 begin
2686 wx := FObj.X + WEAPONPOINT[FDirection].X + IfThen(FDirection = TDirection.D_LEFT, 7, -7);
2687 wy := FObj.Y + WEAPONPOINT[FDirection].Y;
2688 angle := FAngle;
2689 len := 1024;
2690 sz := 2;
2691 case FCurrWeap of
2692 0: begin // Punch
2693 len := 12;
2694 sz := 4;
2695 end;
2696 1: begin // Chainsaw
2697 len := 24;
2698 sz := 6;
2699 end;
2700 2: begin // Pistol
2701 len := 1024;
2702 sz := 2;
2703 if angle = ANGLE_RIGHTUP then Dec(angle, 2);
2704 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2705 if angle = ANGLE_LEFTUP then Inc(angle, 2);
2706 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2707 end;
2708 3: begin // Shotgun
2709 len := 1024;
2710 sz := 3;
2711 if angle = ANGLE_RIGHTUP then Dec(angle, 2);
2712 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2713 if angle = ANGLE_LEFTUP then Inc(angle, 2);
2714 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2715 end;
2716 4: begin // Double Shotgun
2717 len := 1024;
2718 sz := 4;
2719 if angle = ANGLE_RIGHTUP then Dec(angle, 2);
2720 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2721 if angle = ANGLE_LEFTUP then Inc(angle, 2);
2722 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2723 end;
2724 5: begin // Chaingun
2725 len := 1024;
2726 sz := 3;
2727 if angle = ANGLE_RIGHTUP then Dec(angle, 2);
2728 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2729 if angle = ANGLE_LEFTUP then Inc(angle, 2);
2730 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2731 end;
2732 6: begin // Rocket Launcher
2733 len := 1024;
2734 sz := 7;
2735 if angle = ANGLE_RIGHTUP then Inc(angle, 2);
2736 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2737 if angle = ANGLE_LEFTUP then Dec(angle, 2);
2738 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2739 end;
2740 7: begin // Plasmagun
2741 len := 1024;
2742 sz := 5;
2743 if angle = ANGLE_RIGHTUP then Inc(angle);
2744 if angle = ANGLE_RIGHTDOWN then Inc(angle, 3);
2745 if angle = ANGLE_LEFTUP then Dec(angle);
2746 if angle = ANGLE_LEFTDOWN then Dec(angle, 3);
2747 end;
2748 8: begin // BFG
2749 len := 1024;
2750 sz := 12;
2751 if angle = ANGLE_RIGHTUP then Inc(angle, 1);
2752 if angle = ANGLE_RIGHTDOWN then Inc(angle, 2);
2753 if angle = ANGLE_LEFTUP then Dec(angle, 1);
2754 if angle = ANGLE_LEFTDOWN then Dec(angle, 2);
2755 end;
2756 9: begin // Super Chaingun
2757 len := 1024;
2758 sz := 4;
2759 if angle = ANGLE_RIGHTUP then Dec(angle, 2);
2760 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2761 if angle = ANGLE_LEFTUP then Inc(angle, 2);
2762 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2763 end;
2764 end;
2765 xx := Trunc(Cos(-DegToRad(angle)) * len) + wx;
2766 yy := Trunc(Sin(-DegToRad(angle)) * len) + wy;
2767 {$IF DEFINED(D2F_DEBUG)}
2768 drawCast(sz, wx, wy, xx, yy);
2769 {$ELSE}
2770 e_DrawLine(sz, wx, wy, xx, yy, 255, 0, 0, 96);
2771 {$ENDIF}
2772 end;
2774 procedure TPlayer.DrawGUI();
2776 ID: DWORD;
2777 X, Y, SY, a, p, m: Integer;
2778 tw, th: Word;
2779 cw, ch: Byte;
2780 s: string;
2781 stat: TPlayerStatArray;
2782 begin
2783 X := gPlayerScreenSize.X;
2784 SY := gPlayerScreenSize.Y;
2785 Y := 0;
2787 if gShowScore and (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
2788 begin
2789 if gGameSettings.GameMode = GM_CTF
2790 then a := 32 + 8
2791 else a := 0;
2793 if gGameSettings.GameMode = GM_CTF then
2794 begin
2795 s := 'TEXTURE_PLAYER_REDFLAG';
2796 if gFlags[FLAG_RED].State = FLAG_STATE_CAPTURED then
2797 s := 'TEXTURE_PLAYER_REDFLAG_S';
2798 if gFlags[FLAG_RED].State = FLAG_STATE_DROPPED then
2799 s := 'TEXTURE_PLAYER_REDFLAG_D';
2800 if g_Texture_Get(s, ID) then
2801 e_Draw(ID, X-16-32, 240-72-4, 0, True, False);
2802 end;
2804 s := IntToStr(gTeamStat[TEAM_RED].Score);
2805 e_CharFont_GetSize(gMenuFont, s, tw, th);
2806 e_CharFont_PrintEx(gMenuFont, X-16-a-tw, 240-72-4, s, TEAMCOLOR[TEAM_RED]);
2808 if gGameSettings.GameMode = GM_CTF then
2809 begin
2810 s := 'TEXTURE_PLAYER_BLUEFLAG';
2811 if gFlags[FLAG_BLUE].State = FLAG_STATE_CAPTURED then
2812 s := 'TEXTURE_PLAYER_BLUEFLAG_S';
2813 if gFlags[FLAG_BLUE].State = FLAG_STATE_DROPPED then
2814 s := 'TEXTURE_PLAYER_BLUEFLAG_D';
2815 if g_Texture_Get(s, ID) then
2816 e_Draw(ID, X-16-32, 240-32-4, 0, True, False);
2817 end;
2819 s := IntToStr(gTeamStat[TEAM_BLUE].Score);
2820 e_CharFont_GetSize(gMenuFont, s, tw, th);
2821 e_CharFont_PrintEx(gMenuFont, X-16-a-tw, 240-32-4, s, TEAMCOLOR[TEAM_BLUE]);
2822 end;
2824 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID) then
2825 e_DrawFill(ID, X, 0, 1, (gPlayerScreenSize.Y div 256)+IfThen(gPlayerScreenSize.Y mod 256 > 0, 1, 0),
2826 0, False, False);
2828 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID) then
2829 e_Draw(ID, X+2, Y, 0, True, False);
2831 if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
2832 begin
2833 if gShowStat then
2834 begin
2835 s := IntToStr(Frags);
2836 e_CharFont_GetSize(gMenuFont, s, tw, th);
2837 e_CharFont_PrintEx(gMenuFont, X-16-tw, Y, s, _RGB(255, 0, 0));
2839 s := '';
2840 p := 1;
2841 m := 0;
2842 stat := g_Player_GetStats();
2843 if stat <> nil then
2844 begin
2845 p := 1;
2847 for a := 0 to High(stat) do
2848 if stat[a].Name <> Name then
2849 begin
2850 if stat[a].Frags > m then m := stat[a].Frags;
2851 if stat[a].Frags > Frags then p := p+1;
2852 end;
2853 end;
2855 s := IntToStr(p)+' / '+IntToStr(Length(stat))+' ';
2856 if Frags >= m then s := s+'+' else s := s+'-';
2857 s := s+IntToStr(Abs(Frags-m));
2859 e_CharFont_GetSize(gMenuSmallFont, s, tw, th);
2860 e_CharFont_PrintEx(gMenuSmallFont, X-16-tw, Y+32, s, _RGB(255, 0, 0));
2861 end;
2863 if gLMSRespawn > LMS_RESPAWN_NONE then
2864 begin
2865 s := _lc[I_GAME_WARMUP];
2866 e_CharFont_GetSize(gMenuFont, s, tw, th);
2867 s := s + ': ' + IntToStr((gLMSRespawnTime - gTime) div 1000);
2868 e_CharFont_PrintEx(gMenuFont, X-64-tw, SY-32, s, _RGB(0, 255, 0));
2870 else if gShowLives and (gGameSettings.MaxLives > 0) then
2871 begin
2872 s := IntToStr(Lives);
2873 e_CharFont_GetSize(gMenuFont, s, tw, th);
2874 e_CharFont_PrintEx(gMenuFont, X-16-tw, SY-32, s, _RGB(0, 255, 0));
2875 end;
2876 end;
2878 e_CharFont_GetSize(gMenuSmallFont, FName, tw, th);
2879 e_CharFont_PrintEx(gMenuSmallFont, X+98-(tw div 2), Y+8, FName, _RGB(255, 0, 0));
2881 if R_BERSERK in FInventory
2882 then e_Draw(gItemsTexturesID[ITEM_MEDKIT_BLACK], X+37, Y+45, 0, True, False)
2883 else e_Draw(gItemsTexturesID[ITEM_MEDKIT_LARGE], X+37, Y+45, 0, True, False);
2885 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID) then
2886 e_Draw(ID, X+36, Y+77, 0, True, False);
2888 s := IntToStr(IfThen(FHealth > 0, FHealth, 0));
2889 e_CharFont_GetSize(gMenuFont, s, tw, th);
2890 e_CharFont_PrintEx(gMenuFont, X+178-tw, Y+40, s, _RGB(255, 0, 0));
2892 s := IntToStr(FArmor);
2893 e_CharFont_GetSize(gMenuFont, s, tw, th);
2894 e_CharFont_PrintEx(gMenuFont, X+178-tw, Y+68, s, _RGB(255, 0, 0));
2896 s := IntToStr(GetAmmoByWeapon(FCurrWeap));
2898 case FCurrWeap of
2899 WEAPON_IRONFIST:
2900 begin
2901 s := '--';
2902 ID := gItemsTexturesID[ITEM_WEAPON_IRONFIST];
2903 end;
2904 WEAPON_SAW:
2905 begin
2906 s := '--';
2907 ID := gItemsTexturesID[ITEM_WEAPON_SAW];
2908 end;
2909 WEAPON_PISTOL: ID := gItemsTexturesID[ITEM_WEAPON_PISTOL];
2910 WEAPON_CHAINGUN: ID := gItemsTexturesID[ITEM_WEAPON_CHAINGUN];
2911 WEAPON_SHOTGUN1: ID := gItemsTexturesID[ITEM_WEAPON_SHOTGUN1];
2912 WEAPON_SHOTGUN2: ID := gItemsTexturesID[ITEM_WEAPON_SHOTGUN2];
2913 WEAPON_SUPERCHAINGUN: ID := gItemsTexturesID[ITEM_WEAPON_SUPERCHAINGUN];
2914 WEAPON_ROCKETLAUNCHER: ID := gItemsTexturesID[ITEM_WEAPON_ROCKETLAUNCHER];
2915 WEAPON_PLASMA: ID := gItemsTexturesID[ITEM_WEAPON_PLASMA];
2916 WEAPON_BFG: ID := gItemsTexturesID[ITEM_WEAPON_BFG];
2917 WEAPON_FLAMETHROWER: ID := gItemsTexturesID[ITEM_WEAPON_FLAMETHROWER];
2918 end;
2920 e_CharFont_GetSize(gMenuFont, s, tw, th);
2921 e_CharFont_PrintEx(gMenuFont, X+178-tw, Y+158, s, _RGB(255, 0, 0));
2922 e_Draw(ID, X+20, Y+160, 0, True, False);
2924 if R_KEY_RED in FInventory then
2925 e_Draw(gItemsTexturesID[ITEM_KEY_RED], X+78, Y+214, 0, True, False);
2927 if R_KEY_GREEN in FInventory then
2928 e_Draw(gItemsTexturesID[ITEM_KEY_GREEN], X+95, Y+214, 0, True, False);
2930 if R_KEY_BLUE in FInventory then
2931 e_Draw(gItemsTexturesID[ITEM_KEY_BLUE], X+112, Y+214, 0, True, False);
2933 if FJetFuel > 0 then
2934 begin
2935 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID) then
2936 e_Draw(ID, X+2, Y+116, 0, True, False);
2937 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID) then
2938 e_Draw(ID, X+2, Y+126, 0, True, False);
2939 e_DrawLine(4, X+16, Y+122, X+16+Trunc(168*IfThen(FAir > 0, FAir, 0)/AIR_MAX), Y+122, 0, 0, 196);
2940 e_DrawLine(4, X+16, Y+132, X+16+Trunc(168*FJetFuel/JET_MAX), Y+132, 208, 0, 0);
2942 else
2943 begin
2944 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID) then
2945 e_Draw(ID, X+2, Y+124, 0, True, False);
2946 e_DrawLine(4, X+16, Y+130, X+16+Trunc(168*IfThen(FAir > 0, FAir, 0)/AIR_MAX), Y+130, 0, 0, 196);
2947 end;
2949 if gShowPing and g_Game_IsClient then
2950 begin
2951 s := _lc[I_GAME_PING_HUD] + IntToStr(NetPeer.lastRoundTripTime) + _lc[I_NET_SLIST_PING_MS];
2952 e_TextureFontPrint(X + 4, Y + 242, s, gStdFont);
2953 Y := Y + 16;
2954 end;
2956 if FSpectator then
2957 begin
2958 e_TextureFontPrint(X + 4, Y + 242, _lc[I_PLAYER_SPECT], gStdFont);
2959 e_TextureFontPrint(X + 4, Y + 258, _lc[I_PLAYER_SPECT2], gStdFont);
2960 e_TextureFontPrint(X + 4, Y + 274, _lc[I_PLAYER_SPECT1], gStdFont);
2961 if FNoRespawn then
2962 begin
2963 e_TextureFontGetSize(gStdFont, cw, ch);
2964 s := _lc[I_PLAYER_SPECT4];
2965 e_TextureFontPrintEx(gScreenWidth div 2 - cw*(Length(s) div 2),
2966 gScreenHeight-4-ch, s, gStdFont, 255, 255, 255, 1, True);
2967 e_TextureFontPrint(X + 4, Y + 290, _lc[I_PLAYER_SPECT1S], gStdFont);
2968 end;
2970 end;
2971 end;
2973 procedure TPlayer.DrawOverlay();
2975 dr: Boolean;
2976 begin
2977 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2978 if (FPowerups[MR_INVUL] >= gTime) and (FSpawnInvul < gTime) then
2979 begin
2980 if (FPowerups[MR_INVUL]-gTime) <= 2100 then
2981 dr := not Odd((FPowerups[MR_INVUL]-gTime) div 300)
2982 else
2983 dr := True;
2985 if dr then
2986 e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1,
2987 191, 191, 191, 0, TBlending.Invert);
2988 end;
2990 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2991 if FPowerups[MR_SUIT] >= gTime then
2992 begin
2993 if (FPowerups[MR_SUIT]-gTime) <= 2100 then
2994 dr := not Odd((FPowerups[MR_SUIT]-gTime) div 300)
2995 else
2996 dr := True;
2998 if dr then
2999 e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1,
3000 0, 96, 0, 200, TBlending.None);
3001 end;
3003 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
3004 if (FBerserk >= 0) and (LongWord(FBerserk) >= gTime) and (gFlash = 2) then
3005 begin
3006 e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1,
3007 255, 0, 0, 200, TBlending.None);
3008 end;
3009 end;
3011 procedure TPlayer.DrawPain();
3013 a, h: Integer;
3014 begin
3015 if FPain = 0 then Exit;
3017 a := FPain;
3019 if a < 15 then h := 0
3020 else if a < 35 then h := 1
3021 else if a < 55 then h := 2
3022 else if a < 75 then h := 3
3023 else if a < 95 then h := 4
3024 else h := 5;
3026 //if a > 255 then a := 255;
3028 e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255, 0, 0, 255-h*50);
3029 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
3030 end;
3032 procedure TPlayer.DrawPickup();
3034 a, h: Integer;
3035 begin
3036 if FPickup = 0 then Exit;
3038 a := FPickup;
3040 if a < 15 then h := 1
3041 else if a < 35 then h := 2
3042 else if a < 55 then h := 3
3043 else if a < 75 then h := 4
3044 else h := 5;
3046 e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 150, 200, 150, 255-h*50);
3047 end;
3049 procedure TPlayer.DoPunch();
3051 id: DWORD;
3052 st: String;
3053 begin
3054 if FPunchAnim <> nil then
3055 begin
3056 FPunchAnim.reset();
3057 FPunchAnim.Destroy();
3058 end;
3059 st := 'FRAMES_PUNCH';
3060 if R_BERSERK in FInventory then
3061 st := st + '_BERSERK';
3062 if FKeys[KEY_UP].Pressed then
3063 st := st + '_UP'
3064 else if FKeys[KEY_DOWN].Pressed then
3065 st := st + '_DN';
3066 g_Frames_Get(id, st);
3067 FPunchAnim := TAnimation.Create(id, False, 1);
3068 end;
3070 procedure TPlayer.Fire();
3072 f, DidFire: Boolean;
3073 wx, wy, xd, yd: Integer;
3074 locobj: TObj;
3075 ProjID: SizeInt = -1;
3076 begin
3077 if g_Game_IsClient then Exit;
3078 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
3079 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
3081 if FSpectator then
3082 begin
3083 Respawn(False);
3084 Exit;
3085 end;
3087 if FReloading[FCurrWeap] <> 0 then Exit;
3089 DidFire := False;
3091 f := False;
3092 wx := FObj.X+WEAPONPOINT[FDirection].X;
3093 wy := FObj.Y+WEAPONPOINT[FDirection].Y;
3094 xd := wx+IfThen(FDirection = TDirection.D_LEFT, -30, 30);
3095 yd := wy+firediry();
3097 case FCurrWeap of
3098 WEAPON_IRONFIST:
3099 begin
3100 DoPunch();
3101 if R_BERSERK in FInventory then
3102 begin
3103 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
3104 locobj.X := FObj.X+FObj.Rect.X;
3105 locobj.Y := FObj.Y+FObj.Rect.Y;
3106 locobj.rect.X := 0;
3107 locobj.rect.Y := 0;
3108 locobj.rect.Width := 39;
3109 locobj.rect.Height := 52;
3110 locobj.Vel.X := (xd-wx) div 2;
3111 locobj.Vel.Y := (yd-wy) div 2;
3112 locobj.Accel.X := xd-wx;
3113 locobj.Accel.y := yd-wy;
3115 if g_Weapon_Hit(@locobj, 50, FUID, HIT_SOME) <> 0 then
3116 begin
3117 {$IFDEF ENABLE_SOUND}
3118 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj.X, FObj.Y)
3119 {$ENDIF}
3121 else
3122 begin
3123 {$IFDEF ENABLE_SOUND}
3124 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj.X, FObj.Y);
3125 {$ENDIF}
3126 end;
3128 if (gFlash = 1) and (FPain < 50) then FPain := min(FPain + 25, 50);
3130 else
3131 g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 3, FUID);
3133 DidFire := True;
3134 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3135 end;
3137 WEAPON_SAW:
3138 begin
3139 {$IFDEF ENABLE_SOUND}
3140 if g_Weapon_chainsaw(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y,
3141 IfThen(gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF], 9, 3), FUID) <> 0 then
3142 begin
3143 FSawSoundSelect.Stop();
3144 FSawSound.Stop();
3145 FSawSoundHit.PlayAt(FObj.X, FObj.Y);
3147 else if not FSawSoundHit.IsPlaying() then
3148 begin
3149 FSawSoundSelect.Stop();
3150 FSawSound.PlayAt(FObj.X, FObj.Y);
3151 end;
3152 {$ELSE}
3153 g_Weapon_chainsaw(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y,
3154 IfThen(gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF], 9, 3), FUID);
3155 {$ENDIF}
3157 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3158 DidFire := True;
3159 f := True;
3160 end;
3162 WEAPON_PISTOL:
3163 if FAmmo[A_BULLETS] > 0 then
3164 begin
3165 g_Weapon_pistol(wx, wy, xd, yd, FUID);
3166 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3167 Dec(FAmmo[A_BULLETS]);
3168 FFireAngle := FAngle;
3169 f := True;
3170 DidFire := True;
3171 g_Player_CreateShell(
3172 GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
3173 GameVelX, GameVelY-2,
3174 SHELL_BULLET
3176 end;
3178 WEAPON_SHOTGUN1:
3179 if FAmmo[A_SHELLS] > 0 then
3180 begin
3181 g_Weapon_shotgun(wx, wy, xd, yd, FUID);
3182 {$IFDEF ENABLE_SOUND}
3183 if not gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx, wy);
3184 {$ENDIF}
3185 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3186 Dec(FAmmo[A_SHELLS]);
3187 FFireAngle := FAngle;
3188 f := True;
3189 DidFire := True;
3190 FShellTimer := 10;
3191 FShellType := SHELL_SHELL;
3192 end;
3194 WEAPON_SHOTGUN2:
3195 if FAmmo[A_SHELLS] >= 2 then
3196 begin
3197 g_Weapon_dshotgun(wx, wy, xd, yd, FUID);
3198 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3199 Dec(FAmmo[A_SHELLS], 2);
3200 FFireAngle := FAngle;
3201 f := True;
3202 DidFire := True;
3203 FShellTimer := 13;
3204 FShellType := SHELL_DBLSHELL;
3205 end;
3207 WEAPON_CHAINGUN:
3208 if FAmmo[A_BULLETS] > 0 then
3209 begin
3210 g_Weapon_mgun(wx, wy, xd, yd, FUID);
3211 {$IFDEF ENABLE_SOUND}
3212 if not gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx, wy);
3213 {$ENDIF}
3214 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3215 Dec(FAmmo[A_BULLETS]);
3216 FFireAngle := FAngle;
3217 f := True;
3218 DidFire := True;
3219 g_Player_CreateShell(
3220 GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
3221 GameVelX, GameVelY-2,
3222 SHELL_BULLET
3224 end;
3226 WEAPON_ROCKETLAUNCHER:
3227 if FAmmo[A_ROCKETS] > 0 then
3228 begin
3229 ProjID := g_Weapon_rocket(wx, wy, xd, yd, FUID);
3230 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3231 Dec(FAmmo[A_ROCKETS]);
3232 FFireAngle := FAngle;
3233 f := True;
3234 DidFire := True;
3235 end;
3237 WEAPON_PLASMA:
3238 if FAmmo[A_CELLS] > 0 then
3239 begin
3240 ProjID := g_Weapon_plasma(wx, wy, xd, yd, FUID);
3241 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3242 Dec(FAmmo[A_CELLS]);
3243 FFireAngle := FAngle;
3244 f := True;
3245 DidFire := True;
3246 end;
3248 WEAPON_BFG:
3249 if (FAmmo[A_CELLS] >= 40) and (FBFGFireCounter = -1) then
3250 begin
3251 FBFGFireCounter := 17;
3252 {$IFDEF ENABLE_SOUND}
3253 if not FNoReload then
3254 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj.X, FObj.Y);
3255 {$ENDIF}
3256 Dec(FAmmo[A_CELLS], 40);
3257 DidFire := True;
3258 end;
3260 WEAPON_SUPERCHAINGUN:
3261 if FAmmo[A_SHELLS] > 0 then
3262 begin
3263 g_Weapon_shotgun(wx, wy, xd, yd, FUID);
3264 {$IFDEF ENABLE_SOUND}
3265 if not gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx, wy);
3266 {$ENDIF}
3267 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3268 Dec(FAmmo[A_SHELLS]);
3269 FFireAngle := FAngle;
3270 f := True;
3271 DidFire := True;
3272 g_Player_CreateShell(
3273 GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
3274 GameVelX, GameVelY-2,
3275 SHELL_SHELL
3277 end;
3279 WEAPON_FLAMETHROWER:
3280 if FAmmo[A_FUEL] > 0 then
3281 begin
3282 ProjID := g_Weapon_flame(wx, wy, xd, yd, FUID);
3283 FlamerOn();
3284 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3285 Dec(FAmmo[A_FUEL]);
3286 FFireAngle := FAngle;
3287 f := True;
3288 DidFire := True;
3290 else
3291 begin
3292 FlamerOff();
3293 if g_Game_IsNet and g_Game_IsServer then MH_SEND_PlayerStats(FUID);
3294 end;
3295 end;
3297 if g_Game_IsNet then
3298 begin
3299 if DidFire then
3300 begin
3301 if FCurrWeap <> WEAPON_BFG then
3302 MH_SEND_PlayerFire(FUID, FCurrWeap, wx, wy, xd, yd, ProjID)
3303 else
3304 if not FNoReload then
3305 MH_SEND_Sound(FObj.X, FObj.Y, 'SOUND_WEAPON_STARTFIREBFG');
3306 end;
3308 MH_SEND_PlayerStats(FUID);
3309 end;
3311 if not f then Exit;
3313 case FAngle of
3314 0, 180: SetAction(A_ATTACK);
3315 ANGLE_LEFTDOWN, ANGLE_RIGHTDOWN: SetAction(A_ATTACKDOWN);
3316 ANGLE_LEFTUP, ANGLE_RIGHTUP: SetAction(A_ATTACKUP);
3317 end;
3318 end;
3320 function TPlayer.GetAmmoByWeapon(Weapon: Byte): Word;
3321 begin
3322 case Weapon of
3323 WEAPON_PISTOL, WEAPON_CHAINGUN: Result := FAmmo[A_BULLETS];
3324 WEAPON_SHOTGUN1, WEAPON_SHOTGUN2, WEAPON_SUPERCHAINGUN: Result := FAmmo[A_SHELLS];
3325 WEAPON_ROCKETLAUNCHER: Result := FAmmo[A_ROCKETS];
3326 WEAPON_PLASMA, WEAPON_BFG: Result := FAmmo[A_CELLS];
3327 WEAPON_FLAMETHROWER: Result := FAmmo[A_FUEL];
3328 else Result := 0;
3329 end;
3330 end;
3332 function TPlayer.HeadInLiquid(XInc, YInc: Integer): Boolean;
3333 begin
3334 Result := g_Map_CollidePanel(FObj.X+PLAYER_HEADRECT.X+XInc, FObj.Y+PLAYER_HEADRECT.Y+YInc,
3335 PLAYER_HEADRECT.Width, PLAYER_HEADRECT.Height,
3336 PANEL_WATER or PANEL_ACID1 or PANEL_ACID2, True);
3337 end;
3339 procedure TPlayer.FlamerOn;
3340 begin
3341 {$IFDEF ENABLE_SOUND}
3342 FFlameSoundOff.Stop();
3343 FFlameSoundOff.SetPosition(0);
3344 if FFlaming then
3345 begin
3346 if (not FFlameSoundOn.IsPlaying()) and (not FFlameSoundWork.IsPlaying()) then
3347 FFlameSoundWork.PlayAt(FObj.X, FObj.Y);
3349 else
3350 begin
3351 FFlameSoundOn.PlayAt(FObj.X, FObj.Y);
3352 end;
3353 {$ENDIF}
3354 FFlaming := True;
3355 end;
3357 procedure TPlayer.FlamerOff;
3358 begin
3359 {$IFDEF ENABLE_SOUND}
3360 if FFlaming then
3361 begin
3362 FFlameSoundOn.Stop();
3363 FFlameSoundOn.SetPosition(0);
3364 FFlameSoundWork.Stop();
3365 FFlameSoundWork.SetPosition(0);
3366 FFlameSoundOff.PlayAt(FObj.X, FObj.Y);
3367 end;
3368 {$ENDIF}
3369 FFlaming := False;
3370 end;
3372 procedure TPlayer.JetpackOn;
3373 begin
3374 {$IFDEF ENABLE_SOUND}
3375 FJetSoundFly.Stop;
3376 FJetSoundOff.Stop;
3377 FJetSoundOn.SetPosition(0);
3378 FJetSoundOn.PlayAt(FObj.X, FObj.Y);
3379 {$ENDIF}
3380 FlySmoke(8);
3381 end;
3383 procedure TPlayer.JetpackOff;
3384 begin
3385 {$IFDEF ENABLE_SOUND}
3386 FJetSoundFly.Stop;
3387 FJetSoundOn.Stop;
3388 FJetSoundOff.SetPosition(0);
3389 FJetSoundOff.PlayAt(FObj.X, FObj.Y);
3390 {$ENDIF}
3391 end;
3393 procedure TPlayer.CatchFire(Attacker: Word; Timeout: Integer = PLAYER_BURN_TIME);
3394 begin
3395 if Timeout <= 0 then
3396 exit;
3397 if (FPowerups[MR_SUIT] > gTime) or (FPowerups[MR_INVUL] > gTime) then
3398 exit; // Íå çàãîðàåìñÿ êîãäà åñòü çàùèòà
3399 if g_Obj_CollidePanel(@FObj, 0, 0, PANEL_WATER or PANEL_ACID1 or PANEL_ACID2) then
3400 exit; // Íå ïîäãîðàåì â âîäå íà âñÿêèé ñëó÷àé
3401 {$IFDEF ENABLE_SOUND}
3402 if FFireTime <= 0 then
3403 g_Sound_PlayExAt('SOUND_IGNITE', FObj.X, FObj.Y);
3404 {$ENDIF}
3405 FFireTime := Timeout;
3406 FFireAttacker := Attacker;
3407 if g_Game_IsNet and g_Game_IsServer then
3408 MH_SEND_PlayerStats(FUID);
3409 end;
3411 procedure TPlayer.Jump();
3412 begin
3413 if gFly or FJetpack then
3414 begin
3415 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
3416 if FObj.Vel.Y > -VEL_FLY then
3417 FObj.Vel.Y := FObj.Vel.Y - 3;
3418 if FJetpack then
3419 begin
3420 if FJetFuel > 0 then
3421 Dec(FJetFuel);
3422 if (FJetFuel < 1) and g_Game_IsServer then
3423 begin
3424 FJetpack := False;
3425 JetpackOff;
3426 if g_Game_IsNet then
3427 MH_SEND_PlayerStats(FUID);
3428 end;
3429 end;
3430 Exit;
3431 end;
3433 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
3434 if FGhost then
3435 FCanJetpack := False;
3437 // Ïðûãàåì èëè âñïëûâàåì:
3438 if (CollideLevel(0, 1) or
3439 g_Map_CollidePanel(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y+36, PLAYER_RECT.Width,
3440 PLAYER_RECT.Height-33, PANEL_STEP, False)
3441 ) and (FObj.Accel.Y = 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
3442 begin
3443 FObj.Vel.Y := -VEL_JUMP;
3444 FCanJetpack := False;
3446 else
3447 begin
3448 if BodyInLiquid(0, 0) then
3449 FObj.Vel.Y := -VEL_SW
3450 else if (FJetFuel > 0) and FCanJetpack and
3451 g_Game_IsServer and (not g_Obj_CollideLiquid(@FObj, 0, 0)) then
3452 begin
3453 FJetpack := True;
3454 JetpackOn;
3455 if g_Game_IsNet then
3456 MH_SEND_PlayerStats(FUID);
3457 end;
3458 end;
3459 end;
3461 procedure TPlayer.Kill(KillType: Byte; SpawnerUID: Word; t: Byte);
3463 a, i, k, ab, ar: Byte;
3464 s: String;
3465 mon: TMonster;
3466 plr: TPlayer;
3467 srv, netsrv: Boolean;
3468 DoFrags: Boolean;
3469 OldLR: Byte;
3470 KP: TPlayer;
3471 it: PItem;
3473 procedure PushItem(t: Byte);
3475 id: DWORD;
3476 begin
3477 id := g_Items_Create(FObj.X, FObj.Y, t, True, False);
3478 it := g_Items_ByIdx(id);
3479 if KillType = K_EXTRAHARDKILL then // -7..+7; -8..0
3480 begin
3481 g_Obj_Push(@it.Obj, (FObj.Vel.X div 2)-7+Random(15),
3482 (FObj.Vel.Y div 2)-Random(9));
3483 it.positionChanged(); // this updates spatial accelerators
3485 else
3486 begin
3487 if KillType = K_HARDKILL then // -5..+5; -5..0
3488 begin
3489 g_Obj_Push(@it.Obj, (FObj.Vel.X div 2)-5+Random(11),
3490 (FObj.Vel.Y div 2)-Random(6));
3492 else // -3..+3; -3..0
3493 begin
3494 g_Obj_Push(@it.Obj, (FObj.Vel.X div 2)-3+Random(7),
3495 (FObj.Vel.Y div 2)-Random(4));
3496 end;
3497 it.positionChanged(); // this updates spatial accelerators
3498 end;
3500 if g_Game_IsNet and g_Game_IsServer then
3501 MH_SEND_ItemSpawn(True, id);
3502 end;
3504 begin
3505 DoFrags := (gGameSettings.MaxLives = 0) or (gGameSettings.GameMode = GM_COOP);
3506 Srv := g_Game_IsServer;
3507 Netsrv := g_Game_IsServer and g_Game_IsNet;
3508 if Srv then FDeath := FDeath + 1;
3509 if FAlive then
3510 begin
3511 if FGhost then
3512 FGhost := False;
3513 if not FPhysics then
3514 FPhysics := True;
3515 FAlive := False;
3516 end;
3517 FShellTimer := -1;
3519 if (gGameSettings.MaxLives > 0) and Srv and (gLMSRespawn = LMS_RESPAWN_NONE) then
3520 begin
3521 if FLives > 0 then FLives := FLives - 1;
3522 if FLives = 0 then FNoRespawn := True;
3523 end;
3525 // Íîìåð òèïà ñìåðòè:
3526 a := 1;
3527 case KillType of
3528 K_SIMPLEKILL: a := 1;
3529 K_HARDKILL: a := 2;
3530 K_EXTRAHARDKILL: a := 3;
3531 K_FALLKILL: a := 4;
3532 end;
3534 // Çâóê ñìåðòè:
3535 {$IFDEF ENABLE_SOUND}
3536 if not FModel.PlaySound(MODELSOUND_DIE, a, FObj.X, FObj.Y) then
3537 for i := 1 to 3 do
3538 if FModel.PlaySound(MODELSOUND_DIE, i, FObj.X, FObj.Y) then
3539 Break;
3540 {$ENDIF}
3542 // Âðåìÿ ðåñïàóíà:
3543 if Srv then
3544 case KillType of
3545 K_SIMPLEKILL:
3546 FTime[T_RESPAWN] := gTime + TIME_RESPAWN1;
3547 K_HARDKILL:
3548 FTime[T_RESPAWN] := gTime + TIME_RESPAWN2;
3549 K_EXTRAHARDKILL, K_FALLKILL:
3550 FTime[T_RESPAWN] := gTime + TIME_RESPAWN3;
3551 end;
3553 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3554 case KillType of
3555 K_SIMPLEKILL:
3556 SetAction(A_DIE1);
3557 K_HARDKILL, K_EXTRAHARDKILL:
3558 SetAction(A_DIE2);
3559 end;
3561 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3562 if (KillType <> K_FALLKILL) and (Srv) then
3563 g_Monsters_killedp();
3565 if SpawnerUID = FUID then
3566 begin // Ñàìîóáèëñÿ
3567 if Srv then
3568 begin
3569 if gGameSettings.GameMode = GM_TDM then
3570 Dec(gTeamStat[FTeam].Score);
3571 if DoFrags or (gGameSettings.GameMode = GM_TDM) then
3572 begin
3573 Dec(FFrags);
3574 FLastFrag := 0;
3575 end;
3576 end;
3577 g_Console_Add(Format(_lc[I_PLAYER_KILL_SELF], [FName]), True);
3579 else
3580 if g_GetUIDType(SpawnerUID) = UID_PLAYER then
3581 begin // Óáèò äðóãèì èãðîêîì
3582 KP := g_Player_Get(SpawnerUID);
3583 if (KP <> nil) and Srv then
3584 begin
3585 if (DoFrags or (gGameSettings.GameMode = GM_TDM)) then
3586 if SameTeam(FUID, SpawnerUID) then
3587 begin
3588 Dec(KP.FFrags);
3589 KP.FLastFrag := 0;
3590 end else
3591 begin
3592 Inc(KP.FFrags);
3593 KP.FragCombo();
3594 end;
3596 if (gGameSettings.GameMode = GM_TDM) and DoFrags then
3597 Inc(gTeamStat[KP.Team].Score,
3598 IfThen(SameTeam(FUID, SpawnerUID), -1, 1));
3600 if netsrv then MH_SEND_PlayerStats(SpawnerUID);
3601 end;
3603 plr := g_Player_Get(SpawnerUID);
3604 if plr = nil then
3605 s := '?'
3606 else
3607 s := plr.FName;
3609 case KillType of
3610 K_HARDKILL:
3611 g_Console_Add(Format(_lc[I_PLAYER_KILL_EXTRAHARD_2],
3612 [FName, s]),
3613 gShowKillMsg);
3614 K_EXTRAHARDKILL:
3615 g_Console_Add(Format(_lc[I_PLAYER_KILL_EXTRAHARD_1],
3616 [FName, s]),
3617 gShowKillMsg);
3618 else
3619 g_Console_Add(Format(_lc[I_PLAYER_KILL],
3620 [FName, s]),
3621 gShowKillMsg);
3622 end;
3624 else if g_GetUIDType(SpawnerUID) = UID_MONSTER then
3625 begin // Óáèò ìîíñòðîì
3626 mon := g_Monsters_ByUID(SpawnerUID);
3627 if mon = nil then
3628 s := '?'
3629 else
3630 s := g_Mons_GetKilledByTypeId(mon.MonsterType);
3632 case KillType of
3633 K_HARDKILL:
3634 g_Console_Add(Format(_lc[I_PLAYER_KILL_EXTRAHARD_2],
3635 [FName, s]),
3636 gShowKillMsg);
3637 K_EXTRAHARDKILL:
3638 g_Console_Add(Format(_lc[I_PLAYER_KILL_EXTRAHARD_1],
3639 [FName, s]),
3640 gShowKillMsg);
3641 else
3642 g_Console_Add(Format(_lc[I_PLAYER_KILL],
3643 [FName, s]),
3644 gShowKillMsg);
3645 end;
3647 else // Îñîáûå òèïû ñìåðòè
3648 case t of
3649 HIT_DISCON: ;
3650 HIT_SELF: g_Console_Add(Format(_lc[I_PLAYER_KILL_SELF], [FName]), True);
3651 HIT_FALL: g_Console_Add(Format(_lc[I_PLAYER_KILL_FALL], [FName]), True);
3652 HIT_WATER: g_Console_Add(Format(_lc[I_PLAYER_KILL_WATER], [FName]), True);
3653 HIT_ACID: g_Console_Add(Format(_lc[I_PLAYER_KILL_ACID], [FName]), True);
3654 HIT_TRAP: g_Console_Add(Format(_lc[I_PLAYER_KILL_TRAP], [FName]), True);
3655 else g_Console_Add(Format(_lc[I_PLAYER_DIED], [FName]), True);
3656 end;
3658 if Srv then
3659 begin
3660 // Âûáðîñ îðóæèÿ:
3661 for a := WP_FIRST to WP_LAST do
3662 if FWeapon[a] then
3663 begin
3664 case a of
3665 WEAPON_SAW: i := ITEM_WEAPON_SAW;
3666 WEAPON_SHOTGUN1: i := ITEM_WEAPON_SHOTGUN1;
3667 WEAPON_SHOTGUN2: i := ITEM_WEAPON_SHOTGUN2;
3668 WEAPON_CHAINGUN: i := ITEM_WEAPON_CHAINGUN;
3669 WEAPON_ROCKETLAUNCHER: i := ITEM_WEAPON_ROCKETLAUNCHER;
3670 WEAPON_PLASMA: i := ITEM_WEAPON_PLASMA;
3671 WEAPON_BFG: i := ITEM_WEAPON_BFG;
3672 WEAPON_SUPERCHAINGUN: i := ITEM_WEAPON_SUPERCHAINGUN;
3673 WEAPON_FLAMETHROWER: i := ITEM_WEAPON_FLAMETHROWER;
3674 else i := 0;
3675 end;
3677 if i <> 0 then
3678 PushItem(i);
3679 end;
3681 // Âûáðîñ ðþêçàêà:
3682 if R_ITEM_BACKPACK in FInventory then
3683 PushItem(ITEM_AMMO_BACKPACK);
3685 // Âûáðîñ ðàêåòíîãî ðàíöà:
3686 if FJetFuel > 0 then
3687 PushItem(ITEM_JETPACK);
3689 // Âûáðîñ êëþ÷åé:
3690 if (not (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF])) or
3691 (not (TGameOption.DM_KEYS in gGameSettings.Options)) then
3692 begin
3693 if R_KEY_RED in FInventory then
3694 PushItem(ITEM_KEY_RED);
3696 if R_KEY_GREEN in FInventory then
3697 PushItem(ITEM_KEY_GREEN);
3699 if R_KEY_BLUE in FInventory then
3700 PushItem(ITEM_KEY_BLUE);
3701 end;
3703 // Âûáðîñ ôëàãà:
3704 DropFlag(KillType = K_FALLKILL);
3705 end;
3707 FCorpse := g_Player_CreateCorpse(Self);
3709 if Srv and (gGameSettings.MaxLives > 0) and FNoRespawn and
3710 (gLMSRespawn = LMS_RESPAWN_NONE) then
3711 begin
3712 a := 0;
3713 k := 0;
3714 ar := 0;
3715 ab := 0;
3716 for i := Low(gPlayers) to High(gPlayers) do
3717 begin
3718 if gPlayers[i] = nil then continue;
3719 if (not gPlayers[i].FNoRespawn) and (not gPlayers[i].FSpectator) then
3720 begin
3721 Inc(a);
3722 if gPlayers[i].FTeam = TEAM_RED then Inc(ar)
3723 else if gPlayers[i].FTeam = TEAM_BLUE then Inc(ab);
3724 k := i;
3725 end;
3726 end;
3728 OldLR := gLMSRespawn;
3729 if (gGameSettings.GameMode = GM_COOP) then
3730 begin
3731 if (a = 0) then
3732 begin
3733 // everyone is dead, restart the map
3734 g_Game_Message(_lc[I_MESSAGE_LMS_LOSE], 144);
3735 if Netsrv then
3736 MH_SEND_GameEvent(NET_EV_LMS_LOSE);
3737 gLMSRespawn := LMS_RESPAWN_FINAL;
3738 gLMSRespawnTime := gTime + 5000;
3740 else if (a = 1) then
3741 begin
3742 if (gPlayers[k] <> nil) and not (gPlayers[k] is TBot) then
3743 if (gPlayers[k] = gPlayer1) or
3744 (gPlayers[k] = gPlayer2) then
3745 g_Console_Add('*** ' + _lc[I_MESSAGE_LMS_SURVIVOR] + ' ***', True)
3746 else if Netsrv and (gPlayers[k].FClientID >= 0) then
3747 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR, 0, 'N', gPlayers[k].FClientID);
3748 end;
3750 else if (gGameSettings.GameMode = GM_TDM) then
3751 begin
3752 if (ab = 0) and (ar <> 0) then
3753 begin
3754 // blu team ded
3755 g_Game_Message(Format(_lc[I_MESSAGE_TLMS_WIN], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 144);
3756 if Netsrv then
3757 MH_SEND_GameEvent(NET_EV_TLMS_WIN, TEAM_RED);
3758 Inc(gTeamStat[TEAM_RED].Score);
3759 gLMSRespawn := LMS_RESPAWN_FINAL;
3760 gLMSRespawnTime := gTime + 5000;
3762 else if (ar = 0) and (ab <> 0) then
3763 begin
3764 // red team ded
3765 g_Game_Message(Format(_lc[I_MESSAGE_TLMS_WIN], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 144);
3766 if Netsrv then
3767 MH_SEND_GameEvent(NET_EV_TLMS_WIN, TEAM_BLUE);
3768 Inc(gTeamStat[TEAM_BLUE].Score);
3769 gLMSRespawn := LMS_RESPAWN_FINAL;
3770 gLMSRespawnTime := gTime + 5000;
3772 else if (ar = 0) and (ab = 0) then
3773 begin
3774 // everyone ded
3775 g_Game_Message(_lc[I_GAME_WIN_DRAW], 144);
3776 if Netsrv then
3777 MH_SEND_GameEvent(NET_EV_LMS_DRAW, 0, FName);
3778 gLMSRespawn := LMS_RESPAWN_FINAL;
3779 gLMSRespawnTime := gTime + 5000;
3780 end;
3782 else if (gGameSettings.GameMode = GM_DM) then
3783 begin
3784 if (a = 1) then
3785 begin
3786 if gPlayers[k] <> nil then
3787 with gPlayers[k] do
3788 begin
3789 // survivor is the winner
3790 g_Game_Message(Format(_lc[I_MESSAGE_LMS_WIN], [AnsiUpperCase(FName)]), 144);
3791 if Netsrv then
3792 MH_SEND_GameEvent(NET_EV_LMS_WIN, 0, FName);
3793 Inc(FFrags);
3794 end;
3795 gLMSRespawn := LMS_RESPAWN_FINAL;
3796 gLMSRespawnTime := gTime + 5000;
3798 else if (a = 0) then
3799 begin
3800 // everyone is dead, restart the map
3801 g_Game_Message(_lc[I_GAME_WIN_DRAW], 144);
3802 if Netsrv then
3803 MH_SEND_GameEvent(NET_EV_LMS_DRAW, 0, FName);
3804 gLMSRespawn := LMS_RESPAWN_FINAL;
3805 gLMSRespawnTime := gTime + 5000;
3806 end;
3807 end;
3808 if srv and (OldLR = LMS_RESPAWN_NONE) and (gLMSRespawn > LMS_RESPAWN_NONE) then
3809 begin
3810 if NetMode = NET_SERVER then
3811 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, gLMSRespawnTime - gTime)
3812 else
3813 g_Console_Add(Format(_lc[I_MSG_WARMUP_START], [(gLMSRespawnTime - gTime) div 1000]), True);
3814 end;
3815 end;
3817 if Netsrv then
3818 begin
3819 MH_SEND_PlayerStats(FUID);
3820 MH_SEND_PlayerDeath(FUID, KillType, t, SpawnerUID);
3821 if gGameSettings.GameMode = GM_TDM then MH_SEND_GameStats;
3822 end;
3824 if srv and FNoRespawn then Spectate(True);
3825 FWantsInGame := True;
3826 end;
3828 function TPlayer.BodyInLiquid(XInc, YInc: Integer): Boolean;
3829 begin
3830 Result := g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc, PLAYER_RECT.Width,
3831 PLAYER_RECT.Height-20, PANEL_WATER or PANEL_ACID1 or PANEL_ACID2, False);
3832 end;
3834 function TPlayer.BodyInAcid(XInc, YInc: Integer): Boolean;
3835 begin
3836 Result := g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc, PLAYER_RECT.Width,
3837 PLAYER_RECT.Height-20, PANEL_ACID1 or PANEL_ACID2, False);
3838 end;
3840 procedure TPlayer.MakeBloodSimple(Count: Word);
3841 begin
3842 g_GFX_Blood(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)+8,
3843 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2),
3844 Count div 2, 3, -1, 16, (PLAYER_RECT.Height*2 div 3),
3845 FModel.Blood.R, FModel.Blood.G, FModel.Blood.B, FModel.Blood.Kind);
3846 g_GFX_Blood(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-8,
3847 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2),
3848 Count div 2, -3, -1, 16, (PLAYER_RECT.Height*2) div 3,
3849 FModel.Blood.R, FModel.Blood.G, FModel.Blood.B, FModel.Blood.Kind);
3850 end;
3852 procedure TPlayer.MakeBloodVector(Count: Word; VelX, VelY: Integer);
3853 begin
3854 g_GFX_Blood(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2),
3855 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2),
3856 Count, VelX, VelY, 16, (PLAYER_RECT.Height*2) div 3,
3857 FModel.Blood.R, FModel.Blood.G, FModel.Blood.B, FModel.Blood.Kind);
3858 end;
3860 procedure TPlayer.ProcessWeaponAction(Action: Byte);
3861 begin
3862 if g_Game_IsClient then Exit;
3863 case Action of
3864 WP_PREV: PrevWeapon();
3865 WP_NEXT: NextWeapon();
3866 end;
3867 end;
3869 procedure TPlayer.QueueWeaponSwitch(Weapon: Byte);
3870 begin
3871 if g_Game_IsClient then Exit;
3872 if Weapon > High(FWeapon) then Exit;
3873 FNextWeap := FNextWeap or (1 shl Weapon);
3874 end;
3876 procedure TPlayer.resetWeaponQueue ();
3877 begin
3878 FNextWeap := 0;
3879 FNextWeapDelay := 0;
3880 end;
3882 function TPlayer.hasAmmoForWeapon (weapon: Byte): Boolean;
3883 begin
3884 result := false;
3885 case weapon of
3886 WEAPON_IRONFIST, WEAPON_SAW: result := true;
3887 WEAPON_SHOTGUN1, WEAPON_SHOTGUN2, WEAPON_SUPERCHAINGUN: result := (FAmmo[A_SHELLS] > 0);
3888 WEAPON_PISTOL, WEAPON_CHAINGUN: result := (FAmmo[A_BULLETS] > 0);
3889 WEAPON_ROCKETLAUNCHER: result := (FAmmo[A_ROCKETS] > 0);
3890 WEAPON_PLASMA, WEAPON_BFG: result := (FAmmo[A_CELLS] > 0);
3891 WEAPON_FLAMETHROWER: result := (FAmmo[A_FUEL] > 0);
3892 else result := (weapon < length(FWeapon));
3893 end;
3894 end;
3896 function TPlayer.hasAmmoForShooting (weapon: Byte): Boolean;
3897 begin
3898 result := false;
3899 case weapon of
3900 WEAPON_IRONFIST, WEAPON_SAW: result := true;
3901 WEAPON_SHOTGUN1, WEAPON_SUPERCHAINGUN: result := (FAmmo[A_SHELLS] > 0);
3902 WEAPON_SHOTGUN2: result := (FAmmo[A_SHELLS] > 1);
3903 WEAPON_PISTOL, WEAPON_CHAINGUN: result := (FAmmo[A_BULLETS] > 0);
3904 WEAPON_ROCKETLAUNCHER: result := (FAmmo[A_ROCKETS] > 0);
3905 WEAPON_PLASMA: result := (FAmmo[A_CELLS] > 0);
3906 WEAPON_BFG: result := (FAmmo[A_CELLS] >= 40);
3907 WEAPON_FLAMETHROWER: result := (FAmmo[A_FUEL] > 0);
3908 else result := (weapon < length(FWeapon));
3909 end;
3910 end;
3912 function TPlayer.shouldSwitch (weapon: Byte; hadWeapon: Boolean): Boolean;
3913 begin
3914 result := false;
3915 if (weapon > WP_LAST + 1) then
3916 begin
3917 result := false;
3918 exit;
3919 end;
3920 if (FWeapSwitchMode = 1) and not hadWeapon then
3921 result := true
3922 else if (FWeapSwitchMode = 2) then
3923 result := (FWeapPreferences[weapon] > FWeapPreferences[FCurrWeap]);
3924 end;
3926 // return 255 for "no switch"
3927 function TPlayer.getNextWeaponIndex (): Byte;
3929 i: Word;
3930 wantThisWeapon: array[0..64] of Boolean;
3931 wwc: Integer = 0; //HACK!
3932 dir, cwi: Integer;
3933 begin
3934 result := 255; // default result: "no switch"
3935 //e_LogWriteFln('FSWITCHTOEMPTY: %s', [FSwitchToEmpty], TMsgType.Notify);
3936 // had weapon cycling on previous frame? remove that flag
3937 if (FNextWeap and $2000) <> 0 then
3938 begin
3939 FNextWeap := FNextWeap and $1FFF;
3940 FNextWeapDelay := 0;
3941 end;
3942 // cycling has priority
3943 if (FNextWeap and $C000) <> 0 then
3944 begin
3945 if (FNextWeap and $8000) <> 0 then
3946 dir := 1
3947 else
3948 dir := -1;
3949 FNextWeap := FNextWeap or $2000; // we need this
3950 if FNextWeapDelay > 0 then
3951 exit; // cooldown time
3952 cwi := FCurrWeap;
3953 for i := 0 to High(FWeapon) do
3954 begin
3955 cwi := (cwi+length(FWeapon)+dir) mod length(FWeapon);
3956 if FWeapon[cwi] and maySwitch(cwi) then
3957 begin
3958 //e_LogWriteFln(' SWITCH: cur=%d; new=%d %s %s', [FCurrWeap, cwi, FSwitchToEmpty, hasAmmoForWeapon(cwi)], TMsgType.Notify);
3959 result := Byte(cwi);
3960 FNextWeapDelay := WEAPON_DELAY;
3961 exit;
3962 end;
3963 end;
3964 resetWeaponQueue();
3965 exit;
3966 end;
3967 // no cycling
3968 for i := 0 to High(wantThisWeapon) do
3969 wantThisWeapon[i] := false;
3970 for i := 0 to High(FWeapon) do
3971 if (FNextWeap and (1 shl i)) <> 0 then
3972 begin
3973 wantThisWeapon[i] := true;
3974 Inc(wwc);
3975 end;
3977 // exclude currently selected weapon from the set
3978 wantThisWeapon[FCurrWeap] := false;
3979 // slow down alterations a little
3980 if wwc > 1 then
3981 begin
3982 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3983 // more than one weapon requested, assume "alteration" and check alteration delay
3984 if FNextWeapDelay > 0 then
3985 begin
3986 FNextWeap := 0;
3987 exit;
3988 end; // yeah
3989 end;
3990 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3991 // but clear all counters if no weapon should be switched
3992 if wwc < 1 then
3993 begin
3994 resetWeaponQueue();
3995 exit;
3996 end;
3997 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3998 // try weapons in descending order
3999 for i := High(FWeapon) downto 0 do
4000 begin
4001 if wantThisWeapon[i] and FWeapon[i] and ((wwc = 1) or hasAmmoForWeapon(i)) then
4002 begin
4003 // i found her!
4004 result := Byte(i);
4005 resetWeaponQueue();
4006 FNextWeapDelay := WEAPON_DELAY * 2; // anyway, 'cause why not
4007 //e_LogWriteFln('FOUND %s %s %s', [result, FSwitchToEmpty, hasAmmoForWeapon(i)], TMsgType.Notify);
4008 exit;
4009 end;
4010 end;
4011 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
4012 resetWeaponQueue();
4013 end;
4015 procedure TPlayer.RealizeCurrentWeapon();
4016 function switchAllowed (): Boolean;
4018 i: Byte;
4019 begin
4020 result := false;
4021 if FBFGFireCounter <> -1 then
4022 exit;
4023 if FTime[T_SWITCH] > gTime then
4024 exit;
4025 for i := WP_FIRST to WP_LAST do
4026 if FReloading[i] > 0 then
4027 exit;
4028 result := true;
4029 end;
4032 nw: Byte;
4033 begin
4034 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
4035 //FNextWeap := FNextWeap and $1FFF;
4036 if FNextWeapDelay > 0 then Dec(FNextWeapDelay); // "alteration delay"
4038 if not switchAllowed then
4039 begin
4040 //HACK for weapon cycling
4041 if (FNextWeap and $E000) <> 0 then FNextWeap := 0;
4042 exit;
4043 end;
4045 nw := getNextWeaponIndex();
4047 if nw = 255 then exit; // don't reset anything here
4048 if nw > High(FWeapon) then
4049 begin
4050 // don't forget to reset queue here!
4051 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
4052 resetWeaponQueue();
4053 exit;
4054 end;
4056 if FWeapon[nw] then
4057 begin
4058 FCurrWeap := nw;
4059 FTime[T_SWITCH] := gTime+156;
4060 {$IFDEF ENABLE_SOUND}
4061 if FCurrWeap = WEAPON_SAW then FSawSoundSelect.PlayAt(FObj.X, FObj.Y);
4062 {$ENDIF}
4063 FModel.SetWeapon(FCurrWeap);
4064 if g_Game_IsNet then MH_SEND_PlayerStats(FUID);
4065 end;
4066 end;
4068 procedure TPlayer.NextWeapon();
4069 begin
4070 if g_Game_IsClient then Exit;
4071 FNextWeap := $8000;
4072 end;
4074 procedure TPlayer.PrevWeapon();
4075 begin
4076 if g_Game_IsClient then Exit;
4077 FNextWeap := $4000;
4078 end;
4080 procedure TPlayer.SetWeapon(W: Byte);
4081 begin
4082 {$IFDEF ENABLE_SOUND}
4083 if FCurrWeap <> W then
4084 if W = WEAPON_SAW then
4085 FSawSoundSelect.PlayAt(FObj.X, FObj.Y);
4086 {$ENDIF}
4088 FCurrWeap := W;
4089 FModel.SetWeapon(CurrWeap);
4090 resetWeaponQueue();
4091 end;
4093 function TPlayer.PickItem(ItemType: Byte; arespawn: Boolean; var remove: Boolean): Boolean;
4095 a: Boolean;
4096 switchWeapon: Byte = 255;
4097 hadWeapon: Boolean = False;
4098 begin
4099 Result := False;
4100 if g_Game_IsClient then Exit;
4102 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
4103 a := (TGameOption.WEAPONS_STAY in gGameSettings.Options) and arespawn;
4104 remove := not a;
4105 case ItemType of
4106 ITEM_MEDKIT_SMALL:
4107 if (FHealth < PLAYER_HP_SOFT) or (FFireTime > 0) then
4108 begin
4109 if FHealth < PLAYER_HP_SOFT then IncMax(FHealth, 10, PLAYER_HP_SOFT);
4110 Result := True;
4111 remove := True;
4112 FFireTime := 0;
4113 if gFlash = 2 then Inc(FPickup, 5);
4114 end;
4116 ITEM_MEDKIT_LARGE:
4117 if (FHealth < PLAYER_HP_SOFT) or (FFireTime > 0) then
4118 begin
4119 if FHealth < PLAYER_HP_SOFT then IncMax(FHealth, 25, PLAYER_HP_SOFT);
4120 Result := True;
4121 remove := True;
4122 FFireTime := 0;
4123 if gFlash = 2 then Inc(FPickup, 5);
4124 end;
4126 ITEM_ARMOR_GREEN:
4127 if FArmor < PLAYER_AP_SOFT then
4128 begin
4129 FArmor := PLAYER_AP_SOFT;
4130 Result := True;
4131 remove := True;
4132 if gFlash = 2 then Inc(FPickup, 5);
4133 end;
4135 ITEM_ARMOR_BLUE:
4136 if FArmor < PLAYER_AP_LIMIT then
4137 begin
4138 FArmor := PLAYER_AP_LIMIT;
4139 Result := True;
4140 remove := True;
4141 if gFlash = 2 then Inc(FPickup, 5);
4142 end;
4144 ITEM_SPHERE_BLUE:
4145 if (FHealth < PLAYER_HP_LIMIT) or (FFireTime > 0) then
4146 begin
4147 if FHealth < PLAYER_HP_LIMIT then IncMax(FHealth, 100, PLAYER_HP_LIMIT);
4148 Result := True;
4149 remove := True;
4150 FFireTime := 0;
4151 if gFlash = 2 then Inc(FPickup, 5);
4152 end;
4154 ITEM_SPHERE_WHITE:
4155 if (FHealth < PLAYER_HP_LIMIT) or (FArmor < PLAYER_AP_LIMIT) or (FFireTime > 0) then
4156 begin
4157 if FHealth < PLAYER_HP_LIMIT then
4158 FHealth := PLAYER_HP_LIMIT;
4159 if FArmor < PLAYER_AP_LIMIT then
4160 FArmor := PLAYER_AP_LIMIT;
4161 Result := True;
4162 remove := True;
4163 FFireTime := 0;
4164 if gFlash = 2 then Inc(FPickup, 5);
4165 end;
4167 ITEM_WEAPON_SAW:
4168 if (not FWeapon[WEAPON_SAW]) or ((not arespawn) and (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF])) then
4169 begin
4170 hadWeapon := FWeapon[WEAPON_SAW];
4171 switchWeapon := WEAPON_SAW;
4172 FWeapon[WEAPON_SAW] := True;
4173 Result := True;
4174 if gFlash = 2 then Inc(FPickup, 5);
4175 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
4176 end;
4178 ITEM_WEAPON_SHOTGUN1:
4179 if (FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS]) or not FWeapon[WEAPON_SHOTGUN1] then
4180 begin
4181 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
4182 if a and FWeapon[WEAPON_SHOTGUN1] then Exit;
4183 hadWeapon := FWeapon[WEAPON_SHOTGUN1];
4184 switchWeapon := WEAPON_SHOTGUN1;
4185 IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
4186 FWeapon[WEAPON_SHOTGUN1] := True;
4187 Result := True;
4188 if gFlash = 2 then Inc(FPickup, 5);
4189 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
4190 end;
4192 ITEM_WEAPON_SHOTGUN2:
4193 if (FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS]) or not FWeapon[WEAPON_SHOTGUN2] then
4194 begin
4195 if a and FWeapon[WEAPON_SHOTGUN2] then Exit;
4196 hadWeapon := FWeapon[WEAPON_SHOTGUN2];
4197 switchWeapon := WEAPON_SHOTGUN2;
4198 IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
4199 FWeapon[WEAPON_SHOTGUN2] := True;
4200 Result := True;
4201 if gFlash = 2 then Inc(FPickup, 5);
4202 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
4203 end;
4205 ITEM_WEAPON_CHAINGUN:
4206 if (FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS]) or not FWeapon[WEAPON_CHAINGUN] then
4207 begin
4208 if a and FWeapon[WEAPON_CHAINGUN] then Exit;
4209 hadWeapon := FWeapon[WEAPON_CHAINGUN];
4210 switchWeapon := WEAPON_CHAINGUN;
4211 IncMax(FAmmo[A_BULLETS], 50, FMaxAmmo[A_BULLETS]);
4212 FWeapon[WEAPON_CHAINGUN] := True;
4213 Result := True;
4214 if gFlash = 2 then Inc(FPickup, 5);
4215 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
4216 end;
4218 ITEM_WEAPON_ROCKETLAUNCHER:
4219 if (FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS]) or not FWeapon[WEAPON_ROCKETLAUNCHER] then
4220 begin
4221 if a and FWeapon[WEAPON_ROCKETLAUNCHER] then Exit;
4222 switchWeapon := WEAPON_ROCKETLAUNCHER;
4223 hadWeapon := FWeapon[WEAPON_ROCKETLAUNCHER];
4224 IncMax(FAmmo[A_ROCKETS], 2, FMaxAmmo[A_ROCKETS]);
4225 FWeapon[WEAPON_ROCKETLAUNCHER] := True;
4226 Result := True;
4227 if gFlash = 2 then Inc(FPickup, 5);
4228 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
4229 end;
4231 ITEM_WEAPON_PLASMA:
4232 if (FAmmo[A_CELLS] < FMaxAmmo[A_CELLS]) or not FWeapon[WEAPON_PLASMA] then
4233 begin
4234 if a and FWeapon[WEAPON_PLASMA] then Exit;
4235 switchWeapon := WEAPON_PLASMA;
4236 hadWeapon := FWeapon[WEAPON_PLASMA];
4237 IncMax(FAmmo[A_CELLS], 40, FMaxAmmo[A_CELLS]);
4238 FWeapon[WEAPON_PLASMA] := True;
4239 Result := True;
4240 if gFlash = 2 then Inc(FPickup, 5);
4241 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
4242 end;
4244 ITEM_WEAPON_BFG:
4245 if (FAmmo[A_CELLS] < FMaxAmmo[A_CELLS]) or not FWeapon[WEAPON_BFG] then
4246 begin
4247 if a and FWeapon[WEAPON_BFG] then Exit;
4248 switchWeapon := WEAPON_BFG;
4249 hadWeapon := FWeapon[WEAPON_BFG];
4250 IncMax(FAmmo[A_CELLS], 40, FMaxAmmo[A_CELLS]);
4251 FWeapon[WEAPON_BFG] := True;
4252 Result := True;
4253 if gFlash = 2 then Inc(FPickup, 5);
4254 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
4255 end;
4257 ITEM_WEAPON_SUPERCHAINGUN:
4258 if (FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS]) or not FWeapon[WEAPON_SUPERCHAINGUN] then
4259 begin
4260 if a and FWeapon[WEAPON_SUPERCHAINGUN] then Exit;
4261 switchWeapon := WEAPON_SUPERCHAINGUN;
4262 hadWeapon := FWeapon[WEAPON_SUPERCHAINGUN];
4263 IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
4264 FWeapon[WEAPON_SUPERCHAINGUN] := True;
4265 Result := True;
4266 if gFlash = 2 then Inc(FPickup, 5);
4267 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
4268 end;
4270 ITEM_WEAPON_FLAMETHROWER:
4271 if (FAmmo[A_FUEL] < FMaxAmmo[A_FUEL]) or not FWeapon[WEAPON_FLAMETHROWER] then
4272 begin
4273 if a and FWeapon[WEAPON_FLAMETHROWER] then Exit;
4274 switchWeapon := WEAPON_FLAMETHROWER;
4275 hadWeapon := FWeapon[WEAPON_FLAMETHROWER];
4276 IncMax(FAmmo[A_FUEL], 100, FMaxAmmo[A_FUEL]);
4277 FWeapon[WEAPON_FLAMETHROWER] := True;
4278 Result := True;
4279 if gFlash = 2 then Inc(FPickup, 5);
4280 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
4281 end;
4283 ITEM_AMMO_BULLETS:
4284 if FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS] then
4285 begin
4286 IncMax(FAmmo[A_BULLETS], 10, FMaxAmmo[A_BULLETS]);
4287 Result := True;
4288 remove := True;
4289 if gFlash = 2 then Inc(FPickup, 5);
4290 end;
4292 ITEM_AMMO_BULLETS_BOX:
4293 if FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS] then
4294 begin
4295 IncMax(FAmmo[A_BULLETS], 50, FMaxAmmo[A_BULLETS]);
4296 Result := True;
4297 remove := True;
4298 if gFlash = 2 then Inc(FPickup, 5);
4299 end;
4301 ITEM_AMMO_SHELLS:
4302 if FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS] then
4303 begin
4304 IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
4305 Result := True;
4306 remove := True;
4307 if gFlash = 2 then Inc(FPickup, 5);
4308 end;
4310 ITEM_AMMO_SHELLS_BOX:
4311 if FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS] then
4312 begin
4313 IncMax(FAmmo[A_SHELLS], 25, FMaxAmmo[A_SHELLS]);
4314 Result := True;
4315 remove := True;
4316 if gFlash = 2 then Inc(FPickup, 5);
4317 end;
4319 ITEM_AMMO_ROCKET:
4320 if FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS] then
4321 begin
4322 IncMax(FAmmo[A_ROCKETS], 1, FMaxAmmo[A_ROCKETS]);
4323 Result := True;
4324 remove := True;
4325 if gFlash = 2 then Inc(FPickup, 5);
4326 end;
4328 ITEM_AMMO_ROCKET_BOX:
4329 if FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS] then
4330 begin
4331 IncMax(FAmmo[A_ROCKETS], 5, FMaxAmmo[A_ROCKETS]);
4332 Result := True;
4333 remove := True;
4334 if gFlash = 2 then Inc(FPickup, 5);
4335 end;
4337 ITEM_AMMO_CELL:
4338 if FAmmo[A_CELLS] < FMaxAmmo[A_CELLS] then
4339 begin
4340 IncMax(FAmmo[A_CELLS], 40, FMaxAmmo[A_CELLS]);
4341 Result := True;
4342 remove := True;
4343 if gFlash = 2 then Inc(FPickup, 5);
4344 end;
4346 ITEM_AMMO_CELL_BIG:
4347 if FAmmo[A_CELLS] < FMaxAmmo[A_CELLS] then
4348 begin
4349 IncMax(FAmmo[A_CELLS], 100, FMaxAmmo[A_CELLS]);
4350 Result := True;
4351 remove := True;
4352 if gFlash = 2 then Inc(FPickup, 5);
4353 end;
4355 ITEM_AMMO_FUELCAN:
4356 if FAmmo[A_FUEL] < FMaxAmmo[A_FUEL] then
4357 begin
4358 IncMax(FAmmo[A_FUEL], 100, FMaxAmmo[A_FUEL]);
4359 Result := True;
4360 remove := True;
4361 if gFlash = 2 then Inc(FPickup, 5);
4362 end;
4364 ITEM_AMMO_BACKPACK:
4365 if not(R_ITEM_BACKPACK in FInventory) or
4366 (FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS]) or
4367 (FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS]) or
4368 (FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS]) or
4369 (FAmmo[A_CELLS] < FMaxAmmo[A_CELLS]) or
4370 (FAmmo[A_FUEL] < FMaxAmmo[A_FUEL]) then
4371 begin
4372 FMaxAmmo[A_BULLETS] := AmmoLimits[1, A_BULLETS];
4373 FMaxAmmo[A_SHELLS] := AmmoLimits[1, A_SHELLS];
4374 FMaxAmmo[A_ROCKETS] := AmmoLimits[1, A_ROCKETS];
4375 FMaxAmmo[A_CELLS] := AmmoLimits[1, A_CELLS];
4376 FMaxAmmo[A_FUEL] := AmmoLimits[1, A_FUEL];
4378 if FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS] then
4379 IncMax(FAmmo[A_BULLETS], 10, FMaxAmmo[A_BULLETS]);
4380 if FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS] then
4381 IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
4382 if FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS] then
4383 IncMax(FAmmo[A_ROCKETS], 1, FMaxAmmo[A_ROCKETS]);
4384 if FAmmo[A_CELLS] < FMaxAmmo[A_CELLS] then
4385 IncMax(FAmmo[A_CELLS], 40, FMaxAmmo[A_CELLS]);
4386 if FAmmo[A_FUEL] < FMaxAmmo[A_FUEL] then
4387 IncMax(FAmmo[A_FUEL], 50, FMaxAmmo[A_FUEL]);
4389 FInventory += [R_ITEM_BACKPACK];
4390 Result := True;
4391 remove := True;
4392 if gFlash = 2 then FPickup += 5;
4393 end;
4395 ITEM_KEY_RED:
4396 if not(R_KEY_RED in FInventory) then
4397 begin
4398 FInventory += [R_KEY_RED];
4399 Result := True;
4400 remove := (gGameSettings.GameMode <> GM_COOP) and (g_Player_GetCount() < 2);
4401 if gFlash = 2 then Inc(FPickup, 5);
4402 if (not remove) and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETITEM');
4403 end;
4405 ITEM_KEY_GREEN:
4406 if not(R_KEY_GREEN in FInventory) then
4407 begin
4408 FInventory += [R_KEY_GREEN];
4409 Result := True;
4410 remove := (gGameSettings.GameMode <> GM_COOP) and (g_Player_GetCount() < 2);
4411 if gFlash = 2 then Inc(FPickup, 5);
4412 if (not remove) and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETITEM');
4413 end;
4415 ITEM_KEY_BLUE:
4416 if not(R_KEY_BLUE in FInventory) then
4417 begin
4418 FInventory += [R_KEY_BLUE];
4419 Result := True;
4420 remove := (gGameSettings.GameMode <> GM_COOP) and (g_Player_GetCount() < 2);
4421 if gFlash = 2 then Inc(FPickup, 5);
4422 if (not remove) and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETITEM');
4423 end;
4425 ITEM_SUIT:
4426 if FPowerups[MR_SUIT] < gTime+PLAYER_SUIT_TIME then
4427 begin
4428 FPowerups[MR_SUIT] := gTime+PLAYER_SUIT_TIME;
4429 Result := True;
4430 remove := True;
4431 FFireTime := 0;
4432 if gFlash = 2 then Inc(FPickup, 5);
4433 end;
4435 ITEM_OXYGEN:
4436 if FAir < AIR_MAX then
4437 begin
4438 FAir := AIR_MAX;
4439 Result := True;
4440 remove := True;
4441 if gFlash = 2 then Inc(FPickup, 5);
4442 end;
4444 ITEM_MEDKIT_BLACK:
4445 begin
4446 if not (R_BERSERK in FInventory) then
4447 begin
4448 FInventory += [R_BERSERK];
4449 if (FBFGFireCounter = -1) then
4450 begin
4451 FCurrWeap := WEAPON_IRONFIST;
4452 resetWeaponQueue();
4453 FModel.SetWeapon(WEAPON_IRONFIST);
4454 end;
4455 if gFlash <> 0 then
4456 begin
4457 FPain += 100;
4458 if gFlash = 2 then Inc(FPickup, 5);
4459 end;
4460 FBerserk := gTime+30000;
4461 Result := True;
4462 remove := True;
4463 FFireTime := 0;
4464 end;
4465 if (FHealth < PLAYER_HP_SOFT) or (FFireTime > 0) then
4466 begin
4467 if FHealth < PLAYER_HP_SOFT then FHealth := PLAYER_HP_SOFT;
4468 FBerserk := gTime+30000;
4469 Result := True;
4470 remove := True;
4471 FFireTime := 0;
4472 end;
4473 end;
4475 ITEM_INVUL:
4476 if FPowerups[MR_INVUL] < gTime+PLAYER_INVUL_TIME then
4477 begin
4478 FPowerups[MR_INVUL] := gTime+PLAYER_INVUL_TIME;
4479 FSpawnInvul := 0;
4480 Result := True;
4481 remove := True;
4482 if gFlash = 2 then Inc(FPickup, 5);
4483 end;
4485 ITEM_BOTTLE:
4486 if (FHealth < PLAYER_HP_LIMIT) or (FFireTime > 0) then
4487 begin
4488 if FHealth < PLAYER_HP_LIMIT then IncMax(FHealth, 4, PLAYER_HP_LIMIT);
4489 Result := True;
4490 remove := True;
4491 FFireTime := 0;
4492 if gFlash = 2 then Inc(FPickup, 5);
4493 end;
4495 ITEM_HELMET:
4496 if FArmor < PLAYER_AP_LIMIT then
4497 begin
4498 IncMax(FArmor, 5, PLAYER_AP_LIMIT);
4499 Result := True;
4500 remove := True;
4501 if gFlash = 2 then Inc(FPickup, 5);
4502 end;
4504 ITEM_JETPACK:
4505 if FJetFuel < JET_MAX then
4506 begin
4507 FJetFuel := JET_MAX;
4508 Result := True;
4509 remove := True;
4510 if gFlash = 2 then Inc(FPickup, 5);
4511 end;
4513 ITEM_INVIS:
4514 if FPowerups[MR_INVIS] < gTime+PLAYER_INVIS_TIME then
4515 begin
4516 FPowerups[MR_INVIS] := gTime+PLAYER_INVIS_TIME;
4517 Result := True;
4518 remove := True;
4519 if gFlash = 2 then Inc(FPickup, 5);
4520 end;
4521 end;
4523 if (shouldSwitch(switchWeapon, hadWeapon)) then
4524 QueueWeaponSwitch(switchWeapon);
4525 end;
4527 procedure TPlayer.Touch();
4528 begin
4529 if not FAlive then
4530 Exit;
4531 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4532 if FIamBot then
4533 begin
4534 // Áðîñèòü ôëàã òîâàðèùó:
4535 if gGameSettings.GameMode = GM_CTF then
4536 DropFlag();
4537 end;
4538 end;
4540 procedure TPlayer.Push(vx, vy: Integer);
4541 begin
4542 if (not FPhysics) and FGhost then
4543 Exit;
4544 FObj.Accel.X := FObj.Accel.X + vx;
4545 FObj.Accel.Y := FObj.Accel.Y + vy;
4546 if g_Game_IsNet and g_Game_IsServer then
4547 MH_SEND_PlayerPos(True, FUID, NET_EVERYONE);
4548 end;
4550 procedure TPlayer.Reset(Force: Boolean);
4551 begin
4552 if Force then
4553 FAlive := False;
4555 FSpawned := False;
4556 FTime[T_RESPAWN] := 0;
4557 FTime[T_FLAGCAP] := 0;
4558 FGodMode := False;
4559 FNoTarget := False;
4560 FNoReload := False;
4561 FFrags := 0;
4562 FLastFrag := 0;
4563 FComboEvnt := -1;
4564 FKills := 0;
4565 FMonsterKills := 0;
4566 FDeath := 0;
4567 FSecrets := 0;
4568 FSpawnInvul := 0;
4569 FCorpse := -1;
4570 FReady := False;
4571 if FNoRespawn then
4572 begin
4573 FSpectator := False;
4574 FGhost := False;
4575 FPhysics := True;
4576 FSpectatePlayer := -1;
4577 FNoRespawn := False;
4578 end;
4579 FLives := gGameSettings.MaxLives;
4581 SetFlag(FLAG_NONE);
4582 end;
4584 procedure TPlayer.SoftReset();
4585 begin
4586 ReleaseKeys();
4588 FDamageBuffer := 0;
4589 FSlopeOld := 0;
4590 FIncCamOld := 0;
4591 FIncCam := 0;
4592 FBFGFireCounter := -1;
4593 FShellTimer := -1;
4594 FPain := 0;
4595 FLastHit := 0;
4596 FLastFrag := 0;
4597 FComboEvnt := -1;
4599 SetFlag(FLAG_NONE);
4600 SetAction(A_STAND, True);
4601 end;
4603 function TPlayer.GetRespawnPoint(): Byte;
4605 c: Byte;
4606 begin
4607 Result := 255;
4608 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4610 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4611 if gGameSettings.GameMode in [GM_COOP, GM_SINGLE] then
4612 begin
4613 if Self = gPlayer1 then
4614 begin
4615 // player 1 should try to spawn on the player 1 point
4616 if g_Map_GetPointCount(RESPAWNPOINT_PLAYER1) > 0 then
4617 Exit(RESPAWNPOINT_PLAYER1)
4618 else if g_Map_GetPointCount(RESPAWNPOINT_PLAYER2) > 0 then
4619 Exit(RESPAWNPOINT_PLAYER2);
4621 else if Self = gPlayer2 then
4622 begin
4623 // player 2 should try to spawn on the player 2 point
4624 if g_Map_GetPointCount(RESPAWNPOINT_PLAYER2) > 0 then
4625 Exit(RESPAWNPOINT_PLAYER2)
4626 else if g_Map_GetPointCount(RESPAWNPOINT_PLAYER1) > 0 then
4627 Exit(RESPAWNPOINT_PLAYER1);
4629 else
4630 begin
4631 // other players randomly pick either the first or the second point
4632 c := IfThen((Random(2) = 0), RESPAWNPOINT_PLAYER1, RESPAWNPOINT_PLAYER2);
4633 if g_Map_GetPointCount(c) > 0 then
4634 Exit(c);
4635 // try the other one
4636 c := IfThen((c = RESPAWNPOINT_PLAYER1), RESPAWNPOINT_PLAYER2, RESPAWNPOINT_PLAYER1);
4637 if g_Map_GetPointCount(c) > 0 then
4638 Exit(c);
4639 end;
4640 end;
4642 // Ìÿñîïîâàë
4643 if gGameSettings.GameMode = GM_DM then
4644 begin
4645 // try DM points first
4646 if g_Map_GetPointCount(RESPAWNPOINT_DM) > 0 then
4647 Exit(RESPAWNPOINT_DM);
4648 end;
4650 // Êîìàíäíûå
4651 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
4652 begin
4653 // try team points first
4654 c := RESPAWNPOINT_DM;
4655 if FTeam = TEAM_RED then
4656 c := RESPAWNPOINT_RED
4657 else if FTeam = TEAM_BLUE then
4658 c := RESPAWNPOINT_BLUE;
4659 if g_Map_GetPointCount(c) > 0 then
4660 Exit(c);
4661 end;
4663 // still haven't found a spawnpoint, try random shit
4664 Result := g_Map_GetRandomPointType();
4665 end;
4667 procedure TPlayer.Respawn(Silent: Boolean; Force: Boolean = False);
4669 RespawnPoint: TRespawnPoint;
4670 a, b, c: Byte;
4671 Anim: TAnimation;
4672 ID: DWORD;
4673 begin
4674 FSlopeOld := 0;
4675 FIncCamOld := 0;
4676 FIncCam := 0;
4677 FBFGFireCounter := -1;
4678 FShellTimer := -1;
4679 FPain := 0;
4680 FLastHit := 0;
4681 FSpawnInvul := 0;
4682 FCorpse := -1;
4684 if not g_Game_IsServer then
4685 Exit;
4686 if FDummy then
4687 Exit;
4688 FWantsInGame := True;
4689 FJustTeleported := True;
4690 if Force then
4691 begin
4692 FTime[T_RESPAWN] := 0;
4693 FAlive := False;
4694 end;
4695 FNetTime := 0;
4696 // if server changes MaxLives we gotta be ready
4697 if gGameSettings.MaxLives = 0 then FNoRespawn := False;
4699 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4700 if FTime[T_RESPAWN] > gTime then
4701 Exit;
4703 // Ïðîñðàë âñå æèçíè:
4704 if FNoRespawn then
4705 begin
4706 if not FSpectator then Spectate(True);
4707 FWantsInGame := True;
4708 Exit;
4709 end;
4711 if (gGameSettings.GameType <> GT_SINGLE) and (gGameSettings.GameMode <> GM_COOP) then
4712 begin // "Ñâîÿ èãðà"
4713 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4714 FInventory -= [R_BERSERK];
4716 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4717 begin
4718 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4719 FInventory -= [R_KEY_RED, R_KEY_GREEN, R_KEY_BLUE, R_BERSERK];
4720 end;
4722 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4723 c := GetRespawnPoint();
4725 ReleaseKeys();
4726 SetFlag(FLAG_NONE);
4728 // Âîñêðåøåíèå áåç îðóæèÿ:
4729 if not FAlive then
4730 begin
4731 FHealth := Round(PLAYER_HP_SOFT * (FHandicap / 100));
4732 FArmor := 0;
4733 FAlive := True;
4734 FAir := AIR_DEF;
4735 FJetFuel := 0;
4737 for a := WP_FIRST to WP_LAST do
4738 begin
4739 FWeapon[a] := False;
4740 FReloading[a] := 0;
4741 end;
4743 FWeapon[WEAPON_PISTOL] := True;
4744 FWeapon[WEAPON_IRONFIST] := True;
4745 FCurrWeap := WEAPON_PISTOL;
4746 resetWeaponQueue();
4748 FModel.SetWeapon(FCurrWeap);
4750 for b := A_BULLETS to A_HIGH do
4751 FAmmo[b] := 0;
4753 FAmmo[A_BULLETS] := 50;
4755 FMaxAmmo[A_BULLETS] := AmmoLimits[0, A_BULLETS];
4756 FMaxAmmo[A_SHELLS] := AmmoLimits[0, A_SHELLS];
4757 FMaxAmmo[A_ROCKETS] := AmmoLimits[0, A_SHELLS];
4758 FMaxAmmo[A_CELLS] := AmmoLimits[0, A_CELLS];
4759 FMaxAmmo[A_FUEL] := AmmoLimits[0, A_FUEL];
4761 if (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF]) and
4762 (TGameOption.DM_KEYS in gGameSettings.Options)
4763 then FInventory := [R_KEY_RED, R_KEY_GREEN, R_KEY_BLUE]
4764 else FInventory := [];
4765 end;
4767 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4768 if not g_Map_GetPoint(c, RespawnPoint) then
4769 begin
4770 g_FatalError(_lc[I_GAME_ERROR_GET_SPAWN]);
4771 Exit;
4772 end;
4774 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4775 FObj.X := RespawnPoint.X-PLAYER_RECT.X;
4776 FObj.Y := RespawnPoint.Y-PLAYER_RECT.Y;
4777 FObj.oldX := FObj.X; // don't interpolate after respawn
4778 FObj.oldY := FObj.Y;
4779 FObj.Vel.X := 0;
4780 FObj.Vel.Y := 0;
4781 FObj.Accel.X := 0;
4782 FObj.Accel.Y := 0;
4784 FDirection := RespawnPoint.Direction;
4785 if FDirection = TDirection.D_LEFT then
4786 FAngle := 180
4787 else
4788 FAngle := 0;
4790 SetAction(A_STAND, True);
4791 FModel.Direction := FDirection;
4793 for a := Low(FTime) to High(FTime) do
4794 FTime[a] := 0;
4796 for a := Low(FPowerups) to High(FPowerups) do
4797 FPowerups[a] := 0;
4799 // Respawn invulnerability
4800 if (gGameSettings.GameType <> GT_SINGLE) and (gGameSettings.SpawnInvul > 0) then
4801 begin
4802 FPowerups[MR_INVUL] := gTime + gGameSettings.SpawnInvul * 1000;
4803 FSpawnInvul := FPowerups[MR_INVUL];
4804 end;
4806 FDamageBuffer := 0;
4807 FJetpack := False;
4808 FCanJetpack := False;
4809 FFlaming := False;
4810 FFireTime := 0;
4811 FFirePainTime := 0;
4812 FFireAttacker := 0;
4814 // Àíèìàöèÿ âîçðîæäåíèÿ:
4815 if (not gLoadGameMode) and (not Silent) then
4816 if g_Frames_Get(ID, 'FRAMES_TELEPORT') then
4817 begin
4818 Anim := TAnimation.Create(ID, False, 3);
4819 g_GFX_OnceAnim(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
4820 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32, Anim);
4821 Anim.Destroy();
4822 end;
4824 FSpectator := False;
4825 FGhost := False;
4826 FPhysics := True;
4827 FSpectatePlayer := -1;
4828 FSpawned := True;
4830 if (gPlayer1 = nil) and (gSpectLatchPID1 = FUID) then
4831 gPlayer1 := self;
4832 if (gPlayer2 = nil) and (gSpectLatchPID2 = FUID) then
4833 gPlayer2 := self;
4835 if g_Game_IsNet then
4836 begin
4837 MH_SEND_PlayerPos(True, FUID, NET_EVERYONE);
4838 MH_SEND_PlayerStats(FUID, NET_EVERYONE);
4839 if not Silent then
4840 MH_SEND_Effect(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
4841 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32,
4842 0, NET_GFX_TELE);
4843 end;
4844 end;
4846 procedure TPlayer.Spectate(NoMove: Boolean = False);
4847 begin
4848 if FAlive then
4849 Kill(K_EXTRAHARDKILL, FUID, HIT_SOME)
4850 else if (not NoMove) then
4851 begin
4852 GameX := gMapInfo.Width div 2;
4853 GameY := gMapInfo.Height div 2;
4854 end;
4855 FXTo := GameX;
4856 FYTo := GameY;
4858 FAlive := False;
4859 FSpectator := True;
4860 FGhost := True;
4861 FPhysics := False;
4862 FWantsInGame := False;
4863 FSpawned := False;
4864 FCorpse := -1;
4866 if FNoRespawn then
4867 begin
4868 if Self = gPlayer1 then
4869 begin
4870 gSpectLatchPID1 := FUID;
4871 gPlayer1 := nil;
4873 else if Self = gPlayer2 then
4874 begin
4875 gSpectLatchPID2 := FUID;
4876 gPlayer2 := nil;
4877 end;
4878 end;
4880 if g_Game_IsNet then
4881 MH_SEND_PlayerStats(FUID);
4882 end;
4884 procedure TPlayer.SwitchNoClip;
4885 begin
4886 if not FAlive then
4887 Exit;
4888 FGhost := not FGhost;
4889 FPhysics := not FGhost;
4890 if FGhost then
4891 begin
4892 FXTo := FObj.X;
4893 FYTo := FObj.Y;
4894 end else
4895 begin
4896 FObj.Accel.X := 0;
4897 FObj.Accel.Y := 0;
4898 end;
4899 end;
4901 procedure TPlayer.Run(Direction: TDirection);
4903 a, b: Integer;
4904 begin
4905 if MAX_RUNVEL > 8 then
4906 FlySmoke();
4908 // Áåæèì:
4909 if Direction = TDirection.D_LEFT then
4910 begin
4911 if FObj.Vel.X > -MAX_RUNVEL then
4912 FObj.Vel.X := FObj.Vel.X - (MAX_RUNVEL shr 3);
4914 else
4915 if FObj.Vel.X < MAX_RUNVEL then
4916 FObj.Vel.X := FObj.Vel.X + (MAX_RUNVEL shr 3);
4918 // Âîçìîæíî, ïèíàåì êóñêè:
4919 if (FObj.Vel.X <> 0) and (gGibs <> nil) then
4920 begin
4921 b := Abs(FObj.Vel.X);
4922 if b > 1 then b := b * (Random(8 div b) + 1);
4923 for a := 0 to High(gGibs) do
4924 begin
4925 if gGibs[a].alive and
4926 g_Obj_Collide(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y+FObj.Rect.Height-4,
4927 FObj.Rect.Width, 8, @gGibs[a].Obj) and (Random(3) = 0) then
4928 begin
4929 // Ïèíàåì êóñêè
4930 if FObj.Vel.X < 0 then
4931 begin
4932 g_Obj_PushA(@gGibs[a].Obj, b, Random(61)+120) // íàëåâî
4934 else
4935 begin
4936 g_Obj_PushA(@gGibs[a].Obj, b, Random(61)); // íàïðàâî
4937 end;
4938 gGibs[a].positionChanged(); // this updates spatial accelerators
4939 end;
4940 end;
4941 end;
4943 SetAction(A_WALK);
4944 end;
4946 procedure TPlayer.SeeDown();
4947 begin
4948 SetAction(A_SEEDOWN);
4950 if FDirection = TDirection.D_LEFT then FAngle := ANGLE_LEFTDOWN else FAngle := ANGLE_RIGHTDOWN;
4952 if FIncCam > -120 then DecMin(FIncCam, 5, -120);
4953 end;
4955 procedure TPlayer.SeeUp();
4956 begin
4957 SetAction(A_SEEUP);
4959 if FDirection = TDirection.D_LEFT then FAngle := ANGLE_LEFTUP else FAngle := ANGLE_RIGHTUP;
4961 if FIncCam < 120 then IncMax(FIncCam, 5, 120);
4962 end;
4964 procedure TPlayer.SetAction(Action: Byte; Force: Boolean = False);
4966 Prior: Byte;
4967 begin
4968 case Action of
4969 A_WALK: Prior := 3;
4970 A_DIE1: Prior := 5;
4971 A_DIE2: Prior := 5;
4972 A_ATTACK: Prior := 2;
4973 A_SEEUP: Prior := 1;
4974 A_SEEDOWN: Prior := 1;
4975 A_ATTACKUP: Prior := 2;
4976 A_ATTACKDOWN: Prior := 2;
4977 A_PAIN: Prior := 4;
4978 else Prior := 0;
4979 end;
4981 if (Prior > FActionPrior) or Force then
4982 if not ((Prior = 2) and (FCurrWeap = WEAPON_SAW)) then
4983 begin
4984 FActionPrior := Prior;
4985 FActionAnim := Action;
4986 FActionForce := Force;
4987 FActionChanged := True;
4988 end;
4990 if Action in [A_ATTACK, A_ATTACKUP, A_ATTACKDOWN] then FModel.SetFire(True);
4991 end;
4993 function TPlayer.StayOnStep(XInc, YInc: Integer): Boolean;
4994 begin
4995 Result := not g_Map_CollidePanel(FObj.X+PLAYER_RECT.X, FObj.Y+YInc+PLAYER_RECT.Y+PLAYER_RECT.Height-1,
4996 PLAYER_RECT.Width, 1, PANEL_STEP, False)
4997 and g_Map_CollidePanel(FObj.X+PLAYER_RECT.X, FObj.Y+YInc+PLAYER_RECT.Y+PLAYER_RECT.Height,
4998 PLAYER_RECT.Width, 1, PANEL_STEP, False);
4999 end;
5001 function TPlayer.TeleportTo(X, Y: Integer; silent: Boolean; dir: Byte): Boolean;
5003 Anim: TAnimation;
5004 ID: DWORD;
5005 begin
5006 Result := False;
5008 if g_CollideLevel(X, Y, PLAYER_RECT.Width, PLAYER_RECT.Height) then
5009 begin
5010 {$IFDEF ENABLE_SOUND}
5011 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj.X, FObj.Y);
5012 {$ENDIF}
5013 if g_Game_IsServer and g_Game_IsNet then
5014 MH_SEND_Sound(FObj.X, FObj.Y, 'SOUND_GAME_NOTELEPORT');
5015 Exit;
5016 end;
5018 FJustTeleported := True;
5020 Anim := nil;
5021 if not silent then
5022 begin
5023 if g_Frames_Get(ID, 'FRAMES_TELEPORT') then
5024 begin
5025 Anim := TAnimation.Create(ID, False, 3);
5026 end;
5028 {$IFDEF ENABLE_SOUND}
5029 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj.X, FObj.Y);
5030 {$ENDIF}
5031 g_GFX_OnceAnim(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
5032 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32, Anim);
5033 if g_Game_IsServer and g_Game_IsNet then
5034 MH_SEND_Effect(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
5035 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32, 1,
5036 NET_GFX_TELE);
5037 end;
5039 FObj.X := X-PLAYER_RECT.X;
5040 FObj.Y := Y-PLAYER_RECT.Y;
5041 FObj.oldX := FObj.X; // don't interpolate after respawn
5042 FObj.oldY := FObj.Y;
5043 if FAlive and FGhost then
5044 begin
5045 FXTo := FObj.X;
5046 FYTo := FObj.Y;
5047 end;
5049 if not g_Game_IsNet then
5050 begin
5051 if dir = 1 then
5052 begin
5053 SetDirection(TDirection.D_LEFT);
5054 FAngle := 180;
5056 else
5057 if dir = 2 then
5058 begin
5059 SetDirection(TDirection.D_RIGHT);
5060 FAngle := 0;
5062 else
5063 if dir = 3 then
5064 begin // îáðàòíîå
5065 if FDirection = TDirection.D_RIGHT then
5066 begin
5067 SetDirection(TDirection.D_LEFT);
5068 FAngle := 180;
5070 else
5071 begin
5072 SetDirection(TDirection.D_RIGHT);
5073 FAngle := 0;
5074 end;
5075 end;
5076 end;
5078 if not silent and (Anim <> nil) then
5079 begin
5080 g_GFX_OnceAnim(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
5081 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32, Anim);
5082 Anim.Destroy();
5084 if g_Game_IsServer and g_Game_IsNet then
5085 MH_SEND_Effect(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
5086 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32, 0,
5087 NET_GFX_TELE);
5088 end;
5090 Result := True;
5091 end;
5093 function nonz(a: Single): Single;
5094 begin
5095 if a <> 0
5096 then Result := a
5097 else Result := 1;
5098 end;
5100 function TPlayer.refreshCorpse(): Boolean;
5102 i: Integer;
5103 begin
5104 Result := False;
5105 FCorpse := -1;
5106 if FAlive or FSpectator then
5107 Exit;
5109 for i := 0 to High(gCorpses) do
5110 if gCorpses[i] <> nil then
5111 if gCorpses[i].FPlayerUID = FUID then
5112 begin
5113 Result := True;
5114 FCorpse := i;
5115 break;
5116 end;
5117 end;
5119 function TPlayer.getCameraObj(): TObj;
5120 begin
5121 if (not FAlive) and (not FSpectator) and
5122 (Low(gCorpses) <= FCorpse) and (High(gCorpses) >= FCorpse) and
5123 (gCorpses[FCorpse] <> nil) and (gCorpses[FCorpse].FPlayerUID = FUID) then
5124 begin
5125 gCorpses[FCorpse].FObj.slopeUpLeft := FObj.slopeUpLeft;
5126 Result := gCorpses[FCorpse].FObj;
5128 else
5129 begin
5130 Result := FObj;
5131 end;
5132 end;
5134 procedure TPlayer.PreUpdate();
5135 begin
5136 FSlopeOld := FObj.slopeUpLeft;
5137 FIncCamOld := FIncCam;
5138 FObj.oldX := FObj.X;
5139 FObj.oldY := FObj.Y;
5140 end;
5142 procedure TPlayer.Update();
5144 b: Byte;
5145 i, ii, wx, wy, xd, yd, k: Integer;
5146 blockmon, headwater, dospawn: Boolean;
5147 NetServer: Boolean;
5148 AnyServer: Boolean;
5149 SetSpect: Boolean;
5150 ProjID: SizeInt;
5151 begin
5152 NetServer := g_Game_IsNet and g_Game_IsServer;
5153 AnyServer := g_Game_IsServer;
5155 if g_Game_IsClient and (NetInterpLevel > 0) then
5156 DoLerp(NetInterpLevel + 1)
5157 else
5158 if FGhost then
5159 DoLerp(4);
5161 if NetServer then
5162 if (FClientID >= 0) and (NetClients[FClientID].Peer <> nil) then
5163 begin
5164 FPing := NetClients[FClientID].Peer^.lastRoundTripTime;
5165 if NetClients[FClientID].Peer^.packetsSent > 0 then
5166 FLoss := Round(100*NetClients[FClientID].Peer^.packetsLost/NetClients[FClientID].Peer^.packetsSent)
5167 else
5168 FLoss := 0;
5169 end else
5170 begin
5171 FPing := 0;
5172 FLoss := 0;
5173 end;
5175 if FAlive and (FPunchAnim <> nil) then
5176 FPunchAnim.Update();
5178 if FAlive and (gFly or FJetpack) then
5179 FlySmoke();
5181 if FDirection = TDirection.D_LEFT then
5182 FAngle := 180
5183 else
5184 FAngle := 0;
5186 if FAlive and (not FGhost) then
5187 begin
5188 if FKeys[KEY_UP].Pressed then
5189 SeeUp();
5190 if FKeys[KEY_DOWN].Pressed then
5191 SeeDown();
5192 end;
5194 if (not (FKeys[KEY_UP].Pressed or FKeys[KEY_DOWN].Pressed)) and
5195 (FIncCam <> 0) then
5196 begin
5197 i := g_basic.Sign(FIncCam);
5198 FIncCam := Abs(FIncCam);
5199 DecMin(FIncCam, 5, 0);
5200 FIncCam := FIncCam*i;
5201 end;
5203 if gTime mod (GAME_TICK*2) <> 0 then
5204 begin
5205 if (FObj.Vel.X = 0) and FAlive then
5206 begin
5207 if FKeys[KEY_LEFT].Pressed then
5208 Run(TDirection.D_LEFT);
5209 if FKeys[KEY_RIGHT].Pressed then
5210 Run(TDirection.D_RIGHT);
5211 end;
5213 if FPhysics then
5214 begin
5215 g_Obj_Move(@FObj, True, True, True);
5216 positionChanged(); // this updates spatial accelerators
5217 end;
5219 Exit;
5220 end;
5222 FActionChanged := False;
5224 if FAlive then
5225 begin
5226 // Let alive player do some actions
5227 if FKeys[KEY_LEFT].Pressed then Run(TDirection.D_LEFT);
5228 if FKeys[KEY_RIGHT].Pressed then Run(TDirection.D_RIGHT);
5229 if FKeys[KEY_FIRE].Pressed and AnyServer then Fire()
5230 else
5231 begin
5232 if AnyServer then
5233 begin
5234 FlamerOff;
5235 if NetServer then MH_SEND_PlayerStats(FUID);
5236 end;
5237 end;
5238 if FKeys[KEY_OPEN].Pressed and AnyServer then Use();
5239 if FKeys[KEY_JUMP].Pressed then Jump()
5240 else
5241 begin
5242 if AnyServer and FJetpack then
5243 begin
5244 FJetpack := False;
5245 JetpackOff;
5246 if NetServer then MH_SEND_PlayerStats(FUID);
5247 end;
5248 FCanJetpack := True;
5249 end;
5251 else // Dead
5252 begin
5253 dospawn := False;
5254 if not FGhost then
5255 for k := Low(FKeys) to KEY_CHAT-1 do
5256 begin
5257 if FKeys[k].Pressed then
5258 begin
5259 dospawn := True;
5260 break;
5261 end;
5262 end;
5263 if dospawn then
5264 begin
5265 if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
5266 Respawn(False)
5267 else // Single
5268 if (FTime[T_RESPAWN] <= gTime) and
5269 gGameOn and (not FAlive) then
5270 begin
5271 if (g_Player_GetCount() > 1) then
5272 Respawn(False)
5273 else
5274 begin
5275 gExit := EXIT_RESTART;
5276 Exit;
5277 end;
5278 end;
5279 end;
5280 // Dead spectator actions
5281 if FGhost then
5282 begin
5283 if FKeys[KEY_OPEN].Pressed and AnyServer then Fire();
5284 if FKeys[KEY_FIRE].Pressed and AnyServer then
5285 begin
5286 if FSpectator then
5287 begin
5288 if (FSpectatePlayer >= High(gPlayers)) then
5289 FSpectatePlayer := -1
5290 else
5291 begin
5292 SetSpect := False;
5293 for I := FSpectatePlayer + 1 to High(gPlayers) do
5294 if gPlayers[I] <> nil then
5295 if gPlayers[I].alive then
5296 if gPlayers[I].UID <> FUID then
5297 begin
5298 FSpectatePlayer := I;
5299 SetSpect := True;
5300 break;
5301 end;
5303 if not SetSpect then FSpectatePlayer := -1;
5304 end;
5306 ReleaseKeys;
5307 end;
5308 end;
5309 end;
5310 end;
5311 // No clipping
5312 if FGhost then
5313 begin
5314 if FKeys[KEY_UP].Pressed or FKeys[KEY_JUMP].Pressed then
5315 begin
5316 FYTo := FObj.Y - 32;
5317 FSpectatePlayer := -1;
5318 end;
5319 if FKeys[KEY_DOWN].Pressed then
5320 begin
5321 FYTo := FObj.Y + 32;
5322 FSpectatePlayer := -1;
5323 end;
5324 if FKeys[KEY_LEFT].Pressed then
5325 begin
5326 FXTo := FObj.X - 32;
5327 FSpectatePlayer := -1;
5328 end;
5329 if FKeys[KEY_RIGHT].Pressed then
5330 begin
5331 FXTo := FObj.X + 32;
5332 FSpectatePlayer := -1;
5333 end;
5335 if (FXTo < -64) then
5336 FXTo := -64
5337 else if (FXTo > gMapInfo.Width + 32) then
5338 FXTo := gMapInfo.Width + 32;
5339 if (FYTo < -72) then
5340 FYTo := -72
5341 else if (FYTo > gMapInfo.Height + 32) then
5342 FYTo := gMapInfo.Height + 32;
5343 end;
5345 if FPhysics then
5346 begin
5347 g_Obj_Move(@FObj, True, True, True);
5348 positionChanged(); // this updates spatial accelerators
5350 else
5351 begin
5352 FObj.Vel.X := 0;
5353 FObj.Vel.Y := 0;
5354 if FSpectator then
5355 if (FSpectatePlayer <= High(gPlayers)) and (FSpectatePlayer >= 0) then
5356 if gPlayers[FSpectatePlayer] <> nil then
5357 if gPlayers[FSpectatePlayer].alive then
5358 begin
5359 FXTo := gPlayers[FSpectatePlayer].GameX;
5360 FYTo := gPlayers[FSpectatePlayer].GameY;
5361 end;
5362 end;
5364 blockmon := g_Map_CollidePanel(FObj.X+PLAYER_HEADRECT.X, FObj.Y+PLAYER_HEADRECT.Y,
5365 PLAYER_HEADRECT.Width, PLAYER_HEADRECT.Height,
5366 PANEL_BLOCKMON, True);
5367 headwater := HeadInLiquid(0, 0);
5369 // Ñîïðîòèâëåíèå âîçäóõà:
5370 if (not FAlive) or not (FKeys[KEY_LEFT].Pressed or FKeys[KEY_RIGHT].Pressed) then
5371 if FObj.Vel.X <> 0 then
5372 FObj.Vel.X := z_dec(FObj.Vel.X, 1);
5374 if (FLastHit = HIT_TRAP) and (FPain > 90) then FPain := 90;
5375 DecMin(FPain, 5, 0);
5376 DecMin(FPickup, 1, 0);
5378 if FAlive and (FObj.Y > Integer(gMapInfo.Height)+128) and AnyServer then
5379 begin
5380 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
5381 FPowerups[MR_SUIT] := 0;
5382 FPowerups[MR_INVUL] := 0;
5383 FPowerups[MR_INVIS] := 0;
5384 Kill(K_FALLKILL, 0, HIT_FALL);
5385 end;
5387 i := 9;
5389 if FAlive then
5390 begin
5391 {$IFDEF ENABLE_SOUND}
5392 if FCurrWeap = WEAPON_SAW then
5393 if not (FSawSound.IsPlaying() or FSawSoundHit.IsPlaying() or
5394 FSawSoundSelect.IsPlaying()) then
5395 FSawSoundIdle.PlayAt(FObj.X, FObj.Y);
5397 if FJetpack then
5398 if (not FJetSoundFly.IsPlaying()) and (not FJetSoundOn.IsPlaying()) and
5399 (not FJetSoundOff.IsPlaying()) then
5400 begin
5401 FJetSoundFly.SetPosition(0);
5402 FJetSoundFly.PlayAt(FObj.X, FObj.Y);
5403 end;
5404 {$ENDIF}
5406 for b := WP_FIRST to WP_LAST do
5407 if FReloading[b] > 0 then
5408 if FNoReload
5409 then FReloading[b] := 0
5410 else FReloading[b] -= 1;
5412 if FShellTimer > -1 then
5413 if FShellTimer = 0 then
5414 begin
5415 if FShellType = SHELL_SHELL then
5416 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
5417 GameVelX, GameVelY-2, SHELL_SHELL)
5418 else if FShellType = SHELL_DBLSHELL then
5419 begin
5420 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
5421 GameVelX+1, GameVelY-2, SHELL_SHELL);
5422 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
5423 GameVelX-1, GameVelY-2, SHELL_SHELL);
5424 end;
5425 FShellTimer := -1;
5426 end else Dec(FShellTimer);
5428 if (FBFGFireCounter > -1) then
5429 if FBFGFireCounter = 0 then
5430 begin
5431 if AnyServer then
5432 begin
5433 wx := FObj.X+WEAPONPOINT[FDirection].X;
5434 wy := FObj.Y+WEAPONPOINT[FDirection].Y;
5435 xd := wx+IfThen(FDirection = TDirection.D_LEFT, -30, 30);
5436 yd := wy+firediry();
5437 ProjID := g_Weapon_bfgshot(wx, wy, xd, yd, FUID);
5438 if NetServer then MH_SEND_PlayerFire(FUID, WEAPON_BFG, wx, wy, xd, yd, ProjID);
5439 case FAngle of
5440 0, 180: SetAction(A_ATTACK);
5441 ANGLE_LEFTDOWN, ANGLE_RIGHTDOWN: SetAction(A_ATTACKDOWN);
5442 ANGLE_LEFTUP, ANGLE_RIGHTUP: SetAction(A_ATTACKUP);
5443 end;
5444 end;
5446 FReloading[WEAPON_BFG] := WEAPON_RELOAD[WEAPON_BFG];
5447 FBFGFireCounter := -1;
5448 end else
5449 if FNoReload
5450 then FBFGFireCounter := 0
5451 else FBFGFireCounter -= 1;
5453 if (FPowerups[MR_SUIT] < gTime) and AnyServer then
5454 begin
5455 b := g_GetAcidHit(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width, PLAYER_RECT.Height);
5457 if (b > 0) and (gTime mod (15*GAME_TICK) = 0) then Damage(b, 0, 0, 0, HIT_ACID);
5458 end;
5460 if (headwater or blockmon) then
5461 begin
5462 Dec(FAir);
5464 if FAir < -9 then
5465 begin
5466 if AnyServer then Damage(10, 0, 0, 0, HIT_WATER);
5467 FAir := 0;
5469 else if (FAir mod 31 = 0) and not blockmon then
5470 g_Game_Effect_Bubbles(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2),
5471 FObj.Y+PLAYER_RECT.Y-4, 5+Random(6), 8, 4);
5472 end else if FAir < AIR_DEF then
5473 FAir := AIR_DEF;
5475 if FFireTime > 0 then
5476 begin
5477 if BodyInLiquid(0, 0) then
5478 begin
5479 FFireTime := 0;
5480 FFirePainTime := 0;
5482 else if FPowerups[MR_SUIT] >= gTime then
5483 begin
5484 if FPowerups[MR_SUIT] = gTime then
5485 FFireTime := 1;
5486 FFirePainTime := 0;
5488 else
5489 begin
5490 OnFireFlame(1);
5491 if FFirePainTime <= 0 then
5492 begin
5493 if g_Game_IsServer then
5494 Damage(2, FFireAttacker, 0, 0, HIT_FLAME);
5495 FFirePainTime := 12 - FFireTime div 12;
5496 end;
5497 FFirePainTime := FFirePainTime - 1;
5498 FFireTime := FFireTime - 1;
5499 {$IFDEF ENABLE_SOUND}
5500 if ((FFireTime mod 33) = 0) and (FPowerups[MR_INVUL] < gTime) then
5501 FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
5502 {$ENDIF}
5503 if (FFireTime = 0) and g_Game_IsNet and g_Game_IsServer then
5504 MH_SEND_PlayerStats(FUID);
5505 end;
5506 end;
5508 if FDamageBuffer > 0 then
5509 begin
5510 if FDamageBuffer >= 9 then
5511 begin
5512 SetAction(A_PAIN);
5514 if FDamageBuffer < 30 then i := 9
5515 else if FDamageBuffer < 100 then i := 18
5516 else i := 27;
5517 end;
5519 ii := Round(FDamageBuffer*FHealth / nonz(FArmor*(3/4)+FHealth));
5520 FArmor := FArmor-(FDamageBuffer-ii);
5521 FHealth := FHealth-ii;
5522 if FArmor < 0 then
5523 begin
5524 FHealth := FHealth+FArmor;
5525 FArmor := 0;
5526 end;
5528 if AnyServer then
5529 if FHealth <= 0 then
5530 if FHealth > -30 then Kill(K_SIMPLEKILL, FLastSpawnerUID, FLastHit)
5531 else if FHealth > -50 then Kill(K_HARDKILL, FLastSpawnerUID, FLastHit)
5532 else Kill(K_EXTRAHARDKILL, FLastSpawnerUID, FLastHit);
5534 {$IFDEF ENABLE_SOUND}
5535 if FAlive and ((FLastHit <> HIT_FLAME) or (FFireTime <= 0)) then
5536 begin
5537 if FDamageBuffer <= 20 then FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y)
5538 else if FDamageBuffer <= 55 then FModel.PlaySound(MODELSOUND_PAIN, 2, FObj.X, FObj.Y)
5539 else if FDamageBuffer <= 120 then FModel.PlaySound(MODELSOUND_PAIN, 3, FObj.X, FObj.Y)
5540 else FModel.PlaySound(MODELSOUND_PAIN, 4, FObj.X, FObj.Y);
5541 end;
5542 {$ENDIF}
5544 FDamageBuffer := 0;
5545 end;
5547 {CollideItem();}
5548 end; // if FAlive then ...
5550 if (FActionAnim = A_PAIN) and (FModel.Animation <> A_PAIN) then
5551 begin
5552 FModel.ChangeAnimation(FActionAnim, FActionForce);
5553 FModel.GetCurrentAnimation.MinLength := i;
5554 FModel.GetCurrentAnimationMask.MinLength := i;
5555 end else FModel.ChangeAnimation(FActionAnim, FActionForce and (FModel.Animation <> A_STAND));
5557 if (FModel.GetCurrentAnimation.Played or ((not FActionChanged) and (FModel.Animation = A_WALK)))
5558 then SetAction(A_STAND, True);
5560 if not ((FModel.Animation = A_WALK) and (Abs(FObj.Vel.X) < 4) and not FModel.Fire) then FModel.Update;
5562 for b := Low(FKeys) to High(FKeys) do
5563 if FKeys[b].Time = 0 then FKeys[b].Pressed := False else Dec(FKeys[b].Time);
5564 end;
5567 procedure TPlayer.getMapBox (out x, y, w, h: Integer); inline;
5568 begin
5569 x := FObj.X+PLAYER_RECT.X;
5570 y := FObj.Y+PLAYER_RECT.Y;
5571 w := PLAYER_RECT.Width;
5572 h := PLAYER_RECT.Height;
5573 end;
5576 procedure TPlayer.moveBy (dx, dy: Integer); inline;
5577 begin
5578 if (dx <> 0) or (dy <> 0) then
5579 begin
5580 FObj.X += dx;
5581 FObj.Y += dy;
5582 positionChanged();
5583 end;
5584 end;
5587 function TPlayer.Collide(X, Y: Integer; Width, Height: Word): Boolean;
5588 begin
5589 Result := g_Collide(FObj.X+PLAYER_RECT.X,
5590 FObj.Y+PLAYER_RECT.Y,
5591 PLAYER_RECT.Width,
5592 PLAYER_RECT.Height,
5593 X, Y,
5594 Width, Height);
5595 end;
5597 function TPlayer.Collide(Panel: TPanel): Boolean;
5598 begin
5599 Result := g_Collide(FObj.X+PLAYER_RECT.X,
5600 FObj.Y+PLAYER_RECT.Y,
5601 PLAYER_RECT.Width,
5602 PLAYER_RECT.Height,
5603 Panel.X, Panel.Y,
5604 Panel.Width, Panel.Height);
5605 end;
5607 function TPlayer.Collide(X, Y: Integer): Boolean;
5608 begin
5609 X := X-FObj.X-PLAYER_RECT.X;
5610 Y := Y-FObj.Y-PLAYER_RECT.Y;
5611 Result := (x >= 0) and (x <= PLAYER_RECT.Width) and
5612 (y >= 0) and (y <= PLAYER_RECT.Height);
5613 end;
5615 function g_Player_ExistingName(Name: string): Boolean;
5617 a: Integer;
5618 begin
5619 Result := True;
5621 if gPlayers = nil then Exit;
5623 for a := 0 to High(gPlayers) do
5624 if gPlayers[a] <> nil then
5625 if LowerCase(Name) = LowerCase(gPlayers[a].FName) then
5626 begin
5627 Result := False;
5628 Exit;
5629 end;
5630 end;
5632 procedure TPlayer.SetDirection(Direction: TDirection);
5634 d: TDirection;
5635 begin
5636 d := FModel.Direction;
5638 FModel.Direction := Direction;
5639 if d <> Direction then FModel.ChangeAnimation(FModel.Animation, True);
5641 FDirection := Direction;
5642 end;
5644 function TPlayer.GetKeys(): Byte;
5645 begin
5646 Result := 0;
5648 if R_KEY_RED in FInventory then Result := Result or KEY_RED;
5649 if R_KEY_GREEN in FInventory then Result := Result or KEY_GREEN;
5650 if R_KEY_BLUE in FInventory then Result := Result or KEY_BLUE;
5652 if FTeam = TEAM_RED then Result := Result or KEY_REDTEAM;
5653 if FTeam = TEAM_BLUE then Result := Result or KEY_BLUETEAM;
5654 end;
5656 procedure TPlayer.Use();
5658 a: Integer;
5659 begin
5660 if FTime[T_USE] > gTime then Exit;
5662 g_Triggers_PressR(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
5663 PLAYER_RECT.Height, FUID, ACTIVATE_PLAYERPRESS);
5665 for a := 0 to High(gPlayers) do
5666 if (gPlayers[a] <> nil) and (gPlayers[a] <> Self) and
5667 gPlayers[a].alive and SameTeam(FUID, gPlayers[a].FUID) and
5668 g_Obj_Collide(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y,
5669 FObj.Rect.Width, FObj.Rect.Height, @gPlayers[a].FObj) then
5670 begin
5671 gPlayers[a].Touch();
5672 if g_Game_IsNet and g_Game_IsServer then
5673 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH, gPlayers[a].FUID);
5674 end;
5676 FTime[T_USE] := gTime+120;
5677 end;
5679 procedure TPlayer.NetFire(Wpn: Byte; X, Y, AX, AY: Integer; WID: Integer);
5681 locObj: TObj;
5682 visible: Boolean = True;
5683 WX, WY, XD, YD: Integer;
5684 begin
5685 WX := X;
5686 WY := Y;
5687 XD := AX;
5688 YD := AY;
5690 case FCurrWeap of
5691 WEAPON_IRONFIST:
5692 begin
5693 visible := False;
5694 DoPunch();
5695 if R_BERSERK in FInventory then
5696 begin
5697 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5698 locobj.X := FObj.X+FObj.Rect.X;
5699 locobj.Y := FObj.Y+FObj.Rect.Y;
5700 locobj.rect.X := 0;
5701 locobj.rect.Y := 0;
5702 locobj.rect.Width := 39;
5703 locobj.rect.Height := 52;
5704 locobj.Vel.X := (xd-wx) div 2;
5705 locobj.Vel.Y := (yd-wy) div 2;
5706 locobj.Accel.X := xd-wx;
5707 locobj.Accel.y := yd-wy;
5709 if g_Weapon_Hit(@locobj, 50, FUID, HIT_SOME) <> 0 then
5710 begin
5711 {$IFDEF ENABLE_SOUND}
5712 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj.X, FObj.Y)
5713 {$ENDIF}
5715 else
5716 begin
5717 {$IFDEF ENABLE_SOUND}
5718 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj.X, FObj.Y);
5719 {$ENDIF}
5720 end;
5722 if (gFlash = 1) and (FPain < 50) then
5723 FPain := min(FPain + 25, 50);
5724 end else
5725 g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 3, FUID);
5726 end;
5728 WEAPON_SAW:
5729 begin
5730 {$IFDEF ENABLE_SOUND}
5731 if g_Weapon_chainsaw(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y,
5732 IfThen(gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF], 9, 3), FUID) <> 0 then
5733 begin
5734 FSawSoundSelect.Stop();
5735 FSawSound.Stop();
5736 FSawSoundHit.PlayAt(FObj.X, FObj.Y);
5738 else if not FSawSoundHit.IsPlaying() then
5739 begin
5740 FSawSoundSelect.Stop();
5741 FSawSound.PlayAt(FObj.X, FObj.Y);
5742 end;
5743 {$ELSE}
5744 g_Weapon_chainsaw(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y,
5745 IfThen(gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF], 9, 3), FUID);
5746 {$ENDIF}
5747 end;
5749 WEAPON_PISTOL:
5750 begin
5751 {$IFDEF ENABLE_SOUND}
5752 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX, Gamey);
5753 {$ENDIF}
5754 FFireAngle := FAngle;
5755 g_Player_CreateShell(
5756 GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
5757 GameVelX, GameVelY-2,
5758 SHELL_BULLET
5760 end;
5762 WEAPON_SHOTGUN1:
5763 begin
5764 {$IFDEF ENABLE_SOUND}
5765 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex, Gamey);
5766 {$ENDIF}
5767 FFireAngle := FAngle;
5768 FShellTimer := 10;
5769 FShellType := SHELL_SHELL;
5770 end;
5772 WEAPON_SHOTGUN2:
5773 begin
5774 {$IFDEF ENABLE_SOUND}
5775 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex, Gamey);
5776 {$ENDIF}
5777 FFireAngle := FAngle;
5778 FShellTimer := 13;
5779 FShellType := SHELL_DBLSHELL;
5780 end;
5782 WEAPON_CHAINGUN:
5783 begin
5784 {$IFDEF ENABLE_SOUND}
5785 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex, Gamey);
5786 {$ENDIF}
5787 FFireAngle := FAngle;
5788 g_Player_CreateShell(
5789 GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
5790 GameVelX, GameVelY-2,
5791 SHELL_BULLET
5793 end;
5795 WEAPON_ROCKETLAUNCHER:
5796 begin
5797 g_Weapon_Rocket(wx, wy, xd, yd, FUID, WID);
5798 FFireAngle := FAngle;
5799 end;
5801 WEAPON_PLASMA:
5802 begin
5803 g_Weapon_Plasma(wx, wy, xd, yd, FUID, WID);
5804 FFireAngle := FAngle;
5805 end;
5807 WEAPON_BFG:
5808 begin
5809 g_Weapon_BFGShot(wx, wy, xd, yd, FUID, WID);
5810 FFireAngle := FAngle;
5811 end;
5813 WEAPON_SUPERCHAINGUN:
5814 begin
5815 {$IFDEF ENABLE_SOUND}
5816 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex, Gamey);
5817 {$ENDIF}
5818 FFireAngle := FAngle;
5819 g_Player_CreateShell(
5820 GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
5821 GameVelX, GameVelY-2,
5822 SHELL_SHELL
5824 end;
5826 WEAPON_FLAMETHROWER:
5827 begin
5828 g_Weapon_flame(wx, wy, xd, yd, FUID, WID);
5829 FlamerOn;
5830 FFireAngle := FAngle;
5831 end;
5832 end;
5834 if not visible then Exit;
5836 case FAngle of
5837 0, 180: SetAction(A_ATTACK);
5838 ANGLE_LEFTDOWN, ANGLE_RIGHTDOWN: SetAction(A_ATTACKDOWN);
5839 ANGLE_LEFTUP, ANGLE_RIGHTUP: SetAction(A_ATTACKUP);
5840 end;
5841 end;
5843 procedure TPlayer.DoLerp(Level: Integer = 2);
5844 begin
5845 if FObj.X <> FXTo then FObj.X := Lerp(FObj.X, FXTo, Level);
5846 if FObj.Y <> FYTo then FObj.Y := Lerp(FObj.Y, FYTo, Level);
5847 end;
5849 procedure TPlayer.SetLerp(XTo, YTo: Integer);
5851 AX, AY: Integer;
5852 begin
5853 FXTo := XTo;
5854 FYTo := YTo;
5855 if FJustTeleported or (NetInterpLevel < 1) then
5856 begin
5857 FObj.X := XTo;
5858 FObj.Y := YTo;
5859 if FJustTeleported then
5860 begin
5861 FObj.oldX := FObj.X;
5862 FObj.oldY := FObj.Y;
5863 end;
5865 else
5866 begin
5867 AX := Abs(FXTo - FObj.X);
5868 AY := Abs(FYTo - FObj.Y);
5869 if (AX > 32) or (AX <= NetInterpLevel) then
5870 FObj.X := FXTo;
5871 if (AY > 32) or (AY <= NetInterpLevel) then
5872 FObj.Y := FYTo;
5873 end;
5874 end;
5876 function TPlayer.FullInLift(XInc, YInc: Integer): Integer;
5877 begin
5878 if g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc,
5879 PLAYER_RECT.Width, PLAYER_RECT.Height-8,
5880 PANEL_LIFTUP, False) then Result := -1
5881 else
5882 if g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc,
5883 PLAYER_RECT.Width, PLAYER_RECT.Height-8,
5884 PANEL_LIFTDOWN, False) then Result := 1
5885 else Result := 0;
5886 end;
5888 function TPlayer.GetFlag(Flag: Byte): Boolean;
5890 s, ts: String;
5891 evtype: Byte;
5892 {$IFDEF ENABLE_SOUND}
5893 a: Byte;
5894 {$ENDIF}
5895 begin
5896 Result := False;
5898 if Flag = FLAG_NONE then
5899 Exit;
5901 if not g_Game_IsServer then Exit;
5903 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5904 if (Flag = FTeam) and (gFlags[Flag].State = FLAG_STATE_NORMAL) and (FFlag <> FLAG_NONE) then
5905 begin
5906 if FFlag = FLAG_RED
5907 then s := _lc[I_PLAYER_FLAG_RED]
5908 else s := _lc[I_PLAYER_FLAG_BLUE];
5910 evtype := FLAG_STATE_SCORED;
5912 ts := Format('%.4d', [gFlags[FFlag].CaptureTime]);
5913 Insert('.', ts, Length(ts) + 1 - 3);
5914 g_Console_Add(Format(_lc[I_PLAYER_FLAG_CAPTURE], [FName, s, ts]), True);
5916 g_Map_ResetFlag(FFlag);
5917 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_CAPTURE], [AnsiUpperCase(s)]), 144);
5919 {$IFDEF ENABLE_SOUND}
5920 if ((Self = gPlayer1) or (Self = gPlayer2)
5921 or ((gPlayer1 <> nil) and (gPlayer1.Team = FTeam))
5922 or ((gPlayer2 <> nil) and (gPlayer2.Team = FTeam)))
5923 then a := 0
5924 else a := 1;
5926 if not sound_cap_flag[a].IsPlaying() then
5927 sound_cap_flag[a].Play();
5928 {$ENDIF}
5930 gTeamStat[FTeam].Score += 1;
5932 Result := True;
5933 if g_Game_IsNet then
5934 begin
5935 MH_SEND_FlagEvent(evtype, FFlag, FUID, False);
5936 MH_SEND_GameStats;
5937 end;
5939 gFlags[FFlag].CaptureTime := 0;
5940 SetFlag(FLAG_NONE);
5941 Exit;
5942 end;
5944 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5945 if (Flag = FTeam) and (gFlags[Flag].State = FLAG_STATE_DROPPED) then
5946 begin
5947 if Flag = FLAG_RED
5948 then s := _lc[I_PLAYER_FLAG_RED]
5949 else s := _lc[I_PLAYER_FLAG_BLUE];
5951 evtype := FLAG_STATE_RETURNED;
5952 gFlags[Flag].CaptureTime := 0;
5954 g_Console_Add(Format(_lc[I_PLAYER_FLAG_RETURN], [FName, s]), True);
5956 g_Map_ResetFlag(Flag);
5957 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_RETURN], [AnsiUpperCase(s)]), 144);
5959 {$IFDEF ENABLE_SOUND}
5960 if ((Self = gPlayer1) or (Self = gPlayer2)
5961 or ((gPlayer1 <> nil) and (gPlayer1.Team = FTeam))
5962 or ((gPlayer2 <> nil) and (gPlayer2.Team = FTeam)))
5963 then a := 0
5964 else a := 1;
5966 if not sound_ret_flag[a].IsPlaying() then
5967 sound_ret_flag[a].Play();
5968 {$ENDIF}
5970 Result := True;
5971 if g_Game_IsNet then
5972 begin
5973 MH_SEND_FlagEvent(evtype, Flag, FUID, False);
5974 MH_SEND_GameStats;
5975 end;
5976 Exit;
5977 end;
5979 // Ïîäîáðàë ÷óæîé ôëàã:
5980 if (Flag <> FTeam) and (FTime[T_FLAGCAP] <= gTime) then
5981 begin
5982 SetFlag(Flag);
5984 if Flag = FLAG_RED
5985 then s := _lc[I_PLAYER_FLAG_RED]
5986 else s := _lc[I_PLAYER_FLAG_BLUE];
5988 evtype := FLAG_STATE_CAPTURED;
5990 g_Console_Add(Format(_lc[I_PLAYER_FLAG_GET], [FName, s]), True);
5992 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_GET], [AnsiUpperCase(s)]), 144);
5994 gFlags[Flag].State := FLAG_STATE_CAPTURED;
5996 {$IFDEF ENABLE_SOUND}
5997 if ((Self = gPlayer1) or (Self = gPlayer2)
5998 or ((gPlayer1 <> nil) and (gPlayer1.Team = FTeam))
5999 or ((gPlayer2 <> nil) and (gPlayer2.Team = FTeam)))
6000 then a := 0
6001 else a := 1;
6003 if not sound_get_flag[a].IsPlaying() then
6004 sound_get_flag[a].Play();
6005 {$ENDIF}
6007 Result := True;
6008 if g_Game_IsNet then
6009 begin
6010 MH_SEND_FlagEvent(evtype, Flag, FUID, False);
6011 MH_SEND_GameStats;
6012 end;
6013 end;
6014 end;
6016 procedure TPlayer.SetFlag(Flag: Byte);
6017 begin
6018 FFlag := Flag;
6019 if FModel <> nil then
6020 FModel.SetFlag(FFlag);
6021 end;
6023 function TPlayer.TryDropFlag(): Boolean;
6024 begin
6025 if (TGameOption.ALLOW_DROP_FLAG in gGameSettings.Options)
6026 then Result := DropFlag(False, TGameOption.THROW_FLAG in gGameSettings.Options)
6027 else Result := False;
6028 end;
6030 function TPlayer.DropFlag(Silent: Boolean; DoThrow: Boolean): Boolean;
6032 s: String;
6033 a: Byte;
6034 xv, yv: Integer;
6035 begin
6036 Result := False;
6037 if (not g_Game_IsServer) or (FFlag = FLAG_NONE) then
6038 Exit;
6039 FTime[T_FLAGCAP] := gTime + 2000;
6040 with gFlags[FFlag] do
6041 begin
6042 Obj.X := FObj.X;
6043 Obj.Y := FObj.Y;
6044 Direction := FDirection;
6045 State := FLAG_STATE_DROPPED;
6046 Count := FLAG_TIME;
6047 if DoThrow then
6048 begin
6049 xv := FObj.Vel.X + IfThen(Direction = TDirection.D_RIGHT, 10, -10);
6050 yv := FObj.Vel.Y - 2;
6052 else
6053 begin
6054 xv := (FObj.Vel.X div 2);
6055 yv := (FObj.Vel.Y div 2) - 2;
6056 end;
6057 g_Obj_Push(@Obj, xv, yv);
6059 positionChanged(); // this updates spatial accelerators
6061 if FFlag = FLAG_RED
6062 then s := _lc[I_PLAYER_FLAG_RED]
6063 else s := _lc[I_PLAYER_FLAG_BLUE];
6065 g_Console_Add(Format(_lc[I_PLAYER_FLAG_DROP], [FName, s]), True);
6066 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_DROP], [AnsiUpperCase(s)]), 144);
6068 {$IFDEF ENABLE_SOUND}
6069 if ((Self = gPlayer1) or (Self = gPlayer2)
6070 or ((gPlayer1 <> nil) and (gPlayer1.Team = FTeam))
6071 or ((gPlayer2 <> nil) and (gPlayer2.Team = FTeam)))
6072 then a := 0
6073 else a := 1;
6075 if (not Silent) and (not sound_lost_flag[a].IsPlaying()) then
6076 sound_lost_flag[a].Play();
6077 {$ENDIF}
6079 if g_Game_IsNet then
6080 MH_SEND_FlagEvent(FLAG_STATE_DROPPED, Flag, FUID, False);
6081 end;
6082 SetFlag(FLAG_NONE);
6083 Result := True;
6084 end;
6086 procedure TPlayer.GetSecret();
6087 begin
6088 if (self = gPlayer1) or (self = gPlayer2) then
6089 begin
6090 g_Console_Add(Format(_lc[I_PLAYER_SECRET], [FName]), True);
6091 {$IFDEF ENABLE_SOUND}
6092 g_Sound_PlayEx('SOUND_GAME_SECRET');
6093 {$ENDIF}
6094 end;
6095 FSecrets += 1;
6096 end;
6098 procedure TPlayer.PressKey(Key: Byte; Time: Word);
6099 begin
6100 Assert(Key <= High(FKeys));
6102 FKeys[Key].Pressed := True;
6103 FKeys[Key].Time := Time;
6104 end;
6106 function TPlayer.IsKeyPressed(K: Byte): Boolean;
6107 begin
6108 Result := FKeys[K].Pressed;
6109 end;
6111 procedure TPlayer.ReleaseKeys();
6113 a: Integer;
6114 begin
6115 for a := Low(FKeys) to High(FKeys) do
6116 begin
6117 FKeys[a].Pressed := False;
6118 FKeys[a].Time := 0;
6119 end;
6120 end;
6122 procedure TPlayer.OnDamage(Angle: SmallInt);
6123 begin
6124 end;
6126 function TPlayer.firediry(): Integer;
6127 begin
6128 if FKeys[KEY_UP].Pressed then Result := -42
6129 else if FKeys[KEY_DOWN].Pressed then Result := 19
6130 else Result := 0;
6131 end;
6133 procedure TPlayer.PreserveState();
6135 i: Integer;
6136 SavedState: TPlayerSavedState;
6137 begin
6138 SavedState.Health := FHealth;
6139 SavedState.Armor := FArmor;
6140 SavedState.Air := FAir;
6141 SavedState.JetFuel := FJetFuel;
6142 SavedState.CurrWeap := FCurrWeap;
6143 SavedState.NextWeap := FNextWeap;
6144 SavedState.NextWeapDelay := FNextWeapDelay;
6145 for i := Low(FWeapon) to High(FWeapon) do
6146 SavedState.Weapon[i] := FWeapon[i];
6147 for i := Low(FAmmo) to High(FAmmo) do
6148 SavedState.Ammo[i] := FAmmo[i];
6149 for i := Low(FMaxAmmo) to High(FMaxAmmo) do
6150 SavedState.MaxAmmo[i] := FMaxAmmo[i];
6151 SavedState.Inventory := FInventory - [R_KEY_RED, R_KEY_GREEN, R_KEY_BLUE];
6153 FSavedStateNum := -1;
6154 for i := Low(SavedStates) to High(SavedStates) do
6155 if not SavedStates[i].Used then
6156 begin
6157 FSavedStateNum := i;
6158 break;
6159 end;
6160 if FSavedStateNum < 0 then
6161 begin
6162 SetLength(SavedStates, Length(SavedStates) + 1);
6163 FSavedStateNum := High(SavedStates);
6164 end;
6166 SavedState.Used := True;
6167 SavedStates[FSavedStateNum] := SavedState;
6168 end;
6170 procedure TPlayer.RestoreState();
6172 i: Integer;
6173 SavedState: TPlayerSavedState;
6174 begin
6175 if(FSavedStateNum < 0) or (FSavedStateNum > High(SavedStates)) then
6176 Exit;
6178 SavedState := SavedStates[FSavedStateNum];
6179 SavedStates[FSavedStateNum].Used := False;
6180 FSavedStateNum := -1;
6182 FHealth := SavedState.Health;
6183 FArmor := SavedState.Armor;
6184 FAir := SavedState.Air;
6185 FJetFuel := SavedState.JetFuel;
6186 FCurrWeap := SavedState.CurrWeap;
6187 FNextWeap := SavedState.NextWeap;
6188 FNextWeapDelay := SavedState.NextWeapDelay;
6189 for i := Low(FWeapon) to High(FWeapon) do
6190 FWeapon[i] := SavedState.Weapon[i];
6191 for i := Low(FAmmo) to High(FAmmo) do
6192 FAmmo[i] := SavedState.Ammo[i];
6193 for i := Low(FMaxAmmo) to High(FMaxAmmo) do
6194 FMaxAmmo[i] := SavedState.MaxAmmo[i];
6195 FInventory := SavedState.Inventory;
6197 if gGameSettings.GameType = GT_SERVER then
6198 MH_SEND_PlayerStats(FUID);
6199 end;
6201 procedure TPlayer.SaveState (st: TStream);
6203 i: Integer;
6204 begin
6205 // Ñèãíàòóðà èãðîêà
6206 utils.writeSign(st, 'PLYR');
6207 st.WriteByte(PLR_SAVE_VERSION); // version
6209 st.WriteBool(FIamBot); // Áîò èëè ÷åëîâåê
6210 st.WriteWordLE(FUID); // UID èãðîêà
6211 utils.writeStr(st, FName); // Èìÿ èãðîêà
6212 st.WriteByte(FTeam); // Êîìàíäà
6213 st.WriteBool(FAlive); // Æèâ ëè
6214 st.WriteBool(FNoRespawn); // Èçðàñõîäîâàë ëè âñå æèçíè
6216 // Íàïðàâëåíèå
6217 if FDirection = TDirection.D_LEFT
6218 then st.WriteByte(1)
6219 else st.WriteByte(2); // D_RIGHT
6221 st.WriteInt32LE(FHealth); // Çäîðîâüå
6222 st.WriteInt32LE(FHandicap); // Êîýôôèöèåíò èíâàëèäíîñòè
6223 st.WriteByte(FLives); // Æèçíè
6224 st.WriteInt32LE(FArmor); // Áðîíÿ
6225 st.WriteInt32LE(FAir); // Çàïàñ âîçäóõà
6226 st.WriteInt32LE(FJetFuel); // Çàïàñ ãîðþ÷åãî
6227 st.WriteInt32LE(FPain); // Áîëü
6228 st.WriteInt32LE(FKills); // Óáèë
6229 st.WriteInt32LE(FMonsterKills); // Óáèë ìîíñòðîâ
6230 st.WriteInt32LE(FFrags); // Ôðàãîâ
6231 st.WriteByte(FFragCombo); // Ôðàãîâ ïîäðÿä
6232 st.WriteDWordLE(FLastFrag); // Âðåìÿ ïîñëåäíåãî ôðàãà
6233 st.WriteInt32LE(FDeath); // Ñìåðòåé
6234 st.WriteByte(FFlag); // Êàêîé ôëàã íåñåò
6235 st.WriteInt32LE(FSecrets); // Íàøåë ñåêðåòîâ
6236 st.WriteByte(FCurrWeap); // Òåêóùåå îðóæèå
6237 st.WriteWordLE(FNextWeap); // Æåëàåìîå îðóæèå
6238 st.WriteByte(FNextWeapDelay); // ...è ïàóçà
6239 st.WriteInt16LE(FBFGFireCounter); // Âðåìÿ çàðÿäêè BFG
6240 st.WriteInt32LE(FDamageBuffer); // Áóôåð óðîíà
6241 st.WriteWordLE(FLastSpawnerUID); // Ïîñëåäíèé óäàðèâøèé
6242 st.WriteByte(FLastHit); // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6243 Obj_SaveState(st, @FObj); // Îáúåêò èãðîêà
6245 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6246 for i := A_BULLETS to A_HIGH do
6247 st.WriteWordLE(FAmmo[i]);
6249 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6250 for i := A_BULLETS to A_HIGH do
6251 st.WriteWordLE(FMaxAmmo[i]);
6253 // Íàëè÷èå îðóæèÿ
6254 for i := WP_FIRST to WP_LAST do
6255 st.WriteBool(FWeapon[i]);
6257 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6258 for i := WP_FIRST to WP_LAST do
6259 st.WriteWordLE(FReloading[i]);
6261 st.WriteBool(R_ITEM_BACKPACK in FInventory); // Íàëè÷èå ðþêçàêà
6262 st.WriteBool(R_KEY_RED in FInventory); // Íàëè÷èå êðàñíîãî êëþ÷à
6263 st.WriteBool(R_KEY_GREEN in FInventory); // Íàëè÷èå çåëåíîãî êëþ÷à
6264 st.WriteBool(R_KEY_BLUE in FInventory); // Íàëè÷èå ñèíåãî êëþ÷à
6265 st.WriteBool(R_BERSERK in FInventory); // Íàëè÷èå áåðñåðêà
6267 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6268 for i := MR_SUIT to MR_MAX do
6269 st.WriteDWordLE(FPowerups[i]);
6271 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6272 for i := T_RESPAWN to T_FLAGCAP do
6273 st.WriteDWordLE(FTime[i]);
6275 // Íàçâàíèå ìîäåëè
6276 utils.writeStr(st, FModel.Name);
6277 // Öâåò ìîäåëè
6278 st.WriteByte(FColor.R);
6279 st.WriteByte(FColor.G);
6280 st.WriteByte(FColor.B);
6281 end;
6284 procedure TPlayer.LoadState (st: TStream);
6286 i: Integer;
6287 str: String;
6288 begin
6289 Assert(st <> nil);
6291 // Ñèãíàòóðà èãðîêà
6292 if not utils.checkSign(st, 'PLYR') then
6293 Raise XStreamError.Create('invalid player signature');
6294 if st.ReadByte() <> PLR_SAVE_VERSION then
6295 Raise XStreamError.Create('invalid player version');
6297 FIamBot := st.ReadBool(); // Áîò èëè ÷åëîâåê:
6298 FUID := st.ReadWordLE(); // UID èãðîêà
6300 // Èìÿ èãðîêà
6301 str := utils.readStr(st);
6302 if (self <> gPlayer1) and (self <> gPlayer2) then
6303 FName := str;
6305 FTeam := st.ReadByte(); // Êîìàíäà
6306 FAlive := st.ReadBool(); // Æèâ ëè
6307 FNoRespawn := st.ReadBool(); // Èçðàñõîäîâàë ëè âñå æèçíè
6309 // Íàïðàâëåíèå
6310 if st.ReadByte() = 1
6311 then FDirection := TDirection.D_LEFT
6312 else FDirection := TDirection.D_RIGHT; // b = 2
6314 FHealth := st.ReadInt32LE(); // Çäîðîâüå
6315 FHandicap := st.ReadInt32LE(); // Êîýôôèöèåíò èíâàëèäíîñòè
6316 FLives := st.ReadByte(); // Æèçíè
6317 FArmor := st.ReadInt32LE(); // Áðîíÿ
6318 FAir := st.ReadInt32LE(); // Çàïàñ âîçäóõà
6319 FJetFuel := st.ReadInt32LE(); // Çàïàñ ãîðþ÷åãî
6320 FPain := st.ReadInt32LE(); // Áîëü
6321 FKills := st.ReadInt32LE(); // Óáèë
6322 FMonsterKills := st.ReadInt32LE(); // Óáèë ìîíñòðîâ
6323 FFrags := st.ReadInt32LE(); // Ôðàãîâ
6324 FFragCombo := st.ReadByte(); // Ôðàãîâ ïîäðÿä
6325 FLastFrag := st.ReadDWordLE(); // Âðåìÿ ïîñëåäíåãî ôðàãà
6326 FDeath := st.ReadInt32LE(); // Ñìåðòåé
6327 FFlag := st.ReadByte(); // Êàêîé ôëàã íåñåò
6328 FSecrets := st.ReadInt32LE(); // Íàøåë ñåêðåòîâ
6329 FCurrWeap := st.ReadByte(); // Òåêóùåå îðóæèå
6330 FNextWeap := st.ReadWordLE(); // Æåëàåìîå îðóæèå
6331 FNextWeapDelay := st.ReadByte(); // ...è ïàóçà
6332 FBFGFireCounter := st.ReadInt16LE(); // Âðåìÿ çàðÿäêè BFG
6333 FDamageBuffer := st.ReadInt32LE(); // Áóôåð óðîíà
6334 FLastSpawnerUID := st.ReadWordLE(); // Ïîñëåäíèé óäàðèâøèé
6335 FLastHit := st.ReadByte(); // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6336 Obj_LoadState(@FObj, st); // Îáúåêò èãðîêà
6338 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6339 for i := A_BULLETS to A_HIGH do
6340 FAmmo[i] := st.ReadWordLE();
6342 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6343 for i := A_BULLETS to A_HIGH do
6344 FMaxAmmo[i] := st.ReadWordLE();
6346 // Íàëè÷èå îðóæèÿ
6347 for i := WP_FIRST to WP_LAST do
6348 FWeapon[i] := st.ReadBool();
6350 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6351 for i := WP_FIRST to WP_LAST do
6352 FReloading[i] := st.ReadWordLE();
6354 if st.ReadBool() then FInventory += [R_ITEM_BACKPACK]; // Íàëè÷èå ðþêçàêà
6355 if st.ReadBool() then FInventory += [R_KEY_RED]; // Íàëè÷èå êðàñíîãî êëþ÷à
6356 if st.ReadBool() then FInventory += [R_KEY_GREEN]; // Íàëè÷èå çåëåíîãî êëþ÷à
6357 if st.ReadBool() then FInventory += [R_KEY_BLUE]; // Íàëè÷èå ñèíåãî êëþ÷à
6358 if st.ReadBool() then FInventory += [R_BERSERK]; // Íàëè÷èå áåðñåðêà
6360 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6361 for i := MR_SUIT to MR_MAX do
6362 FPowerups[i] := st.ReadDWordLE();
6364 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6365 for i := T_RESPAWN to T_FLAGCAP do
6366 FTime[i] := st.ReadDWordLE();
6368 // Íàçâàíèå ìîäåëè
6369 str := utils.readStr(st);
6370 // Öâåò ìîäåëè
6371 FColor.R := st.ReadByte();
6372 FColor.G := st.ReadByte();
6373 FColor.B := st.ReadByte();
6375 // Îáíîâëÿåì ìîäåëü èãðîêà
6376 if self = gPlayer1 then
6377 begin
6378 str := gPlayer1Settings.Model;
6379 FColor := gPlayer1Settings.Color;
6381 else if self = gPlayer2 then
6382 begin
6383 str := gPlayer2Settings.Model;
6384 FColor := gPlayer2Settings.Color;
6385 end;
6387 SetModel(str);
6388 if gGameSettings.GameMode in [GM_TDM, GM_CTF]
6389 then FModel.Color := TEAMCOLOR[FTeam]
6390 else FModel.Color := FColor;
6391 end;
6394 procedure TPlayer.TankRamboCheats(Health: Boolean);
6396 a: Integer;
6397 begin
6398 if Health then
6399 begin
6400 FHealth := PLAYER_HP_LIMIT;
6401 FArmor := PLAYER_AP_LIMIT;
6402 Exit;
6403 end;
6405 for a := WP_FIRST to WP_LAST do FWeapon[a] := True;
6406 for a := A_BULLETS to A_HIGH do FAmmo[a] := 30000;
6407 FInventory += [R_KEY_RED, R_KEY_GREEN, R_KEY_BLUE];
6408 end;
6410 procedure TPlayer.RestoreHealthArmor();
6411 begin
6412 FHealth := PLAYER_HP_LIMIT;
6413 FArmor := PLAYER_AP_LIMIT;
6414 end;
6416 procedure TPlayer.FragCombo();
6418 Param: Integer;
6419 begin
6420 if (gGameSettings.GameMode in [GM_COOP, GM_SINGLE]) or g_Game_IsClient then
6421 Exit;
6422 if gTime - FLastFrag < FRAG_COMBO_TIME then
6423 begin
6424 if FFragCombo < 5 then
6425 Inc(FFragCombo);
6426 Param := FUID or (FFragCombo shl 16);
6427 if (FComboEvnt >= Low(gDelayedEvents)) and
6428 (FComboEvnt <= High(gDelayedEvents)) and
6429 gDelayedEvents[FComboEvnt].Pending and
6430 (gDelayedEvents[FComboEvnt].DEType = DE_KILLCOMBO) and
6431 (gDelayedEvents[FComboEvnt].DENum and $FFFF = FUID) then
6432 begin
6433 gDelayedEvents[FComboEvnt].Time := gTime + 500;
6434 gDelayedEvents[FComboEvnt].DENum := Param;
6436 else
6437 FComboEvnt := g_Game_DelayEvent(DE_KILLCOMBO, 500, Param);
6439 else
6440 FFragCombo := 1;
6442 FLastFrag := gTime;
6443 end;
6445 procedure TPlayer.GiveItem(ItemType: Byte);
6446 begin
6447 case ItemType of
6448 ITEM_SUIT:
6449 if FPowerups[MR_SUIT] < gTime+PLAYER_SUIT_TIME then
6450 FPowerups[MR_SUIT] := gTime+PLAYER_SUIT_TIME;
6452 ITEM_OXYGEN:
6453 if FAir < AIR_MAX then FAir := AIR_MAX;
6455 ITEM_MEDKIT_BLACK:
6456 begin
6457 if not (R_BERSERK in FInventory) then
6458 begin
6459 FInventory += [R_BERSERK];
6460 if FBFGFireCounter < 1 then
6461 begin
6462 FCurrWeap := WEAPON_IRONFIST;
6463 resetWeaponQueue();
6464 FModel.SetWeapon(WEAPON_IRONFIST);
6465 end;
6466 if gFlash <> 0 then FPain += 100;
6467 FBerserk := gTime+30000;
6468 end;
6469 if FHealth < PLAYER_HP_SOFT then
6470 begin
6471 FHealth := PLAYER_HP_SOFT;
6472 FBerserk := gTime+30000;
6473 end;
6474 end;
6476 ITEM_INVUL:
6477 if FPowerups[MR_INVUL] < gTime+PLAYER_INVUL_TIME then
6478 begin
6479 FPowerups[MR_INVUL] := gTime+PLAYER_INVUL_TIME;
6480 FSpawnInvul := 0;
6481 end;
6483 ITEM_INVIS:
6484 if FPowerups[MR_INVIS] < gTime+PLAYER_INVIS_TIME then
6485 FPowerups[MR_INVIS] := gTime+PLAYER_INVIS_TIME;
6487 ITEM_JETPACK:
6488 if FJetFuel < JET_MAX then FJetFuel := JET_MAX;
6490 ITEM_MEDKIT_SMALL: if FHealth < PLAYER_HP_SOFT then IncMax(FHealth, 10, PLAYER_HP_SOFT);
6491 ITEM_MEDKIT_LARGE: if FHealth < PLAYER_HP_SOFT then IncMax(FHealth, 25, PLAYER_HP_SOFT);
6493 ITEM_ARMOR_GREEN: if FArmor < PLAYER_AP_SOFT then FArmor := PLAYER_AP_SOFT;
6494 ITEM_ARMOR_BLUE: if FArmor < PLAYER_AP_LIMIT then FArmor := PLAYER_AP_LIMIT;
6496 ITEM_SPHERE_BLUE: if FHealth < PLAYER_HP_LIMIT then IncMax(FHealth, 100, PLAYER_HP_LIMIT);
6497 ITEM_SPHERE_WHITE:
6498 if (FHealth < PLAYER_HP_LIMIT) or (FArmor < PLAYER_AP_LIMIT) then
6499 begin
6500 if FHealth < PLAYER_HP_LIMIT then FHealth := PLAYER_HP_LIMIT;
6501 if FArmor < PLAYER_AP_LIMIT then FArmor := PLAYER_AP_LIMIT;
6502 end;
6504 ITEM_WEAPON_SAW: FWeapon[WEAPON_SAW] := True;
6505 ITEM_WEAPON_SHOTGUN1: FWeapon[WEAPON_SHOTGUN1] := True;
6506 ITEM_WEAPON_SHOTGUN2: FWeapon[WEAPON_SHOTGUN2] := True;
6507 ITEM_WEAPON_CHAINGUN: FWeapon[WEAPON_CHAINGUN] := True;
6508 ITEM_WEAPON_ROCKETLAUNCHER: FWeapon[WEAPON_ROCKETLAUNCHER] := True;
6509 ITEM_WEAPON_PLASMA: FWeapon[WEAPON_PLASMA] := True;
6510 ITEM_WEAPON_BFG: FWeapon[WEAPON_BFG] := True;
6511 ITEM_WEAPON_SUPERCHAINGUN: FWeapon[WEAPON_SUPERCHAINGUN] := True;
6512 ITEM_WEAPON_FLAMETHROWER: FWeapon[WEAPON_FLAMETHROWER] := True;
6514 ITEM_AMMO_BULLETS: if FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS] then IncMax(FAmmo[A_BULLETS], 10, FMaxAmmo[A_BULLETS]);
6515 ITEM_AMMO_BULLETS_BOX: if FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS] then IncMax(FAmmo[A_BULLETS], 50, FMaxAmmo[A_BULLETS]);
6516 ITEM_AMMO_SHELLS: if FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS] then IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
6517 ITEM_AMMO_SHELLS_BOX: if FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS] then IncMax(FAmmo[A_SHELLS], 25, FMaxAmmo[A_SHELLS]);
6518 ITEM_AMMO_ROCKET: if FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS] then IncMax(FAmmo[A_ROCKETS], 1, FMaxAmmo[A_ROCKETS]);
6519 ITEM_AMMO_ROCKET_BOX: if FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS] then IncMax(FAmmo[A_ROCKETS], 5, FMaxAmmo[A_ROCKETS]);
6520 ITEM_AMMO_CELL: if FAmmo[A_CELLS] < FMaxAmmo[A_CELLS] then IncMax(FAmmo[A_CELLS], 40, FMaxAmmo[A_CELLS]);
6521 ITEM_AMMO_CELL_BIG: if FAmmo[A_CELLS] < FMaxAmmo[A_CELLS] then IncMax(FAmmo[A_CELLS], 100, FMaxAmmo[A_CELLS]);
6522 ITEM_AMMO_FUELCAN: if FAmmo[A_FUEL] < FMaxAmmo[A_FUEL] then IncMax(FAmmo[A_FUEL], 100, FMaxAmmo[A_FUEL]);
6524 ITEM_AMMO_BACKPACK:
6525 if (FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS]) or
6526 (FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS]) or
6527 (FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS]) or
6528 (FAmmo[A_CELLS] < FMaxAmmo[A_CELLS]) or
6529 (FMaxAmmo[A_FUEL] < AmmoLimits[1, A_FUEL]) then
6530 begin
6531 FMaxAmmo[A_BULLETS] := AmmoLimits[1, A_BULLETS];
6532 FMaxAmmo[A_SHELLS] := AmmoLimits[1, A_SHELLS];
6533 FMaxAmmo[A_ROCKETS] := AmmoLimits[1, A_ROCKETS];
6534 FMaxAmmo[A_CELLS] := AmmoLimits[1, A_CELLS];
6535 FMaxAmmo[A_FUEL] := AmmoLimits[1, A_FUEL];
6537 if FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS] then IncMax(FAmmo[A_BULLETS], 10, FMaxAmmo[A_BULLETS]);
6538 if FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS] then IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
6539 if FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS] then IncMax(FAmmo[A_ROCKETS], 1, FMaxAmmo[A_ROCKETS]);
6540 if FAmmo[A_CELLS] < FMaxAmmo[A_CELLS] then IncMax(FAmmo[A_CELLS], 40, FMaxAmmo[A_CELLS]);
6542 FInventory += [R_ITEM_BACKPACK];
6543 end;
6545 ITEM_KEY_RED: if not (R_KEY_RED in FInventory) then FInventory += [R_KEY_RED];
6546 ITEM_KEY_GREEN: if not (R_KEY_GREEN in FInventory) then FInventory += [R_KEY_GREEN];
6547 ITEM_KEY_BLUE: if not (R_KEY_BLUE in FInventory) then FInventory += [R_KEY_BLUE];
6549 ITEM_BOTTLE: if FHealth < PLAYER_HP_LIMIT then IncMax(FHealth, 4, PLAYER_HP_LIMIT);
6550 ITEM_HELMET: if FArmor < PLAYER_AP_LIMIT then IncMax(FArmor, 5, PLAYER_AP_LIMIT);
6552 else
6553 Exit;
6554 end;
6555 if g_Game_IsNet and g_Game_IsServer then
6556 MH_SEND_PlayerStats(FUID);
6557 end;
6559 procedure TPlayer.FlySmoke(Times: DWORD = 1);
6561 id, i: DWORD;
6562 Anim: TAnimation;
6563 begin
6564 if (Random(5) = 1) and (Times = 1) then
6565 Exit;
6567 if BodyInLiquid(0, 0) then
6568 begin
6569 g_Game_Effect_Bubbles(Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2)+Random(3)-1,
6570 Obj.Y+Obj.Rect.Height+8, 1, 8, 4);
6571 Exit;
6572 end;
6574 if g_Frames_Get(id, 'FRAMES_SMOKE') then
6575 begin
6576 for i := 1 to Times do
6577 begin
6578 Anim := TAnimation.Create(id, False, 3);
6579 Anim.Alpha := 150;
6580 g_GFX_OnceAnim(Obj.X+Obj.Rect.X+Random(Obj.Rect.Width+Times*2)-(Anim.Width div 2),
6581 Obj.Y+Obj.Rect.Height-4+Random(8+Times*2), Anim, ONCEANIM_SMOKE);
6582 Anim.Destroy();
6583 end;
6584 end;
6585 end;
6587 procedure TPlayer.OnFireFlame(Times: DWORD = 1);
6589 id, i: DWORD;
6590 Anim: TAnimation;
6591 begin
6592 if (Random(10) = 1) and (Times = 1) then
6593 Exit;
6595 if g_Frames_Get(id, 'FRAMES_FLAME') then
6596 begin
6597 for i := 1 to Times do
6598 begin
6599 Anim := TAnimation.Create(id, False, 3);
6600 Anim.Alpha := 0;
6601 g_GFX_OnceAnim(Obj.X+Obj.Rect.X+Random(Obj.Rect.Width+Times*2)-(Anim.Width div 2),
6602 Obj.Y+8+Random(8+Times*2), Anim, ONCEANIM_SMOKE);
6603 Anim.Destroy();
6604 end;
6605 end;
6606 end;
6608 {$IFDEF ENABLE_SOUND}
6609 procedure TPlayer.PauseSounds(Enable: Boolean);
6610 begin
6611 FSawSound.Pause(Enable);
6612 FSawSoundIdle.Pause(Enable);
6613 FSawSoundHit.Pause(Enable);
6614 FSawSoundSelect.Pause(Enable);
6615 FFlameSoundOn.Pause(Enable);
6616 FFlameSoundOff.Pause(Enable);
6617 FFlameSoundWork.Pause(Enable);
6618 FJetSoundFly.Pause(Enable);
6619 FJetSoundOn.Pause(Enable);
6620 FJetSoundOff.Pause(Enable);
6621 end;
6622 {$ENDIF}
6624 { TCorpse: }
6626 constructor TCorpse.Create(X, Y: Integer; ModelName: String; aMess: Boolean);
6627 begin
6628 g_Obj_Init(@FObj);
6629 FObj.X := X;
6630 FObj.Y := Y;
6631 FObj.Rect := PLAYER_CORPSERECT;
6632 FModelName := ModelName;
6633 FMess := aMess;
6635 if FMess then
6636 begin
6637 FState := CORPSE_STATE_MESS;
6638 g_PlayerModel_GetAnim(ModelName, A_DIE2, FAnimation, FAnimationMask);
6640 else
6641 begin
6642 FState := CORPSE_STATE_NORMAL;
6643 g_PlayerModel_GetAnim(ModelName, A_DIE1, FAnimation, FAnimationMask);
6644 end;
6645 end;
6647 destructor TCorpse.Destroy();
6648 begin
6649 FAnimation.Free();
6650 FAnimationMask.Free();
6652 inherited;
6653 end;
6655 function TCorpse.ObjPtr (): PObj; inline;
6656 begin
6657 Result := @FObj;
6658 end;
6660 procedure TCorpse.positionChanged (); inline;
6661 begin
6662 end;
6664 procedure TCorpse.moveBy (dx, dy: Integer); inline;
6665 begin
6666 if (dx <> 0) or (dy <> 0) then
6667 begin
6668 FObj.X += dx;
6669 FObj.Y += dy;
6670 positionChanged();
6671 end;
6672 end;
6675 procedure TCorpse.getMapBox (out x, y, w, h: Integer); inline;
6676 begin
6677 x := FObj.X+PLAYER_CORPSERECT.X;
6678 y := FObj.Y+PLAYER_CORPSERECT.Y;
6679 w := PLAYER_CORPSERECT.Width;
6680 h := PLAYER_CORPSERECT.Height;
6681 end;
6684 procedure TCorpse.Damage(Value: Word; SpawnerUID: Word; vx, vy: Integer);
6686 pm: TPlayerModel;
6687 Blood: TModelBlood;
6688 begin
6689 if FState = CORPSE_STATE_REMOVEME then
6690 Exit;
6692 FDamage := FDamage + Value;
6694 if FDamage > 150 then
6695 begin
6696 if FAnimation <> nil then
6697 begin
6698 FAnimation.Free();
6699 FAnimation := nil;
6701 FState := CORPSE_STATE_REMOVEME;
6703 g_Player_CreateGibs(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
6704 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
6705 FModelName, FColor);
6707 {$IFDEF ENABLE_SOUND}
6708 // Çâóê ìÿñà îò òðóïà:
6709 pm := g_PlayerModel_Get(FModelName);
6710 pm.PlaySound(MODELSOUND_DIE, 5, FObj.X, FObj.Y);
6711 pm.Free;
6712 {$ENDIF}
6714 // Çëîâåùèé ñìåõ:
6715 if (gBodyKillEvent <> -1)
6716 and gDelayedEvents[gBodyKillEvent].Pending then
6717 gDelayedEvents[gBodyKillEvent].Pending := False;
6718 gBodyKillEvent := g_Game_DelayEvent(DE_BODYKILL, 1050, SpawnerUID);
6719 end;
6721 else
6722 begin
6723 Blood := g_PlayerModel_GetBlood(FModelName);
6724 FObj.Vel.X := FObj.Vel.X + vx;
6725 FObj.Vel.Y := FObj.Vel.Y + vy;
6726 g_GFX_Blood(FObj.X+PLAYER_CORPSERECT.X+(PLAYER_CORPSERECT.Width div 2),
6727 FObj.Y+PLAYER_CORPSERECT.Y+(PLAYER_CORPSERECT.Height div 2),
6728 Value, vx, vy, 16, (PLAYER_CORPSERECT.Height*2) div 3,
6729 Blood.R, Blood.G, Blood.B, Blood.Kind);
6730 end;
6731 end;
6733 procedure TCorpse.Draw();
6735 fX, fY: Integer;
6736 begin
6737 if FState = CORPSE_STATE_REMOVEME then
6738 Exit;
6740 FObj.lerp(gLerpFactor, fX, fY);
6742 if FAnimation <> nil then
6743 FAnimation.Draw(fX, fY, TMirrorType.None);
6745 if FAnimationMask <> nil then
6746 begin
6747 e_Colors := FColor;
6748 FAnimationMask.Draw(fX, fY, TMirrorType.None);
6749 e_Colors.R := 255;
6750 e_Colors.G := 255;
6751 e_Colors.B := 255;
6752 end;
6753 end;
6755 procedure TCorpse.Update();
6757 st: Word;
6758 begin
6759 if FState = CORPSE_STATE_REMOVEME then
6760 Exit;
6762 FObj.oldX := FObj.X;
6763 FObj.oldY := FObj.Y;
6765 if gTime mod (GAME_TICK*2) <> 0 then
6766 begin
6767 g_Obj_Move(@FObj, True, True, True);
6768 positionChanged(); // this updates spatial accelerators
6769 Exit;
6770 end;
6772 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6773 FObj.Vel.X := z_dec(FObj.Vel.X, 1);
6775 st := g_Obj_Move(@FObj, True, True, True);
6776 positionChanged(); // this updates spatial accelerators
6778 if WordBool(st and MOVE_FALLOUT) then
6779 begin
6780 FState := CORPSE_STATE_REMOVEME;
6781 Exit;
6782 end;
6784 if FAnimation <> nil then
6785 FAnimation.Update();
6786 if FAnimationMask <> nil then
6787 FAnimationMask.Update();
6788 end;
6791 procedure TCorpse.SaveState (st: TStream);
6793 anim: Boolean;
6794 begin
6795 Assert(st <> nil);
6797 // Ñèãíàòóðà òðóïà
6798 utils.writeSign(st, 'CORP');
6799 st.WriteByte(0);
6801 st.WriteByte(FState); // Ñîñòîÿíèå
6802 st.WriteByte(FDamage); // Íàêîïëåííûé óðîí
6804 // Öâåò
6805 st.WriteByte(FColor.R);
6806 st.WriteByte(FColor.G);
6807 st.WriteByte(FColor.B);
6809 // Îáúåêò òðóïà
6810 Obj_SaveState(st, @FObj);
6811 st.WriteWordLE(FPlayerUID);
6813 // Åñòü ëè àíèìàöèÿ
6814 anim := FAnimation <> nil;
6815 st.WriteBool(anim);
6816 // Åñëè åñòü - ñîõðàíÿåì
6817 if anim then FAnimation.SaveState(st);
6819 // Åñòü ëè ìàñêà àíèìàöèè
6820 anim := FAnimationMask <> nil;
6821 st.WriteBool(anim);
6822 // Åñëè åñòü - ñîõðàíÿåì
6823 if anim then FAnimationMask.SaveState(st);
6824 end;
6827 procedure TCorpse.LoadState (st: TStream);
6829 anim: Boolean;
6830 begin
6831 Assert(st <> nil);
6833 // Ñèãíàòóðà òðóïà
6834 if not utils.checkSign(st, 'CORP') then
6835 Raise XStreamError.Create('invalid corpse signature');
6836 if st.ReadByte() <> 0 then
6837 Raise XStreamError.Create('invalid corpse version');
6839 FState := st.ReadByte(); // Ñîñòîÿíèå
6840 FDamage := st.ReadByte(); // Íàêîïëåííûé óðîí
6842 // Öâåò
6843 FColor.R := st.ReadByte();
6844 FColor.G := st.ReadByte();
6845 FColor.B := st.ReadByte();
6847 // Îáúåêò òðóïà
6848 Obj_LoadState(@FObj, st);
6849 FPlayerUID := st.ReadWordLE();
6851 // Åñòü ëè àíèìàöèÿ
6852 anim := st.ReadBool();
6853 // Åñëè åñòü - çàãðóæàåì
6854 if anim then
6855 begin
6856 Assert(FAnimation <> nil, 'TCorpse.LoadState: no FAnimation');
6857 FAnimation.LoadState(st);
6858 end;
6860 // Åñòü ëè ìàñêà àíèìàöèè
6861 anim := st.ReadBool();
6862 // Åñëè åñòü - çàãðóæàåì
6863 if anim then
6864 begin
6865 Assert(FAnimationMask <> nil, 'TCorpse.LoadState: no FAnimationMask');
6866 FAnimationMask.LoadState(st);
6867 end;
6868 end;
6870 { T B o t : }
6872 constructor TBot.Create();
6874 a: Integer;
6875 begin
6876 inherited Create();
6878 FPhysics := True;
6879 FSpectator := False;
6880 FGhost := False;
6882 FIamBot := True;
6884 Inc(gNumBots);
6886 for a := WP_FIRST to WP_LAST do
6887 begin
6888 FDifficult.WeaponPrior[a] := WEAPON_PRIOR1[a];
6889 FDifficult.CloseWeaponPrior[a] := WEAPON_PRIOR2[a];
6890 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6891 end;
6892 end;
6894 destructor TBot.Destroy();
6895 begin
6896 Dec(gNumBots);
6897 inherited Destroy();
6898 end;
6900 procedure TBot.Draw();
6901 begin
6902 inherited Draw();
6904 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6905 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6906 end;
6908 procedure TBot.Respawn(Silent: Boolean; Force: Boolean = False);
6909 begin
6910 inherited Respawn(Silent, Force);
6912 FAIFlags := nil;
6913 FSelectedWeapon := FCurrWeap;
6914 resetWeaponQueue();
6915 FTargetUID := 0;
6916 end;
6918 procedure TBot.UpdateCombat();
6919 type
6920 TTarget = record
6921 UID: Word;
6922 X, Y: Integer;
6923 Rect: TRectWH;
6924 cX, cY: Integer;
6925 Dist: Word;
6926 Line: Boolean;
6927 Visible: Boolean;
6928 IsPlayer: Boolean;
6929 end;
6931 TTargetRecord = array of TTarget;
6933 function Compare(a, b: TTarget): Integer;
6934 begin
6935 if a.Line and not b.Line then // A íà ëèíèè îãíÿ
6936 Result := -1
6937 else
6938 if not a.Line and b.Line then // B íà ëèíèè îãíÿ
6939 Result := 1
6940 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6941 if (a.Line and b.Line) or ((not a.Line) and (not b.Line)) then
6942 begin
6943 if a.Dist > b.Dist then // B áëèæå
6944 Result := 1
6945 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6946 Result := -1;
6948 else // Ñòðàííî -> A
6949 Result := -1;
6950 end;
6953 a, x1, y1, x2, y2: Integer;
6954 targets: TTargetRecord;
6955 ammo: Word;
6956 Target, BestTarget: TTarget;
6957 firew, fireh: Integer;
6958 angle: SmallInt;
6959 mon: TMonster;
6960 pla, tpla: TPlayer;
6961 vsPlayer, vsMonster, ok: Boolean;
6964 function monsUpdate (mon: TMonster): Boolean;
6965 begin
6966 result := false; // don't stop
6967 if mon.alive and (mon.MonsterType <> MONSTER_BARREL) then
6968 begin
6969 if not TargetOnScreen(mon.Obj.X+mon.Obj.Rect.X, mon.Obj.Y+mon.Obj.Rect.Y) then exit;
6971 x2 := mon.Obj.X+mon.Obj.Rect.X+(mon.Obj.Rect.Width div 2);
6972 y2 := mon.Obj.Y+mon.Obj.Rect.Y+(mon.Obj.Rect.Height div 2);
6974 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6975 if g_TraceVector(x1, y1, x2, y2) then
6976 begin
6977 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6978 SetLength(targets, Length(targets)+1);
6979 with targets[High(targets)] do
6980 begin
6981 UID := mon.UID;
6982 X := mon.Obj.X;
6983 Y := mon.Obj.Y;
6984 cX := x2;
6985 cY := y2;
6986 Rect := mon.Obj.Rect;
6987 Dist := g_PatchLength(x1, y1, x2, y2);
6988 Line := (y1+4 < Target.Y + mon.Obj.Rect.Y + mon.Obj.Rect.Height) and
6989 (y1-4 > Target.Y + mon.Obj.Rect.Y);
6990 Visible := True;
6991 IsPlayer := False;
6992 end;
6993 end;
6994 end;
6995 end;
6997 begin
6998 vsPlayer := TGameOption.BOTS_VS_PLAYERS in gGameSettings.Options;
6999 vsMonster := TGameOption.BOTS_VS_MONSTERS in gGameSettings.Options;
7001 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
7002 if FCurrWeap <> FSelectedWeapon then
7003 NextWeapon();
7005 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
7006 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap = FSelectedWeapon) then
7007 begin
7008 RemoveAIFlag('NEEDFIRE');
7010 case FCurrWeap of
7011 WEAPON_PLASMA, WEAPON_SUPERCHAINGUN, WEAPON_CHAINGUN: PressKey(KEY_FIRE, 20);
7012 WEAPON_SAW, WEAPON_IRONFIST, WEAPON_FLAMETHROWER: PressKey(KEY_FIRE, 40);
7013 else PressKey(KEY_FIRE);
7014 end;
7015 end;
7017 // Êîîðäèíàòû ñòâîëà:
7018 x1 := FObj.X + WEAPONPOINT[FDirection].X;
7019 y1 := FObj.Y + WEAPONPOINT[FDirection].Y;
7021 Target.UID := FTargetUID;
7023 ok := False;
7024 if Target.UID <> 0 then
7025 begin // Öåëü åñòü - íàñòðàèâàåì
7026 if (g_GetUIDType(Target.UID) = UID_PLAYER) and
7027 vsPlayer then
7028 begin // Èãðîê
7029 tpla := g_Player_Get(Target.UID);
7030 if tpla <> nil then
7031 with tpla do
7032 begin
7033 if (@FObj) <> nil then
7034 begin
7035 Target.X := FObj.X;
7036 Target.Y := FObj.Y;
7037 end;
7038 end;
7040 Target.cX := Target.X + PLAYER_RECT_CX;
7041 Target.cY := Target.Y + PLAYER_RECT_CY;
7042 Target.Rect := PLAYER_RECT;
7043 Target.Visible := g_TraceVector(x1, y1, Target.cX, Target.cY);
7044 Target.Line := (y1+4 < Target.Y+PLAYER_RECT.Y+PLAYER_RECT.Height) and
7045 (y1-4 > Target.Y+PLAYER_RECT.Y);
7046 Target.IsPlayer := True;
7047 ok := True;
7049 else
7050 if (g_GetUIDType(Target.UID) = UID_MONSTER) and
7051 vsMonster then
7052 begin // Ìîíñòð
7053 mon := g_Monsters_ByUID(Target.UID);
7054 if mon <> nil then
7055 begin
7056 Target.X := mon.Obj.X;
7057 Target.Y := mon.Obj.Y;
7059 Target.cX := Target.X + mon.Obj.Rect.X + (mon.Obj.Rect.Width div 2);
7060 Target.cY := Target.Y + mon.Obj.Rect.Y + (mon.Obj.Rect.Height div 2);
7061 Target.Rect := mon.Obj.Rect;
7062 Target.Visible := g_TraceVector(x1, y1, Target.cX, Target.cY);
7063 Target.Line := (y1+4 < Target.Y + mon.Obj.Rect.Y + mon.Obj.Rect.Height) and
7064 (y1-4 > Target.Y + mon.Obj.Rect.Y);
7065 Target.IsPlayer := False;
7066 ok := True;
7067 end;
7068 end;
7069 end;
7071 if not ok then
7072 begin // Öåëè íåò - îáíóëÿåì
7073 Target.X := 0;
7074 Target.Y := 0;
7075 Target.cX := 0;
7076 Target.cY := 0;
7077 Target.Visible := False;
7078 Target.Line := False;
7079 Target.IsPlayer := False;
7080 end;
7082 targets := nil;
7084 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
7085 if (not Target.Line) or (not Target.Visible) then
7086 begin
7087 // Èãðîêè:
7088 if vsPlayer then
7089 for a := 0 to High(gPlayers) do
7090 if (gPlayers[a] <> nil) and (gPlayers[a].alive) and
7091 (gPlayers[a].FUID <> FUID) and
7092 (not SameTeam(FUID, gPlayers[a].FUID)) and
7093 (not gPlayers[a].NoTarget) and
7094 (gPlayers[a].FPowerups[MR_INVIS] < gTime) then
7095 begin
7096 if not TargetOnScreen(gPlayers[a].FObj.X + PLAYER_RECT.X,
7097 gPlayers[a].FObj.Y + PLAYER_RECT.Y) then
7098 Continue;
7100 x2 := gPlayers[a].FObj.X + PLAYER_RECT_CX;
7101 y2 := gPlayers[a].FObj.Y + PLAYER_RECT_CY;
7103 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
7104 if g_TraceVector(x1, y1, x2, y2) then
7105 begin
7106 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
7107 SetLength(targets, Length(targets)+1);
7108 with targets[High(targets)] do
7109 begin
7110 UID := gPlayers[a].FUID;
7111 X := gPlayers[a].FObj.X;
7112 Y := gPlayers[a].FObj.Y;
7113 cX := x2;
7114 cY := y2;
7115 Rect := PLAYER_RECT;
7116 Dist := g_PatchLength(x1, y1, x2, y2);
7117 Line := (y1+4 < Target.Y+PLAYER_RECT.Y+PLAYER_RECT.Height) and
7118 (y1-4 > Target.Y+PLAYER_RECT.Y);
7119 Visible := True;
7120 IsPlayer := True;
7121 end;
7122 end;
7123 end;
7125 // Ìîíñòðû:
7126 if vsMonster then g_Mons_ForEach(monsUpdate);
7127 end;
7129 // Åñëè åñòü âîçìîæíûå öåëè:
7130 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
7131 if targets <> nil then
7132 begin
7133 // Âûáèðàåì íàèëó÷øóþ öåëü:
7134 BestTarget := targets[0];
7135 if Length(targets) > 1 then
7136 for a := 1 to High(targets) do
7137 if Compare(BestTarget, targets[a]) = 1 then
7138 BestTarget := targets[a];
7140 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
7141 if ((not Target.Visible) and BestTarget.Visible and (Target.UID <> BestTarget.UID)) or
7142 ((not Target.Line) and BestTarget.Line and BestTarget.Visible) then
7143 begin
7144 Target := BestTarget;
7146 if (Healthy() = 3) or ((Healthy() = 2)) then
7147 begin // Åñëè çäîðîâû - äîãîíÿåì
7148 if ((RunDirection() = TDirection.D_LEFT) and (Target.X > FObj.X)) then
7149 SetAIFlag('GORIGHT', '1');
7150 if ((RunDirection() = TDirection.D_RIGHT) and (Target.X < FObj.X)) then
7151 SetAIFlag('GOLEFT', '1');
7153 else
7154 begin // Åñëè ïîáèòû - óáåãàåì
7155 if ((RunDirection() = TDirection.D_LEFT) and (Target.X < FObj.X)) then
7156 SetAIFlag('GORIGHT', '1');
7157 if ((RunDirection() = TDirection.D_RIGHT) and (Target.X > FObj.X)) then
7158 SetAIFlag('GOLEFT', '1');
7159 end;
7161 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
7162 SelectWeapon(Abs(x1-Target.cX));
7163 end;
7164 end;
7166 // Åñëè åñòü öåëü:
7167 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
7168 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
7169 if Target.UID <> 0 then
7170 begin
7171 if not TargetOnScreen(Target.X + Target.Rect.X,
7172 Target.Y + Target.Rect.Y) then
7173 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
7174 if (Healthy() = 3) or ((Healthy() = 2)) then
7175 begin // Åñëè çäîðîâû - äîãîíÿåì
7176 if ((RunDirection() = TDirection.D_LEFT) and (Target.X > FObj.X)) then
7177 SetAIFlag('GORIGHT', '1');
7178 if ((RunDirection() = TDirection.D_RIGHT) and (Target.X < FObj.X)) then
7179 SetAIFlag('GOLEFT', '1');
7181 else
7182 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
7183 Target.UID := 0;
7184 if ((RunDirection() = TDirection.D_LEFT) and (Target.X < FObj.X)) then
7185 SetAIFlag('GORIGHT', '1');
7186 if ((RunDirection() = TDirection.D_RIGHT) and (Target.X > FObj.X)) then
7187 SetAIFlag('GOLEFT', '1');
7188 end;
7190 else
7191 begin // Öåëü ïîêà íà "ýêðàíå"
7192 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
7193 if g_TraceVector(x1, y1, Target.cX, Target.cY) then
7194 FLastVisible := gTime;
7195 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
7196 if (Abs(FObj.Y-Target.Y) <= 128) then
7197 begin
7198 if ((RunDirection() = TDirection.D_LEFT) and (Target.X > FObj.X)) then
7199 SetAIFlag('GORIGHT', '1');
7200 if ((RunDirection() = TDirection.D_RIGHT) and (Target.X < FObj.X)) then
7201 SetAIFlag('GOLEFT', '1');
7202 end;
7203 end;
7205 // Âûáèðàåì óãîë ââåðõ:
7206 if FDirection = TDirection.D_LEFT then
7207 angle := ANGLE_LEFTUP
7208 else
7209 angle := ANGLE_RIGHTUP;
7211 firew := Trunc(Cos(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
7212 fireh := Trunc(Sin(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
7214 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
7215 if g_CollideLine(x1, y1, x1+firew, y1+fireh,
7216 Target.X+Target.Rect.X+GetInterval(FDifficult.DiagPrecision, 128), //96
7217 Target.Y+Target.Rect.Y+GetInterval(FDifficult.DiagPrecision, 128),
7218 Target.Rect.Width, Target.Rect.Height) and
7219 g_TraceVector(x1, y1, Target.cX, Target.cY) then
7220 begin // òî íóæíî ñòðåëÿòü ââåðõ
7221 SetAIFlag('NEEDFIRE', '1');
7222 SetAIFlag('NEEDSEEUP', '1');
7223 end;
7225 // Âûáèðàåì óãîë âíèç:
7226 if FDirection = TDirection.D_LEFT then
7227 angle := ANGLE_LEFTDOWN
7228 else
7229 angle := ANGLE_RIGHTDOWN;
7231 firew := Trunc(Cos(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
7232 fireh := Trunc(Sin(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
7234 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
7235 if g_CollideLine(x1, y1, x1+firew, y1+fireh,
7236 Target.X+Target.Rect.X+GetInterval(FDifficult.DiagPrecision, 128),
7237 Target.Y+Target.Rect.Y+GetInterval(FDifficult.DiagPrecision, 128),
7238 Target.Rect.Width, Target.Rect.Height) and
7239 g_TraceVector(x1, y1, Target.cX, Target.cY) then
7240 begin // òî íóæíî ñòðåëÿòü âíèç
7241 SetAIFlag('NEEDFIRE', '1');
7242 SetAIFlag('NEEDSEEDOWN', '1');
7243 end;
7245 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
7246 if Target.Visible and
7247 (y1+4 < Target.Y+Target.Rect.Y+Target.Rect.Height) and
7248 (y1-4 > Target.Y+Target.Rect.Y) then
7249 begin
7250 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
7251 if ((FDirection = TDirection.D_LEFT) and (Target.X < FObj.X)) or
7252 ((FDirection = TDirection.D_RIGHT) and (Target.X > FObj.X)) then
7253 begin // òî íóæíî ñòðåëÿòü âïåðåä
7254 SetAIFlag('NEEDFIRE', '1');
7255 SetAIFlag('NEEDSEEDOWN', '');
7256 SetAIFlag('NEEDSEEUP', '');
7257 end;
7258 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
7259 if Abs(FObj.X-Target.X) < Trunc(gPlayerScreenSize.X*0.75) then
7260 if GetRnd(FDifficult.CloseJump) then
7261 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
7262 if Abs(FObj.X-Target.X) < 128 then
7263 a := 4
7264 else
7265 a := 30;
7266 if Random(a) = 0 then
7267 SetAIFlag('NEEDJUMP', '1');
7268 end;
7269 end;
7271 // Åñëè öåëü âñå åùå åñòü:
7272 if Target.UID <> 0 then
7273 if gTime-FLastVisible > 2000 then // Åñëè âèäåëè äàâíî
7274 Target.UID := 0 // òî çàáûòü öåëü
7275 else // Åñëè âèäåëè íåäàâíî
7276 begin // íî öåëü óáèëè
7277 if Target.IsPlayer then
7278 begin // Öåëü - èãðîê
7279 pla := g_Player_Get(Target.UID);
7280 if (pla = nil) or (not pla.alive) or pla.NoTarget or
7281 (pla.FPowerups[MR_INVIS] >= gTime) then
7282 Target.UID := 0; // òî çàáûòü öåëü
7284 else
7285 begin // Öåëü - ìîíñòð
7286 mon := g_Monsters_ByUID(Target.UID);
7287 if (mon = nil) or (not mon.alive) then
7288 Target.UID := 0; // òî çàáûòü öåëü
7289 end;
7290 end;
7291 end; // if Target.UID <> 0
7293 FTargetUID := Target.UID;
7295 // Åñëè âîçìîæíûõ öåëåé íåò:
7296 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
7297 if targets = nil then
7298 if GetAIFlag('ATTACKLEFT') <> '' then
7299 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
7300 RemoveAIFlag('ATTACKLEFT');
7302 SetAIFlag('NEEDJUMP', '1');
7304 if RunDirection() = TDirection.D_RIGHT then
7305 begin // Èäåì íå â òó ñòîðîíó
7306 if (Healthy() > 1) and GetRnd(FDifficult.InvisFire) then
7307 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
7308 SetAIFlag('NEEDFIRE', '1');
7309 SetAIFlag('GOLEFT', '1');
7310 end;
7312 else
7313 begin // Èäåì â íóæíóþ ñòîðîíó
7314 if GetRnd(FDifficult.InvisFire) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7315 SetAIFlag('NEEDFIRE', '1');
7316 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7317 SetAIFlag('GORIGHT', '1');
7318 end;
7320 else
7321 if GetAIFlag('ATTACKRIGHT') <> '' then
7322 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
7323 RemoveAIFlag('ATTACKRIGHT');
7325 SetAIFlag('NEEDJUMP', '1');
7327 if RunDirection() = TDirection.D_LEFT then
7328 begin // Èäåì íå â òó ñòîðîíó
7329 if (Healthy() > 1) and GetRnd(FDifficult.InvisFire) then
7330 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
7331 SetAIFlag('NEEDFIRE', '1');
7332 SetAIFlag('GORIGHT', '1');
7333 end;
7335 else
7336 begin
7337 if GetRnd(FDifficult.InvisFire) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7338 SetAIFlag('NEEDFIRE', '1');
7339 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7340 SetAIFlag('GOLEFT', '1');
7341 end;
7342 end;
7344 //HACK! (does it belongs there?)
7345 RealizeCurrentWeapon();
7347 // Åñëè åñòü âîçìîæíûå öåëè:
7348 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
7349 if (targets <> nil) and (GetAIFlag('NEEDFIRE') <> '') then
7350 for a := 0 to High(targets) do
7351 begin
7352 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
7353 if GetRnd(FDifficult.DiagFire) then
7354 begin
7355 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
7356 if FDirection = TDirection.D_LEFT then
7357 angle := ANGLE_LEFTUP
7358 else
7359 angle := ANGLE_RIGHTUP;
7361 firew := Trunc(Cos(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
7362 fireh := Trunc(Sin(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
7364 if g_CollideLine(x1, y1, x1+firew, y1+fireh,
7365 targets[a].X+targets[a].Rect.X+GetInterval(FDifficult.DiagPrecision, 128),
7366 targets[a].Y+targets[a].Rect.Y+GetInterval(FDifficult.DiagPrecision, 128),
7367 targets[a].Rect.Width, targets[a].Rect.Height) and
7368 g_TraceVector(x1, y1, targets[a].cX, targets[a].cY) then
7369 begin
7370 SetAIFlag('NEEDFIRE', '1');
7371 SetAIFlag('NEEDSEEUP', '1');
7372 end;
7374 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
7375 if FDirection = TDirection.D_LEFT then
7376 angle := ANGLE_LEFTDOWN
7377 else
7378 angle := ANGLE_RIGHTDOWN;
7380 firew := Trunc(Cos(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
7381 fireh := Trunc(Sin(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
7383 if g_CollideLine(x1, y1, x1+firew, y1+fireh,
7384 targets[a].X+targets[a].Rect.X+GetInterval(FDifficult.DiagPrecision, 128),
7385 targets[a].Y+targets[a].Rect.Y+GetInterval(FDifficult.DiagPrecision, 128),
7386 targets[a].Rect.Width, targets[a].Rect.Height) and
7387 g_TraceVector(x1, y1, targets[a].cX, targets[a].cY) then
7388 begin
7389 SetAIFlag('NEEDFIRE', '1');
7390 SetAIFlag('NEEDSEEDOWN', '1');
7391 end;
7392 end;
7394 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
7395 if targets[a].Line and targets[a].Visible and
7396 (((FDirection = TDirection.D_LEFT) and (targets[a].X < FObj.X)) or
7397 ((FDirection = TDirection.D_RIGHT) and (targets[a].X > FObj.X))) then
7398 begin
7399 SetAIFlag('NEEDFIRE', '1');
7400 Break;
7401 end;
7402 end;
7404 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
7405 if g_Weapon_Danger(FUID, FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y,
7406 PLAYER_RECT.Width, PLAYER_RECT.Height,
7407 40+GetInterval(FDifficult.Cover, 40)) then
7408 SetAIFlag('NEEDJUMP', '1');
7410 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
7411 ammo := GetAmmoByWeapon(FCurrWeap);
7412 if ((FCurrWeap = WEAPON_SHOTGUN2) and (ammo < 2)) or
7413 ((FCurrWeap = WEAPON_BFG) and (ammo < 40)) or
7414 (ammo = 0) then
7415 SetAIFlag('SELECTWEAPON', '1');
7417 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
7418 if GetAIFlag('SELECTWEAPON') = '1' then
7419 begin
7420 SelectWeapon(-1);
7421 RemoveAIFlag('SELECTWEAPON');
7422 end;
7423 end;
7425 procedure TBot.Update();
7427 EnableAI: Boolean;
7428 begin
7429 if not FAlive then
7430 begin // Respawn
7431 ReleaseKeys();
7432 PressKey(KEY_UP);
7434 else
7435 begin
7436 EnableAI := True;
7438 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
7439 if (g_debug_BotAIOff = 1) and (Team = TEAM_RED) then
7440 EnableAI := False;
7441 if (g_debug_BotAIOff = 2) and (Team = TEAM_BLUE) then
7442 EnableAI := False;
7443 if g_debug_BotAIOff = 3 then
7444 EnableAI := False;
7446 if EnableAI then
7447 begin
7448 UpdateMove();
7449 UpdateCombat();
7451 else
7452 begin
7453 RealizeCurrentWeapon();
7454 end;
7455 end;
7457 inherited Update();
7458 end;
7460 procedure TBot.ReleaseKey(Key: Byte);
7461 begin
7462 with FKeys[Key] do
7463 begin
7464 Pressed := False;
7465 Time := 0;
7466 end;
7467 end;
7469 function TBot.KeyPressed(Key: Word): Boolean;
7470 begin
7471 Result := FKeys[Key].Pressed;
7472 end;
7474 function TBot.GetAIFlag(const aName: String): String;
7476 i: Integer;
7477 begin
7478 Result := '';
7479 if FAIFlags = nil then Exit;
7481 for i := 0 to High(FAIFlags) do
7482 if CompareText(aName, FAIFlags[i].Name) = 0 then
7483 Exit(FAIFlags[i].Value);
7484 end;
7486 procedure TBot.RemoveAIFlag(const aName: String);
7488 a, b: Integer;
7489 begin
7490 if FAIFlags = nil then Exit;
7492 for a := 0 to High(FAIFlags) do
7493 if CompareText(aName, FAIFlags[a].Name) = 0 then
7494 begin
7495 if a <> High(FAIFlags) then
7496 for b := a to High(FAIFlags)-1 do
7497 FAIFlags[b] := FAIFlags[b+1];
7499 SetLength(FAIFlags, Length(FAIFlags)-1);
7500 Break;
7501 end;
7502 end;
7504 procedure TBot.SetAIFlag(const aName, fValue: String);
7506 a: Integer;
7507 ok: Boolean;
7508 begin
7509 a := 0;
7510 ok := False;
7512 if FAIFlags <> nil then
7513 for a := 0 to High(FAIFlags) do
7514 if CompareText(aName, FAIFlags[a].Name) = 0 then
7515 begin
7516 ok := True;
7517 Break;
7518 end;
7520 if ok then FAIFlags[a].Value := fValue
7521 else
7522 begin
7523 SetLength(FAIFlags, Length(FAIFlags)+1);
7524 with FAIFlags[High(FAIFlags)] do
7525 begin
7526 Name := aName;
7527 Value := fValue;
7528 end;
7529 end;
7530 end;
7532 procedure TBot.UpdateMove;
7534 procedure GoLeft(Time: Word = 1);
7535 begin
7536 ReleaseKey(KEY_LEFT);
7537 ReleaseKey(KEY_RIGHT);
7538 PressKey(KEY_LEFT, Time);
7539 SetDirection(TDirection.D_LEFT);
7540 end;
7542 procedure GoRight(Time: Word = 1);
7543 begin
7544 ReleaseKey(KEY_LEFT);
7545 ReleaseKey(KEY_RIGHT);
7546 PressKey(KEY_RIGHT, Time);
7547 SetDirection(TDirection.D_RIGHT);
7548 end;
7550 function Rnd(a: Word): Boolean; inline;
7551 begin
7552 Result := Random(a) = 0;
7553 end;
7555 procedure Turn(Time: Word = 1200);
7556 begin
7557 if RunDirection() = TDirection.D_LEFT
7558 then GoRight(Time)
7559 else GoLeft(Time);
7560 end;
7562 procedure Stop();
7563 begin
7564 ReleaseKey(KEY_LEFT);
7565 ReleaseKey(KEY_RIGHT);
7566 end;
7568 function CanRunLeft(): Boolean;
7569 begin
7570 Result := not CollideLevel(-1, 0);
7571 end;
7573 function CanRunRight(): Boolean;
7574 begin
7575 Result := not CollideLevel(1, 0);
7576 end;
7578 function CanRun(): Boolean;
7579 begin
7580 if RunDirection() = TDirection.D_LEFT then Result := CanRunLeft() else Result := CanRunRight();
7581 end;
7583 procedure Jump(Time: Word = 30);
7584 begin
7585 PressKey(KEY_JUMP, Time);
7586 end;
7588 function NearHole(): Boolean;
7590 x, sx: Integer;
7591 begin
7592 { TODO 5 : Ëåñòíèöû }
7593 sx := IfThen(RunDirection() = TDirection.D_LEFT, -1, 1);
7594 for x := 1 to PLAYER_RECT.Width do
7595 if (not StayOnStep(x*sx, 0)) and
7596 (not CollideLevel(x*sx, PLAYER_RECT.Height)) and
7597 (not CollideLevel(x*sx, PLAYER_RECT.Height*2)) then
7598 begin
7599 Result := True;
7600 Exit;
7601 end;
7603 Result := False;
7604 end;
7606 function BorderHole(): Boolean;
7608 x, sx, xx: Integer;
7609 begin
7610 { TODO 5 : Ëåñòíèöû }
7611 sx := IfThen(RunDirection() = TDirection.D_LEFT, -1, 1);
7612 for x := 1 to PLAYER_RECT.Width do
7613 if (not StayOnStep(x*sx, 0)) and
7614 (not CollideLevel(x*sx, PLAYER_RECT.Height)) and
7615 (not CollideLevel(x*sx, PLAYER_RECT.Height*2)) then
7616 begin
7617 for xx := x to x+32 do
7618 if CollideLevel(xx*sx, PLAYER_RECT.Height) then
7619 begin
7620 Result := True;
7621 Exit;
7622 end;
7623 end;
7625 Result := False;
7626 end;
7628 function NearDeepHole(): Boolean;
7630 x, sx, y: Integer;
7631 begin
7632 Result := False;
7634 sx := IfThen(RunDirection() = TDirection.D_LEFT, -1, 1);
7635 y := 3;
7637 for x := 1 to PLAYER_RECT.Width do
7638 if (not StayOnStep(x*sx, 0)) and
7639 (not CollideLevel(x*sx, PLAYER_RECT.Height)) and
7640 (not CollideLevel(x*sx, PLAYER_RECT.Height*2)) then
7641 begin
7642 while FObj.Y+y*PLAYER_RECT.Height < gMapInfo.Height do
7643 begin
7644 if CollideLevel(x*sx, PLAYER_RECT.Height*y) then Exit;
7645 y := y+1;
7646 end;
7648 Result := True;
7649 end else Result := False;
7650 end;
7652 function OverDeepHole(): Boolean;
7654 y: Integer;
7655 begin
7656 Result := False;
7658 y := 1;
7659 while FObj.Y+y*PLAYER_RECT.Height < gMapInfo.Height do
7660 begin
7661 if CollideLevel(0, PLAYER_RECT.Height*y) then Exit;
7662 y := y+1;
7663 end;
7665 Result := True;
7666 end;
7668 function OnGround(): Boolean;
7669 begin
7670 Result := StayOnStep(0, 0) or CollideLevel(0, 1);
7671 end;
7673 function OnLadder(): Boolean;
7674 begin
7675 Result := FullInStep(0, 0);
7676 end;
7678 function BelowLadder(): Boolean;
7679 begin
7680 Result := (FullInStep(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -PLAYER_RECT.Height) and
7681 not CollideLevel(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -PLAYER_RECT.Height)) or
7682 (FullInStep(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -BOT_MAXJUMP) and
7683 not CollideLevel(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -BOT_MAXJUMP));
7684 end;
7686 function BelowLiftUp(): Boolean;
7687 begin
7688 Result := ((FullInLift(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -PLAYER_RECT.Height) = -1) and
7689 not CollideLevel(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -PLAYER_RECT.Height)) or
7690 ((FullInLift(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -BOT_MAXJUMP) = -1) and
7691 not CollideLevel(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -BOT_MAXJUMP));
7692 end;
7694 function OnTopLift(): Boolean;
7695 begin
7696 Result := (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7697 end;
7699 function CanJumpOver(): Boolean;
7701 sx, y: Integer;
7702 begin
7703 sx := IfThen(RunDirection() = TDirection.D_LEFT, -1, 1);
7705 Result := False;
7707 if not CollideLevel(sx, 0) then Exit;
7709 for y := 1 to BOT_MAXJUMP do
7710 if CollideLevel(0, -y) then Exit else
7711 if not CollideLevel(sx, -y) then
7712 begin
7713 Result := True;
7714 Exit;
7715 end;
7716 end;
7718 function CanJumpUp(Dist: ShortInt): Boolean;
7720 y, yy: Integer;
7721 c: Boolean;
7722 begin
7723 Result := False;
7725 if CollideLevel(Dist, 0) then Exit;
7727 c := False;
7728 for y := 0 to BOT_MAXJUMP do
7729 if CollideLevel(Dist, -y) then
7730 begin
7731 c := True;
7732 Break;
7733 end;
7735 if not c then Exit;
7737 c := False;
7738 for yy := y+1 to BOT_MAXJUMP do
7739 if not CollideLevel(Dist, -yy) then
7740 begin
7741 c := True;
7742 Break;
7743 end;
7745 if not c then Exit;
7747 c := False;
7748 for y := 0 to BOT_MAXJUMP do
7749 if CollideLevel(0, -y) then
7750 begin
7751 c := True;
7752 Break;
7753 end;
7755 if c then Exit;
7757 if y < yy then Exit;
7759 Result := True;
7760 end;
7762 function IsSafeTrigger(): Boolean;
7764 a: Integer;
7765 begin
7766 Result := True;
7767 for a := 0 to High(gTriggers) do
7768 if Collide(gTriggers[a].X, gTriggers[a].Y, gTriggers[a].Width, gTriggers[a].Height)
7769 and (gTriggers[a].TriggerType in [TRIGGER_EXIT, TRIGGER_CLOSEDOOR, TRIGGER_CLOSETRAP,
7770 TRIGGER_TRAP, TRIGGER_PRESS, TRIGGER_ON, TRIGGER_OFF, TRIGGER_ONOFF,
7771 TRIGGER_SPAWNMONSTER, TRIGGER_DAMAGE, TRIGGER_SHOT]) then Exit(False);
7772 end;
7774 begin
7775 // Âîçìîæíî, íàæèìàåì êíîïêó:
7776 if Rnd(16) and IsSafeTrigger() then
7777 PressKey(KEY_OPEN);
7779 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7780 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7781 begin
7782 ReleaseKey(KEY_LEFT);
7783 ReleaseKey(KEY_RIGHT);
7784 Jump();
7785 end;
7787 // Èäåì âëåâî, åñëè íàäî áûëî:
7788 if GetAIFlag('GOLEFT') <> '' then
7789 begin
7790 RemoveAIFlag('GOLEFT');
7791 if CanRunLeft() then
7792 GoLeft(360);
7793 end;
7795 // Èäåì âïðàâî, åñëè íàäî áûëî:
7796 if GetAIFlag('GORIGHT') <> '' then
7797 begin
7798 RemoveAIFlag('GORIGHT');
7799 if CanRunRight() then
7800 GoRight(360);
7801 end;
7803 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7804 if FObj.X < -32 then
7805 GoRight(360)
7806 else
7807 if FObj.X+32 > gMapInfo.Width then
7808 GoLeft(360);
7810 // Ïðûãàåì, åñëè íàäî áûëî:
7811 if GetAIFlag('NEEDJUMP') <> '' then
7812 begin
7813 Jump(0);
7814 RemoveAIFlag('NEEDJUMP');
7815 end;
7817 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7818 if GetAIFlag('NEEDSEEUP') <> '' then
7819 begin
7820 ReleaseKey(KEY_UP);
7821 ReleaseKey(KEY_DOWN);
7822 PressKey(KEY_UP, 20);
7823 RemoveAIFlag('NEEDSEEUP');
7824 end;
7826 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7827 if GetAIFlag('NEEDSEEDOWN') <> '' then
7828 begin
7829 ReleaseKey(KEY_UP);
7830 ReleaseKey(KEY_DOWN);
7831 PressKey(KEY_DOWN, 20);
7832 RemoveAIFlag('NEEDSEEDOWN');
7833 end;
7835 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7836 if GetAIFlag('GOINHOLE') <> '' then
7837 if not OnGround() then
7838 begin
7839 ReleaseKey(KEY_LEFT);
7840 ReleaseKey(KEY_RIGHT);
7841 RemoveAIFlag('GOINHOLE');
7842 SetAIFlag('FALLINHOLE', '1');
7843 end;
7845 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7846 if GetAIFlag('FALLINHOLE') <> '' then
7847 if OnGround() then
7848 RemoveAIFlag('FALLINHOLE');
7850 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7851 if not (KeyPressed(KEY_LEFT) or KeyPressed(KEY_RIGHT)) then
7852 if GetAIFlag('FALLINHOLE') = '' then
7853 if (not OnLadder()) or (FObj.Vel.Y >= 0) or (OnTopLift()) then
7854 if Rnd(2) then
7855 GoLeft(360)
7856 else
7857 GoRight(360);
7859 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7860 if OnGround() and
7861 CanJumpUp(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*32) and
7862 Rnd(8) then
7863 Jump();
7865 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7866 if OnGround() and NearHole() then
7867 if NearDeepHole() then // Åñëè ýòî áåçäíà
7868 case Random(6) of
7869 0..3: Turn(); // Áåæèì îáðàòíî
7870 4: Jump(); // Ïðûãàåì
7871 5: begin // Ïðûãàåì îáðàòíî
7872 Turn();
7873 Jump();
7874 end;
7876 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7877 if GetAIFlag('GOINHOLE') = '' then
7878 case Random(6) of
7879 0: Turn(); // Íå íóæíî òóäà
7880 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7881 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7882 if BorderHole() then
7883 SetAIFlag('GOINHOLE', '1');
7884 end;
7886 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7887 if (not CanRun()) and OnGround() then
7888 begin
7889 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7890 if CanJumpOver() or OnLadder() then
7891 Jump()
7892 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7893 if Random(2) = 0 then
7894 begin
7895 if IsSafeTrigger() then
7896 PressKey(KEY_OPEN);
7897 end else
7898 Turn();
7899 end;
7901 // Îñòàëîñü ìàëî âîçäóõà:
7902 if FAir < 36 * 2 then
7903 Jump(20);
7905 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7906 if (FPowerups[MR_SUIT] < gTime) and ((FLastHit = HIT_ACID) or (Healthy() <= 1)) then
7907 if BodyInAcid(0, 0) then
7908 Jump();
7909 end;
7911 function TBot.FullInStep(XInc, YInc: Integer): Boolean;
7912 begin
7913 Result := g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc,
7914 PLAYER_RECT.Width, PLAYER_RECT.Height, PANEL_STEP, False);
7915 end;
7917 {function TBot.NeedItem(Item: Byte): Byte;
7918 begin
7919 Result := 4;
7920 end;}
7922 procedure TBot.SelectWeapon(Dist: Integer);
7924 a: Integer;
7926 function HaveAmmo(weapon: Byte): Boolean;
7927 begin
7928 case weapon of
7929 WEAPON_PISTOL: Result := FAmmo[A_BULLETS] >= 1;
7930 WEAPON_SHOTGUN1: Result := FAmmo[A_SHELLS] >= 1;
7931 WEAPON_SHOTGUN2: Result := FAmmo[A_SHELLS] >= 2;
7932 WEAPON_CHAINGUN: Result := FAmmo[A_BULLETS] >= 10;
7933 WEAPON_ROCKETLAUNCHER: Result := FAmmo[A_ROCKETS] >= 1;
7934 WEAPON_PLASMA: Result := FAmmo[A_CELLS] >= 10;
7935 WEAPON_BFG: Result := FAmmo[A_CELLS] >= 40;
7936 WEAPON_SUPERCHAINGUN: Result := FAmmo[A_SHELLS] >= 1;
7937 WEAPON_FLAMETHROWER: Result := FAmmo[A_FUEL] >= 1;
7938 else Result := True;
7939 end;
7940 end;
7942 begin
7943 if Dist = -1 then Dist := BOT_LONGDIST;
7945 if Dist > BOT_LONGDIST then
7946 begin // Äàëüíèé áîé
7947 for a := 0 to 9 do
7948 if FWeapon[FDifficult.WeaponPrior[a]] and HaveAmmo(FDifficult.WeaponPrior[a]) then
7949 begin
7950 FSelectedWeapon := FDifficult.WeaponPrior[a];
7951 Break;
7952 end;
7954 else //if Dist > BOT_UNSAFEDIST then
7955 begin // Áëèæíèé áîé
7956 for a := 0 to 9 do
7957 if FWeapon[FDifficult.CloseWeaponPrior[a]] and HaveAmmo(FDifficult.CloseWeaponPrior[a]) then
7958 begin
7959 FSelectedWeapon := FDifficult.CloseWeaponPrior[a];
7960 Break;
7961 end;
7962 end;
7963 { else
7964 begin
7965 for a := 0 to 9 do
7966 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7967 begin
7968 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7969 Break;
7970 end;
7971 end;}
7972 end;
7974 function TBot.PickItem(ItemType: Byte; force: Boolean; var remove: Boolean): Boolean;
7975 begin
7976 Result := inherited PickItem(ItemType, force, remove);
7978 if Result then SetAIFlag('SELECTWEAPON', '1');
7979 end;
7981 function TBot.Heal(value: Word; Soft: Boolean): Boolean;
7982 begin
7983 Result := inherited Heal(value, Soft);
7984 end;
7986 function TBot.Healthy(): Byte;
7987 begin
7988 if FPowerups[MR_INVUL] >= gTime then Result := 3
7989 else if (FHealth > 80) or ((FHealth > 50) and (FArmor > 20)) then Result := 3
7990 else if (FHealth > 50) then Result := 2
7991 else if (FHealth > 20) then Result := 1
7992 else Result := 0;
7993 end;
7995 function TBot.TargetOnScreen(TX, TY: Integer): Boolean;
7996 begin
7997 Result := (Abs(FObj.X-TX) <= Trunc(gPlayerScreenSize.X*0.6)) and
7998 (Abs(FObj.Y-TY) <= Trunc(gPlayerScreenSize.Y*0.6));
7999 end;
8001 procedure TBot.OnDamage(Angle: SmallInt);
8003 pla: TPlayer;
8004 mon: TMonster;
8005 ok: Boolean;
8006 begin
8007 inherited;
8009 if (Angle = 0) or (Angle = 180) then
8010 begin
8011 ok := False;
8012 if (g_GetUIDType(FLastSpawnerUID) = UID_PLAYER) and
8013 (TGameOption.BOTS_VS_PLAYERS in gGameSettings.Options) then
8014 begin // Èãðîê
8015 pla := g_Player_Get(FLastSpawnerUID);
8016 ok := not TargetOnScreen(pla.FObj.X + PLAYER_RECT.X,
8017 pla.FObj.Y + PLAYER_RECT.Y);
8019 else
8020 if (g_GetUIDType(FLastSpawnerUID) = UID_MONSTER) and
8021 (TGameOption.BOTS_VS_MONSTERS in gGameSettings.Options) then
8022 begin // Ìîíñòð
8023 mon := g_Monsters_ByUID(FLastSpawnerUID);
8024 ok := not TargetOnScreen(mon.Obj.X + mon.Obj.Rect.X,
8025 mon.Obj.Y + mon.Obj.Rect.Y);
8026 end;
8028 if ok then
8029 if Angle = 0 then
8030 SetAIFlag('ATTACKLEFT', '1')
8031 else
8032 SetAIFlag('ATTACKRIGHT', '1');
8033 end;
8034 end;
8036 function TBot.RunDirection(): TDirection;
8037 begin
8038 if Abs(Vel.X) >= 1 then
8039 begin
8040 if Vel.X > 0 then Result := TDirection.D_RIGHT else Result := TDirection.D_LEFT;
8041 end else
8042 Result := FDirection;
8043 end;
8045 function TBot.GetRnd(a: Byte): Boolean;
8046 begin
8047 if a = 0 then Result := False
8048 else if a = 255 then Result := True
8049 else Result := Random(256) > 255-a;
8050 end;
8052 function TBot.GetInterval(a: Byte; radius: SmallInt): SmallInt;
8053 begin
8054 Result := Round((255-a)/255*radius*(Random(2)-1));
8055 end;
8058 procedure TDifficult.save (st: TStream);
8059 begin
8060 st.WriteByte(DiagFire);
8061 st.WriteByte(InvisFire);
8062 st.WriteByte(DiagPrecision);
8063 st.WriteByte(FlyPrecision);
8064 st.WriteByte(Cover);
8065 st.WriteByte(CloseJump);
8066 st.WriteBuffer(WeaponPrior[Low(WeaponPrior)], SizeOf(WeaponPrior));
8067 st.WriteBuffer(CloseWeaponPrior[Low(CloseWeaponPrior)], SizeOf(CloseWeaponPrior));
8068 end;
8070 procedure TDifficult.load (st: TStream);
8071 begin
8072 DiagFire := st.ReadByte();
8073 InvisFire := st.ReadByte();
8074 DiagPrecision := st.ReadByte();
8075 FlyPrecision := st.ReadByte();
8076 Cover := st.ReadByte();
8077 CloseJump := st.ReadByte();
8078 st.ReadBuffer(WeaponPrior[Low(WeaponPrior)], SizeOf(WeaponPrior));
8079 st.ReadBuffer(CloseWeaponPrior[Low(CloseWeaponPrior)], SizeOf(CloseWeaponPrior));
8080 end;
8083 procedure TBot.SaveState (st: TStream);
8085 dw: SizeUInt;
8086 i: SizeInt;
8087 begin
8088 inherited SaveState(st);
8089 utils.writeSign(st, 'BOT0');
8091 st.WriteByte(FSelectedWeapon); // Âûáðàííîå îðóæèå
8092 st.WriteWordLE(FTargetUID); // UID öåëè
8093 st.WriteDWordLE(FLastVisible); // Âðåìÿ ïîòåðè öåëè
8095 // Êîëè÷åñòâî ôëàãîâ ÈÈ
8096 dw := Length(FAIFlags);
8097 st.WriteDWordLE(dw);
8099 // Ôëàãè ÈÈ
8100 for i := 0 to dw-1 do
8101 begin
8102 utils.writeStr(st, FAIFlags[i].Name, 20);
8103 utils.writeStr(st, FAIFlags[i].Value, 20);
8104 end;
8106 // Íàñòðîéêè ñëîæíîñòè
8107 FDifficult.save(st);
8108 end;
8111 procedure TBot.LoadState (st: TStream);
8113 dw: SizeUInt;
8114 i: SizeInt;
8115 begin
8116 inherited LoadState(st);
8117 if not utils.checkSign(st, 'BOT0') then
8118 Raise XStreamError.Create('invalid bot signature');
8120 FSelectedWeapon := st.ReadByte(); // Âûáðàííîå îðóæèå
8121 FTargetUID := st.ReadWordLE(); // UID öåëè
8122 FLastVisible := st.ReadDWordLE(); // Âðåìÿ ïîòåðè öåëè
8124 // Êîëè÷åñòâî ôëàãîâ ÈÈ
8125 dw := st.ReadDWordLE();
8126 if dw > 16384 then
8127 Raise XStreamError.Create('invalid number of bot AI flags');
8128 SetLength(FAIFlags, dw);
8130 // Ôëàãè ÈÈ
8131 for i := 0 to dw-1 do
8132 begin
8133 FAIFlags[i].Name := utils.readStr(st, 20);
8134 FAIFlags[i].Value := utils.readStr(st, 20);
8135 end;
8137 // Íàñòðîéêè ñëîæíîñòè
8138 FDifficult.load(st);
8139 end;
8142 begin
8143 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');
8144 conRegVar('player_indicator_style', @gPlayerIndicatorStyle, 'Visual appearance of indicator', 'Visual appearance of indicator');
8145 end.