network: server is weapon authority!
[d2df-sdl.git] / src / game / g_player.pas
blob66f0099063c3027084c4b32418d174acf77ed4e3
1 (* Copyright (C) Doom 2D: Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. 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 e_graphics, g_playermodel, g_basic, g_textures,
26 g_weapons, g_phys, g_sound, g_saveload, MAPDEF,
27 g_panel;
29 const
30 KEY_LEFT = 1;
31 KEY_RIGHT = 2;
32 KEY_UP = 3;
33 KEY_DOWN = 4;
34 KEY_FIRE = 5;
35 KEY_NEXTWEAPON = 6;
36 KEY_PREVWEAPON = 7;
37 KEY_OPEN = 8;
38 KEY_JUMP = 9;
39 KEY_CHAT = 10;
41 R_ITEM_BACKPACK = 0;
42 R_KEY_RED = 1;
43 R_KEY_GREEN = 2;
44 R_KEY_BLUE = 3;
45 R_BERSERK = 4;
47 MR_SUIT = 0;
48 MR_INVUL = 1;
49 MR_INVIS = 2;
50 MR_MAX = 2;
52 A_BULLETS = 0;
53 A_SHELLS = 1;
54 A_ROCKETS = 2;
55 A_CELLS = 3;
56 A_FUEL = 4;
57 A_HIGH = 4;
59 AmmoLimits: Array [0..1] of Array [A_BULLETS..A_HIGH] of Word =
60 ((200, 50, 50, 300, 100),
61 (400, 100, 100, 600, 200));
63 K_SIMPLEKILL = 0;
64 K_HARDKILL = 1;
65 K_EXTRAHARDKILL = 2;
66 K_FALLKILL = 3;
68 T_RESPAWN = 0;
69 T_SWITCH = 1;
70 T_USE = 2;
71 T_FLAGCAP = 3;
73 TEAM_NONE = 0;
74 TEAM_RED = 1;
75 TEAM_BLUE = 2;
76 TEAM_COOP = 3;
78 SHELL_BULLET = 0;
79 SHELL_SHELL = 1;
80 SHELL_DBLSHELL = 2;
82 ANGLE_NONE = Low(SmallInt);
84 CORPSE_STATE_REMOVEME = 0;
85 CORPSE_STATE_NORMAL = 1;
86 CORPSE_STATE_MESS = 2;
88 PLAYER_RECT: TRectWH = (X:15; Y:12; Width:34; Height:52);
89 PLAYER_RECT_CX = 15+(34 div 2);
90 PLAYER_RECT_CY = 12+(52 div 2);
91 PLAYER_CORPSERECT: TRectWH = (X:15; Y:48; Width:34; Height:16);
93 PLAYER_HP_SOFT = 100;
94 PLAYER_HP_LIMIT = 200;
95 PLAYER_AP_SOFT = 100;
96 PLAYER_AP_LIMIT = 200;
97 SUICIDE_DAMAGE = 112;
99 PLAYER1_DEF_COLOR: TRGB = (R:64; G:175; B:48);
100 PLAYER2_DEF_COLOR: TRGB = (R:96; G:96; B:96);
102 type
103 TPlayerStat = record
104 Ping: Word;
105 Loss: Byte;
106 Name: String;
107 Team: Byte;
108 Frags: SmallInt;
109 Deaths: SmallInt;
110 Lives: Byte;
111 Kills: Word;
112 Color: TRGB;
113 Spectator: Boolean;
114 end;
116 TPlayerStatArray = Array of TPlayerStat;
118 TPlayerSavedState = record
119 Health: Integer;
120 Armor: Integer;
121 Air: Integer;
122 JetFuel: Integer;
123 CurrWeap: Byte;
124 NextWeap: WORD;
125 NextWeapDelay: Byte;
126 Ammo: Array [A_BULLETS..A_HIGH] of Word;
127 MaxAmmo: Array [A_BULLETS..A_HIGH] of Word;
128 Weapon: Array [WP_FIRST..WP_LAST] of Boolean;
129 Rulez: Set of R_ITEM_BACKPACK..R_BERSERK;
130 WaitRecall: Boolean;
131 end;
133 TKeyState = record
134 Pressed: Boolean;
135 Time: Word;
136 end;
138 TPlayer = class{$IFDEF USE_MEMPOOL}(TPoolObject){$ENDIF}
139 private
140 FIamBot: Boolean;
141 FUID: Word;
142 FName: String;
143 FTeam: Byte;
144 FAlive: Boolean;
145 FSpawned: Boolean;
146 FDirection: TDirection;
147 FHealth: Integer;
148 FLives: Byte;
149 FArmor: Integer;
150 FAir: Integer;
151 FPain: Integer;
152 FPickup: Integer;
153 FKills: Integer;
154 FMonsterKills: Integer;
155 FFrags: Integer;
156 FFragCombo: Byte;
157 FLastFrag: LongWord;
158 FComboEvnt: Integer;
159 FDeath: Integer;
160 FCanJetpack: Boolean;
161 FJetFuel: Integer;
162 FFlag: Byte;
163 FSecrets: Integer;
164 FCurrWeap: Byte;
165 //FNetForceWeap: Byte; // spam server with this -- this is new weapon we want to use
166 FNetForceWeapFIdx: LongWord; // frame index; ignore weapon change if it is lesser than this
167 //FCurrFrameIdx: LongWord; // increased in each `Update()`
168 FNextWeap: WORD;
169 FNextWeapDelay: Byte; // frames (unused)
170 FBFGFireCounter: SmallInt;
171 FLastSpawnerUID: Word;
172 FLastHit: Byte;
173 FObj: TObj;
174 FXTo, FYTo: Integer;
175 FSpectatePlayer: Integer;
176 FFirePainTime: Integer;
177 FFireAttacker: Word;
179 FSavedState: TPlayerSavedState;
181 FModel: TPlayerModel;
182 FPunchAnim: TAnimation;
183 FActionPrior: Byte;
184 FActionAnim: Byte;
185 FActionForce: Boolean;
186 FActionChanged: Boolean;
187 FAngle: SmallInt;
188 FFireAngle: SmallInt;
189 FIncCam: Integer;
190 FShellTimer: Integer;
191 FShellType: Byte;
192 FSawSound: TPlayableSound;
193 FSawSoundIdle: TPlayableSound;
194 FSawSoundHit: TPlayableSound;
195 FSawSoundSelect: TPlayableSound;
196 FJetSoundOn: TPlayableSound;
197 FJetSoundOff: TPlayableSound;
198 FJetSoundFly: TPlayableSound;
199 FGodMode: Boolean;
200 FNoTarget: Boolean;
201 FNoReload: Boolean;
202 FJustTeleported: Boolean;
203 FNetTime: LongWord;
204 mEDamageType: Integer;
206 // client-side only
207 weaponSwitchKeyReleased: array[0..16] of Byte; // bit 0: was released on prev frame; bit 1: new status
210 function CollideLevel(XInc, YInc: Integer): Boolean;
211 function StayOnStep(XInc, YInc: Integer): Boolean;
212 function HeadInLiquid(XInc, YInc: Integer): Boolean;
213 function BodyInLiquid(XInc, YInc: Integer): Boolean;
214 function BodyInAcid(XInc, YInc: Integer): Boolean;
215 function FullInLift(XInc, YInc: Integer): Integer;
216 {procedure CollideItem();}
217 procedure FlySmoke(Times: DWORD = 1);
218 procedure OnFireFlame(Times: DWORD = 1);
219 function GetAmmoByWeapon(Weapon: Byte): Word;
220 procedure SetAction(Action: Byte; Force: Boolean = False);
221 procedure OnDamage(Angle: SmallInt); virtual;
222 function firediry(): Integer;
223 procedure DoPunch();
225 procedure Run(Direction: TDirection);
226 procedure NextWeapon();
227 procedure PrevWeapon();
228 procedure SeeUp();
229 procedure SeeDown();
230 procedure Fire();
231 procedure Jump();
232 procedure Use();
234 function getNextWeaponIndex (): Byte; // return 255 for "no switch"
235 procedure resetWeaponQueue ();
236 function hasAmmoForWeapon (weapon: Byte): Boolean;
238 procedure doDamage (v: Integer);
240 function followCorpse(): Boolean;
242 public
243 FDamageBuffer: Integer;
245 FAmmo: Array [A_BULLETS..A_HIGH] of Word;
246 FMaxAmmo: Array [A_BULLETS..A_HIGH] of Word;
247 FWeapon: Array [WP_FIRST..WP_LAST] of Boolean;
248 FRulez: Set of R_ITEM_BACKPACK..R_BERSERK;
249 FBerserk: Integer;
250 FMegaRulez: Array [MR_SUIT..MR_MAX] of DWORD;
251 FReloading: Array [WP_FIRST..WP_LAST] of Word;
252 FTime: Array [T_RESPAWN..T_FLAGCAP] of DWORD;
253 FKeys: Array [KEY_LEFT..KEY_CHAT] of TKeyState;
254 FColor: TRGB;
255 FPreferredTeam: Byte;
256 FSpectator: Boolean;
257 FNoRespawn: Boolean;
258 FWantsInGame: Boolean;
259 FGhost: Boolean;
260 FPhysics: Boolean;
261 FJetpack: Boolean;
262 FActualModelName: string;
263 FClientID: SmallInt;
264 FPing: Word;
265 FLoss: Byte;
266 FDummy: Boolean;
267 FFireTime: Integer;
269 // debug: viewport offset
270 viewPortX, viewPortY, viewPortW, viewPortH: Integer;
272 function isValidViewPort (): Boolean; inline;
274 constructor Create(); virtual;
275 destructor Destroy(); override;
276 procedure Respawn(Silent: Boolean; Force: Boolean = False); virtual;
277 function GetRespawnPoint(): Byte;
278 procedure PressKey(Key: Byte; Time: Word = 1);
279 procedure ReleaseKeys();
280 procedure ReleaseKeysNoWeapon();
281 procedure SetModel(ModelName: String);
282 procedure SetColor(Color: TRGB);
283 procedure SetWeaponHost(W: Byte);
284 function IsKeyPressed(K: Byte): Boolean;
285 function GetKeys(): Byte;
286 function PickItem(ItemType: Byte; arespawn: Boolean; var remove: Boolean): Boolean; virtual;
287 function Collide(X, Y: Integer; Width, Height: Word): Boolean; overload;
288 function Collide(Panel: TPanel): Boolean; overload;
289 function Collide(X, Y: Integer): Boolean; overload;
290 procedure SetDirection(Direction: TDirection);
291 procedure GetSecret();
292 function TeleportTo(X, Y: Integer; silent: Boolean; dir: Byte): Boolean;
293 procedure Touch();
294 procedure Push(vx, vy: Integer);
295 procedure ChangeModel(ModelName: String);
296 procedure SwitchTeam;
297 procedure ChangeTeam(Team: Byte);
298 procedure BFGHit();
299 function GetFlag(Flag: Byte): Boolean;
300 procedure SetFlag(Flag: Byte);
301 function DropFlag(): Boolean;
302 procedure AllRulez(Health: Boolean);
303 procedure RestoreHealthArmor();
304 procedure FragCombo();
305 procedure GiveItem(ItemType: Byte);
306 procedure Damage(value: Word; SpawnerUID: Word; vx, vy: Integer; t: Byte); virtual;
307 function Heal(value: Word; Soft: Boolean): Boolean; virtual;
308 procedure MakeBloodVector(Count: Word; VelX, VelY: Integer);
309 procedure MakeBloodSimple(Count: Word);
310 procedure Kill(KillType: Byte; SpawnerUID: Word; t: Byte);
311 procedure Reset(Force: Boolean);
312 procedure Spectate(NoMove: Boolean = False);
313 procedure SwitchNoClip;
314 procedure SoftReset();
315 procedure Draw(); virtual;
316 procedure DrawPain();
317 procedure DrawPickup();
318 procedure DrawRulez();
319 procedure DrawAim();
320 procedure DrawBubble();
321 procedure DrawGUI();
322 procedure Update(); virtual;
323 procedure RememberState();
324 procedure RecallState();
325 procedure SaveState (st: TStream); virtual;
326 procedure LoadState (st: TStream); virtual;
327 procedure PauseSounds(Enable: Boolean);
328 procedure NetFire(Wpn: Byte; X, Y, AX, AY: Integer; WID: Integer = -1);
329 procedure DoLerp(Level: Integer = 2);
330 procedure SetLerp(XTo, YTo: Integer);
331 procedure QueueWeaponSwitch(Weapon: Byte);
332 procedure RealizeCurrentWeapon();
333 procedure JetpackOn;
334 procedure JetpackOff;
335 procedure CatchFire(Attacker: Word);
337 //WARNING! this does nothing for now, but still call it!
338 procedure positionChanged (); //WARNING! call this after entity position was changed, or coldet will not work right!
340 procedure getMapBox (out x, y, w, h: Integer); inline;
341 procedure moveBy (dx, dy: Integer); inline;
343 procedure releaseAllWeaponSwitchKeys ();
344 procedure weaponSwitchKeysStateChange (index: Integer; pressed: Boolean);
345 function isWeaponSwitchKeyReleased (index: Integer): Boolean;
346 procedure weaponSwitchKeysShiftNewStates ();
348 public
349 property Vel: TPoint2i read FObj.Vel;
350 property Obj: TObj read FObj;
352 property Name: String read FName write FName;
353 property Model: TPlayerModel read FModel;
354 property Health: Integer read FHealth write FHealth;
355 property Lives: Byte read FLives write FLives;
356 property Armor: Integer read FArmor write FArmor;
357 property Air: Integer read FAir write FAir;
358 property JetFuel: Integer read FJetFuel write FJetFuel;
359 property Frags: Integer read FFrags write FFrags;
360 property Death: Integer read FDeath write FDeath;
361 property Kills: Integer read FKills write FKills;
362 property CurrWeap: Byte read FCurrWeap write FCurrWeap;
363 //property NetForceWeap: Byte read FNetForceWeap write FNetForceWeap;
364 property NetForceWeapFIdx: LongWord read FNetForceWeapFIdx write FNetForceWeapFIdx;
365 //property CurrFrameIdx: LongWord read FCurrFrameIdx write FCurrFrameIdx;
366 property MonsterKills: Integer read FMonsterKills write FMonsterKills;
367 property Secrets: Integer read FSecrets;
368 property GodMode: Boolean read FGodMode write FGodMode;
369 property NoTarget: Boolean read FNoTarget write FNoTarget;
370 property NoReload: Boolean read FNoReload write FNoReload;
371 property alive: Boolean read FAlive write FAlive;
372 property Flag: Byte read FFlag;
373 property Team: Byte read FTeam write FTeam;
374 property Direction: TDirection read FDirection;
375 property GameX: Integer read FObj.X write FObj.X;
376 property GameY: Integer read FObj.Y write FObj.Y;
377 property GameVelX: Integer read FObj.Vel.X write FObj.Vel.X;
378 property GameVelY: Integer read FObj.Vel.Y write FObj.Vel.Y;
379 property GameAccelX: Integer read FObj.Accel.X write FObj.Accel.X;
380 property GameAccelY: Integer read FObj.Accel.Y write FObj.Accel.Y;
381 property IncCam: Integer read FIncCam write FIncCam;
382 property UID: Word read FUID write FUID;
383 property JustTeleported: Boolean read FJustTeleported write FJustTeleported;
384 property NetTime: LongWord read FNetTime write FNetTime;
386 published
387 property eName: String read FName write FName;
388 property eHealth: Integer read FHealth write FHealth;
389 property eLives: Byte read FLives write FLives;
390 property eArmor: Integer read FArmor write FArmor;
391 property eAir: Integer read FAir write FAir;
392 property eJetFuel: Integer read FJetFuel write FJetFuel;
393 property eFrags: Integer read FFrags write FFrags;
394 property eDeath: Integer read FDeath write FDeath;
395 property eKills: Integer read FKills write FKills;
396 property eCurrWeap: Byte read FCurrWeap write FCurrWeap;
397 property eMonsterKills: Integer read FMonsterKills write FMonsterKills;
398 property eSecrets: Integer read FSecrets write FSecrets;
399 property eGodMode: Boolean read FGodMode write FGodMode;
400 property eNoTarget: Boolean read FNoTarget write FNoTarget;
401 property eNoReload: Boolean read FNoReload write FNoReload;
402 property eAlive: Boolean read FAlive write FAlive;
403 property eFlag: Byte read FFlag;
404 property eTeam: Byte read FTeam write FTeam;
405 property eDirection: TDirection read FDirection;
406 property eGameX: Integer read FObj.X write FObj.X;
407 property eGameY: Integer read FObj.Y write FObj.Y;
408 property eGameVelX: Integer read FObj.Vel.X write FObj.Vel.X;
409 property eGameVelY: Integer read FObj.Vel.Y write FObj.Vel.Y;
410 property eGameAccelX: Integer read FObj.Accel.X write FObj.Accel.X;
411 property eGameAccelY: Integer read FObj.Accel.Y write FObj.Accel.Y;
412 property eIncCam: Integer read FIncCam write FIncCam;
413 property eUID: Word read FUID;
414 property eJustTeleported: Boolean read FJustTeleported;
415 property eNetTime: LongWord read FNetTime;
417 // set this before assigning something to `eDamage`
418 property eDamageType: Integer read mEDamageType write mEDamageType;
419 property eDamage: Integer write doDamage;
420 end;
422 TDifficult = record
423 public
424 DiagFire: Byte;
425 InvisFire: Byte;
426 DiagPrecision: Byte;
427 FlyPrecision: Byte;
428 Cover: Byte;
429 CloseJump: Byte;
430 WeaponPrior: packed array [WP_FIRST..WP_LAST] of Byte;
431 CloseWeaponPrior: packed array [WP_FIRST..WP_LAST] of Byte;
432 //SafeWeaponPrior: Array [WP_FIRST..WP_LAST] of Byte;
434 public
435 procedure save (st: TStream);
436 procedure load (st: TStream);
437 end;
439 TAIFlag = record
440 Name: String;
441 Value: String;
442 end;
444 TBot = class(TPlayer)
445 private
446 FSelectedWeapon: Byte;
447 FTargetUID: Word;
448 FLastVisible: DWORD;
449 FAIFlags: Array of TAIFlag;
450 FDifficult: TDifficult;
452 function GetRnd(a: Byte): Boolean;
453 function GetInterval(a: Byte; radius: SmallInt): SmallInt;
454 function RunDirection(): TDirection;
455 function FullInStep(XInc, YInc: Integer): Boolean;
456 //function NeedItem(Item: Byte): Byte;
457 procedure SelectWeapon(Dist: Integer);
458 procedure SetAIFlag(aName, fValue: String20);
459 function GetAIFlag(aName: String20): String20;
460 procedure RemoveAIFlag(aName: String20);
461 function Healthy(): Byte;
462 procedure UpdateMove();
463 procedure UpdateCombat();
464 function KeyPressed(Key: Word): Boolean;
465 procedure ReleaseKey(Key: Byte);
466 function TargetOnScreen(TX, TY: Integer): Boolean;
467 procedure OnDamage(Angle: SmallInt); override;
469 public
470 procedure Respawn(Silent: Boolean; Force: Boolean = False); override;
471 constructor Create(); override;
472 destructor Destroy(); override;
473 procedure Draw(); override;
474 function PickItem(ItemType: Byte; force: Boolean; var remove: Boolean): Boolean; override;
475 function Heal(value: Word; Soft: Boolean): Boolean; override;
476 procedure Update(); override;
477 procedure SaveState (st: TStream); override;
478 procedure LoadState (st: TStream); override;
479 end;
481 PGib = ^TGib;
482 TGib = record
483 alive: Boolean;
484 ID: DWORD;
485 MaskID: DWORD;
486 RAngle: Integer;
487 Color: TRGB;
488 Obj: TObj;
490 procedure getMapBox (out x, y, w, h: Integer); inline;
491 procedure moveBy (dx, dy: Integer); inline;
493 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
494 end;
497 PShell = ^TShell;
498 TShell = record
499 SpriteID: DWORD;
500 alive: Boolean;
501 SType: Byte;
502 RAngle: Integer;
503 Timeout: Cardinal;
504 CX, CY: Integer;
505 Obj: TObj;
507 procedure getMapBox (out x, y, w, h: Integer); inline;
508 procedure moveBy (dx, dy: Integer); inline;
510 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
511 end;
513 TCorpse = class{$IFDEF USE_MEMPOOL}(TPoolObject){$ENDIF}
514 private
515 FModelName: String;
516 FMess: Boolean;
517 FState: Byte;
518 FDamage: Byte;
519 FColor: TRGB;
520 FObj: TObj;
521 FPlayerUID: Word;
522 FAnimation: TAnimation;
523 FAnimationMask: TAnimation;
525 public
526 constructor Create(X, Y: Integer; ModelName: String; aMess: Boolean);
527 destructor Destroy(); override;
528 procedure Damage(Value: Word; vx, vy: Integer);
529 procedure Update();
530 procedure Draw();
531 procedure SaveState (st: TStream);
532 procedure LoadState (st: TStream);
534 procedure getMapBox (out x, y, w, h: Integer); inline;
535 procedure moveBy (dx, dy: Integer); inline;
537 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
539 function ObjPtr (): PObj; inline;
541 property Obj: TObj read FObj; // copies object
542 property State: Byte read FState;
543 property Mess: Boolean read FMess;
544 end;
546 TTeamStat = Array [TEAM_RED..TEAM_BLUE] of
547 record
548 Goals: SmallInt;
549 end;
552 gPlayers: Array of TPlayer;
553 gCorpses: Array of TCorpse;
554 gGibs: Array of TGib;
555 gShells: Array of TShell;
556 gTeamStat: TTeamStat;
557 gFly: Boolean = False;
558 gAimLine: Boolean = False;
559 gChatBubble: Byte = 0;
560 gNumBots: Word = 0;
561 gLMSPID1: Word = 0;
562 gLMSPID2: Word = 0;
563 MAX_RUNVEL: Integer = 8;
564 VEL_JUMP: Integer = 10;
565 SHELL_TIMEOUT: Cardinal = 60000;
567 function Lerp(X, Y, Factor: Integer): Integer;
569 procedure g_Gibs_SetMax(Count: Word);
570 function g_Gibs_GetMax(): Word;
571 procedure g_Corpses_SetMax(Count: Word);
572 function g_Corpses_GetMax(): Word;
573 procedure g_Shells_SetMax(Count: Word);
574 function g_Shells_GetMax(): Word;
576 procedure g_Player_Init();
577 procedure g_Player_Free();
578 function g_Player_Create(ModelName: String; Color: TRGB; Team: Byte; Bot: Boolean): Word;
579 function g_Player_CreateFromState (st: TStream): Word;
580 procedure g_Player_Remove(UID: Word);
581 procedure g_Player_ResetTeams();
582 procedure g_Player_UpdateAll();
583 procedure g_Player_DrawAll();
584 procedure g_Player_DrawDebug(p: TPlayer);
585 procedure g_Player_DrawHealth();
586 procedure g_Player_RememberAll();
587 procedure g_Player_ResetAll(Force, Silent: Boolean);
588 function g_Player_Get(UID: Word): TPlayer;
589 function g_Player_GetCount(): Byte;
590 function g_Player_GetStats(): TPlayerStatArray;
591 function g_Player_ValidName(Name: String): Boolean;
592 procedure g_Player_CreateCorpse(Player: TPlayer);
593 procedure g_Player_CreateGibs(fX, fY: Integer; ModelName: String; fColor: TRGB);
594 procedure g_Player_CreateShell(fX, fY, dX, dY: Integer; T: Byte);
595 procedure g_Player_UpdatePhysicalObjects();
596 procedure g_Player_DrawCorpses();
597 procedure g_Player_DrawShells();
598 procedure g_Player_RemoveAllCorpses();
599 procedure g_Player_Corpses_SaveState (st: TStream);
600 procedure g_Player_Corpses_LoadState (st: TStream);
601 procedure g_Bot_Add(Team, Difficult: Byte);
602 procedure g_Bot_AddList(Team: Byte; lname: ShortString; num: Integer = -1);
603 procedure g_Bot_MixNames();
604 procedure g_Bot_RemoveAll();
606 implementation
608 uses
609 {$INCLUDE ../nogl/noGLuses.inc}
610 {$IFDEF ENABLE_HOLMES}
611 g_holmes,
612 {$ENDIF}
613 e_log, g_map, g_items, g_console, g_gfx, Math,
614 g_options, g_triggers, g_menu, g_game, g_grid,
615 wadreader, g_main, g_monsters, CONFIG, g_language,
616 g_net, g_netmsg, g_window,
617 utils, xstreams;
619 const PLR_SAVE_VERSION = 0;
621 type
622 TBotProfile = record
623 name: ShortString;
624 model: ShortString;
625 team: Byte;
626 color: TRGB;
627 diag_fire: Byte;
628 invis_fire: Byte;
629 diag_precision: Byte;
630 fly_precision: Byte;
631 cover: Byte;
632 close_jump: Byte;
633 w_prior1: Array [WP_FIRST..WP_LAST] of Byte;
634 w_prior2: Array [WP_FIRST..WP_LAST] of Byte;
635 w_prior3: Array [WP_FIRST..WP_LAST] of Byte;
636 end;
638 const
639 TIME_RESPAWN1 = 1500;
640 TIME_RESPAWN2 = 2000;
641 TIME_RESPAWN3 = 3000;
642 AIR_DEF = 360;
643 AIR_MAX = 1091;
644 JET_MAX = 540; // ~30 sec
645 PLAYER_SUIT_TIME = 30000;
646 PLAYER_INVUL_TIME = 30000;
647 PLAYER_INVIS_TIME = 35000;
648 FRAG_COMBO_TIME = 3000;
649 VEL_SW = 4;
650 VEL_FLY = 6;
651 ANGLE_RIGHTUP = 55;
652 ANGLE_RIGHTDOWN = -35;
653 ANGLE_LEFTUP = 125;
654 ANGLE_LEFTDOWN = -145;
655 PLAYER_HEADRECT: TRectWH = (X:24; Y:12; Width:20; Height:12);
656 WEAPONPOINT: Array [TDirection] of TDFPoint = ((X:16; Y:32), (X:47; Y:32));
657 BOT_MAXJUMP = 84;
658 BOT_LONGDIST = 300;
659 BOT_UNSAFEDIST = 128;
660 TEAMCOLOR: Array [TEAM_RED..TEAM_BLUE] of TRGB = ((R:255; G:0; B:0),
661 (R:0; G:0; B:255));
662 DIFFICULT_EASY: TDifficult = (DiagFire: 32; InvisFire: 32; DiagPrecision: 32;
663 FlyPrecision: 32; Cover: 32; CloseJump: 32;
664 WeaponPrior:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior:(0,0,0,0,0,0,0,0,0,0,0));
665 DIFFICULT_MEDIUM: TDifficult = (DiagFire: 127; InvisFire: 127; DiagPrecision: 127;
666 FlyPrecision: 127; Cover: 127; CloseJump: 127;
667 WeaponPrior:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior:(0,0,0,0,0,0,0,0,0,0,0));
668 DIFFICULT_HARD: TDifficult = (DiagFire: 255; InvisFire: 255; DiagPrecision: 255;
669 FlyPrecision: 255; Cover: 255; CloseJump: 255;
670 WeaponPrior:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior:(0,0,0,0,0,0,0,0,0,0,0));
671 WEAPON_PRIOR1: Array [WP_FIRST..WP_LAST] of Byte =
672 (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
673 WEAPON_SHOTGUN2, WEAPON_SHOTGUN1,
674 WEAPON_CHAINGUN, WEAPON_PLASMA, WEAPON_ROCKETLAUNCHER,
675 WEAPON_BFG, WEAPON_PISTOL, WEAPON_SAW, WEAPON_KASTET);
676 WEAPON_PRIOR2: Array [WP_FIRST..WP_LAST] of Byte =
677 (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
678 WEAPON_BFG, WEAPON_ROCKETLAUNCHER,
679 WEAPON_SHOTGUN2, WEAPON_PLASMA, WEAPON_SHOTGUN1,
680 WEAPON_CHAINGUN, WEAPON_PISTOL, WEAPON_SAW, WEAPON_KASTET);
681 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
682 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
683 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
684 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
685 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
686 WEAPON_RELOAD: Array [WP_FIRST..WP_LAST] of Byte =
687 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
689 PLAYER_SIGNATURE = $52594C50; // 'PLYR'
690 CORPSE_SIGNATURE = $50524F43; // 'CORP'
692 BOTNAMES_FILENAME = 'botnames.txt';
693 BOTLIST_FILENAME = 'botlist.txt';
696 MaxGibs: Word = 150;
697 MaxCorpses: Word = 20;
698 MaxShells: Word = 300;
699 CurrentGib: Integer = 0;
700 CurrentShell: Integer = 0;
701 BotNames: Array of String;
702 BotList: Array of TBotProfile;
705 function Lerp(X, Y, Factor: Integer): Integer;
706 begin
707 Result := X + ((Y - X) div Factor);
708 end;
710 function SameTeam(UID1, UID2: Word): Boolean;
711 begin
712 Result := False;
714 if (UID1 > UID_MAX_PLAYER) or (UID1 <= UID_MAX_GAME) or
715 (UID2 > UID_MAX_PLAYER) or (UID2 <= UID_MAX_GAME) then Exit;
717 if (g_Player_Get(UID1) = nil) or (g_Player_Get(UID2) = nil) then Exit;
719 if ((g_Player_Get(UID1).Team = TEAM_NONE) or
720 (g_Player_Get(UID2).Team = TEAM_NONE)) then Exit;
722 Result := g_Player_Get(UID1).FTeam = g_Player_Get(UID2).FTeam;
723 end;
725 procedure g_Gibs_SetMax(Count: Word);
726 begin
727 MaxGibs := Count;
728 SetLength(gGibs, Count);
730 if CurrentGib >= Count then
731 CurrentGib := 0;
732 end;
734 function g_Gibs_GetMax(): Word;
735 begin
736 Result := MaxGibs;
737 end;
739 procedure g_Shells_SetMax(Count: Word);
740 begin
741 MaxShells := Count;
742 SetLength(gShells, Count);
744 if CurrentShell >= Count then
745 CurrentShell := 0;
746 end;
748 function g_Shells_GetMax(): Word;
749 begin
750 Result := MaxShells;
751 end;
754 procedure g_Corpses_SetMax(Count: Word);
755 begin
756 MaxCorpses := Count;
757 SetLength(gCorpses, Count);
758 end;
760 function g_Corpses_GetMax(): Word;
761 begin
762 Result := MaxCorpses;
763 end;
765 function g_Player_Create(ModelName: String; Color: TRGB; Team: Byte; Bot: Boolean): Word;
767 a: Integer;
768 ok: Boolean;
769 begin
770 Result := 0;
772 ok := False;
773 a := 0;
775 // Åñòü ëè ìåñòî â gPlayers:
776 if gPlayers <> nil then
777 for a := 0 to High(gPlayers) do
778 if gPlayers[a] = nil then
779 begin
780 ok := True;
781 Break;
782 end;
784 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
785 if not ok then
786 begin
787 SetLength(gPlayers, Length(gPlayers)+1);
788 a := High(gPlayers);
789 end;
791 // Ñîçäàåì îáúåêò èãðîêà:
792 if Bot then
793 gPlayers[a] := TBot.Create()
794 else
795 gPlayers[a] := TPlayer.Create();
798 gPlayers[a].FActualModelName := ModelName;
799 gPlayers[a].SetModel(ModelName);
801 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
802 if gPlayers[a].FModel = nil then
803 begin
804 gPlayers[a].Free();
805 gPlayers[a] := nil;
806 g_FatalError(Format(_lc[I_GAME_ERROR_MODEL], [ModelName]));
807 Exit;
808 end;
810 if not (Team in [TEAM_RED, TEAM_BLUE]) then
811 if Random(2) = 0 then
812 Team := TEAM_RED
813 else
814 Team := TEAM_BLUE;
815 gPlayers[a].FPreferredTeam := Team;
817 case gGameSettings.GameMode of
818 GM_DM: gPlayers[a].FTeam := TEAM_NONE;
819 GM_TDM,
820 GM_CTF: gPlayers[a].FTeam := gPlayers[a].FPreferredTeam;
821 GM_SINGLE,
822 GM_COOP: gPlayers[a].FTeam := TEAM_COOP;
823 end;
825 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
826 gPlayers[a].FColor := Color;
827 if gPlayers[a].FTeam in [TEAM_RED, TEAM_BLUE] then
828 gPlayers[a].FModel.Color := TEAMCOLOR[gPlayers[a].FTeam]
829 else
830 gPlayers[a].FModel.Color := Color;
832 gPlayers[a].FUID := g_CreateUID(UID_PLAYER);
833 gPlayers[a].FAlive := False;
835 Result := gPlayers[a].FUID;
836 end;
838 function g_Player_CreateFromState (st: TStream): Word;
840 a, i: Integer;
841 ok, Bot: Boolean;
842 b: Byte;
843 begin
844 result := 0;
845 if (st = nil) then exit; //???
847 // Ñèãíàòóðà èãðîêà
848 if not utils.checkSign(st, 'PLYR') then raise XStreamError.Create('invalid player signature');
849 if (utils.readByte(st) <> PLR_SAVE_VERSION) then raise XStreamError.Create('invalid player version');
851 // Áîò èëè ÷åëîâåê:
852 Bot := utils.readBool(st);
854 ok := false;
855 a := 0;
857 // Åñòü ëè ìåñòî â gPlayers:
858 for a := 0 to High(gPlayers) do if (gPlayers[a] = nil) then begin ok := true; break; end;
860 // Íåò ìåñòà - ðàñøèðÿåì gPlayers
861 if not ok then
862 begin
863 SetLength(gPlayers, Length(gPlayers)+1);
864 a := High(gPlayers);
865 end;
867 // Ñîçäàåì îáúåêò èãðîêà
868 if Bot then
869 gPlayers[a] := TBot.Create()
870 else
871 gPlayers[a] := TPlayer.Create();
872 gPlayers[a].FIamBot := Bot;
873 gPlayers[a].FPhysics := True;
875 // UID èãðîêà
876 gPlayers[a].FUID := utils.readWord(st);
877 // Èìÿ èãðîêà
878 gPlayers[a].FName := utils.readStr(st);
879 // Êîìàíäà
880 gPlayers[a].FTeam := utils.readByte(st);
881 gPlayers[a].FPreferredTeam := gPlayers[a].FTeam;
882 // Æèâ ëè
883 gPlayers[a].FAlive := utils.readBool(st);
884 // Èçðàñõîäîâàë ëè âñå æèçíè
885 gPlayers[a].FNoRespawn := utils.readBool(st);
886 // Íàïðàâëåíèå
887 b := utils.readByte(st);
888 if b = 1 then gPlayers[a].FDirection := TDirection.D_LEFT else gPlayers[a].FDirection := TDirection.D_RIGHT; // b = 2
889 // Çäîðîâüå
890 gPlayers[a].FHealth := utils.readLongInt(st);
891 // Æèçíè
892 gPlayers[a].FLives := utils.readByte(st);
893 // Áðîíÿ
894 gPlayers[a].FArmor := utils.readLongInt(st);
895 // Çàïàñ âîçäóõà
896 gPlayers[a].FAir := utils.readLongInt(st);
897 // Çàïàñ ãîðþ÷åãî
898 gPlayers[a].FJetFuel := utils.readLongInt(st);
899 // Áîëü
900 gPlayers[a].FPain := utils.readLongInt(st);
901 // Óáèë
902 gPlayers[a].FKills := utils.readLongInt(st);
903 // Óáèë ìîíñòðîâ
904 gPlayers[a].FMonsterKills := utils.readLongInt(st);
905 // Ôðàãîâ
906 gPlayers[a].FFrags := utils.readLongInt(st);
907 // Ôðàãîâ ïîäðÿä
908 gPlayers[a].FFragCombo := utils.readByte(st);
909 // Âðåìÿ ïîñëåäíåãî ôðàãà
910 gPlayers[a].FLastFrag := utils.readLongWord(st);
911 // Ñìåðòåé
912 gPlayers[a].FDeath := utils.readLongInt(st);
913 // Êàêîé ôëàã íåñåò
914 gPlayers[a].FFlag := utils.readByte(st);
915 // Íàøåë ñåêðåòîâ
916 gPlayers[a].FSecrets := utils.readLongInt(st);
917 // Òåêóùåå îðóæèå
918 gPlayers[a].FCurrWeap := utils.readByte(st);
919 //gPlayers[a].FNetForceWeap := gPlayers[a].FCurrWeap;
920 // Ñëåäóþùåå æåëàåìîå îðóæèå
921 gPlayers[a].FNextWeap := utils.readWord(st);
922 // ...è ïàóçà
923 gPlayers[a].FNextWeapDelay := utils.readByte(st);
924 // Âðåìÿ çàðÿäêè BFG
925 gPlayers[a].FBFGFireCounter := utils.readSmallInt(st);
926 // Áóôåð óðîíà
927 gPlayers[a].FDamageBuffer := utils.readLongInt(st);
928 // Ïîñëåäíèé óäàðèâøèé
929 gPlayers[a].FLastSpawnerUID := utils.readWord(st);
930 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
931 gPlayers[a].FLastHit := utils.readByte(st);
932 // Îáúåêò èãðîêà:
933 Obj_LoadState(@gPlayers[a].FObj, st);
934 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
935 for i := A_BULLETS to A_HIGH do gPlayers[a].FAmmo[i] := utils.readWord(st);
936 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
937 for i := A_BULLETS to A_HIGH do gPlayers[a].FMaxAmmo[i] := utils.readWord(st);
938 // Íàëè÷èå îðóæèÿ
939 for i := WP_FIRST to WP_LAST do gPlayers[a].FWeapon[i] := utils.readBool(st);
940 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
941 for i := WP_FIRST to WP_LAST do gPlayers[a].FReloading[i] := utils.readWord(st);
942 // Íàëè÷èå ðþêçàêà
943 if utils.readBool(st) then Include(gPlayers[a].FRulez, R_ITEM_BACKPACK);
944 // Íàëè÷èå êðàñíîãî êëþ÷à
945 if utils.readBool(st) then Include(gPlayers[a].FRulez, R_KEY_RED);
946 // Íàëè÷èå çåëåíîãî êëþ÷à
947 if utils.readBool(st) then Include(gPlayers[a].FRulez, R_KEY_GREEN);
948 // Íàëè÷èå ñèíåãî êëþ÷à
949 if utils.readBool(st) then Include(gPlayers[a].FRulez, R_KEY_BLUE);
950 // Íàëè÷èå áåðñåðêà
951 if utils.readBool(st) then Include(gPlayers[a].FRulez, R_BERSERK);
952 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
953 for i := MR_SUIT to MR_MAX do gPlayers[a].FMegaRulez[i] := utils.readLongWord(st);
954 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
955 for i := T_RESPAWN to T_FLAGCAP do gPlayers[a].FTime[i] := utils.readLongWord(st);
957 // Íàçâàíèå ìîäåëè:
958 gPlayers[a].FActualModelName := utils.readStr(st);
959 // Öâåò ìîäåëè
960 gPlayers[a].FColor.R := utils.readByte(st);
961 gPlayers[a].FColor.G := utils.readByte(st);
962 gPlayers[a].FColor.B := utils.readByte(st);
963 // Îáíîâëÿåì ìîäåëü èãðîêà
964 gPlayers[a].SetModel(gPlayers[a].FActualModelName);
966 // Íåò ìîäåëè - ñîçäàíèå íåâîçìîæíî
967 if (gPlayers[a].FModel = nil) then
968 begin
969 gPlayers[a].Free();
970 gPlayers[a] := nil;
971 g_FatalError(Format(_lc[I_GAME_ERROR_MODEL], [gPlayers[a].FActualModelName]));
972 exit;
973 end;
975 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû
976 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
977 gPlayers[a].FModel.Color := TEAMCOLOR[gPlayers[a].FTeam]
978 else
979 gPlayers[a].FModel.Color := gPlayers[a].FColor;
981 result := gPlayers[a].FUID;
982 end;
985 procedure g_Player_ResetTeams();
987 a: Integer;
988 begin
989 if g_Game_IsClient then
990 Exit;
991 if gPlayers = nil then
992 Exit;
993 for a := Low(gPlayers) to High(gPlayers) do
994 if gPlayers[a] <> nil then
995 case gGameSettings.GameMode of
996 GM_DM:
997 gPlayers[a].ChangeTeam(TEAM_NONE);
998 GM_TDM, GM_CTF:
999 if not (gPlayers[a].Team in [TEAM_RED, TEAM_BLUE]) then
1000 if gPlayers[a].FPreferredTeam in [TEAM_RED, TEAM_BLUE] then
1001 gPlayers[a].ChangeTeam(gPlayers[a].FPreferredTeam)
1002 else
1003 if a mod 2 = 0 then
1004 gPlayers[a].ChangeTeam(TEAM_RED)
1005 else
1006 gPlayers[a].ChangeTeam(TEAM_BLUE);
1007 GM_SINGLE,
1008 GM_COOP:
1009 gPlayers[a].ChangeTeam(TEAM_COOP);
1010 end;
1011 end;
1013 procedure g_Bot_Add(Team, Difficult: Byte);
1015 m: SSArray;
1016 _name, _model: String;
1017 a, tr, tb: Integer;
1018 begin
1019 if not g_Game_IsServer then Exit;
1021 // Ñïèñîê íàçâàíèé ìîäåëåé:
1022 m := g_PlayerModel_GetNames();
1023 if m = nil then
1024 Exit;
1026 // Êîìàíäà:
1027 if (gGameSettings.GameType = GT_SINGLE) or (gGameSettings.GameMode = GM_COOP) then
1028 Team := TEAM_COOP // COOP
1029 else
1030 if gGameSettings.GameMode = GM_DM then
1031 Team := TEAM_NONE // DM
1032 else
1033 if Team = TEAM_NONE then // CTF / TDM
1034 begin
1035 // Àâòîáàëàíñ êîìàíä:
1036 tr := 0;
1037 tb := 0;
1039 for a := 0 to High(gPlayers) do
1040 if gPlayers[a] <> nil then
1041 begin
1042 if gPlayers[a].Team = TEAM_RED then
1043 Inc(tr)
1044 else
1045 if gPlayers[a].Team = TEAM_BLUE then
1046 Inc(tb);
1047 end;
1049 if tr > tb then
1050 Team := TEAM_BLUE
1051 else
1052 if tb > tr then
1053 Team := TEAM_RED
1054 else // tr = tb
1055 if Random(2) = 0 then
1056 Team := TEAM_RED
1057 else
1058 Team := TEAM_BLUE;
1059 end;
1061 // Âûáèðàåì áîòó èìÿ:
1062 _name := '';
1063 if BotNames <> nil then
1064 for a := 0 to High(BotNames) do
1065 if g_Player_ValidName(BotNames[a]) then
1066 begin
1067 _name := BotNames[a];
1068 Break;
1069 end;
1071 // Èìåíè íåò, çàäàåì ñëó÷àéíîå:
1072 if _name = '' then
1073 repeat
1074 _name := Format('DFBOT%.2d', [Random(100)]);
1075 until g_Player_ValidName(_name);
1077 // Âûáèðàåì ñëó÷àéíóþ ìîäåëü:
1078 _model := m[Random(Length(m))];
1080 // Ñîçäàåì áîòà:
1081 with g_Player_Get(g_Player_Create(_model,
1082 _RGB(Min(Random(9)*32, 255),
1083 Min(Random(9)*32, 255),
1084 Min(Random(9)*32, 255)),
1085 Team, True)) as TBot do
1086 begin
1087 Name := _name;
1089 case Difficult of
1090 1: FDifficult := DIFFICULT_EASY;
1091 2: FDifficult := DIFFICULT_MEDIUM;
1092 else FDifficult := DIFFICULT_HARD;
1093 end;
1095 for a := WP_FIRST to WP_LAST do
1096 begin
1097 FDifficult.WeaponPrior[a] := WEAPON_PRIOR1[a];
1098 FDifficult.CloseWeaponPrior[a] := WEAPON_PRIOR2[a];
1099 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1100 end;
1102 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [Name]), True);
1104 if g_Game_IsNet then MH_SEND_PlayerCreate(UID);
1105 if g_Game_IsServer and (gGameSettings.MaxLives > 0) then
1106 Spectate();
1107 end;
1108 end;
1110 procedure g_Bot_AddList(Team: Byte; lName: ShortString; num: Integer = -1);
1112 m: SSArray;
1113 _name, _model: String;
1114 a: Integer;
1115 begin
1116 if not g_Game_IsServer then Exit;
1118 // Ñïèñîê íàçâàíèé ìîäåëåé:
1119 m := g_PlayerModel_GetNames();
1120 if m = nil then
1121 Exit;
1123 // Êîìàíäà:
1124 if (gGameSettings.GameType = GT_SINGLE) or (gGameSettings.GameMode = GM_COOP) then
1125 Team := TEAM_COOP // COOP
1126 else
1127 if gGameSettings.GameMode = GM_DM then
1128 Team := TEAM_NONE // DM
1129 else
1130 if Team = TEAM_NONE then
1131 Team := BotList[num].team; // CTF / TDM
1133 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1134 lName := AnsiLowerCase(lName);
1135 if (num < 0) or (num > Length(BotList)-1) then
1136 num := -1;
1137 if (num = -1) and (lName <> '') and (BotList <> nil) then
1138 for a := 0 to High(BotList) do
1139 if AnsiLowerCase(BotList[a].name) = lName then
1140 begin
1141 num := a;
1142 Break;
1143 end;
1144 if num = -1 then
1145 Exit;
1147 // Èìÿ áîòà:
1148 _name := BotList[num].name;
1149 // Çàíÿòî - âûáèðàåì ñëó÷àéíîå:
1150 if not g_Player_ValidName(_name) then
1151 repeat
1152 _name := Format('DFBOT%.2d', [Random(100)]);
1153 until g_Player_ValidName(_name);
1155 // Ìîäåëü:
1156 _model := BotList[num].model;
1157 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1158 if not InSArray(_model, m) then
1159 _model := m[Random(Length(m))];
1161 // Ñîçäàåì áîòà:
1162 with g_Player_Get(g_Player_Create(_model, BotList[num].color, Team, True)) as TBot do
1163 begin
1164 Name := _name;
1166 FDifficult.DiagFire := BotList[num].diag_fire;
1167 FDifficult.InvisFire := BotList[num].invis_fire;
1168 FDifficult.DiagPrecision := BotList[num].diag_precision;
1169 FDifficult.FlyPrecision := BotList[num].fly_precision;
1170 FDifficult.Cover := BotList[num].cover;
1171 FDifficult.CloseJump := BotList[num].close_jump;
1173 for a := WP_FIRST to WP_LAST do
1174 begin
1175 FDifficult.WeaponPrior[a] := BotList[num].w_prior1[a];
1176 FDifficult.CloseWeaponPrior[a] := BotList[num].w_prior2[a];
1177 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1178 end;
1180 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [Name]), True);
1182 if g_Game_IsNet then MH_SEND_PlayerCreate(UID);
1183 end;
1184 end;
1186 procedure g_Bot_RemoveAll();
1188 a: Integer;
1189 begin
1190 if not g_Game_IsServer then Exit;
1191 if gPlayers = nil then Exit;
1193 for a := 0 to High(gPlayers) do
1194 if gPlayers[a] <> nil then
1195 if gPlayers[a] is TBot then
1196 begin
1197 gPlayers[a].Lives := 0;
1198 gPlayers[a].Kill(K_SIMPLEKILL, 0, HIT_DISCON);
1199 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [gPlayers[a].Name]), True);
1200 g_Player_Remove(gPlayers[a].FUID);
1201 end;
1203 g_Bot_MixNames();
1204 end;
1206 procedure g_Bot_MixNames();
1208 s: String;
1209 a, b: Integer;
1210 begin
1211 if BotNames <> nil then
1212 for a := 0 to High(BotNames) do
1213 begin
1214 b := Random(Length(BotNames));
1215 s := BotNames[a];
1216 Botnames[a] := BotNames[b];
1217 BotNames[b] := s;
1218 end;
1219 end;
1221 procedure g_Player_Remove(UID: Word);
1223 i: Integer;
1224 begin
1225 if gPlayers = nil then Exit;
1227 if g_Game_IsServer and g_Game_IsNet then
1228 MH_SEND_PlayerDelete(UID);
1230 for i := 0 to High(gPlayers) do
1231 if gPlayers[i] <> nil then
1232 if gPlayers[i].FUID = UID then
1233 begin
1234 if gPlayers[i] is TPlayer then
1235 TPlayer(gPlayers[i]).Free()
1236 else
1237 TBot(gPlayers[i]).Free();
1238 gPlayers[i] := nil;
1239 Exit;
1240 end;
1241 end;
1243 procedure g_Player_Init();
1245 F: TextFile;
1246 s: String;
1247 a, b: Integer;
1248 config: TConfig;
1249 sa: SSArray;
1250 begin
1251 BotNames := nil;
1253 if not FileExists(DataDir + BOTNAMES_FILENAME) then
1254 Exit;
1256 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1257 AssignFile(F, DataDir + BOTNAMES_FILENAME);
1258 Reset(F);
1260 while not EOF(F) do
1261 begin
1262 ReadLn(F, s);
1264 s := Trim(s);
1265 if s = '' then
1266 Continue;
1268 SetLength(BotNames, Length(BotNames)+1);
1269 BotNames[High(BotNames)] := s;
1270 end;
1272 CloseFile(F);
1274 // Ïåðåìåøèâàåì èõ:
1275 g_Bot_MixNames();
1277 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1278 config := TConfig.CreateFile(DataDir + BOTLIST_FILENAME);
1279 BotList := nil;
1280 a := 0;
1282 while config.SectionExists(IntToStr(a)) do
1283 begin
1284 SetLength(BotList, Length(BotList)+1);
1286 with BotList[High(BotList)] do
1287 begin
1288 // Èìÿ áîòà:
1289 name := config.ReadStr(IntToStr(a), 'name', '');
1290 // Ìîäåëü:
1291 model := config.ReadStr(IntToStr(a), 'model', '');
1292 // Êîìàíäà:
1293 if config.ReadStr(IntToStr(a), 'team', 'red') = 'red' then
1294 team := TEAM_RED
1295 else
1296 team := TEAM_BLUE;
1297 // Öâåò ìîäåëè:
1298 sa := parse(config.ReadStr(IntToStr(a), 'color', ''));
1299 color.R := StrToIntDef(sa[0], 0);
1300 color.G := StrToIntDef(sa[1], 0);
1301 color.B := StrToIntDef(sa[2], 0);
1302 // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì:
1303 diag_fire := config.ReadInt(IntToStr(a), 'diag_fire', 0);
1304 // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó:
1305 invis_fire := config.ReadInt(IntToStr(a), 'invis_fire', 0);
1306 // Òî÷íîñòü ñòðåëüáû ïîä óãëîì:
1307 diag_precision := config.ReadInt(IntToStr(a), 'diag_precision', 0);
1308 // Òî÷íîñòü ñòðåëüáû â ïîëåòå:
1309 fly_precision := config.ReadInt(IntToStr(a), 'fly_precision', 0);
1310 // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ:
1311 cover := config.ReadInt(IntToStr(a), 'cover', 0);
1312 // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà:
1313 close_jump := config.ReadInt(IntToStr(a), 'close_jump', 0);
1314 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ:
1315 sa := parse(config.ReadStr(IntToStr(a), 'w_prior1', ''));
1316 if Length(sa) = 10 then
1317 for b := 0 to 9 do
1318 w_prior1[b] := EnsureRange(StrToInt(sa[b]), 0, 9);
1319 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ:
1320 sa := parse(config.ReadStr(IntToStr(a), 'w_prior2', ''));
1321 if Length(sa) = 10 then
1322 for b := 0 to 9 do
1323 w_prior2[b] := EnsureRange(StrToInt(sa[b]), 0, 9);
1325 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1326 if Length(sa) = 10 then
1327 for b := 0 to 9 do
1328 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1329 end;
1331 a := a + 1;
1332 end;
1334 config.Free();
1335 end;
1337 procedure g_Player_Free();
1339 i: Integer;
1340 begin
1341 if gPlayers <> nil then
1342 begin
1343 for i := 0 to High(gPlayers) do
1344 if gPlayers[i] <> nil then
1345 begin
1346 if gPlayers[i] is TPlayer then
1347 TPlayer(gPlayers[i]).Free()
1348 else
1349 TBot(gPlayers[i]).Free();
1350 gPlayers[i] := nil;
1351 end;
1353 gPlayers := nil;
1354 end;
1356 gPlayer1 := nil;
1357 gPlayer2 := nil;
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 //if (gPlayers[i].NetForceWeapFIdx > gTime) then writeln('*** PLAYER #', i, '; gTime=', gTime, '; nfwf=', gPlayers[i].NetForceWeapFIdx);
1374 gPlayers[i].Update();
1375 if (not gPlayers[i].alive) or (gPlayers[i].NetForceWeapFIdx >= gTime+15) then gPlayers[i].NetForceWeapFIdx := 0; // just in case
1376 gPlayers[i].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1378 else
1379 begin
1380 // bot updates weapons in `UpdateCombat()`
1381 TBot(gPlayers[i]).Update();
1382 end;
1383 end;
1384 end;
1385 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1386 end;
1388 procedure g_Player_DrawAll();
1390 i: Integer;
1391 begin
1392 if gPlayers = nil then Exit;
1394 for i := 0 to High(gPlayers) do
1395 if gPlayers[i] <> nil then
1396 if gPlayers[i] is TPlayer then gPlayers[i].Draw()
1397 else TBot(gPlayers[i]).Draw();
1398 end;
1400 procedure g_Player_DrawDebug(p: TPlayer);
1402 fW, fH: Byte;
1403 begin
1404 if p = nil then Exit;
1405 if (@p.FObj) = nil then Exit;
1407 e_TextureFontGetSize(gStdFont, fW, fH);
1409 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p.FObj.X), gStdFont);
1410 e_TextureFontPrint(0, fH , 'Pos Y: ' + IntToStr(p.FObj.Y), gStdFont);
1411 e_TextureFontPrint(0, fH * 2, 'Vel X: ' + IntToStr(p.FObj.Vel.X), gStdFont);
1412 e_TextureFontPrint(0, fH * 3, 'Vel Y: ' + IntToStr(p.FObj.Vel.Y), gStdFont);
1413 e_TextureFontPrint(0, fH * 4, 'Acc X: ' + IntToStr(p.FObj.Accel.X), gStdFont);
1414 e_TextureFontPrint(0, fH * 5, 'Acc Y: ' + IntToStr(p.FObj.Accel.Y), 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_Player_GetStats(): TPlayerStatArray;
1471 a: Integer;
1472 begin
1473 Result := nil;
1475 if gPlayers = nil then Exit;
1477 for a := 0 to High(gPlayers) do
1478 if gPlayers[a] <> nil then
1479 begin
1480 SetLength(Result, Length(Result)+1);
1481 with Result[High(Result)] do
1482 begin
1483 Ping := gPlayers[a].FPing;
1484 Loss := gPlayers[a].FLoss;
1485 Name := gPlayers[a].FName;
1486 Team := gPlayers[a].FTeam;
1487 Frags := gPlayers[a].FFrags;
1488 Deaths := gPlayers[a].FDeath;
1489 Kills := gPlayers[a].FKills;
1490 Color := gPlayers[a].FModel.Color;
1491 Lives := gPlayers[a].FLives;
1492 Spectator := gPlayers[a].FSpectator;
1493 end;
1494 end;
1495 end;
1497 procedure g_Player_RememberAll;
1499 i: Integer;
1500 begin
1501 for i := Low(gPlayers) to High(gPlayers) do
1502 if (gPlayers[i] <> nil) and gPlayers[i].alive then
1503 gPlayers[i].RememberState;
1504 end;
1506 procedure g_Player_ResetAll(Force, Silent: Boolean);
1508 i: Integer;
1509 begin
1510 gTeamStat[TEAM_RED].Goals := 0;
1511 gTeamStat[TEAM_BLUE].Goals := 0;
1513 if gPlayers <> nil then
1514 for i := 0 to High(gPlayers) do
1515 if gPlayers[i] <> nil then
1516 begin
1517 gPlayers[i].Reset(Force);
1519 if gPlayers[i] is TPlayer then
1520 begin
1521 if (not gPlayers[i].FSpectator) or gPlayers[i].FWantsInGame then
1522 gPlayers[i].Respawn(Silent)
1523 else
1524 gPlayers[i].Spectate();
1526 else
1527 TBot(gPlayers[i]).Respawn(Silent);
1528 end;
1529 end;
1531 procedure g_Player_CreateCorpse(Player: TPlayer);
1533 i: Integer;
1534 find_id: DWORD;
1535 ok: Boolean;
1536 begin
1537 if Player.alive then
1538 Exit;
1540 // Ðàçðûâàåì ñâÿçü ñ ïðåæíèì òðóïîì:
1541 if gCorpses <> nil then
1542 for i := 0 to High(gCorpses) do
1543 if gCorpses[i] <> nil then
1544 if gCorpses[i].FPlayerUID = Player.FUID then
1545 gCorpses[i].FPlayerUID := 0;
1547 if Player.FObj.Y >= gMapInfo.Height+128 then
1548 Exit;
1550 with Player do
1551 begin
1552 if (FHealth >= -50) or (gGibsCount = 0) then
1553 begin
1554 if (gCorpses = nil) or (Length(gCorpses) = 0) then
1555 Exit;
1557 ok := False;
1558 for find_id := 0 to High(gCorpses) do
1559 if gCorpses[find_id] = nil then
1560 begin
1561 ok := True;
1562 Break;
1563 end;
1565 if not ok then
1566 find_id := Random(Length(gCorpses));
1568 gCorpses[find_id] := TCorpse.Create(FObj.X, FObj.Y, FModel.Name, FHealth < -20);
1569 gCorpses[find_id].FColor := FModel.Color;
1570 gCorpses[find_id].FObj.Vel := FObj.Vel;
1571 gCorpses[find_id].FObj.Accel := FObj.Accel;
1572 gCorpses[find_id].FPlayerUID := FUID;
1574 else
1575 g_Player_CreateGibs(FObj.X + PLAYER_RECT_CX,
1576 FObj.Y + PLAYER_RECT_CY,
1577 FModel.Name, FModel.Color);
1578 end;
1579 end;
1581 procedure g_Player_CreateShell(fX, fY, dX, dY: Integer; T: Byte);
1583 SID: DWORD;
1584 begin
1585 if (gShells = nil) or (Length(gShells) = 0) then
1586 Exit;
1588 with gShells[CurrentShell] do
1589 begin
1590 SpriteID := 0;
1591 g_Obj_Init(@Obj);
1592 Obj.Rect.X := 0;
1593 Obj.Rect.Y := 0;
1594 if T = SHELL_BULLET then
1595 begin
1596 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID) then
1597 SpriteID := SID;
1598 CX := 2;
1599 CY := 1;
1600 Obj.Rect.Width := 4;
1601 Obj.Rect.Height := 2;
1603 else
1604 begin
1605 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID) then
1606 SpriteID := SID;
1607 CX := 4;
1608 CY := 2;
1609 Obj.Rect.Width := 7;
1610 Obj.Rect.Height := 3;
1611 end;
1612 SType := T;
1613 alive := True;
1614 Obj.X := fX;
1615 Obj.Y := fY;
1616 g_Obj_Push(@Obj, dX + Random(4)-Random(4), dY-Random(4));
1617 positionChanged(); // this updates spatial accelerators
1618 RAngle := Random(360);
1619 Timeout := gTime + SHELL_TIMEOUT;
1621 if CurrentShell >= High(gShells) then
1622 CurrentShell := 0
1623 else
1624 Inc(CurrentShell);
1625 end;
1626 end;
1628 procedure g_Player_CreateGibs(fX, fY: Integer; ModelName: string; fColor: TRGB);
1630 a: Integer;
1631 GibsArray: TGibsArray;
1632 Blood: TModelBlood;
1633 begin
1634 if (gGibs = nil) or (Length(gGibs) = 0) then
1635 Exit;
1636 if not g_PlayerModel_GetGibs(ModelName, GibsArray) then
1637 Exit;
1638 Blood := g_PlayerModel_GetBlood(ModelName);
1640 for a := 0 to High(GibsArray) do
1641 with gGibs[CurrentGib] do
1642 begin
1643 Color := fColor;
1644 ID := GibsArray[a].ID;
1645 MaskID := GibsArray[a].MaskID;
1646 alive := True;
1647 g_Obj_Init(@Obj);
1648 Obj.Rect := GibsArray[a].Rect;
1649 Obj.X := fX-GibsArray[a].Rect.X-(GibsArray[a].Rect.Width div 2);
1650 Obj.Y := fY-GibsArray[a].Rect.Y-(GibsArray[a].Rect.Height div 2);
1651 g_Obj_PushA(@Obj, 25 + Random(10), Random(361));
1652 positionChanged(); // this updates spatial accelerators
1653 RAngle := Random(360);
1655 if gBloodCount > 0 then
1656 g_GFX_Blood(fX, fY, 16*gBloodCount+Random(5*gBloodCount), -16+Random(33), -16+Random(33),
1657 Random(48), Random(48), Blood.R, Blood.G, Blood.B, Blood.Kind);
1659 if CurrentGib >= High(gGibs) then
1660 CurrentGib := 0
1661 else
1662 Inc(CurrentGib);
1663 end;
1664 end;
1666 procedure g_Player_UpdatePhysicalObjects();
1668 i: Integer;
1669 vel: TPoint2i;
1670 mr: Word;
1672 procedure ShellSound_Bounce(X, Y: Integer; T: Byte);
1674 k: Integer;
1675 begin
1676 k := 1 + Random(2);
1677 if T = SHELL_BULLET then
1678 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k), X, Y)
1679 else
1680 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k), X, Y);
1681 end;
1683 begin
1684 // Êóñêè ìÿñà:
1685 if gGibs <> nil then
1686 for i := 0 to High(gGibs) do
1687 if gGibs[i].alive then
1688 with gGibs[i] do
1689 begin
1690 vel := Obj.Vel;
1691 mr := g_Obj_Move(@Obj, True, False, True);
1692 positionChanged(); // this updates spatial accelerators
1694 if WordBool(mr and MOVE_FALLOUT) then
1695 begin
1696 alive := False;
1697 Continue;
1698 end;
1700 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1701 if WordBool(mr and MOVE_HITWALL) then
1702 Obj.Vel.X := -(vel.X div 2);
1703 if WordBool(mr and (MOVE_HITCEIL or MOVE_HITLAND)) then
1704 Obj.Vel.Y := -(vel.Y div 2);
1706 if (Obj.Vel.X >= 0) then
1707 begin // Clockwise
1708 RAngle := RAngle + Abs(Obj.Vel.X)*6 + Abs(Obj.Vel.Y);
1709 if RAngle >= 360 then
1710 RAngle := RAngle mod 360;
1711 end else begin // Counter-clockwise
1712 RAngle := RAngle - Abs(Obj.Vel.X)*6 - Abs(Obj.Vel.Y);
1713 if RAngle < 0 then
1714 RAngle := (360 - (Abs(RAngle) mod 360)) mod 360;
1715 end;
1717 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1718 if gTime mod (GAME_TICK*3) = 0 then
1719 Obj.Vel.X := z_dec(Obj.Vel.X, 1);
1720 end;
1722 // Òðóïû:
1723 if gCorpses <> nil then
1724 for i := 0 to High(gCorpses) do
1725 if gCorpses[i] <> nil then
1726 if gCorpses[i].State = CORPSE_STATE_REMOVEME then
1727 begin
1728 gCorpses[i].Free();
1729 gCorpses[i] := nil;
1731 else
1732 gCorpses[i].Update();
1734 // Ãèëüçû:
1735 if gShells <> nil then
1736 for i := 0 to High(gShells) do
1737 if gShells[i].alive then
1738 with gShells[i] do
1739 begin
1740 vel := Obj.Vel;
1741 mr := g_Obj_Move(@Obj, True, False, True);
1742 positionChanged(); // this updates spatial accelerators
1744 if WordBool(mr and MOVE_FALLOUT) or (gShells[i].Timeout < gTime) then
1745 begin
1746 alive := False;
1747 Continue;
1748 end;
1750 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1751 if WordBool(mr and MOVE_HITWALL) then
1752 begin
1753 Obj.Vel.X := -(vel.X div 2);
1754 if not WordBool(mr and MOVE_INWATER) then
1755 ShellSound_Bounce(Obj.X, Obj.Y, SType);
1756 end;
1757 if WordBool(mr and (MOVE_HITCEIL or MOVE_HITLAND)) then
1758 begin
1759 Obj.Vel.Y := -(vel.Y div 2);
1760 if Obj.Vel.X <> 0 then Obj.Vel.X := Obj.Vel.X div 2;
1761 if (Obj.Vel.X = 0) and (Obj.Vel.Y = 0) then
1762 begin
1763 if RAngle mod 90 <> 0 then
1764 RAngle := (RAngle div 90) * 90;
1766 else if not WordBool(mr and MOVE_INWATER) then
1767 ShellSound_Bounce(Obj.X, Obj.Y, SType);
1768 end;
1770 if (Obj.Vel.X >= 0) then
1771 begin // Clockwise
1772 RAngle := RAngle + Abs(Obj.Vel.X)*8 + Abs(Obj.Vel.Y);
1773 if RAngle >= 360 then
1774 RAngle := RAngle mod 360;
1775 end else begin // Counter-clockwise
1776 RAngle := RAngle - Abs(Obj.Vel.X)*8 - Abs(Obj.Vel.Y);
1777 if RAngle < 0 then
1778 RAngle := (360 - (Abs(RAngle) mod 360)) mod 360;
1779 end;
1780 end;
1781 end;
1784 procedure TGib.getMapBox (out x, y, w, h: Integer); inline;
1785 begin
1786 x := Obj.X+Obj.Rect.X;
1787 y := Obj.Y+Obj.Rect.Y;
1788 w := Obj.Rect.Width;
1789 h := Obj.Rect.Height;
1790 end;
1792 procedure TGib.moveBy (dx, dy: Integer); inline;
1793 begin
1794 if (dx <> 0) or (dy <> 0) then
1795 begin
1796 Obj.X += dx;
1797 Obj.Y += dy;
1798 positionChanged();
1799 end;
1800 end;
1803 procedure TShell.getMapBox (out x, y, w, h: Integer); inline;
1804 begin
1805 x := Obj.X;
1806 y := Obj.Y;
1807 w := Obj.Rect.Width;
1808 h := Obj.Rect.Height;
1809 end;
1811 procedure TShell.moveBy (dx, dy: Integer); inline;
1812 begin
1813 if (dx <> 0) or (dy <> 0) then
1814 begin
1815 Obj.X += dx;
1816 Obj.Y += dy;
1817 positionChanged();
1818 end;
1819 end;
1822 procedure TGib.positionChanged (); inline; begin end;
1823 procedure TShell.positionChanged (); inline; begin end;
1826 procedure g_Player_DrawCorpses();
1828 i: Integer;
1829 a: TDFPoint;
1830 begin
1831 if gGibs <> nil then
1832 for i := 0 to High(gGibs) do
1833 if gGibs[i].alive then
1834 with gGibs[i] do
1835 begin
1836 if not g_Obj_Collide(sX, sY, sWidth, sHeight, @Obj) then
1837 Continue;
1839 a.X := Obj.Rect.X+(Obj.Rect.Width div 2);
1840 a.y := Obj.Rect.Y+(Obj.Rect.Height div 2);
1842 e_DrawAdv(ID, Obj.X, Obj.Y, 0, True, False, RAngle, @a, TMirrorType.None);
1844 e_Colors := Color;
1845 e_DrawAdv(MaskID, Obj.X, Obj.Y, 0, True, False, RAngle, @a, TMirrorType.None);
1846 e_Colors.R := 255;
1847 e_Colors.G := 255;
1848 e_Colors.B := 255;
1849 end;
1851 if gCorpses <> nil then
1852 for i := 0 to High(gCorpses) do
1853 if gCorpses[i] <> nil then
1854 gCorpses[i].Draw();
1855 end;
1857 procedure g_Player_DrawShells();
1859 i: Integer;
1860 a: TDFPoint;
1861 begin
1862 if gShells <> nil then
1863 for i := 0 to High(gShells) do
1864 if gShells[i].alive then
1865 with gShells[i] do
1866 begin
1867 if not g_Obj_Collide(sX, sY, sWidth, sHeight, @Obj) then
1868 Continue;
1870 a.X := CX;
1871 a.Y := CY;
1873 e_DrawAdv(SpriteID, Obj.X, Obj.Y, 0, True, False, RAngle, @a, TMirrorType.None);
1874 end;
1875 end;
1877 procedure g_Player_RemoveAllCorpses();
1879 i: Integer;
1880 begin
1881 gGibs := nil;
1882 gShells := nil;
1883 SetLength(gGibs, MaxGibs);
1884 SetLength(gShells, MaxGibs);
1885 CurrentGib := 0;
1886 CurrentShell := 0;
1888 if gCorpses <> nil then
1889 for i := 0 to High(gCorpses) do
1890 gCorpses[i].Free();
1892 gCorpses := nil;
1893 SetLength(gCorpses, MaxCorpses);
1894 end;
1896 procedure g_Player_Corpses_SaveState (st: TStream);
1898 count, i: Integer;
1899 begin
1900 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ
1901 count := 0;
1902 for i := 0 to High(gCorpses) do if (gCorpses[i] <> nil) then Inc(count);
1904 // Êîëè÷åñòâî òðóïîâ
1905 utils.writeInt(st, LongInt(count));
1907 if (count = 0) then exit;
1909 // Ñîõðàíÿåì òðóïû
1910 for i := 0 to High(gCorpses) do
1911 begin
1912 if gCorpses[i] <> nil then
1913 begin
1914 // Íàçâàíèå ìîäåëè
1915 utils.writeStr(st, gCorpses[i].FModelName);
1916 // Òèï ñìåðòè
1917 utils.writeBool(st, gCorpses[i].Mess);
1918 // Ñîõðàíÿåì äàííûå òðóïà:
1919 gCorpses[i].SaveState(st);
1920 end;
1921 end;
1922 end;
1925 procedure g_Player_Corpses_LoadState (st: TStream);
1927 count, i: Integer;
1928 str: String;
1929 b: Boolean;
1930 begin
1931 assert(st <> nil);
1933 g_Player_RemoveAllCorpses();
1935 // Êîëè÷åñòâî òðóïîâ:
1936 count := utils.readLongInt(st);
1937 if (count < 0) or (count > Length(gCorpses)) then raise XStreamError.Create('invalid number of corpses');
1939 if (count = 0) then exit;
1941 // Çàãðóæàåì òðóïû
1942 for i := 0 to count-1 do
1943 begin
1944 // Íàçâàíèå ìîäåëè:
1945 str := utils.readStr(st);
1946 // Òèï ñìåðòè
1947 b := utils.readBool(st);
1948 // Ñîçäàåì òðóï
1949 gCorpses[i] := TCorpse.Create(0, 0, str, b);
1950 // Çàãðóæàåì äàííûå òðóïà
1951 gCorpses[i].LoadState(st);
1952 end;
1953 end;
1956 { T P l a y e r : }
1958 function TPlayer.isValidViewPort (): Boolean; inline; begin result := (viewPortW > 0) and (viewPortH > 0); end;
1960 procedure TPlayer.BFGHit();
1961 begin
1962 g_Weapon_BFGHit(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
1963 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2));
1964 if g_Game_IsServer and g_Game_IsNet then
1965 MH_SEND_Effect(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
1966 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
1967 0, NET_GFX_BFGHIT);
1968 end;
1970 procedure TPlayer.ChangeModel(ModelName: string);
1972 locModel: TPlayerModel;
1973 begin
1974 locModel := g_PlayerModel_Get(ModelName);
1975 if locModel = nil then Exit;
1977 FModel.Free();
1978 FModel := locModel;
1979 end;
1981 procedure TPlayer.SetModel(ModelName: string);
1983 m: TPlayerModel;
1984 begin
1985 m := g_PlayerModel_Get(ModelName);
1986 if m = nil then
1987 begin
1988 g_SimpleError(Format(_lc[I_GAME_ERROR_MODEL_FALLBACK], [ModelName]));
1989 m := g_PlayerModel_Get('doomer');
1990 if m = nil then
1991 begin
1992 g_FatalError(Format(_lc[I_GAME_ERROR_MODEL], ['doomer']));
1993 Exit;
1994 end;
1995 end;
1997 if FModel <> nil then
1998 FModel.Free();
2000 FModel := m;
2002 if not (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
2003 FModel.Color := FColor
2004 else
2005 FModel.Color := TEAMCOLOR[FTeam];
2006 FModel.SetWeapon(FCurrWeap);
2007 FModel.SetFlag(FFlag);
2008 SetDirection(FDirection);
2009 end;
2011 procedure TPlayer.SetColor(Color: TRGB);
2012 begin
2013 FColor := Color;
2014 if not (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
2015 if FModel <> nil then FModel.Color := Color;
2016 end;
2018 procedure TPlayer.SwitchTeam;
2019 begin
2020 if g_Game_IsClient then
2021 Exit;
2022 if not (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then Exit;
2024 if gGameOn and FAlive then
2025 Kill(K_SIMPLEKILL, FUID, HIT_SELF);
2027 if FTeam = TEAM_RED then
2028 begin
2029 ChangeTeam(TEAM_BLUE);
2030 g_Console_Add(Format(_lc[I_PLAYER_CHTEAM_BLUE], [FName]), True);
2031 if g_Game_IsNet then
2032 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM, TEAM_BLUE, FName);
2034 else
2035 begin
2036 ChangeTeam(TEAM_RED);
2037 g_Console_Add(Format(_lc[I_PLAYER_CHTEAM_RED], [FName]), True);
2038 if g_Game_IsNet then
2039 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM, TEAM_RED, FName);
2040 end;
2041 FPreferredTeam := FTeam;
2042 end;
2044 procedure TPlayer.ChangeTeam(Team: Byte);
2046 OldTeam: Byte;
2047 begin
2048 OldTeam := FTeam;
2049 FTeam := Team;
2050 case Team of
2051 TEAM_RED, TEAM_BLUE:
2052 FModel.Color := TEAMCOLOR[Team];
2053 else
2054 FModel.Color := FColor;
2055 end;
2056 if (FTeam <> OldTeam) and g_Game_IsNet and g_Game_IsServer then
2057 MH_SEND_PlayerStats(FUID);
2058 end;
2061 procedure TPlayer.CollideItem();
2063 i: Integer;
2064 r: Boolean;
2065 begin
2066 if gItems = nil then Exit;
2067 if not FAlive then Exit;
2069 for i := 0 to High(gItems) do
2070 with gItems[i] do
2071 begin
2072 if (ItemType <> ITEM_NONE) and alive then
2073 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
2074 PLAYER_RECT.Height, @Obj) then
2075 begin
2076 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
2078 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
2079 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
2080 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
2081 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
2082 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
2084 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
2085 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
2086 (gGameSettings.GameType = GT_SINGLE) and
2087 (g_Player_GetCount() > 1)) then
2088 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
2089 end;
2090 end;
2091 end;
2094 function TPlayer.CollideLevel(XInc, YInc: Integer): Boolean;
2095 begin
2096 Result := g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc,
2097 PLAYER_RECT.Width, PLAYER_RECT.Height, PANEL_WALL,
2098 False);
2099 end;
2101 constructor TPlayer.Create();
2102 begin
2103 viewPortX := 0;
2104 viewPortY := 0;
2105 viewPortW := 0;
2106 viewPortH := 0;
2107 mEDamageType := HIT_SOME;
2109 FIamBot := False;
2110 FDummy := False;
2111 FSpawned := False;
2113 FSawSound := TPlayableSound.Create();
2114 FSawSoundIdle := TPlayableSound.Create();
2115 FSawSoundHit := TPlayableSound.Create();
2116 FSawSoundSelect := TPlayableSound.Create();
2117 FJetSoundFly := TPlayableSound.Create();
2118 FJetSoundOn := TPlayableSound.Create();
2119 FJetSoundOff := TPlayableSound.Create();
2121 FSawSound.SetByName('SOUND_WEAPON_FIRESAW');
2122 FSawSoundIdle.SetByName('SOUND_WEAPON_IDLESAW');
2123 FSawSoundHit.SetByName('SOUND_WEAPON_HITSAW');
2124 FSawSoundSelect.SetByName('SOUND_WEAPON_SELECTSAW');
2125 FJetSoundFly.SetByName('SOUND_PLAYER_JETFLY');
2126 FJetSoundOn.SetByName('SOUND_PLAYER_JETON');
2127 FJetSoundOff.SetByName('SOUND_PLAYER_JETOFF');
2129 FSpectatePlayer := -1;
2130 FClientID := -1;
2131 FPing := 0;
2132 FLoss := 0;
2133 FSavedState.WaitRecall := False;
2134 FShellTimer := -1;
2135 FFireTime := 0;
2136 FFirePainTime := 0;
2137 FFireAttacker := 0;
2139 FActualModelName := 'doomer';
2141 g_Obj_Init(@FObj);
2142 FObj.Rect := PLAYER_RECT;
2144 FBFGFireCounter := -1;
2145 FJustTeleported := False;
2146 FNetTime := 0;
2148 //FNetForceWeap := FCurrWeap;
2149 FNetForceWeapFIdx := 0;
2150 //FCurrFrameIdx := 0;
2152 resetWeaponQueue();
2153 releaseAllWeaponSwitchKeys();
2154 end;
2157 procedure TPlayer.releaseAllWeaponSwitchKeys ();
2159 f: Integer;
2160 begin
2161 for f := 0 to High(weaponSwitchKeyReleased) do weaponSwitchKeyReleased[f] := $03;
2162 end;
2164 procedure TPlayer.weaponSwitchKeysStateChange (index: Integer; pressed: Boolean);
2165 begin
2166 Inc(index, 2); // -2: prev; -1: next
2167 if (index < 0) or (index > High(weaponSwitchKeyReleased)) then exit;
2168 weaponSwitchKeyReleased[index] := weaponSwitchKeyReleased[index] or $02;
2169 if (pressed) then weaponSwitchKeyReleased[index] := weaponSwitchKeyReleased[index] xor $02;
2170 end;
2172 function TPlayer.isWeaponSwitchKeyReleased (index: Integer): Boolean;
2173 begin
2174 Inc(index, 2); // -2: prev; -1: next
2175 if (index < 0) or (index > High(weaponSwitchKeyReleased)) then
2176 begin
2177 result := true;
2179 else
2180 begin
2181 result := (weaponSwitchKeyReleased[index] and $01) <> 0;
2182 end;
2183 end;
2185 procedure TPlayer.weaponSwitchKeysShiftNewStates ();
2187 f: Integer;
2188 begin
2189 // copy bit 1 to bit 0
2190 for f := 0 to High(weaponSwitchKeyReleased) do
2191 begin
2192 weaponSwitchKeyReleased[f] :=
2193 (weaponSwitchKeyReleased[f] and $02) or
2194 ((weaponSwitchKeyReleased[f] shr 1) and $01);
2195 end;
2196 end;
2199 procedure TPlayer.positionChanged (); inline;
2200 begin
2201 end;
2203 procedure TPlayer.doDamage (v: Integer);
2204 begin
2205 if (v <= 0) then exit;
2206 if (v > 32767) then v := 32767;
2207 Damage(v, 0, 0, 0, mEDamageType);
2208 end;
2210 procedure TPlayer.Damage(value: Word; SpawnerUID: Word; vx, vy: Integer; t: Byte);
2212 c: Word;
2213 begin
2214 if (not g_Game_IsClient) and (not FAlive) then
2215 Exit;
2217 FLastHit := t;
2219 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2220 if ((t = HIT_TRAP) or (t = HIT_SELF)) and (not FGodMode) then
2221 begin
2222 if not g_Game_IsClient then
2223 begin
2224 FArmor := 0;
2225 if t = HIT_TRAP then
2226 begin
2227 // Ëîâóøêà óáèâàåò ñðàçó:
2228 FHealth := -100;
2229 Kill(K_EXTRAHARDKILL, SpawnerUID, t);
2230 end;
2231 if t = HIT_SELF then
2232 begin
2233 // Ñàìîóáèéñòâî:
2234 FHealth := 0;
2235 Kill(K_SIMPLEKILL, SpawnerUID, t);
2236 end;
2237 end;
2238 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2239 FMegaRulez[MR_SUIT] := 0;
2240 FMegaRulez[MR_INVUL] := 0;
2241 FMegaRulez[MR_INVIS] := 0;
2242 FBerserk := 0;
2243 end;
2245 // Íî îò îñòàëüíîãî ñïàñàåò:
2246 if FMegaRulez[MR_INVUL] >= gTime then
2247 Exit;
2249 // ×èò-êîä "ÃÎÐÅÖ":
2250 if FGodMode then
2251 Exit;
2253 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2254 if LongBool(gGameSettings.Options and GAME_OPTION_TEAMDAMAGE) or
2255 (SpawnerUID = FUID) or
2256 (not SameTeam(FUID, SpawnerUID)) then
2257 begin
2258 FLastSpawnerUID := SpawnerUID;
2260 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2261 if gBloodCount > 0 then
2262 begin
2263 c := Min(value, 200)*gBloodCount + Random(Min(value, 200) div 2);
2264 if value div 4 <= c then
2265 c := c - (value div 4)
2266 else
2267 c := 0;
2269 if (t = HIT_SOME) and (vx = 0) and (vy = 0) then
2270 MakeBloodSimple(c)
2271 else
2272 case t of
2273 HIT_TRAP, HIT_ACID, HIT_FLAME, HIT_SELF: MakeBloodSimple(c);
2274 HIT_BFG, HIT_ROCKET, HIT_SOME: MakeBloodVector(c, vx, vy);
2275 end;
2277 if t = HIT_WATER then
2278 g_GFX_Bubbles(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2),
2279 FObj.Y+PLAYER_RECT.Y-4, value div 2, 8, 4);
2280 end;
2282 // Áóôåð óðîíà:
2283 if FAlive then
2284 Inc(FDamageBuffer, value);
2286 // Âñïûøêà áîëè:
2287 if gFlash <> 0 then
2288 FPain := FPain + value;
2289 end;
2291 if g_Game_IsServer and g_Game_IsNet then
2292 begin
2293 MH_SEND_PlayerDamage(FUID, t, SpawnerUID, value, vx, vy);
2294 MH_SEND_PlayerStats(FUID);
2295 MH_SEND_PlayerPos(False, FUID);
2296 end;
2297 end;
2299 function TPlayer.Heal(value: Word; Soft: Boolean): Boolean;
2300 begin
2301 Result := False;
2302 if g_Game_IsClient then
2303 Exit;
2304 if not FAlive then
2305 Exit;
2307 if Soft and (FHealth < PLAYER_HP_SOFT) then
2308 begin
2309 IncMax(FHealth, value, PLAYER_HP_SOFT);
2310 Result := True;
2311 end;
2312 if (not Soft) and (FHealth < PLAYER_HP_LIMIT) then
2313 begin
2314 IncMax(FHealth, value, PLAYER_HP_LIMIT);
2315 Result := True;
2316 end;
2318 if Result and g_Game_IsServer and g_Game_IsNet then
2319 MH_SEND_PlayerStats(FUID);
2320 end;
2322 destructor TPlayer.Destroy();
2323 begin
2324 if (gPlayer1 <> nil) and (gPlayer1.FUID = FUID) then
2325 gPlayer1 := nil;
2326 if (gPlayer2 <> nil) and (gPlayer2.FUID = FUID) then
2327 gPlayer2 := nil;
2329 FSawSound.Free();
2330 FSawSoundIdle.Free();
2331 FSawSoundHit.Free();
2332 FJetSoundFly.Free();
2333 FJetSoundOn.Free();
2334 FJetSoundOff.Free();
2335 FModel.Free();
2336 if FPunchAnim <> nil then
2337 FPunchAnim.Free();
2339 inherited;
2340 end;
2342 procedure TPlayer.DrawBubble();
2344 bubX, bubY: Integer;
2345 ID: LongWord;
2346 Rb, Gb, Bb,
2347 Rw, Gw, Bw: SmallInt;
2348 Dot: Byte;
2349 begin
2350 bubX := FObj.X+FObj.Rect.X + IfThen(FDirection = TDirection.D_LEFT, -4, 18);
2351 bubY := FObj.Y+FObj.Rect.Y - 18;
2352 Rb := 64;
2353 Gb := 64;
2354 Bb := 64;
2355 Rw := 240;
2356 Gw := 240;
2357 Bw := 240;
2358 case gChatBubble of
2359 1: // simple textual non-bubble
2360 begin
2361 bubX := FObj.X+FObj.Rect.X - 11;
2362 bubY := FObj.Y+FObj.Rect.Y - 17;
2363 e_TextureFontPrint(bubX, bubY, '[...]', gStdFont);
2364 Exit;
2365 end;
2366 2: // advanced pixel-perfect bubble
2367 begin
2368 if FTeam = TEAM_RED then
2369 Rb := 255
2370 else
2371 if FTeam = TEAM_BLUE then
2372 Bb := 255;
2373 end;
2374 3: // colored bubble
2375 begin
2376 Rb := FModel.Color.R;
2377 Gb := FModel.Color.G;
2378 Bb := FModel.Color.B;
2379 Rw := Min(Rb * 2 + 64, 255);
2380 Gw := Min(Gb * 2 + 64, 255);
2381 Bw := Min(Bb * 2 + 64, 255);
2382 if (Abs(Rw - Rb) < 32)
2383 or (Abs(Gw - Gb) < 32)
2384 or (Abs(Bw - Bb) < 32) then
2385 begin
2386 Rb := Max(Rw div 2 - 16, 0);
2387 Gb := Max(Gw div 2 - 16, 0);
2388 Bb := Max(Bw div 2 - 16, 0);
2389 end;
2390 end;
2391 4: // custom textured bubble
2392 begin
2393 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID) then
2394 if FDirection = TDirection.D_RIGHT then
2395 e_Draw(ID, bubX - 6, bubY - 7, 0, True, False)
2396 else
2397 e_Draw(ID, bubX - 6, bubY - 7, 0, True, False, TMirrorType.Horizontal);
2398 Exit;
2399 end;
2400 end;
2402 // Outer borders
2403 e_DrawQuad(bubX + 1, bubY , bubX + 18, bubY + 13, Rb, Gb, Bb);
2404 e_DrawQuad(bubX , bubY + 1, bubX + 19, bubY + 12, Rb, Gb, Bb);
2405 // Inner box
2406 e_DrawFillQuad(bubX + 1, bubY + 1, bubX + 18, bubY + 12, Rw, Gw, Bw, 0);
2408 // Tail
2409 Dot := IfThen(FDirection = TDirection.D_LEFT, 14, 5);
2410 e_DrawLine(1, bubX + Dot, bubY + 14, bubX + Dot, bubY + 16, Rb, Gb, Bb);
2411 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);
2412 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);
2413 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);
2414 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);
2416 // Dots
2417 Dot := 6;
2418 e_DrawFillQuad(bubX + Dot, bubY + 8, bubX + Dot + 1, bubY + 9, Rb, Gb, Bb, 0);
2419 e_DrawFillQuad(bubX + Dot + 3, bubY + 8, bubX + Dot + 4, bubY + 9, Rb, Gb, Bb, 0);
2420 e_DrawFillQuad(bubX + Dot + 6, bubY + 8, bubX + Dot + 7, bubY + 9, Rb, Gb, Bb, 0);
2421 end;
2423 procedure TPlayer.Draw();
2425 ID: DWORD;
2426 w, h: Word;
2427 dr: Boolean;
2428 Mirror: TMirrorType;
2429 begin
2430 if FAlive then
2431 begin
2432 if Direction = TDirection.D_RIGHT then
2433 Mirror := TMirrorType.None
2434 else
2435 Mirror := TMirrorType.Horizontal;
2437 if FPunchAnim <> nil then
2438 begin
2439 FPunchAnim.Draw(FObj.X+IfThen(Direction = TDirection.D_LEFT, 15-FObj.Rect.X, FObj.Rect.X-15),
2440 FObj.Y+FObj.Rect.Y-11, Mirror);
2441 if FPunchAnim.played then
2442 begin
2443 FPunchAnim.Free;
2444 FPunchAnim := nil;
2445 end;
2446 end;
2448 if (FMegaRulez[MR_INVUL] > gTime) and (gPlayerDrawn <> Self) then
2449 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID) then
2450 begin
2451 e_GetTextureSize(ID, @w, @h);
2452 if FDirection = TDirection.D_LEFT then
2453 e_Draw(ID, FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2)-(w div 2)+4,
2454 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2)-(h div 2)-7+FObj.slopeUpLeft, 0, True, False)
2455 else
2456 e_Draw(ID, FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2)-(w div 2)-2,
2457 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2)-(h div 2)-7+FObj.slopeUpLeft, 0, True, False);
2458 end;
2460 if FMegaRulez[MR_INVIS] > gTime then
2461 begin
2462 if (gPlayerDrawn <> nil) and ((Self = gPlayerDrawn) or
2463 ((FTeam = gPlayerDrawn.Team) and (gGameSettings.GameMode <> GM_DM))) then
2464 begin
2465 if (FMegaRulez[MR_INVIS] - gTime) <= 2100 then
2466 dr := not Odd((FMegaRulez[MR_INVIS] - gTime) div 300)
2467 else
2468 dr := True;
2469 if dr then
2470 FModel.Draw(FObj.X, FObj.Y+FObj.slopeUpLeft, 200)
2471 else
2472 FModel.Draw(FObj.X, FObj.Y+FObj.slopeUpLeft);
2474 else
2475 FModel.Draw(FObj.X, FObj.Y+FObj.slopeUpLeft, 254);
2477 else
2478 FModel.Draw(FObj.X, FObj.Y+FObj.slopeUpLeft);
2479 end;
2481 if g_debug_Frames then
2482 begin
2483 e_DrawQuad(FObj.X+FObj.Rect.X,
2484 FObj.Y+FObj.Rect.Y,
2485 FObj.X+FObj.Rect.X+FObj.Rect.Width-1,
2486 FObj.Y+FObj.Rect.Y+FObj.Rect.Height-1,
2487 0, 255, 0);
2488 end;
2490 if (gChatBubble > 0) and (FKeys[KEY_CHAT].Pressed) and not FGhost then
2491 DrawBubble();
2492 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2493 if gAimLine and alive and
2494 ((Self = gPlayer1) or (Self = gPlayer2)) then
2495 DrawAim();
2496 end;
2499 procedure TPlayer.DrawAim();
2500 procedure drawCast (sz: Integer; ax0, ay0, ax1, ay1: Integer);
2502 ex, ey: Integer;
2503 begin
2505 {$IFDEF ENABLE_HOLMES}
2506 if isValidViewPort and (self = gPlayer1) then
2507 begin
2508 g_Holmes_plrLaser(ax0, ay0, ax1, ay1);
2509 end;
2510 {$ENDIF}
2512 e_DrawLine(sz, ax0, ay0, ax1, ay1, 255, 0, 0, 96);
2513 if (g_Map_traceToNearestWall(ax0, ay0, ax1, ay1, @ex, @ey) <> nil) then
2514 begin
2515 e_DrawLine(sz, ax0, ay0, ex, ey, 0, 255, 0, 96);
2517 else
2518 begin
2519 e_DrawLine(sz, ax0, ay0, ex, ey, 0, 0, 255, 96);
2520 end;
2521 end;
2524 wx, wy, xx, yy: Integer;
2525 angle: SmallInt;
2526 sz, len: Word;
2527 begin
2528 wx := FObj.X + WEAPONPOINT[FDirection].X + IfThen(FDirection = TDirection.D_LEFT, 7, -7);
2529 wy := FObj.Y + WEAPONPOINT[FDirection].Y;
2530 angle := FAngle;
2531 len := 1024;
2532 sz := 2;
2533 case FCurrWeap of
2534 0: begin // Punch
2535 len := 12;
2536 sz := 4;
2537 end;
2538 1: begin // Chainsaw
2539 len := 24;
2540 sz := 6;
2541 end;
2542 2: begin // Pistol
2543 len := 1024;
2544 sz := 2;
2545 if angle = ANGLE_RIGHTUP then Dec(angle, 2);
2546 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2547 if angle = ANGLE_LEFTUP then Inc(angle, 2);
2548 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2549 end;
2550 3: begin // Shotgun
2551 len := 1024;
2552 sz := 3;
2553 if angle = ANGLE_RIGHTUP then Dec(angle, 2);
2554 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2555 if angle = ANGLE_LEFTUP then Inc(angle, 2);
2556 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2557 end;
2558 4: begin // Double Shotgun
2559 len := 1024;
2560 sz := 4;
2561 if angle = ANGLE_RIGHTUP then Dec(angle, 2);
2562 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2563 if angle = ANGLE_LEFTUP then Inc(angle, 2);
2564 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2565 end;
2566 5: begin // Chaingun
2567 len := 1024;
2568 sz := 3;
2569 if angle = ANGLE_RIGHTUP then Dec(angle, 2);
2570 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2571 if angle = ANGLE_LEFTUP then Inc(angle, 2);
2572 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2573 end;
2574 6: begin // Rocket Launcher
2575 len := 1024;
2576 sz := 7;
2577 if angle = ANGLE_RIGHTUP then Inc(angle, 2);
2578 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2579 if angle = ANGLE_LEFTUP then Dec(angle, 2);
2580 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2581 end;
2582 7: begin // Plasmagun
2583 len := 1024;
2584 sz := 5;
2585 if angle = ANGLE_RIGHTUP then Inc(angle);
2586 if angle = ANGLE_RIGHTDOWN then Inc(angle, 3);
2587 if angle = ANGLE_LEFTUP then Dec(angle);
2588 if angle = ANGLE_LEFTDOWN then Dec(angle, 3);
2589 end;
2590 8: begin // BFG
2591 len := 1024;
2592 sz := 12;
2593 if angle = ANGLE_RIGHTUP then Inc(angle, 1);
2594 if angle = ANGLE_RIGHTDOWN then Inc(angle, 2);
2595 if angle = ANGLE_LEFTUP then Dec(angle, 1);
2596 if angle = ANGLE_LEFTDOWN then Dec(angle, 2);
2597 end;
2598 9: begin // Super Chaingun
2599 len := 1024;
2600 sz := 4;
2601 if angle = ANGLE_RIGHTUP then Dec(angle, 2);
2602 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2603 if angle = ANGLE_LEFTUP then Inc(angle, 2);
2604 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2605 end;
2606 end;
2607 xx := Trunc(Cos(-DegToRad(angle)) * len) + wx;
2608 yy := Trunc(Sin(-DegToRad(angle)) * len) + wy;
2609 {$IF DEFINED(D2F_DEBUG)}
2610 drawCast(sz, wx, wy, xx, yy);
2611 {$ELSE}
2612 e_DrawLine(sz, wx, wy, xx, yy, 255, 0, 0, 96);
2613 {$ENDIF}
2614 end;
2616 procedure TPlayer.DrawGUI();
2618 ID: DWORD;
2619 X, Y, SY, a, p, m: Integer;
2620 tw, th: Word;
2621 cw, ch: Byte;
2622 s: string;
2623 stat: TPlayerStatArray;
2624 begin
2625 X := gPlayerScreenSize.X;
2626 SY := gPlayerScreenSize.Y;
2627 Y := 0;
2629 if gShowGoals and (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
2630 begin
2631 if gGameSettings.GameMode = GM_CTF then
2632 a := 32 + 8
2633 else
2634 a := 0;
2635 if gGameSettings.GameMode = GM_CTF then
2636 begin
2637 s := 'TEXTURE_PLAYER_REDFLAG';
2638 if gFlags[FLAG_RED].State = FLAG_STATE_CAPTURED then
2639 s := 'TEXTURE_PLAYER_REDFLAG_S';
2640 if gFlags[FLAG_RED].State = FLAG_STATE_DROPPED then
2641 s := 'TEXTURE_PLAYER_REDFLAG_D';
2642 if g_Texture_Get(s, ID) then
2643 e_Draw(ID, X-16-32, 240-72-4, 0, True, False);
2644 end;
2646 s := IntToStr(gTeamStat[TEAM_RED].Goals);
2647 e_CharFont_GetSize(gMenuFont, s, tw, th);
2648 e_CharFont_PrintEx(gMenuFont, X-16-a-tw, 240-72-4, s, TEAMCOLOR[TEAM_RED]);
2650 if gGameSettings.GameMode = GM_CTF then
2651 begin
2652 s := 'TEXTURE_PLAYER_BLUEFLAG';
2653 if gFlags[FLAG_BLUE].State = FLAG_STATE_CAPTURED then
2654 s := 'TEXTURE_PLAYER_BLUEFLAG_S';
2655 if gFlags[FLAG_BLUE].State = FLAG_STATE_DROPPED then
2656 s := 'TEXTURE_PLAYER_BLUEFLAG_D';
2657 if g_Texture_Get(s, ID) then
2658 e_Draw(ID, X-16-32, 240-32-4, 0, True, False);
2659 end;
2661 s := IntToStr(gTeamStat[TEAM_BLUE].Goals);
2662 e_CharFont_GetSize(gMenuFont, s, tw, th);
2663 e_CharFont_PrintEx(gMenuFont, X-16-a-tw, 240-32-4, s, TEAMCOLOR[TEAM_BLUE]);
2664 end;
2666 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID) then
2667 e_DrawFill(ID, X, 0, 1, (gPlayerScreenSize.Y div 256)+IfThen(gPlayerScreenSize.Y mod 256 > 0, 1, 0),
2668 0, False, False);
2670 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID) then
2671 e_Draw(ID, X+2, Y, 0, True, False);
2673 if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
2674 begin
2675 if gShowStat then
2676 begin
2677 s := IntToStr(Frags);
2678 e_CharFont_GetSize(gMenuFont, s, tw, th);
2679 e_CharFont_PrintEx(gMenuFont, X-16-tw, Y, s, _RGB(255, 0, 0));
2681 s := '';
2682 p := 1;
2683 m := 0;
2684 stat := g_Player_GetStats();
2685 if stat <> nil then
2686 begin
2687 p := 1;
2689 for a := 0 to High(stat) do
2690 if stat[a].Name <> Name then
2691 begin
2692 if stat[a].Frags > m then m := stat[a].Frags;
2693 if stat[a].Frags > Frags then p := p+1;
2694 end;
2695 end;
2697 s := IntToStr(p)+' / '+IntToStr(Length(stat))+' ';
2698 if Frags >= m then s := s+'+' else s := s+'-';
2699 s := s+IntToStr(Abs(Frags-m));
2701 e_CharFont_GetSize(gMenuSmallFont, s, tw, th);
2702 e_CharFont_PrintEx(gMenuSmallFont, X-16-tw, Y+32, s, _RGB(255, 0, 0));
2703 end;
2705 if gShowLives and (gGameSettings.MaxLives > 0) then
2706 begin
2707 s := IntToStr(Lives);
2708 e_CharFont_GetSize(gMenuFont, s, tw, th);
2709 e_CharFont_PrintEx(gMenuFont, X-16-tw, SY-32, s, _RGB(0, 255, 0));
2710 end;
2711 end;
2713 e_CharFont_GetSize(gMenuSmallFont, FName, tw, th);
2714 e_CharFont_PrintEx(gMenuSmallFont, X+98-(tw div 2), Y+8, FName, _RGB(255, 0, 0));
2716 if R_BERSERK in FRulez then
2717 e_Draw(gItemsTexturesID[ITEM_MEDKIT_BLACK], X+37, Y+45, 0, True, False)
2718 else
2719 e_Draw(gItemsTexturesID[ITEM_MEDKIT_LARGE], X+37, Y+45, 0, True, False);
2721 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID) then
2722 e_Draw(ID, X+36, Y+77, 0, True, False);
2724 s := IntToStr(IfThen(FHealth > 0, FHealth, 0));
2725 e_CharFont_GetSize(gMenuFont, s, tw, th);
2726 e_CharFont_PrintEx(gMenuFont, X+178-tw, Y+40, s, _RGB(255, 0, 0));
2728 s := IntToStr(FArmor);
2729 e_CharFont_GetSize(gMenuFont, s, tw, th);
2730 e_CharFont_PrintEx(gMenuFont, X+178-tw, Y+68, s, _RGB(255, 0, 0));
2732 s := IntToStr(GetAmmoByWeapon(FCurrWeap));
2734 case FCurrWeap of
2735 WEAPON_KASTET:
2736 begin
2737 s := '--';
2738 ID := gItemsTexturesID[ITEM_WEAPON_KASTET];
2739 end;
2740 WEAPON_SAW:
2741 begin
2742 s := '--';
2743 ID := gItemsTexturesID[ITEM_WEAPON_SAW];
2744 end;
2745 WEAPON_PISTOL: ID := gItemsTexturesID[ITEM_WEAPON_PISTOL];
2746 WEAPON_CHAINGUN: ID := gItemsTexturesID[ITEM_WEAPON_CHAINGUN];
2747 WEAPON_SHOTGUN1: ID := gItemsTexturesID[ITEM_WEAPON_SHOTGUN1];
2748 WEAPON_SHOTGUN2: ID := gItemsTexturesID[ITEM_WEAPON_SHOTGUN2];
2749 WEAPON_SUPERPULEMET: ID := gItemsTexturesID[ITEM_WEAPON_SUPERPULEMET];
2750 WEAPON_ROCKETLAUNCHER: ID := gItemsTexturesID[ITEM_WEAPON_ROCKETLAUNCHER];
2751 WEAPON_PLASMA: ID := gItemsTexturesID[ITEM_WEAPON_PLASMA];
2752 WEAPON_BFG: ID := gItemsTexturesID[ITEM_WEAPON_BFG];
2753 WEAPON_FLAMETHROWER: ID := gItemsTexturesID[ITEM_WEAPON_FLAMETHROWER];
2754 end;
2756 e_CharFont_GetSize(gMenuFont, s, tw, th);
2757 e_CharFont_PrintEx(gMenuFont, X+178-tw, Y+158, s, _RGB(255, 0, 0));
2758 e_Draw(ID, X+20, Y+160, 0, True, False);
2760 if R_KEY_RED in FRulez then
2761 e_Draw(gItemsTexturesID[ITEM_KEY_RED], X+78, Y+214, 0, True, False);
2763 if R_KEY_GREEN in FRulez then
2764 e_Draw(gItemsTexturesID[ITEM_KEY_GREEN], X+95, Y+214, 0, True, False);
2766 if R_KEY_BLUE in FRulez then
2767 e_Draw(gItemsTexturesID[ITEM_KEY_BLUE], X+112, Y+214, 0, True, False);
2769 if FJetFuel > 0 then
2770 begin
2771 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID) then
2772 e_Draw(ID, X+2, Y+116, 0, True, False);
2773 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID) then
2774 e_Draw(ID, X+2, Y+126, 0, True, False);
2775 e_DrawLine(4, X+16, Y+122, X+16+Trunc(168*IfThen(FAir > 0, FAir, 0)/AIR_MAX), Y+122, 0, 0, 196);
2776 e_DrawLine(4, X+16, Y+132, X+16+Trunc(168*FJetFuel/JET_MAX), Y+132, 208, 0, 0);
2778 else
2779 begin
2780 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID) then
2781 e_Draw(ID, X+2, Y+124, 0, True, False);
2782 e_DrawLine(4, X+16, Y+130, X+16+Trunc(168*IfThen(FAir > 0, FAir, 0)/AIR_MAX), Y+130, 0, 0, 196);
2783 end;
2785 if gShowPing and g_Game_IsClient then
2786 begin
2787 s := _lc[I_GAME_PING_HUD] + IntToStr(NetPeer.lastRoundTripTime) + _lc[I_NET_SLIST_PING_MS];
2788 e_TextureFontPrint(X + 4, Y + 242, s, gStdFont);
2789 Y := Y + 16;
2790 end;
2792 if FSpectator then
2793 begin
2794 e_TextureFontPrint(X + 4, Y + 242, _lc[I_PLAYER_SPECT], gStdFont);
2795 e_TextureFontPrint(X + 4, Y + 258, _lc[I_PLAYER_SPECT2], gStdFont);
2796 e_TextureFontPrint(X + 4, Y + 274, _lc[I_PLAYER_SPECT1], gStdFont);
2797 if FNoRespawn then
2798 begin
2799 e_TextureFontGetSize(gStdFont, cw, ch);
2800 s := _lc[I_PLAYER_SPECT4];
2801 e_TextureFontPrintEx(gScreenWidth div 2 - cw*(Length(s) div 2),
2802 gScreenHeight-4-ch, s, gStdFont, 255, 255, 255, 1, True);
2803 e_TextureFontPrint(X + 4, Y + 290, _lc[I_PLAYER_SPECT1S], gStdFont);
2804 end;
2806 end;
2807 end;
2809 procedure TPlayer.DrawRulez();
2811 dr: Boolean;
2812 begin
2813 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2814 if FMegaRulez[MR_INVUL] >= gTime then
2815 begin
2816 if (FMegaRulez[MR_INVUL]-gTime) <= 2100 then
2817 dr := not Odd((FMegaRulez[MR_INVUL]-gTime) div 300)
2818 else
2819 dr := True;
2821 if dr then
2822 e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1,
2823 191, 191, 191, 0, TBlending.Invert);
2824 end;
2826 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2827 if FMegaRulez[MR_SUIT] >= gTime then
2828 begin
2829 if (FMegaRulez[MR_SUIT]-gTime) <= 2100 then
2830 dr := not Odd((FMegaRulez[MR_SUIT]-gTime) div 300)
2831 else
2832 dr := True;
2834 if dr then
2835 e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1,
2836 0, 96, 0, 200, TBlending.None);
2837 end;
2839 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2840 if (FBerserk >= 0) and (LongWord(FBerserk) >= gTime) and (gFlash = 2) then
2841 begin
2842 e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1,
2843 255, 0, 0, 200, TBlending.None);
2844 end;
2845 end;
2847 procedure TPlayer.DrawPain();
2849 a, h: Integer;
2850 begin
2851 if FPain = 0 then Exit;
2853 a := FPain;
2855 if a < 15 then h := 0
2856 else if a < 35 then h := 1
2857 else if a < 55 then h := 2
2858 else if a < 75 then h := 3
2859 else if a < 95 then h := 4
2860 else h := 5;
2862 //if a > 255 then a := 255;
2864 e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255, 0, 0, 255-h*50);
2865 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2866 end;
2868 procedure TPlayer.DrawPickup();
2870 a, h: Integer;
2871 begin
2872 if FPickup = 0 then Exit;
2874 a := FPickup;
2876 if a < 15 then h := 1
2877 else if a < 35 then h := 2
2878 else if a < 55 then h := 3
2879 else if a < 75 then h := 4
2880 else h := 5;
2882 e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 150, 200, 150, 255-h*50);
2883 end;
2885 procedure TPlayer.DoPunch();
2887 id: DWORD;
2888 st: String;
2889 begin
2890 if FPunchAnim <> nil then begin
2891 FPunchAnim.reset();
2892 FPunchAnim.Free;
2893 FPunchAnim := nil;
2894 end;
2895 st := 'FRAMES_PUNCH';
2896 if R_BERSERK in FRulez then
2897 st := st + '_BERSERK';
2898 if FKeys[KEY_UP].Pressed then
2899 st := st + '_UP'
2900 else if FKeys[KEY_DOWN].Pressed then
2901 st := st + '_DN';
2902 g_Frames_Get(id, st);
2903 FPunchAnim := TAnimation.Create(id, False, 1);
2904 end;
2906 procedure TPlayer.Fire();
2908 f, DidFire: Boolean;
2909 wx, wy, xd, yd: Integer;
2910 locobj: TObj;
2911 begin
2912 if g_Game_IsClient then Exit;
2913 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
2914 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
2916 if FSpectator then
2917 begin
2918 Respawn(False);
2919 Exit;
2920 end;
2922 if FReloading[FCurrWeap] <> 0 then Exit;
2924 DidFire := False;
2926 f := False;
2927 wx := FObj.X+WEAPONPOINT[FDirection].X;
2928 wy := FObj.Y+WEAPONPOINT[FDirection].Y;
2929 xd := wx+IfThen(FDirection = TDirection.D_LEFT, -30, 30);
2930 yd := wy+firediry();
2932 case FCurrWeap of
2933 WEAPON_KASTET:
2934 begin
2935 DoPunch();
2936 if R_BERSERK in FRulez then
2937 begin
2938 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2939 locobj.X := FObj.X+FObj.Rect.X;
2940 locobj.Y := FObj.Y+FObj.Rect.Y;
2941 locobj.rect.X := 0;
2942 locobj.rect.Y := 0;
2943 locobj.rect.Width := 39;
2944 locobj.rect.Height := 52;
2945 locobj.Vel.X := (xd-wx) div 2;
2946 locobj.Vel.Y := (yd-wy) div 2;
2947 locobj.Accel.X := xd-wx;
2948 locobj.Accel.y := yd-wy;
2950 if g_Weapon_Hit(@locobj, 50, FUID, HIT_SOME) <> 0 then
2951 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj.X, FObj.Y)
2952 else
2953 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj.X, FObj.Y);
2955 if (gFlash = 1) and (FPain < 50) then FPain := min(FPain + 25, 50);
2957 else
2958 begin
2959 g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 3, FUID);
2960 end;
2962 DidFire := True;
2963 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
2964 end;
2966 WEAPON_SAW:
2967 begin
2968 if g_Weapon_chainsaw(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y,
2969 IfThen(gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF], 9, 3), FUID) <> 0 then
2970 begin
2971 FSawSoundSelect.Stop();
2972 FSawSound.Stop();
2973 FSawSoundHit.PlayAt(FObj.X, FObj.Y);
2975 else if not FSawSoundHit.IsPlaying() then
2976 begin
2977 FSawSoundSelect.Stop();
2978 FSawSound.PlayAt(FObj.X, FObj.Y);
2979 end;
2981 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
2982 DidFire := True;
2983 f := True;
2984 end;
2986 WEAPON_PISTOL:
2987 if FAmmo[A_BULLETS] > 0 then
2988 begin
2989 g_Weapon_pistol(wx, wy, xd, yd, FUID);
2990 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
2991 Dec(FAmmo[A_BULLETS]);
2992 FFireAngle := FAngle;
2993 f := True;
2994 DidFire := True;
2995 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
2996 GameVelX, GameVelY-2, SHELL_BULLET);
2997 end;
2999 WEAPON_SHOTGUN1:
3000 if FAmmo[A_SHELLS] > 0 then
3001 begin
3002 g_Weapon_shotgun(wx, wy, xd, yd, FUID);
3003 if not gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx, wy);
3004 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3005 Dec(FAmmo[A_SHELLS]);
3006 FFireAngle := FAngle;
3007 f := True;
3008 DidFire := True;
3009 FShellTimer := 10;
3010 FShellType := SHELL_SHELL;
3011 end;
3013 WEAPON_SHOTGUN2:
3014 if FAmmo[A_SHELLS] >= 2 then
3015 begin
3016 g_Weapon_dshotgun(wx, wy, xd, yd, FUID);
3017 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3018 Dec(FAmmo[A_SHELLS], 2);
3019 FFireAngle := FAngle;
3020 f := True;
3021 DidFire := True;
3022 FShellTimer := 13;
3023 FShellType := SHELL_DBLSHELL;
3024 end;
3026 WEAPON_CHAINGUN:
3027 if FAmmo[A_BULLETS] > 0 then
3028 begin
3029 g_Weapon_mgun(wx, wy, xd, yd, FUID);
3030 if not gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx, wy);
3031 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3032 Dec(FAmmo[A_BULLETS]);
3033 FFireAngle := FAngle;
3034 f := True;
3035 DidFire := True;
3036 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
3037 GameVelX, GameVelY-2, SHELL_BULLET);
3038 end;
3040 WEAPON_ROCKETLAUNCHER:
3041 if FAmmo[A_ROCKETS] > 0 then
3042 begin
3043 g_Weapon_rocket(wx, wy, xd, yd, FUID);
3044 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3045 Dec(FAmmo[A_ROCKETS]);
3046 FFireAngle := FAngle;
3047 f := True;
3048 DidFire := True;
3049 end;
3051 WEAPON_PLASMA:
3052 if FAmmo[A_CELLS] > 0 then
3053 begin
3054 g_Weapon_plasma(wx, wy, xd, yd, FUID);
3055 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3056 Dec(FAmmo[A_CELLS]);
3057 FFireAngle := FAngle;
3058 f := True;
3059 DidFire := True;
3060 end;
3062 WEAPON_BFG:
3063 if (FAmmo[A_CELLS] >= 40) and (FBFGFireCounter = -1) then
3064 begin
3065 FBFGFireCounter := 17;
3066 if not FNoReload then
3067 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj.X, FObj.Y);
3068 Dec(FAmmo[A_CELLS], 40);
3069 DidFire := True;
3070 end;
3072 WEAPON_SUPERPULEMET:
3073 if FAmmo[A_SHELLS] > 0 then
3074 begin
3075 g_Weapon_shotgun(wx, wy, xd, yd, FUID);
3076 if not gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx, wy);
3077 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3078 Dec(FAmmo[A_SHELLS]);
3079 FFireAngle := FAngle;
3080 f := True;
3081 DidFire := True;
3082 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
3083 GameVelX, GameVelY-2, SHELL_SHELL);
3084 end;
3086 WEAPON_FLAMETHROWER:
3087 if FAmmo[A_FUEL] > 0 then
3088 begin
3089 g_Weapon_flame(wx, wy, xd, yd, FUID);
3090 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3091 Dec(FAmmo[A_FUEL]);
3092 FFireAngle := FAngle;
3093 f := True;
3094 DidFire := True;
3095 end;
3096 end;
3098 if g_Game_IsNet then
3099 begin
3100 if DidFire then
3101 begin
3102 if FCurrWeap <> WEAPON_BFG then
3103 MH_SEND_PlayerFire(FUID, FCurrWeap, wx, wy, xd, yd, LastShotID)
3104 else
3105 if not FNoReload then
3106 MH_SEND_Sound(FObj.X, FObj.Y, 'SOUND_WEAPON_STARTFIREBFG');
3107 end;
3109 MH_SEND_PlayerStats(FUID);
3110 end;
3112 if not f then Exit;
3114 if (FAngle = 0) or (FAngle = 180) then SetAction(A_ATTACK)
3115 else if (FAngle = ANGLE_LEFTDOWN) or (FAngle = ANGLE_RIGHTDOWN) then SetAction(A_ATTACKDOWN)
3116 else if (FAngle = ANGLE_LEFTUP) or (FAngle = ANGLE_RIGHTUP) then SetAction(A_ATTACKUP);
3117 end;
3119 function TPlayer.GetAmmoByWeapon(Weapon: Byte): Word;
3120 begin
3121 case Weapon of
3122 WEAPON_PISTOL, WEAPON_CHAINGUN: Result := FAmmo[A_BULLETS];
3123 WEAPON_SHOTGUN1, WEAPON_SHOTGUN2, WEAPON_SUPERPULEMET: Result := FAmmo[A_SHELLS];
3124 WEAPON_ROCKETLAUNCHER: Result := FAmmo[A_ROCKETS];
3125 WEAPON_PLASMA, WEAPON_BFG: Result := FAmmo[A_CELLS];
3126 WEAPON_FLAMETHROWER: Result := FAmmo[A_FUEL];
3127 else Result := 0;
3128 end;
3129 end;
3131 function TPlayer.HeadInLiquid(XInc, YInc: Integer): Boolean;
3132 begin
3133 Result := g_Map_CollidePanel(FObj.X+PLAYER_HEADRECT.X+XInc, FObj.Y+PLAYER_HEADRECT.Y+YInc,
3134 PLAYER_HEADRECT.Width, PLAYER_HEADRECT.Height,
3135 PANEL_WATER or PANEL_ACID1 or PANEL_ACID2, True);
3136 end;
3138 procedure TPlayer.JetpackOn;
3139 begin
3140 FJetSoundFly.Stop;
3141 FJetSoundOff.Stop;
3142 FJetSoundOn.SetPosition(0);
3143 FJetSoundOn.PlayAt(FObj.X, FObj.Y);
3144 FlySmoke(8);
3145 end;
3147 procedure TPlayer.JetpackOff;
3148 begin
3149 FJetSoundFly.Stop;
3150 FJetSoundOn.Stop;
3151 FJetSoundOff.SetPosition(0);
3152 FJetSoundOff.PlayAt(FObj.X, FObj.Y);
3153 end;
3155 procedure TPlayer.CatchFire(Attacker: Word);
3156 begin
3157 FFireTime := 100;
3158 FFireAttacker := Attacker;
3159 if g_Game_IsNet and g_Game_IsServer then
3160 MH_SEND_PlayerStats(FUID);
3161 end;
3163 procedure TPlayer.Jump();
3164 begin
3165 if gFly or FJetpack then
3166 begin
3167 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
3168 if FObj.Vel.Y > -VEL_FLY then
3169 FObj.Vel.Y := FObj.Vel.Y - 3;
3170 if FJetpack then
3171 begin
3172 if FJetFuel > 0 then
3173 Dec(FJetFuel);
3174 if (FJetFuel < 1) and g_Game_IsServer then
3175 begin
3176 FJetpack := False;
3177 JetpackOff;
3178 if g_Game_IsNet then
3179 MH_SEND_PlayerStats(FUID);
3180 end;
3181 end;
3182 Exit;
3183 end;
3185 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
3186 if FGhost then
3187 FCanJetpack := False;
3189 // Ïðûãàåì èëè âñïëûâàåì:
3190 if (CollideLevel(0, 1) or
3191 g_Map_CollidePanel(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y+36, PLAYER_RECT.Width,
3192 PLAYER_RECT.Height-33, PANEL_STEP, False)
3193 ) and (FObj.Accel.Y = 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
3194 begin
3195 FObj.Vel.Y := -VEL_JUMP;
3196 FCanJetpack := False;
3198 else
3199 begin
3200 if BodyInLiquid(0, 0) then
3201 FObj.Vel.Y := -VEL_SW
3202 else if (FJetFuel > 0) and FCanJetpack and
3203 g_Game_IsServer and (not g_Obj_CollideLiquid(@FObj, 0, 0)) then
3204 begin
3205 FJetpack := True;
3206 JetpackOn;
3207 if g_Game_IsNet then
3208 MH_SEND_PlayerStats(FUID);
3209 end;
3210 end;
3211 end;
3213 procedure TPlayer.Kill(KillType: Byte; SpawnerUID: Word; t: Byte);
3215 a, i, k, ab, ar: Byte;
3216 s: String;
3217 mon: TMonster;
3218 plr: TPlayer;
3219 srv, netsrv: Boolean;
3220 DoFrags: Boolean;
3221 OldLR: Byte;
3222 KP: TPlayer;
3223 it: PItem;
3225 procedure PushItem(t: Byte);
3227 id: DWORD;
3228 begin
3229 id := g_Items_Create(FObj.X, FObj.Y, t, True, False);
3230 it := g_Items_ByIdx(id);
3231 if KillType = K_EXTRAHARDKILL then // -7..+7; -8..0
3232 begin
3233 g_Obj_Push(@it.Obj, (FObj.Vel.X div 2)-7+Random(15),
3234 (FObj.Vel.Y div 2)-Random(9));
3235 it.positionChanged(); // this updates spatial accelerators
3237 else
3238 begin
3239 if KillType = K_HARDKILL then // -5..+5; -5..0
3240 begin
3241 g_Obj_Push(@it.Obj, (FObj.Vel.X div 2)-5+Random(11),
3242 (FObj.Vel.Y div 2)-Random(6));
3244 else // -3..+3; -3..0
3245 begin
3246 g_Obj_Push(@it.Obj, (FObj.Vel.X div 2)-3+Random(7),
3247 (FObj.Vel.Y div 2)-Random(4));
3248 end;
3249 it.positionChanged(); // this updates spatial accelerators
3250 end;
3252 if g_Game_IsNet and g_Game_IsServer then
3253 MH_SEND_ItemSpawn(True, id);
3254 end;
3256 begin
3257 DoFrags := (gGameSettings.MaxLives = 0) or (gGameSettings.GameMode = GM_COOP);
3258 Srv := g_Game_IsServer;
3259 Netsrv := g_Game_IsServer and g_Game_IsNet;
3260 if Srv then FDeath := FDeath + 1;
3261 if FAlive then
3262 begin
3263 if FGhost then
3264 FGhost := False;
3265 if not FPhysics then
3266 FPhysics := True;
3267 FAlive := False;
3268 end;
3269 FShellTimer := -1;
3271 if (gGameSettings.MaxLives > 0) and Srv and (gLMSRespawn = LMS_RESPAWN_NONE) then
3272 begin
3273 if FLives > 0 then FLives := FLives - 1;
3274 if FLives = 0 then FNoRespawn := True;
3275 end;
3277 // Íîìåð òèïà ñìåðòè:
3278 a := 1;
3279 case KillType of
3280 K_SIMPLEKILL: a := 1;
3281 K_HARDKILL: a := 2;
3282 K_EXTRAHARDKILL: a := 3;
3283 K_FALLKILL: a := 4;
3284 end;
3286 // Çâóê ñìåðòè:
3287 if not FModel.PlaySound(MODELSOUND_DIE, a, FObj.X, FObj.Y) then
3288 for i := 1 to 3 do
3289 if FModel.PlaySound(MODELSOUND_DIE, i, FObj.X, FObj.Y) then
3290 Break;
3292 // Âðåìÿ ðåñïàóíà:
3293 if Srv then
3294 case KillType of
3295 K_SIMPLEKILL:
3296 FTime[T_RESPAWN] := gTime + TIME_RESPAWN1;
3297 K_HARDKILL:
3298 FTime[T_RESPAWN] := gTime + TIME_RESPAWN2;
3299 K_EXTRAHARDKILL, K_FALLKILL:
3300 FTime[T_RESPAWN] := gTime + TIME_RESPAWN3;
3301 end;
3303 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3304 case KillType of
3305 K_SIMPLEKILL:
3306 SetAction(A_DIE1);
3307 K_HARDKILL, K_EXTRAHARDKILL:
3308 SetAction(A_DIE2);
3309 end;
3311 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3312 if (KillType <> K_FALLKILL) and (Srv) then
3313 g_Monsters_killedp();
3315 if SpawnerUID = FUID then
3316 begin // Ñàìîóáèëñÿ
3317 if Srv and (DoFrags or (gGameSettings.GameMode = GM_TDM)) then
3318 begin
3319 Dec(FFrags);
3320 FLastFrag := 0;
3321 end;
3322 g_Console_Add(Format(_lc[I_PLAYER_KILL_SELF], [FName]), True);
3324 else
3325 if g_GetUIDType(SpawnerUID) = UID_PLAYER then
3326 begin // Óáèò äðóãèì èãðîêîì
3327 KP := g_Player_Get(SpawnerUID);
3328 if (KP <> nil) and Srv then
3329 begin
3330 if (DoFrags or (gGameSettings.GameMode = GM_TDM)) then
3331 if SameTeam(FUID, SpawnerUID) then
3332 begin
3333 Dec(KP.FFrags);
3334 KP.FLastFrag := 0;
3335 end else
3336 begin
3337 Inc(KP.FFrags);
3338 KP.FragCombo();
3339 end;
3341 if (gGameSettings.GameMode = GM_TDM) and DoFrags then
3342 Inc(gTeamStat[KP.Team].Goals,
3343 IfThen(SameTeam(FUID, SpawnerUID), -1, 1));
3345 if netsrv then MH_SEND_PlayerStats(SpawnerUID);
3346 end;
3348 plr := g_Player_Get(SpawnerUID);
3349 if plr = nil then
3350 s := '?'
3351 else
3352 s := plr.FName;
3354 case KillType of
3355 K_HARDKILL:
3356 g_Console_Add(Format(_lc[I_PLAYER_KILL_EXTRAHARD_2],
3357 [FName, s]),
3358 gShowKillMsg);
3359 K_EXTRAHARDKILL:
3360 g_Console_Add(Format(_lc[I_PLAYER_KILL_EXTRAHARD_1],
3361 [FName, s]),
3362 gShowKillMsg);
3363 else
3364 g_Console_Add(Format(_lc[I_PLAYER_KILL],
3365 [FName, s]),
3366 gShowKillMsg);
3367 end;
3369 else if g_GetUIDType(SpawnerUID) = UID_MONSTER then
3370 begin // Óáèò ìîíñòðîì
3371 mon := g_Monsters_ByUID(SpawnerUID);
3372 if mon = nil then
3373 s := '?'
3374 else
3375 s := g_Mons_GetKilledByTypeId(mon.MonsterType);
3377 case KillType of
3378 K_HARDKILL:
3379 g_Console_Add(Format(_lc[I_PLAYER_KILL_EXTRAHARD_2],
3380 [FName, s]),
3381 gShowKillMsg);
3382 K_EXTRAHARDKILL:
3383 g_Console_Add(Format(_lc[I_PLAYER_KILL_EXTRAHARD_1],
3384 [FName, s]),
3385 gShowKillMsg);
3386 else
3387 g_Console_Add(Format(_lc[I_PLAYER_KILL],
3388 [FName, s]),
3389 gShowKillMsg);
3390 end;
3392 else // Îñîáûå òèïû ñìåðòè
3393 case t of
3394 HIT_DISCON: ;
3395 HIT_SELF: g_Console_Add(Format(_lc[I_PLAYER_KILL_SELF], [FName]), True);
3396 HIT_FALL: g_Console_Add(Format(_lc[I_PLAYER_KILL_FALL], [FName]), True);
3397 HIT_WATER: g_Console_Add(Format(_lc[I_PLAYER_KILL_WATER], [FName]), True);
3398 HIT_ACID: g_Console_Add(Format(_lc[I_PLAYER_KILL_ACID], [FName]), True);
3399 HIT_TRAP: g_Console_Add(Format(_lc[I_PLAYER_KILL_TRAP], [FName]), True);
3400 else g_Console_Add(Format(_lc[I_PLAYER_DIED], [FName]), True);
3401 end;
3403 if Srv then
3404 begin
3405 // Âûáðîñ îðóæèÿ:
3406 for a := WP_FIRST to WP_LAST do
3407 if FWeapon[a] then
3408 begin
3409 case a of
3410 WEAPON_SAW: i := ITEM_WEAPON_SAW;
3411 WEAPON_SHOTGUN1: i := ITEM_WEAPON_SHOTGUN1;
3412 WEAPON_SHOTGUN2: i := ITEM_WEAPON_SHOTGUN2;
3413 WEAPON_CHAINGUN: i := ITEM_WEAPON_CHAINGUN;
3414 WEAPON_ROCKETLAUNCHER: i := ITEM_WEAPON_ROCKETLAUNCHER;
3415 WEAPON_PLASMA: i := ITEM_WEAPON_PLASMA;
3416 WEAPON_BFG: i := ITEM_WEAPON_BFG;
3417 WEAPON_SUPERPULEMET: i := ITEM_WEAPON_SUPERPULEMET;
3418 WEAPON_FLAMETHROWER: i := ITEM_WEAPON_FLAMETHROWER;
3419 else i := 0;
3420 end;
3422 if i <> 0 then
3423 PushItem(i);
3424 end;
3426 // Âûáðîñ ðþêçàêà:
3427 if R_ITEM_BACKPACK in FRulez then
3428 PushItem(ITEM_AMMO_BACKPACK);
3430 // Âûáðîñ ðàêåòíîãî ðàíöà:
3431 if FJetFuel > 0 then
3432 PushItem(ITEM_JETPACK);
3434 // Âûáðîñ êëþ÷åé:
3435 if not (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF]) then
3436 begin
3437 if R_KEY_RED in FRulez then
3438 PushItem(ITEM_KEY_RED);
3440 if R_KEY_GREEN in FRulez then
3441 PushItem(ITEM_KEY_GREEN);
3443 if R_KEY_BLUE in FRulez then
3444 PushItem(ITEM_KEY_BLUE);
3445 end;
3447 // Âûáðîñ ôëàãà:
3448 DropFlag();
3449 end;
3451 g_Player_CreateCorpse(Self);
3453 if Srv and (gGameSettings.MaxLives > 0) and FNoRespawn and
3454 (gLMSRespawn = LMS_RESPAWN_NONE) then
3455 begin
3456 a := 0;
3457 k := 0;
3458 ar := 0;
3459 ab := 0;
3460 for i := Low(gPlayers) to High(gPlayers) do
3461 begin
3462 if gPlayers[i] = nil then continue;
3463 if (not gPlayers[i].FNoRespawn) and (not gPlayers[i].FSpectator) then
3464 begin
3465 Inc(a);
3466 if gPlayers[i].FTeam = TEAM_RED then Inc(ar)
3467 else if gPlayers[i].FTeam = TEAM_BLUE then Inc(ab);
3468 k := i;
3469 end;
3470 end;
3472 OldLR := gLMSRespawn;
3473 if (gGameSettings.GameMode = GM_COOP) then
3474 begin
3475 if (a = 0) then
3476 begin
3477 // everyone is dead, restart the map
3478 g_Game_Message(_lc[I_MESSAGE_LMS_LOSE], 144);
3479 if Netsrv then
3480 MH_SEND_GameEvent(NET_EV_LMS_LOSE);
3481 gLMSRespawn := LMS_RESPAWN_FINAL;
3482 gLMSRespawnTime := gTime + 5000;
3484 else if (a = 1) then
3485 begin
3486 if (gPlayers[k] <> nil) and not (gPlayers[k] is TBot) then
3487 if (gPlayers[k] = gPlayer1) or
3488 (gPlayers[k] = gPlayer2) then
3489 g_Console_Add('*** ' + _lc[I_MESSAGE_LMS_SURVIVOR] + ' ***', True)
3490 else if Netsrv and (gPlayers[k].FClientID >= 0) then
3491 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR, 0, 'N', gPlayers[k].FClientID);
3492 end;
3494 else if (gGameSettings.GameMode = GM_TDM) then
3495 begin
3496 if (ab = 0) and (ar <> 0) then
3497 begin
3498 // blu team ded
3499 g_Game_Message(Format(_lc[I_MESSAGE_TLMS_WIN], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 144);
3500 if Netsrv then
3501 MH_SEND_GameEvent(NET_EV_TLMS_WIN, TEAM_RED);
3502 Inc(gTeamStat[TEAM_RED].Goals);
3503 gLMSRespawn := LMS_RESPAWN_FINAL;
3504 gLMSRespawnTime := gTime + 5000;
3506 else if (ar = 0) and (ab <> 0) then
3507 begin
3508 // red team ded
3509 g_Game_Message(Format(_lc[I_MESSAGE_TLMS_WIN], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 144);
3510 if Netsrv then
3511 MH_SEND_GameEvent(NET_EV_TLMS_WIN, TEAM_BLUE);
3512 Inc(gTeamStat[TEAM_BLUE].Goals);
3513 gLMSRespawn := LMS_RESPAWN_FINAL;
3514 gLMSRespawnTime := gTime + 5000;
3516 else if (ar = 0) and (ab = 0) then
3517 begin
3518 // everyone ded
3519 g_Game_Message(_lc[I_GAME_WIN_DRAW], 144);
3520 if Netsrv then
3521 MH_SEND_GameEvent(NET_EV_LMS_DRAW, 0, FName);
3522 gLMSRespawn := LMS_RESPAWN_FINAL;
3523 gLMSRespawnTime := gTime + 5000;
3524 end;
3526 else if (gGameSettings.GameMode = GM_DM) then
3527 begin
3528 if (a = 1) then
3529 begin
3530 if gPlayers[k] <> nil then
3531 with gPlayers[k] do
3532 begin
3533 // survivor is the winner
3534 g_Game_Message(Format(_lc[I_MESSAGE_LMS_WIN], [AnsiUpperCase(FName)]), 144);
3535 if Netsrv then
3536 MH_SEND_GameEvent(NET_EV_LMS_WIN, 0, FName);
3537 Inc(FFrags);
3538 end;
3539 gLMSRespawn := LMS_RESPAWN_FINAL;
3540 gLMSRespawnTime := gTime + 5000;
3542 else if (a = 0) then
3543 begin
3544 // everyone is dead, restart the map
3545 g_Game_Message(_lc[I_GAME_WIN_DRAW], 144);
3546 if Netsrv then
3547 MH_SEND_GameEvent(NET_EV_LMS_DRAW, 0, FName);
3548 gLMSRespawn := LMS_RESPAWN_FINAL;
3549 gLMSRespawnTime := gTime + 5000;
3550 end;
3551 end;
3552 if srv and (OldLR = LMS_RESPAWN_NONE) and (gLMSRespawn > LMS_RESPAWN_NONE) then
3553 begin
3554 if NetMode = NET_SERVER then
3555 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, (gLMSRespawnTime - gTime) div 1000)
3556 else
3557 g_Console_Add(Format(_lc[I_MSG_WARMUP_START], [(gLMSRespawnTime - gTime) div 1000]), True);
3558 end;
3559 end;
3561 if Netsrv then
3562 begin
3563 MH_SEND_PlayerStats(FUID);
3564 MH_SEND_PlayerDeath(FUID, KillType, t, SpawnerUID);
3565 if gGameSettings.GameMode = GM_TDM then MH_SEND_GameStats;
3566 end;
3568 if srv and FNoRespawn then Spectate(True);
3569 FWantsInGame := True;
3570 end;
3572 function TPlayer.BodyInLiquid(XInc, YInc: Integer): Boolean;
3573 begin
3574 Result := g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc, PLAYER_RECT.Width,
3575 PLAYER_RECT.Height-20, PANEL_WATER or PANEL_ACID1 or PANEL_ACID2, False);
3576 end;
3578 function TPlayer.BodyInAcid(XInc, YInc: Integer): Boolean;
3579 begin
3580 Result := g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc, PLAYER_RECT.Width,
3581 PLAYER_RECT.Height-20, PANEL_ACID1 or PANEL_ACID2, False);
3582 end;
3584 procedure TPlayer.MakeBloodSimple(Count: Word);
3585 begin
3586 g_GFX_Blood(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)+8,
3587 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2),
3588 Count div 2, 3, -1, 16, (PLAYER_RECT.Height*2 div 3),
3589 FModel.Blood.R, FModel.Blood.G, FModel.Blood.B, FModel.Blood.Kind);
3590 g_GFX_Blood(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-8,
3591 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2),
3592 Count div 2, -3, -1, 16, (PLAYER_RECT.Height*2) div 3,
3593 FModel.Blood.R, FModel.Blood.G, FModel.Blood.B, FModel.Blood.Kind);
3594 end;
3596 procedure TPlayer.MakeBloodVector(Count: Word; VelX, VelY: Integer);
3597 begin
3598 g_GFX_Blood(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2),
3599 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2),
3600 Count, VelX, VelY, 16, (PLAYER_RECT.Height*2) div 3,
3601 FModel.Blood.R, FModel.Blood.G, FModel.Blood.B, FModel.Blood.Kind);
3602 end;
3604 procedure TPlayer.QueueWeaponSwitch(Weapon: Byte);
3605 begin
3606 //if g_Game_IsClient then Exit;
3607 if Weapon > High(FWeapon) then Exit;
3608 FNextWeap := FNextWeap or (1 shl Weapon);
3609 end;
3611 procedure TPlayer.resetWeaponQueue ();
3612 begin
3613 FNextWeap := 0;
3614 FNextWeapDelay := 0;
3615 end;
3617 function TPlayer.hasAmmoForWeapon (weapon: Byte): Boolean;
3618 begin
3619 result := false;
3620 case weapon of
3621 WEAPON_KASTET, WEAPON_SAW: result := true;
3622 WEAPON_SHOTGUN1, WEAPON_SHOTGUN2, WEAPON_SUPERPULEMET: result := (FAmmo[A_SHELLS] > 0);
3623 WEAPON_PISTOL, WEAPON_CHAINGUN: result := (FAmmo[A_BULLETS] > 0);
3624 WEAPON_ROCKETLAUNCHER: result := (FAmmo[A_ROCKETS] > 0);
3625 WEAPON_PLASMA, WEAPON_BFG: result := (FAmmo[A_CELLS] > 0);
3626 WEAPON_FLAMETHROWER: result := (FAmmo[A_FUEL] > 0);
3627 else result := (weapon < length(FWeapon));
3628 end;
3629 end;
3631 // return 255 for "no switch"
3632 function TPlayer.getNextWeaponIndex (): Byte;
3634 i: Word;
3635 wantThisWeapon: array[0..64] of Boolean;
3636 weaponOrder: array[0..16] of Integer; // value: index in `FWeapon`
3637 wwc: Integer;
3638 f, dir, cwi, rwidx, curlidx: Integer;
3640 function real2log (ridx: Integer): Integer;
3642 f: Integer;
3643 begin
3644 if (ridx >= 0) then
3645 begin
3646 for f := 0 to High(weaponOrder) do if (weaponOrder[f] = ridx) then begin result := f; exit; end;
3647 end;
3648 result := -1;
3649 end;
3651 begin
3652 result := 255; // default result: "no switch"
3654 // had weapon cycling on previous frame? remove that flag
3655 if (FNextWeap and $2000) <> 0 then
3656 begin
3657 FNextWeap := FNextWeap and $1FFF;
3658 FNextWeapDelay := 0;
3659 end;
3661 for f := 0 to High(weaponOrder) do weaponOrder[f] := -1;
3663 // build weapon order (k8: i know, i know, learn how to do constants and such... gtfo, please!)
3664 // two knuckles are for "normal" and "berserk" (see `if` below -- it removes the one that is not needed)
3665 // priorities:
3666 // bfg, launcher, plasma, flamethrower, ssg, minigun, sg, pistol, berserk, chainsaw, fist
3667 weaponOrder[0] := WEAPON_SUPERPULEMET;
3668 weaponOrder[1] := WEAPON_BFG;
3669 weaponOrder[2] := WEAPON_ROCKETLAUNCHER;
3670 weaponOrder[3] := WEAPON_PLASMA;
3671 weaponOrder[4] := WEAPON_FLAMETHROWER;
3672 weaponOrder[5] := WEAPON_SHOTGUN2;
3673 weaponOrder[6] := WEAPON_CHAINGUN;
3674 weaponOrder[7] := WEAPON_SHOTGUN1;
3675 weaponOrder[8] := WEAPON_PISTOL;
3676 weaponOrder[9] := WEAPON_KASTET+666; // berserk fist
3677 weaponOrder[10] := WEAPON_SAW;
3678 weaponOrder[11] := WEAPON_KASTET; // normal fist
3680 for f := 0 to High(weaponOrder) do
3681 begin
3682 if (weaponOrder[f] = WEAPON_KASTET) then
3683 begin
3684 // normal fist: remove if we have a berserk pack
3685 if (R_BERSERK in FRulez) then weaponOrder[f] := -1;
3687 else
3688 if (weaponOrder[f] = WEAPON_KASTET+666) then
3689 begin
3690 // berserk fist: remove if we don't have a berserk pack
3691 if (R_BERSERK in FRulez) then weaponOrder[f] := WEAPON_KASTET else weaponOrder[f] := -1;
3692 end;
3693 end;
3696 WEAPON_KASTET = 0;
3697 WEAPON_SAW = 1;
3698 WEAPON_PISTOL = 2;
3699 WEAPON_SHOTGUN1 = 3;
3700 WEAPON_SHOTGUN2 = 4;
3701 WEAPON_CHAINGUN = 5;
3702 WEAPON_ROCKETLAUNCHER = 6;
3703 WEAPON_PLASMA = 7;
3704 WEAPON_BFG = 8;
3705 WEAPON_SUPERPULEMET = 9;
3706 WEAPON_FLAMETHROWER = 10;
3710 if (FNextWeap <> 0) or (FNextWeapDelay <> 0) then
3711 begin
3712 e_WriteLog(Format('!!! FNextWeap=%04x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), TMsgType.Warning);
3713 end;
3716 // cycling has priority
3717 if (FNextWeap and $C000) <> 0 then
3718 begin
3719 if (FNextWeap and $8000) <> 0 then dir := 1 else dir := -1; // should be reversed if we want "priority-driven cycling"
3720 FNextWeap := FNextWeap or $2000; // we need this
3721 if FNextWeapDelay > 0 then exit; // cooldown time
3722 //cwi := real2log(FCurrWeap);
3723 //if (cwi < 0) then cwi := 0;
3724 cwi := FCurrWeap;
3725 for i := 0 to High(FWeapon) do
3726 begin
3727 cwi := (cwi+length(FWeapon)+dir) mod length(FWeapon);
3728 //rwidx := weaponOrder[cwi];
3729 rwidx := cwi; // sorry
3730 if (rwidx < 0) then continue;
3731 if FWeapon[rwidx] then
3732 begin
3733 //e_WriteLog(Format(' SWITCH: cur=%d; new=%d (dir=%d; log=%d)', [FCurrWeap, rwidx, dir, cwi]), TMsgType.Warning);
3734 result := Byte(rwidx);
3735 //FNextWeapDelay := 10; //k8: not needed anymore
3736 exit;
3737 end;
3738 end;
3739 resetWeaponQueue();
3740 exit;
3741 end;
3743 // no cycling
3744 for i := 0 to High(wantThisWeapon) do wantThisWeapon[i] := false;
3745 wwc := 0;
3747 curlidx := -1; // start from a weapon with a highest priority (-1, 'cause loop will immediately increment this index)
3749 for i := 0 to High(FWeapon) do
3750 begin
3751 if (FNextWeap and (1 shl i)) <> 0 then
3752 begin
3753 cwi := real2log(i);
3754 if (cwi >= 0) then
3755 begin
3756 wantThisWeapon[cwi] := true;
3757 Inc(wwc);
3758 // if we hit currently selected weapon, start seachring from it, so we'll get "next weaker" weapon
3759 if (i = FCurrWeap) then curlidx := cwi; // compare real, start from logical
3760 end;
3761 end;
3762 end;
3764 // slow down alterations a little
3765 if (wwc > 1) then
3766 begin
3767 // more than one weapon requested, assume "alteration", and check alteration delay
3768 if FNextWeapDelay > 0 then
3769 begin
3770 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), TMsgType.Warning);
3771 FNextWeap := 0;
3772 exit;
3773 end; // yeah
3774 end;
3776 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3777 // but clear all counters if no weapon should be switched
3778 if (wwc < 1) then
3779 begin
3780 resetWeaponQueue();
3781 exit;
3782 end;
3784 //e_WriteLog(Format('*** wwc=%d; currweap=%d; logweap=%d', [wwc, FCurrWeap, curlidx]), TMsgType.Warning);
3786 // find next weapon to switch onto
3787 cwi := curlidx;
3788 for i := 0 to High(weaponOrder) do
3789 begin
3790 cwi := (cwi+length(weaponOrder)+1) mod length(weaponOrder);
3791 if (cwi = curlidx) then continue; // skip current weapon
3792 if not wantThisWeapon[cwi] then continue;
3793 rwidx := weaponOrder[cwi];
3794 if (rwidx < 0) then continue;
3795 //e_WriteLog(Format(' trying logical %d (real %d); has=%d, hasammo=%d', [cwi, rwidx, Integer(FWeapon[rwidx]), Integer(hasAmmoForWeapon(rwidx))]), TMsgType.Warning);
3796 if FWeapon[rwidx] and ((wwc = 1) or hasAmmoForWeapon(rwidx)) then
3797 begin
3798 //e_WriteLog(' I FOUND HER!', TMsgType.Warning);
3799 // i found her!
3800 result := Byte(rwidx);
3801 resetWeaponQueue();
3802 //FNextWeapDelay := 10; // anyway, 'cause why not; k8: not needed anymore
3803 exit;
3804 end;
3805 end;
3807 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3808 resetWeaponQueue();
3809 end;
3811 procedure TPlayer.RealizeCurrentWeapon();
3812 function switchAllowed (): Boolean;
3814 i: Byte;
3815 begin
3816 result := false;
3817 if FBFGFireCounter <> -1 then
3818 exit;
3819 if FTime[T_SWITCH] > gTime then
3820 exit;
3821 for i := WP_FIRST to WP_LAST do
3822 if FReloading[i] > 0 then
3823 exit;
3824 result := true;
3825 end;
3828 nw: Byte;
3829 begin
3830 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3831 //FNextWeap := FNextWeap and $1FFF;
3832 //HACK: alteration delay will be reset when player released any weapon switch key
3833 FNextWeapDelay := 0; //k8: just in case
3834 //if FNextWeapDelay > 0 then Dec(FNextWeapDelay); // "alteration delay"
3836 if not switchAllowed then
3837 begin
3838 //writeln('WEAPON SWITCHING IS NOT ALLOWED! FBFGFireCounter=', FBFGFireCounter, '; gTime=', gTime, '; FTime[T_SWITCH]=', FTime[T_SWITCH]);
3839 //HACK for weapon cycling
3840 if (FNextWeap and $E000) <> 0 then FNextWeap := 0;
3841 exit;
3842 end;
3844 if (FNetForceWeapFIdx >= gTime+15) then FNetForceWeapFIdx := 0;
3846 nw := getNextWeaponIndex();
3847 if nw = 255 then exit; // don't reset anything here
3848 if nw > High(FWeapon) then
3849 begin
3850 // don't forget to reset queue here!
3851 //e_WriteLog(Format(' RealizeCurrentWeapon: WUTAFUUUU?! (%d)', [nw]), TMsgType.Warning);
3852 resetWeaponQueue();
3853 exit;
3854 end;
3856 if FWeapon[nw] then
3857 begin
3858 //k8: emulate this on client immediately, or wait for server confirmation?
3860 if g_Game_IsClient then
3861 begin
3862 FNetForceWeap := nw;
3863 //FNetForceWeapFIdx := FCurrFrameIdx+5; // force for ~5 frames
3864 FNetForceWeapFIdx := gTime+5; // force for ~5 frames
3865 writeln('NETWEAPONSWITCH: fw=', NetForceWeap, '; fwfidx=', NetForceWeapFIdx, '; cfrm=', gTime);
3866 end;
3868 FNetForceWeapFIdx := gTime+5; // force for ~5 frames
3869 FCurrWeap := nw;
3870 if nw = WEAPON_SAW then FSawSoundSelect.PlayAt(FObj.X, FObj.Y);
3871 FModel.SetWeapon(nw);
3872 FTime[T_SWITCH] := gTime+156;
3873 if g_Game_IsNet then MH_SEND_PlayerStats(FUID);
3874 //if g_Game_IsNet and g_Game_IsClient then
3875 end;
3876 end;
3878 procedure TPlayer.NextWeapon();
3879 begin
3880 //if g_Game_IsClient then Exit;
3881 FNextWeap := $8000;
3882 end;
3884 procedure TPlayer.PrevWeapon();
3885 begin
3886 //if g_Game_IsClient then Exit;
3887 FNextWeap := $4000;
3888 end;
3890 // used exclusively by network layer
3891 procedure TPlayer.SetWeaponHost(W: Byte);
3892 begin
3893 if (W > High(FWeapon)) then exit;
3894 if (not FWeapon[W]) then exit; // server is authority!
3896 if FCurrWeap <> W then
3897 if (W = WEAPON_SAW) then
3898 FSawSoundSelect.PlayAt(FObj.X, FObj.Y);
3900 FCurrWeap := W;
3901 FModel.SetWeapon(CurrWeap);
3902 //if g_Game_IsClient then resetWeaponQueue();
3903 end;
3905 function TPlayer.PickItem(ItemType: Byte; arespawn: Boolean; var remove: Boolean): Boolean;
3907 function allowBerserkSwitching (): Boolean;
3908 begin
3909 if (FBFGFireCounter <> -1) then begin result := false; exit; end;
3910 result := true;
3911 if gBerserkAutoswitch then exit;
3912 if not conIsCheatsEnabled then exit;
3913 result := false;
3914 end;
3917 a: Boolean;
3918 begin
3919 Result := False;
3920 if g_Game_IsClient then Exit;
3922 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3923 a := LongBool(gGameSettings.Options and GAME_OPTION_WEAPONSTAY) and arespawn;
3924 remove := not a;
3926 case ItemType of
3927 ITEM_MEDKIT_SMALL:
3928 if FHealth < PLAYER_HP_SOFT then
3929 begin
3930 IncMax(FHealth, 10, PLAYER_HP_SOFT);
3931 Result := True;
3932 remove := True;
3933 FFireTime := 0;
3934 if gFlash = 2 then Inc(FPickup, 5);
3935 end;
3937 ITEM_MEDKIT_LARGE:
3938 if FHealth < PLAYER_HP_SOFT then
3939 begin
3940 IncMax(FHealth, 25, PLAYER_HP_SOFT);
3941 Result := True;
3942 remove := True;
3943 FFireTime := 0;
3944 if gFlash = 2 then Inc(FPickup, 5);
3945 end;
3947 ITEM_ARMOR_GREEN:
3948 if FArmor < PLAYER_AP_SOFT then
3949 begin
3950 FArmor := PLAYER_AP_SOFT;
3951 Result := True;
3952 remove := True;
3953 if gFlash = 2 then Inc(FPickup, 5);
3954 end;
3956 ITEM_ARMOR_BLUE:
3957 if FArmor < PLAYER_AP_LIMIT then
3958 begin
3959 FArmor := PLAYER_AP_LIMIT;
3960 Result := True;
3961 remove := True;
3962 if gFlash = 2 then Inc(FPickup, 5);
3963 end;
3965 ITEM_SPHERE_BLUE:
3966 if FHealth < PLAYER_HP_LIMIT then
3967 begin
3968 IncMax(FHealth, 100, PLAYER_HP_LIMIT);
3969 Result := True;
3970 remove := True;
3971 FFireTime := 0;
3972 if gFlash = 2 then Inc(FPickup, 5);
3973 end;
3975 ITEM_SPHERE_WHITE:
3976 if (FHealth < PLAYER_HP_LIMIT) or (FArmor < PLAYER_AP_LIMIT) then
3977 begin
3978 if FHealth < PLAYER_HP_LIMIT then
3979 FHealth := PLAYER_HP_LIMIT;
3980 if FArmor < PLAYER_AP_LIMIT then
3981 FArmor := PLAYER_AP_LIMIT;
3982 Result := True;
3983 remove := True;
3984 FFireTime := 0;
3985 if gFlash = 2 then Inc(FPickup, 5);
3986 end;
3988 ITEM_WEAPON_SAW:
3989 if (not FWeapon[WEAPON_SAW]) or ((not arespawn) and (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF])) then
3990 begin
3991 FWeapon[WEAPON_SAW] := True;
3992 Result := True;
3993 if gFlash = 2 then Inc(FPickup, 5);
3994 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
3995 end;
3997 ITEM_WEAPON_SHOTGUN1:
3998 if (FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS]) or not FWeapon[WEAPON_SHOTGUN1] then
3999 begin
4000 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
4001 if a and FWeapon[WEAPON_SHOTGUN1] then Exit;
4003 IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
4004 FWeapon[WEAPON_SHOTGUN1] := True;
4005 Result := True;
4006 if gFlash = 2 then Inc(FPickup, 5);
4007 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
4008 end;
4010 ITEM_WEAPON_SHOTGUN2:
4011 if (FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS]) or not FWeapon[WEAPON_SHOTGUN2] then
4012 begin
4013 if a and FWeapon[WEAPON_SHOTGUN2] then Exit;
4015 IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
4016 FWeapon[WEAPON_SHOTGUN2] := True;
4017 Result := True;
4018 if gFlash = 2 then Inc(FPickup, 5);
4019 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
4020 end;
4022 ITEM_WEAPON_CHAINGUN:
4023 if (FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS]) or not FWeapon[WEAPON_CHAINGUN] then
4024 begin
4025 if a and FWeapon[WEAPON_CHAINGUN] then Exit;
4027 IncMax(FAmmo[A_BULLETS], 50, FMaxAmmo[A_BULLETS]);
4028 FWeapon[WEAPON_CHAINGUN] := True;
4029 Result := True;
4030 if gFlash = 2 then Inc(FPickup, 5);
4031 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
4032 end;
4034 ITEM_WEAPON_ROCKETLAUNCHER:
4035 if (FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS]) or not FWeapon[WEAPON_ROCKETLAUNCHER] then
4036 begin
4037 if a and FWeapon[WEAPON_ROCKETLAUNCHER] then Exit;
4039 IncMax(FAmmo[A_ROCKETS], 2, FMaxAmmo[A_ROCKETS]);
4040 FWeapon[WEAPON_ROCKETLAUNCHER] := True;
4041 Result := True;
4042 if gFlash = 2 then Inc(FPickup, 5);
4043 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
4044 end;
4046 ITEM_WEAPON_PLASMA:
4047 if (FAmmo[A_CELLS] < FMaxAmmo[A_CELLS]) or not FWeapon[WEAPON_PLASMA] then
4048 begin
4049 if a and FWeapon[WEAPON_PLASMA] then Exit;
4051 IncMax(FAmmo[A_CELLS], 40, FMaxAmmo[A_CELLS]);
4052 FWeapon[WEAPON_PLASMA] := True;
4053 Result := True;
4054 if gFlash = 2 then Inc(FPickup, 5);
4055 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
4056 end;
4058 ITEM_WEAPON_BFG:
4059 if (FAmmo[A_CELLS] < FMaxAmmo[A_CELLS]) or not FWeapon[WEAPON_BFG] then
4060 begin
4061 if a and FWeapon[WEAPON_BFG] then Exit;
4063 IncMax(FAmmo[A_CELLS], 40, FMaxAmmo[A_CELLS]);
4064 FWeapon[WEAPON_BFG] := True;
4065 Result := True;
4066 if gFlash = 2 then Inc(FPickup, 5);
4067 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
4068 end;
4070 ITEM_WEAPON_SUPERPULEMET:
4071 if (FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS]) or not FWeapon[WEAPON_SUPERPULEMET] then
4072 begin
4073 if a and FWeapon[WEAPON_SUPERPULEMET] then Exit;
4075 IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
4076 FWeapon[WEAPON_SUPERPULEMET] := True;
4077 Result := True;
4078 if gFlash = 2 then Inc(FPickup, 5);
4079 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
4080 end;
4082 ITEM_WEAPON_FLAMETHROWER:
4083 if (FAmmo[A_FUEL] < FMaxAmmo[A_FUEL]) or not FWeapon[WEAPON_FLAMETHROWER] then
4084 begin
4085 if a and FWeapon[WEAPON_FLAMETHROWER] then Exit;
4087 IncMax(FAmmo[A_FUEL], 100, FMaxAmmo[A_FUEL]);
4088 FWeapon[WEAPON_FLAMETHROWER] := True;
4089 Result := True;
4090 if gFlash = 2 then Inc(FPickup, 5);
4091 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
4092 end;
4094 ITEM_AMMO_BULLETS:
4095 if FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS] then
4096 begin
4097 IncMax(FAmmo[A_BULLETS], 10, FMaxAmmo[A_BULLETS]);
4098 Result := True;
4099 remove := True;
4100 if gFlash = 2 then Inc(FPickup, 5);
4101 end;
4103 ITEM_AMMO_BULLETS_BOX:
4104 if FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS] then
4105 begin
4106 IncMax(FAmmo[A_BULLETS], 50, FMaxAmmo[A_BULLETS]);
4107 Result := True;
4108 remove := True;
4109 if gFlash = 2 then Inc(FPickup, 5);
4110 end;
4112 ITEM_AMMO_SHELLS:
4113 if FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS] then
4114 begin
4115 IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
4116 Result := True;
4117 remove := True;
4118 if gFlash = 2 then Inc(FPickup, 5);
4119 end;
4121 ITEM_AMMO_SHELLS_BOX:
4122 if FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS] then
4123 begin
4124 IncMax(FAmmo[A_SHELLS], 25, FMaxAmmo[A_SHELLS]);
4125 Result := True;
4126 remove := True;
4127 if gFlash = 2 then Inc(FPickup, 5);
4128 end;
4130 ITEM_AMMO_ROCKET:
4131 if FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS] then
4132 begin
4133 IncMax(FAmmo[A_ROCKETS], 1, FMaxAmmo[A_ROCKETS]);
4134 Result := True;
4135 remove := True;
4136 if gFlash = 2 then Inc(FPickup, 5);
4137 end;
4139 ITEM_AMMO_ROCKET_BOX:
4140 if FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS] then
4141 begin
4142 IncMax(FAmmo[A_ROCKETS], 5, FMaxAmmo[A_ROCKETS]);
4143 Result := True;
4144 remove := True;
4145 if gFlash = 2 then Inc(FPickup, 5);
4146 end;
4148 ITEM_AMMO_CELL:
4149 if FAmmo[A_CELLS] < FMaxAmmo[A_CELLS] then
4150 begin
4151 IncMax(FAmmo[A_CELLS], 40, FMaxAmmo[A_CELLS]);
4152 Result := True;
4153 remove := True;
4154 if gFlash = 2 then Inc(FPickup, 5);
4155 end;
4157 ITEM_AMMO_CELL_BIG:
4158 if FAmmo[A_CELLS] < FMaxAmmo[A_CELLS] then
4159 begin
4160 IncMax(FAmmo[A_CELLS], 100, FMaxAmmo[A_CELLS]);
4161 Result := True;
4162 remove := True;
4163 if gFlash = 2 then Inc(FPickup, 5);
4164 end;
4166 ITEM_AMMO_FUELCAN:
4167 if FAmmo[A_FUEL] < FMaxAmmo[A_FUEL] then
4168 begin
4169 IncMax(FAmmo[A_FUEL], 100, FMaxAmmo[A_FUEL]);
4170 Result := True;
4171 remove := True;
4172 if gFlash = 2 then Inc(FPickup, 5);
4173 end;
4175 ITEM_AMMO_BACKPACK:
4176 if not(R_ITEM_BACKPACK in FRulez) or
4177 (FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS]) or
4178 (FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS]) or
4179 (FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS]) or
4180 (FAmmo[A_CELLS] < FMaxAmmo[A_CELLS]) or
4181 (FMaxAmmo[A_FUEL] < AmmoLimits[1, A_FUEL]) then
4182 begin
4183 FMaxAmmo[A_BULLETS] := AmmoLimits[1, A_BULLETS];
4184 FMaxAmmo[A_SHELLS] := AmmoLimits[1, A_SHELLS];
4185 FMaxAmmo[A_ROCKETS] := AmmoLimits[1, A_ROCKETS];
4186 FMaxAmmo[A_CELLS] := AmmoLimits[1, A_CELLS];
4187 FMaxAmmo[A_FUEL] := AmmoLimits[1, A_FUEL];
4189 if FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS] then
4190 IncMax(FAmmo[A_BULLETS], 10, FMaxAmmo[A_BULLETS]);
4191 if FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS] then
4192 IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
4193 if FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS] then
4194 IncMax(FAmmo[A_ROCKETS], 1, FMaxAmmo[A_ROCKETS]);
4195 if FAmmo[A_CELLS] < FMaxAmmo[A_CELLS] then
4196 IncMax(FAmmo[A_CELLS], 40, FMaxAmmo[A_CELLS]);
4198 FRulez := FRulez + [R_ITEM_BACKPACK];
4199 Result := True;
4200 remove := True;
4201 if gFlash = 2 then Inc(FPickup, 5);
4202 end;
4204 ITEM_KEY_RED:
4205 if not(R_KEY_RED in FRulez) then
4206 begin
4207 Include(FRulez, R_KEY_RED);
4208 Result := True;
4209 remove := (gGameSettings.GameMode <> GM_COOP) and (g_Player_GetCount() < 2);
4210 if gFlash = 2 then Inc(FPickup, 5);
4211 if (not remove) and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETITEM');
4212 end;
4214 ITEM_KEY_GREEN:
4215 if not(R_KEY_GREEN in FRulez) then
4216 begin
4217 Include(FRulez, R_KEY_GREEN);
4218 Result := True;
4219 remove := (gGameSettings.GameMode <> GM_COOP) and (g_Player_GetCount() < 2);
4220 if gFlash = 2 then Inc(FPickup, 5);
4221 if (not remove) and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETITEM');
4222 end;
4224 ITEM_KEY_BLUE:
4225 if not(R_KEY_BLUE in FRulez) then
4226 begin
4227 Include(FRulez, R_KEY_BLUE);
4228 Result := True;
4229 remove := (gGameSettings.GameMode <> GM_COOP) and (g_Player_GetCount() < 2);
4230 if gFlash = 2 then Inc(FPickup, 5);
4231 if (not remove) and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETITEM');
4232 end;
4234 ITEM_SUIT:
4235 if FMegaRulez[MR_SUIT] < gTime+PLAYER_SUIT_TIME then
4236 begin
4237 FMegaRulez[MR_SUIT] := gTime+PLAYER_SUIT_TIME;
4238 Result := True;
4239 remove := True;
4240 FFireTime := 0;
4241 if gFlash = 2 then Inc(FPickup, 5);
4242 end;
4244 ITEM_OXYGEN:
4245 if FAir < AIR_MAX then
4246 begin
4247 FAir := AIR_MAX;
4248 Result := True;
4249 remove := True;
4250 if gFlash = 2 then Inc(FPickup, 5);
4251 end;
4253 ITEM_MEDKIT_BLACK:
4254 begin
4255 if not (R_BERSERK in FRulez) then
4256 begin
4257 Include(FRulez, R_BERSERK);
4258 if allowBerserkSwitching then
4259 begin
4260 FCurrWeap := WEAPON_KASTET;
4261 //FNetForceWeap := FCurrWeap;
4262 resetWeaponQueue();
4263 FModel.SetWeapon(WEAPON_KASTET);
4264 end;
4265 if gFlash <> 0 then
4266 begin
4267 Inc(FPain, 100);
4268 if gFlash = 2 then Inc(FPickup, 5);
4269 end;
4270 FBerserk := gTime+30000;
4271 Result := True;
4272 remove := True;
4273 FFireTime := 0;
4274 //k8:do we need it? if g_Game_IsNet and g_Game_IsServer then MH_SEND_PlayerStats(FUID);
4275 end;
4276 if FHealth < PLAYER_HP_SOFT then
4277 begin
4278 FHealth := PLAYER_HP_SOFT;
4279 FBerserk := gTime+30000;
4280 Result := True;
4281 remove := True;
4282 FFireTime := 0;
4283 end;
4284 end;
4286 ITEM_INVUL:
4287 if FMegaRulez[MR_INVUL] < gTime+PLAYER_INVUL_TIME then
4288 begin
4289 FMegaRulez[MR_INVUL] := gTime+PLAYER_INVUL_TIME;
4290 Result := True;
4291 remove := True;
4292 if gFlash = 2 then Inc(FPickup, 5);
4293 end;
4295 ITEM_BOTTLE:
4296 if FHealth < PLAYER_HP_LIMIT then
4297 begin
4298 IncMax(FHealth, 4, PLAYER_HP_LIMIT);
4299 Result := True;
4300 remove := True;
4301 FFireTime := 0;
4302 if gFlash = 2 then Inc(FPickup, 5);
4303 end;
4305 ITEM_HELMET:
4306 if FArmor < PLAYER_AP_LIMIT then
4307 begin
4308 IncMax(FArmor, 5, PLAYER_AP_LIMIT);
4309 Result := True;
4310 remove := True;
4311 if gFlash = 2 then Inc(FPickup, 5);
4312 end;
4314 ITEM_JETPACK:
4315 if FJetFuel < JET_MAX then
4316 begin
4317 FJetFuel := JET_MAX;
4318 Result := True;
4319 remove := True;
4320 if gFlash = 2 then Inc(FPickup, 5);
4321 end;
4323 ITEM_INVIS:
4324 if FMegaRulez[MR_INVIS] < gTime+PLAYER_INVIS_TIME then
4325 begin
4326 FMegaRulez[MR_INVIS] := gTime+PLAYER_INVIS_TIME;
4327 Result := True;
4328 remove := True;
4329 if gFlash = 2 then Inc(FPickup, 5);
4330 end;
4331 end;
4332 end;
4334 procedure TPlayer.Touch();
4335 begin
4336 if not FAlive then
4337 Exit;
4338 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4339 if FIamBot then
4340 begin
4341 // Áðîñèòü ôëàã òîâàðèùó:
4342 if gGameSettings.GameMode = GM_CTF then
4343 DropFlag();
4344 end;
4345 end;
4347 procedure TPlayer.Push(vx, vy: Integer);
4348 begin
4349 if (not FPhysics) and FGhost then
4350 Exit;
4351 FObj.Accel.X := FObj.Accel.X + vx;
4352 FObj.Accel.Y := FObj.Accel.Y + vy;
4353 if g_Game_IsNet and g_Game_IsServer then
4354 MH_SEND_PlayerPos(True, FUID, NET_EVERYONE);
4355 end;
4357 procedure TPlayer.Reset(Force: Boolean);
4359 i: Integer;
4360 begin
4361 if Force then
4362 FAlive := False;
4364 FSpawned := False;
4365 FTime[T_RESPAWN] := 0;
4366 FTime[T_FLAGCAP] := 0;
4367 FGodMode := False;
4368 FNoTarget := False;
4369 FNoReload := False;
4370 FFrags := 0;
4371 FLastFrag := 0;
4372 FComboEvnt := -1;
4373 FKills := 0;
4374 FMonsterKills := 0;
4375 FDeath := 0;
4376 FSecrets := 0;
4377 //FCurrFrameIdx := 0;
4378 //FNetForceWeap := FCurrWeap;
4379 FNetForceWeapFIdx := 0;
4380 resetWeaponQueue();
4381 if FNoRespawn then
4382 begin
4383 FSpectator := False;
4384 FGhost := False;
4385 FPhysics := True;
4386 FSpectatePlayer := -1;
4387 FNoRespawn := False;
4388 end;
4389 FLives := gGameSettings.MaxLives;
4391 FBFGFireCounter := -1;
4392 FTime[T_SWITCH] := 0;
4393 for i := WP_FIRST to WP_LAST do FReloading[i] := 0;
4395 SetFlag(FLAG_NONE);
4396 end;
4398 procedure TPlayer.SoftReset();
4400 i: Integer;
4401 begin
4402 ReleaseKeys();
4404 FDamageBuffer := 0;
4405 FIncCam := 0;
4406 FBFGFireCounter := -1;
4407 FShellTimer := -1;
4408 FPain := 0;
4409 FLastHit := 0;
4410 FLastFrag := 0;
4411 FComboEvnt := -1;
4412 FNetForceWeapFIdx := 0;
4413 resetWeaponQueue();
4415 FBFGFireCounter := -1;
4416 FTime[T_SWITCH] := 0;
4417 for i := WP_FIRST to WP_LAST do FReloading[i] := 0;
4419 SetFlag(FLAG_NONE);
4420 SetAction(A_STAND, True);
4421 end;
4423 function TPlayer.GetRespawnPoint(): Byte;
4425 c: Byte;
4426 begin
4427 Result := 255;
4428 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4430 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4431 if gGameSettings.GameMode in [GM_COOP, GM_SINGLE] then
4432 begin
4433 if (Self = gPlayer1) or (Self = gPlayer2) then
4434 begin
4435 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
4436 if Self = gPlayer1 then
4437 c := RESPAWNPOINT_PLAYER1
4438 else
4439 c := RESPAWNPOINT_PLAYER2;
4440 if g_Map_GetPointCount(c) > 0 then
4441 begin
4442 Result := c;
4443 Exit;
4444 end;
4446 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
4447 if Self = gPlayer1 then
4448 c := RESPAWNPOINT_PLAYER2
4449 else
4450 c := RESPAWNPOINT_PLAYER1;
4451 if g_Map_GetPointCount(c) > 0 then
4452 begin
4453 Result := c;
4454 Exit;
4455 end;
4456 end else
4457 begin
4458 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
4459 if Random(2) = 0 then
4460 c := RESPAWNPOINT_PLAYER1
4461 else
4462 c := RESPAWNPOINT_PLAYER2;
4463 if g_Map_GetPointCount(c) > 0 then
4464 begin
4465 Result := c;
4466 Exit;
4467 end;
4468 end;
4470 // Òî÷êà ëþáîé èç êîìàíä
4471 if Random(2) = 0 then
4472 c := RESPAWNPOINT_RED
4473 else
4474 c := RESPAWNPOINT_BLUE;
4475 if g_Map_GetPointCount(c) > 0 then
4476 begin
4477 Result := c;
4478 Exit;
4479 end;
4481 // Òî÷êà DM
4482 c := RESPAWNPOINT_DM;
4483 if g_Map_GetPointCount(c) > 0 then
4484 begin
4485 Result := c;
4486 Exit;
4487 end;
4488 end;
4490 // Ìÿñîïîâàë
4491 if gGameSettings.GameMode = GM_DM then
4492 begin
4493 // Òî÷êà DM
4494 c := RESPAWNPOINT_DM;
4495 if g_Map_GetPointCount(c) > 0 then
4496 begin
4497 Result := c;
4498 Exit;
4499 end;
4501 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4502 if Random(2) = 0 then
4503 c := RESPAWNPOINT_PLAYER1
4504 else
4505 c := RESPAWNPOINT_PLAYER2;
4506 if g_Map_GetPointCount(c) > 0 then
4507 begin
4508 Result := c;
4509 Exit;
4510 end;
4512 // Òî÷êà ëþáîé èç êîìàíä
4513 if Random(2) = 0 then
4514 c := RESPAWNPOINT_RED
4515 else
4516 c := RESPAWNPOINT_BLUE;
4517 if g_Map_GetPointCount(c) > 0 then
4518 begin
4519 Result := c;
4520 Exit;
4521 end;
4522 end;
4524 // Êîìàíäíûå
4525 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
4526 begin
4527 // Òî÷êà ñâîåé êîìàíäû
4528 c := RESPAWNPOINT_DM;
4529 if FTeam = TEAM_RED then
4530 c := RESPAWNPOINT_RED;
4531 if FTeam = TEAM_BLUE then
4532 c := RESPAWNPOINT_BLUE;
4533 if g_Map_GetPointCount(c) > 0 then
4534 begin
4535 Result := c;
4536 Exit;
4537 end;
4539 // Òî÷êà DM
4540 c := RESPAWNPOINT_DM;
4541 if g_Map_GetPointCount(c) > 0 then
4542 begin
4543 Result := c;
4544 Exit;
4545 end;
4547 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4548 if Random(2) = 0 then
4549 c := RESPAWNPOINT_PLAYER1
4550 else
4551 c := RESPAWNPOINT_PLAYER2;
4552 if g_Map_GetPointCount(c) > 0 then
4553 begin
4554 Result := c;
4555 Exit;
4556 end;
4558 // Òî÷êà äðóãîé êîìàíäû
4559 c := RESPAWNPOINT_DM;
4560 if FTeam = TEAM_RED then
4561 c := RESPAWNPOINT_BLUE;
4562 if FTeam = TEAM_BLUE then
4563 c := RESPAWNPOINT_RED;
4564 if g_Map_GetPointCount(c) > 0 then
4565 begin
4566 Result := c;
4567 Exit;
4568 end;
4569 end;
4570 end;
4572 procedure TPlayer.Respawn(Silent: Boolean; Force: Boolean = False);
4574 RespawnPoint: TRespawnPoint;
4575 a, b, c: Byte;
4576 Anim: TAnimation;
4577 ID: DWORD;
4578 i: Integer;
4579 begin
4580 FIncCam := 0;
4581 FBFGFireCounter := -1;
4582 FShellTimer := -1;
4583 FPain := 0;
4584 FLastHit := 0;
4585 //FNetForceWeap := FCurrWeap;
4586 FNetForceWeapFIdx := 0;
4587 resetWeaponQueue();
4589 FBFGFireCounter := -1;
4590 FTime[T_SWITCH] := 0;
4591 for i := WP_FIRST to WP_LAST do FReloading[i] := 0;
4593 if not g_Game_IsServer then
4594 Exit;
4595 if FDummy then
4596 Exit;
4597 FWantsInGame := True;
4598 FJustTeleported := True;
4599 if Force then
4600 begin
4601 FTime[T_RESPAWN] := 0;
4602 FAlive := False;
4603 end;
4604 FNetTime := 0;
4605 // if server changes MaxLives we gotta be ready
4606 if gGameSettings.MaxLives = 0 then FNoRespawn := False;
4608 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4609 if FTime[T_RESPAWN] > gTime then
4610 Exit;
4612 // Ïðîñðàë âñå æèçíè:
4613 if FNoRespawn then
4614 begin
4615 if not FSpectator then Spectate(True);
4616 FWantsInGame := True;
4617 Exit;
4618 end;
4620 if (gGameSettings.GameType <> GT_SINGLE) and (gGameSettings.GameMode <> GM_COOP) then
4621 begin // "Ñâîÿ èãðà"
4622 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4623 FRulez := FRulez-[R_BERSERK];
4625 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4626 begin
4627 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4628 FRulez := FRulez-[R_KEY_RED, R_KEY_GREEN, R_KEY_BLUE, R_BERSERK];
4629 end;
4631 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4632 c := GetRespawnPoint();
4634 ReleaseKeys();
4635 SetFlag(FLAG_NONE);
4637 // Âîñêðåøåíèå áåç îðóæèÿ:
4638 if not FAlive then
4639 begin
4640 FHealth := PLAYER_HP_SOFT;
4641 FArmor := 0;
4642 FAlive := True;
4643 FAir := AIR_DEF;
4644 FJetFuel := 0;
4646 for a := WP_FIRST to WP_LAST do
4647 begin
4648 FWeapon[a] := False;
4649 FReloading[a] := 0;
4650 end;
4652 FWeapon[WEAPON_PISTOL] := True;
4653 FWeapon[WEAPON_KASTET] := True;
4654 FCurrWeap := WEAPON_PISTOL;
4655 //FNetForceWeap := FCurrWeap;
4656 FNetForceWeapFIdx := 0;
4657 resetWeaponQueue();
4659 FModel.SetWeapon(FCurrWeap);
4661 for b := A_BULLETS to A_HIGH do
4662 FAmmo[b] := 0;
4664 FAmmo[A_BULLETS] := 50;
4666 FMaxAmmo[A_BULLETS] := AmmoLimits[0, A_BULLETS];
4667 FMaxAmmo[A_SHELLS] := AmmoLimits[0, A_SHELLS];
4668 FMaxAmmo[A_ROCKETS] := AmmoLimits[0, A_SHELLS];
4669 FMaxAmmo[A_CELLS] := AmmoLimits[0, A_CELLS];
4670 FMaxAmmo[A_FUEL] := AmmoLimits[0, A_FUEL];
4672 if gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF] then
4673 FRulez := [R_KEY_RED, R_KEY_GREEN, R_KEY_BLUE]
4674 else
4675 FRulez := [];
4676 end;
4678 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4679 if not g_Map_GetPoint(c, RespawnPoint) then
4680 begin
4681 g_FatalError(_lc[I_GAME_ERROR_GET_SPAWN]);
4682 Exit;
4683 end;
4685 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4686 FObj.X := RespawnPoint.X-PLAYER_RECT.X;
4687 FObj.Y := RespawnPoint.Y-PLAYER_RECT.Y;
4688 FObj.Vel.X := 0;
4689 FObj.Vel.Y := 0;
4690 FObj.Accel.X := 0;
4691 FObj.Accel.Y := 0;
4693 FDirection := RespawnPoint.Direction;
4694 if FDirection = TDirection.D_LEFT then
4695 FAngle := 180
4696 else
4697 FAngle := 0;
4699 SetAction(A_STAND, True);
4700 FModel.Direction := FDirection;
4702 for a := Low(FTime) to High(FTime) do
4703 FTime[a] := 0;
4705 for a := Low(FMegaRulez) to High(FMegaRulez) do
4706 FMegaRulez[a] := 0;
4708 FDamageBuffer := 0;
4709 FJetpack := False;
4710 FCanJetpack := False;
4711 FFireTime := 0;
4712 FFirePainTime := 0;
4713 FFireAttacker := 0;
4715 // Àíèìàöèÿ âîçðîæäåíèÿ:
4716 if (not gLoadGameMode) and (not Silent) then
4717 if g_Frames_Get(ID, 'FRAMES_TELEPORT') then
4718 begin
4719 Anim := TAnimation.Create(ID, False, 3);
4720 g_GFX_OnceAnim(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
4721 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32, Anim);
4722 Anim.Free();
4723 end;
4725 FSpectator := False;
4726 FGhost := False;
4727 FPhysics := True;
4728 FSpectatePlayer := -1;
4729 FSpawned := True;
4731 if (gPlayer1 = nil) and (gLMSPID1 = FUID) then
4732 gPlayer1 := self;
4733 if (gPlayer2 = nil) and (gLMSPID2 = FUID) then
4734 gPlayer2 := self;
4736 //FNetForceWeap := FCurrWeap;
4738 if g_Game_IsNet then
4739 begin
4740 MH_SEND_PlayerPos(True, FUID, NET_EVERYONE);
4741 MH_SEND_PlayerStats(FUID, NET_EVERYONE);
4742 if not Silent then
4743 MH_SEND_Effect(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
4744 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32,
4745 0, NET_GFX_TELE);
4746 end;
4747 end;
4749 procedure TPlayer.Spectate(NoMove: Boolean = False);
4750 begin
4751 if FAlive then
4752 Kill(K_EXTRAHARDKILL, FUID, HIT_SOME)
4753 else if (not NoMove) then
4754 begin
4755 GameX := gMapInfo.Width div 2;
4756 GameY := gMapInfo.Height div 2;
4757 end;
4758 FXTo := GameX;
4759 FYTo := GameY;
4761 FAlive := False;
4762 FSpectator := True;
4763 FGhost := True;
4764 FPhysics := False;
4765 FWantsInGame := False;
4766 FSpawned := False;
4768 if FNoRespawn then
4769 begin
4770 if Self = gPlayer1 then
4771 begin
4772 gLMSPID1 := FUID;
4773 gPlayer1 := nil;
4774 end;
4775 if Self = gPlayer2 then
4776 begin
4777 gLMSPID2 := FUID;
4778 gPlayer2 := nil;
4779 end;
4780 end;
4782 if g_Game_IsNet then
4783 MH_SEND_PlayerStats(FUID);
4784 end;
4786 procedure TPlayer.SwitchNoClip;
4787 begin
4788 if not FAlive then
4789 Exit;
4790 FGhost := not FGhost;
4791 FPhysics := not FGhost;
4792 if FGhost then
4793 begin
4794 FXTo := FObj.X;
4795 FYTo := FObj.Y;
4796 end else
4797 begin
4798 FObj.Accel.X := 0;
4799 FObj.Accel.Y := 0;
4800 end;
4801 end;
4803 procedure TPlayer.Run(Direction: TDirection);
4805 a, b: Integer;
4806 begin
4807 if MAX_RUNVEL > 8 then
4808 FlySmoke();
4810 // Áåæèì:
4811 if Direction = TDirection.D_LEFT then
4812 begin
4813 if FObj.Vel.X > -MAX_RUNVEL then
4814 FObj.Vel.X := FObj.Vel.X - (MAX_RUNVEL shr 3);
4816 else
4817 if FObj.Vel.X < MAX_RUNVEL then
4818 FObj.Vel.X := FObj.Vel.X + (MAX_RUNVEL shr 3);
4820 // Âîçìîæíî, ïèíàåì êóñêè:
4821 if (FObj.Vel.X <> 0) and (gGibs <> nil) then
4822 begin
4823 b := Abs(FObj.Vel.X);
4824 if b > 1 then b := b * (Random(8 div b) + 1);
4825 for a := 0 to High(gGibs) do
4826 begin
4827 if gGibs[a].alive and
4828 g_Obj_Collide(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y+FObj.Rect.Height-4,
4829 FObj.Rect.Width, 8, @gGibs[a].Obj) and (Random(3) = 0) then
4830 begin
4831 // Ïèíàåì êóñêè
4832 if FObj.Vel.X < 0 then
4833 begin
4834 g_Obj_PushA(@gGibs[a].Obj, b, Random(61)+120) // íàëåâî
4836 else
4837 begin
4838 g_Obj_PushA(@gGibs[a].Obj, b, Random(61)); // íàïðàâî
4839 end;
4840 gGibs[a].positionChanged(); // this updates spatial accelerators
4841 end;
4842 end;
4843 end;
4845 SetAction(A_WALK);
4846 end;
4848 procedure TPlayer.SeeDown();
4849 begin
4850 SetAction(A_SEEDOWN);
4852 if FDirection = TDirection.D_LEFT then FAngle := ANGLE_LEFTDOWN else FAngle := ANGLE_RIGHTDOWN;
4854 if FIncCam > -120 then DecMin(FIncCam, 5, -120);
4855 end;
4857 procedure TPlayer.SeeUp();
4858 begin
4859 SetAction(A_SEEUP);
4861 if FDirection = TDirection.D_LEFT then FAngle := ANGLE_LEFTUP else FAngle := ANGLE_RIGHTUP;
4863 if FIncCam < 120 then IncMax(FIncCam, 5, 120);
4864 end;
4866 procedure TPlayer.SetAction(Action: Byte; Force: Boolean = False);
4868 Prior: Byte;
4869 begin
4870 case Action of
4871 A_WALK: Prior := 3;
4872 A_DIE1: Prior := 5;
4873 A_DIE2: Prior := 5;
4874 A_ATTACK: Prior := 2;
4875 A_SEEUP: Prior := 1;
4876 A_SEEDOWN: Prior := 1;
4877 A_ATTACKUP: Prior := 2;
4878 A_ATTACKDOWN: Prior := 2;
4879 A_PAIN: Prior := 4;
4880 else Prior := 0;
4881 end;
4883 if (Prior > FActionPrior) or Force then
4884 if not ((Prior = 2) and (FCurrWeap = WEAPON_SAW)) then
4885 begin
4886 FActionPrior := Prior;
4887 FActionAnim := Action;
4888 FActionForce := Force;
4889 FActionChanged := True;
4890 end;
4892 if Action in [A_ATTACK, A_ATTACKUP, A_ATTACKDOWN] then FModel.SetFire(True);
4893 end;
4895 function TPlayer.StayOnStep(XInc, YInc: Integer): Boolean;
4896 begin
4897 Result := not g_Map_CollidePanel(FObj.X+PLAYER_RECT.X, FObj.Y+YInc+PLAYER_RECT.Y+PLAYER_RECT.Height-1,
4898 PLAYER_RECT.Width, 1, PANEL_STEP, False)
4899 and g_Map_CollidePanel(FObj.X+PLAYER_RECT.X, FObj.Y+YInc+PLAYER_RECT.Y+PLAYER_RECT.Height,
4900 PLAYER_RECT.Width, 1, PANEL_STEP, False);
4901 end;
4903 function TPlayer.TeleportTo(X, Y: Integer; silent: Boolean; dir: Byte): Boolean;
4905 Anim: TAnimation;
4906 ID: DWORD;
4907 begin
4908 Result := False;
4910 if g_CollideLevel(X, Y, PLAYER_RECT.Width, PLAYER_RECT.Height) then
4911 begin
4912 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj.X, FObj.Y);
4913 if g_Game_IsServer and g_Game_IsNet then
4914 MH_SEND_Sound(FObj.X, FObj.Y, 'SOUND_GAME_NOTELEPORT');
4915 Exit;
4916 end;
4918 FJustTeleported := True;
4920 Anim := nil;
4921 if not silent then
4922 begin
4923 if g_Frames_Get(ID, 'FRAMES_TELEPORT') then
4924 begin
4925 Anim := TAnimation.Create(ID, False, 3);
4926 end;
4928 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj.X, FObj.Y);
4929 g_GFX_OnceAnim(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
4930 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32, Anim);
4931 if g_Game_IsServer and g_Game_IsNet then
4932 MH_SEND_Effect(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
4933 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32, 1,
4934 NET_GFX_TELE);
4935 end;
4937 FObj.X := X-PLAYER_RECT.X;
4938 FObj.Y := Y-PLAYER_RECT.Y;
4939 if FAlive and FGhost then
4940 begin
4941 FXTo := FObj.X;
4942 FYTo := FObj.Y;
4943 end;
4945 if not g_Game_IsNet then
4946 begin
4947 if dir = 1 then
4948 begin
4949 SetDirection(TDirection.D_LEFT);
4950 FAngle := 180;
4952 else
4953 if dir = 2 then
4954 begin
4955 SetDirection(TDirection.D_RIGHT);
4956 FAngle := 0;
4958 else
4959 if dir = 3 then
4960 begin // îáðàòíîå
4961 if FDirection = TDirection.D_RIGHT then
4962 begin
4963 SetDirection(TDirection.D_LEFT);
4964 FAngle := 180;
4966 else
4967 begin
4968 SetDirection(TDirection.D_RIGHT);
4969 FAngle := 0;
4970 end;
4971 end;
4972 end;
4974 if not silent and (Anim <> nil) then
4975 begin
4976 g_GFX_OnceAnim(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
4977 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32, Anim);
4978 Anim.Free();
4980 if g_Game_IsServer and g_Game_IsNet then
4981 MH_SEND_Effect(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
4982 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32, 0,
4983 NET_GFX_TELE);
4984 end;
4986 Result := True;
4987 end;
4989 function nonz(a: Single): Single;
4990 begin
4991 if a <> 0 then
4992 Result := a
4993 else
4994 Result := 1;
4995 end;
4997 function TPlayer.followCorpse(): Boolean;
4999 i: Integer;
5000 begin
5001 Result := False;
5002 if FAlive or FSpectator then
5003 Exit;
5004 if (gCorpses = nil) or (Length(gCorpses) = 0) then
5005 Exit;
5006 for i := 0 to High(gCorpses) do
5007 if gCorpses[i] <> nil then
5008 if gCorpses[i].FPlayerUID = FUID then
5009 begin
5010 Result := True;
5011 FObj.X := gCorpses[i].FObj.X;
5012 FObj.Y := gCorpses[i].FObj.Y;
5013 FObj.Vel.X := gCorpses[i].FObj.Vel.X;
5014 FObj.Vel.Y := gCorpses[i].FObj.Vel.Y;
5015 FObj.Accel.X := gCorpses[i].FObj.Accel.X;
5016 FObj.Accel.Y := gCorpses[i].FObj.Accel.Y;
5017 break;
5018 end;
5019 end;
5021 procedure TPlayer.Update();
5023 b: Byte;
5024 i, ii, wx, wy, xd, yd, k: Integer;
5025 blockmon, headwater, dospawn: Boolean;
5026 NetServer: Boolean;
5027 AnyServer: Boolean;
5028 SetSpect: Boolean;
5029 begin
5030 //Inc(FCurrFrameIdx);
5032 NetServer := g_Game_IsNet and g_Game_IsServer;
5033 AnyServer := g_Game_IsServer;
5035 if g_Game_IsClient and (NetInterpLevel > 0) then
5036 DoLerp(NetInterpLevel + 1)
5037 else
5038 if FGhost then
5039 DoLerp(4);
5041 if NetServer then
5042 begin
5043 if FClientID >= 0 then
5044 begin
5045 FPing := NetClients[FClientID].Peer^.lastRoundTripTime;
5046 if NetClients[FClientID].Peer^.packetsSent > 0 then
5047 FLoss := Round(100*NetClients[FClientID].Peer^.packetsLost/NetClients[FClientID].Peer^.packetsSent)
5048 else
5049 FLoss := 0;
5050 end else
5051 begin
5052 FPing := 0;
5053 FLoss := 0;
5054 end;
5055 end;
5057 if FAlive and (FPunchAnim <> nil) then
5058 FPunchAnim.Update();
5060 if FAlive and (gFly or FJetpack) then
5061 FlySmoke();
5063 if FDirection = TDirection.D_LEFT then
5064 FAngle := 180
5065 else
5066 FAngle := 0;
5068 if FAlive and (not FGhost) then
5069 begin
5070 if FKeys[KEY_UP].Pressed then
5071 SeeUp();
5072 if FKeys[KEY_DOWN].Pressed then
5073 SeeDown();
5074 end;
5076 if (not (FKeys[KEY_UP].Pressed or FKeys[KEY_DOWN].Pressed)) and
5077 (FIncCam <> 0) then
5078 begin
5079 i := g_basic.Sign(FIncCam);
5080 FIncCam := Abs(FIncCam);
5081 DecMin(FIncCam, 5, 0);
5082 FIncCam := FIncCam*i;
5083 end;
5085 // no need to do that each second frame, weapon queue will take care of it
5086 if FAlive and FKeys[KEY_NEXTWEAPON].Pressed {and AnyServer} then NextWeapon();
5087 if FAlive and FKeys[KEY_PREVWEAPON].Pressed {and AnyServer} then PrevWeapon();
5089 if gTime mod (GAME_TICK*2) <> 0 then
5090 begin
5091 if (FObj.Vel.X = 0) and FAlive then
5092 begin
5093 if FKeys[KEY_LEFT].Pressed then
5094 Run(TDirection.D_LEFT);
5095 if FKeys[KEY_RIGHT].Pressed then
5096 Run(TDirection.D_RIGHT);
5097 end;
5099 if FPhysics then
5100 begin
5101 if not followCorpse() then
5102 g_Obj_Move(@FObj, True, True, True);
5103 positionChanged(); // this updates spatial accelerators
5104 end;
5106 Exit;
5107 end;
5109 FActionChanged := False;
5111 if FAlive then
5112 begin
5113 // Let alive player do some actions
5114 if FKeys[KEY_LEFT].Pressed then Run(TDirection.D_LEFT);
5115 if FKeys[KEY_RIGHT].Pressed then Run(TDirection.D_RIGHT);
5116 //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
5117 //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
5118 if FKeys[KEY_FIRE].Pressed and AnyServer then Fire();
5119 if FKeys[KEY_OPEN].Pressed and AnyServer then Use();
5120 if FKeys[KEY_JUMP].Pressed then Jump()
5121 else
5122 begin
5123 if AnyServer and FJetpack then
5124 begin
5125 FJetpack := False;
5126 JetpackOff;
5127 if NetServer then MH_SEND_PlayerStats(FUID);
5128 end;
5129 FCanJetpack := True;
5130 end;
5132 else // Dead
5133 begin
5134 dospawn := False;
5135 if not FGhost then
5136 for k := Low(FKeys) to KEY_CHAT-1 do
5137 begin
5138 if FKeys[k].Pressed then
5139 begin
5140 dospawn := True;
5141 break;
5142 end;
5143 end;
5144 if dospawn then
5145 begin
5146 if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
5147 Respawn(False)
5148 else // Single
5149 if (FTime[T_RESPAWN] <= gTime) and
5150 gGameOn and (not FAlive) then
5151 begin
5152 if (g_Player_GetCount() > 1) then
5153 Respawn(False)
5154 else
5155 begin
5156 gExit := EXIT_RESTART;
5157 Exit;
5158 end;
5159 end;
5160 end;
5161 // Dead spectator actions
5162 if FGhost then
5163 begin
5164 if FKeys[KEY_OPEN].Pressed and AnyServer then Fire();
5165 if FKeys[KEY_FIRE].Pressed and AnyServer then
5166 begin
5167 if FSpectator then
5168 begin
5169 if (FSpectatePlayer >= High(gPlayers)) then
5170 FSpectatePlayer := -1
5171 else
5172 begin
5173 SetSpect := False;
5174 for I := FSpectatePlayer + 1 to High(gPlayers) do
5175 if gPlayers[I] <> nil then
5176 if gPlayers[I].alive then
5177 if gPlayers[I].UID <> FUID then
5178 begin
5179 FSpectatePlayer := I;
5180 SetSpect := True;
5181 break;
5182 end;
5184 if not SetSpect then FSpectatePlayer := -1;
5185 end;
5187 ReleaseKeys;
5188 end;
5189 end;
5190 end;
5191 end;
5192 // No clipping
5193 if FGhost then
5194 begin
5195 if FKeys[KEY_UP].Pressed or FKeys[KEY_JUMP].Pressed then
5196 begin
5197 FYTo := FObj.Y - 32;
5198 FSpectatePlayer := -1;
5199 end;
5200 if FKeys[KEY_DOWN].Pressed then
5201 begin
5202 FYTo := FObj.Y + 32;
5203 FSpectatePlayer := -1;
5204 end;
5205 if FKeys[KEY_LEFT].Pressed then
5206 begin
5207 FXTo := FObj.X - 32;
5208 FSpectatePlayer := -1;
5209 end;
5210 if FKeys[KEY_RIGHT].Pressed then
5211 begin
5212 FXTo := FObj.X + 32;
5213 FSpectatePlayer := -1;
5214 end;
5216 if (FXTo < -64) then
5217 FXTo := -64
5218 else if (FXTo > gMapInfo.Width + 32) then
5219 FXTo := gMapInfo.Width + 32;
5220 if (FYTo < -72) then
5221 FYTo := -72
5222 else if (FYTo > gMapInfo.Height + 32) then
5223 FYTo := gMapInfo.Height + 32;
5224 end;
5226 if FPhysics then
5227 begin
5228 if not followCorpse() then
5229 g_Obj_Move(@FObj, True, True, True);
5230 positionChanged(); // this updates spatial accelerators
5232 else
5233 begin
5234 FObj.Vel.X := 0;
5235 FObj.Vel.Y := 0;
5236 if FSpectator then
5237 if (FSpectatePlayer <= High(gPlayers)) and (FSpectatePlayer >= 0) then
5238 if gPlayers[FSpectatePlayer] <> nil then
5239 if gPlayers[FSpectatePlayer].alive then
5240 begin
5241 FXTo := gPlayers[FSpectatePlayer].GameX;
5242 FYTo := gPlayers[FSpectatePlayer].GameY;
5243 end;
5244 end;
5246 blockmon := g_Map_CollidePanel(FObj.X+PLAYER_HEADRECT.X, FObj.Y+PLAYER_HEADRECT.Y,
5247 PLAYER_HEADRECT.Width, PLAYER_HEADRECT.Height,
5248 PANEL_BLOCKMON, True);
5249 headwater := HeadInLiquid(0, 0);
5251 // Ñîïðîòèâëåíèå âîçäóõà:
5252 if (not FAlive) or not (FKeys[KEY_LEFT].Pressed or FKeys[KEY_RIGHT].Pressed) then
5253 if FObj.Vel.X <> 0 then
5254 FObj.Vel.X := z_dec(FObj.Vel.X, 1);
5256 if (FLastHit = HIT_TRAP) and (FPain > 90) then FPain := 90;
5257 DecMin(FPain, 5, 0);
5258 DecMin(FPickup, 1, 0);
5260 if FAlive and (FObj.Y > Integer(gMapInfo.Height)+128) and AnyServer then
5261 begin
5262 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
5263 FMegaRulez[MR_SUIT] := 0;
5264 FMegaRulez[MR_INVUL] := 0;
5265 FMegaRulez[MR_INVIS] := 0;
5266 Kill(K_FALLKILL, 0, HIT_FALL);
5267 end;
5269 i := 9;
5271 if FAlive then
5272 begin
5273 if FCurrWeap = WEAPON_SAW then
5274 if not (FSawSound.IsPlaying() or FSawSoundHit.IsPlaying() or
5275 FSawSoundSelect.IsPlaying()) then
5276 FSawSoundIdle.PlayAt(FObj.X, FObj.Y);
5278 if FJetpack then
5279 if (not FJetSoundFly.IsPlaying()) and (not FJetSoundOn.IsPlaying()) and
5280 (not FJetSoundOff.IsPlaying()) then
5281 begin
5282 FJetSoundFly.SetPosition(0);
5283 FJetSoundFly.PlayAt(FObj.X, FObj.Y);
5284 end;
5286 for b := WP_FIRST to WP_LAST do
5287 if FReloading[b] > 0 then
5288 if FNoReload then
5289 FReloading[b] := 0
5290 else
5291 Dec(FReloading[b]);
5293 if FShellTimer > -1 then
5294 if FShellTimer = 0 then
5295 begin
5296 if FShellType = SHELL_SHELL then
5297 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
5298 GameVelX, GameVelY-2, SHELL_SHELL)
5299 else if FShellType = SHELL_DBLSHELL then
5300 begin
5301 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
5302 GameVelX+1, GameVelY-2, SHELL_SHELL);
5303 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
5304 GameVelX-1, GameVelY-2, SHELL_SHELL);
5305 end;
5306 FShellTimer := -1;
5307 end else Dec(FShellTimer);
5309 if (FBFGFireCounter > -1) then
5310 if FBFGFireCounter = 0 then
5311 begin
5312 if AnyServer then
5313 begin
5314 wx := FObj.X+WEAPONPOINT[FDirection].X;
5315 wy := FObj.Y+WEAPONPOINT[FDirection].Y;
5316 xd := wx+IfThen(FDirection = TDirection.D_LEFT, -30, 30);
5317 yd := wy+firediry();
5318 g_Weapon_bfgshot(wx, wy, xd, yd, FUID);
5319 if NetServer then MH_SEND_PlayerFire(FUID, WEAPON_BFG, wx, wy, xd, yd);
5320 if (FAngle = 0) or (FAngle = 180) then SetAction(A_ATTACK)
5321 else if (FAngle = ANGLE_LEFTDOWN) or (FAngle = ANGLE_RIGHTDOWN) then SetAction(A_ATTACKDOWN)
5322 else if (FAngle = ANGLE_LEFTUP) or (FAngle = ANGLE_RIGHTUP) then SetAction(A_ATTACKUP);
5323 end;
5325 FReloading[WEAPON_BFG] := WEAPON_RELOAD[WEAPON_BFG];
5326 FBFGFireCounter := -1;
5327 end else
5328 if FNoReload then
5329 FBFGFireCounter := 0
5330 else
5331 Dec(FBFGFireCounter);
5333 if (FMegaRulez[MR_SUIT] < gTime) and AnyServer then
5334 begin
5335 b := g_GetAcidHit(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width, PLAYER_RECT.Height);
5337 if (b > 0) and (gTime mod (15*GAME_TICK) = 0) then Damage(b, 0, 0, 0, HIT_ACID);
5338 end;
5340 if (headwater or blockmon) then
5341 begin
5342 Dec(FAir);
5344 if FAir < -9 then
5345 begin
5346 if AnyServer then Damage(10, 0, 0, 0, HIT_WATER);
5347 FAir := 0;
5349 else if (FAir mod 31 = 0) and not blockmon then
5350 begin
5351 g_GFX_Bubbles(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2), FObj.Y+PLAYER_RECT.Y-4, 5+Random(6), 8, 4);
5352 if Random(2) = 0 then
5353 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj.X, FObj.Y)
5354 else
5355 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj.X, FObj.Y);
5356 end;
5357 end else if FAir < AIR_DEF then
5358 FAir := AIR_DEF;
5360 if FFireTime > 0 then
5361 begin
5362 if BodyInLiquid(0, 0) then
5363 begin
5364 FFireTime := 0;
5365 FFirePainTime := 0;
5367 else if FMegaRulez[MR_SUIT] >= gTime then
5368 begin
5369 if FMegaRulez[MR_SUIT] = gTime then
5370 FFireTime := 1;
5371 FFirePainTime := 0;
5373 else
5374 begin
5375 OnFireFlame(1);
5376 if FFirePainTime <= 0 then
5377 begin
5378 if g_Game_IsServer then
5379 Damage(5, FFireAttacker, 0, 0, HIT_FLAME);
5380 FFirePainTime := 18;
5381 end;
5382 FFirePainTime := FFirePainTime - 1;
5383 FFireTime := FFireTime - 1;
5384 if (FFireTime = 0) and g_Game_IsNet and g_Game_IsServer then
5385 MH_SEND_PlayerStats(FUID);
5386 end;
5387 end;
5389 if FDamageBuffer > 0 then
5390 begin
5391 if FDamageBuffer >= 9 then
5392 begin
5393 SetAction(A_PAIN);
5395 if FDamageBuffer < 30 then i := 9
5396 else if FDamageBuffer < 100 then i := 18
5397 else i := 27;
5398 end;
5400 ii := Round(FDamageBuffer*FHealth / nonz(FArmor*(3/4)+FHealth));
5401 FArmor := FArmor-(FDamageBuffer-ii);
5402 FHealth := FHealth-ii;
5403 if FArmor < 0 then
5404 begin
5405 FHealth := FHealth+FArmor;
5406 FArmor := 0;
5407 end;
5409 if AnyServer then
5410 if FHealth <= 0 then
5411 if FHealth > -30 then Kill(K_SIMPLEKILL, FLastSpawnerUID, FLastHit)
5412 else if FHealth > -50 then Kill(K_HARDKILL, FLastSpawnerUID, FLastHit)
5413 else Kill(K_EXTRAHARDKILL, FLastSpawnerUID, FLastHit);
5415 if FAlive then
5416 begin
5417 if FDamageBuffer <= 20 then FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y)
5418 else if FDamageBuffer <= 55 then FModel.PlaySound(MODELSOUND_PAIN, 2, FObj.X, FObj.Y)
5419 else if FDamageBuffer <= 120 then FModel.PlaySound(MODELSOUND_PAIN, 3, FObj.X, FObj.Y)
5420 else FModel.PlaySound(MODELSOUND_PAIN, 4, FObj.X, FObj.Y);
5421 end;
5423 FDamageBuffer := 0;
5424 end;
5426 {CollideItem();}
5427 end; // if FAlive then ...
5429 if (FActionAnim = A_PAIN) and (FModel.Animation <> A_PAIN) then
5430 begin
5431 FModel.ChangeAnimation(FActionAnim, FActionForce);
5432 FModel.GetCurrentAnimation.MinLength := i;
5433 FModel.GetCurrentAnimationMask.MinLength := i;
5434 end else FModel.ChangeAnimation(FActionAnim, FActionForce and (FModel.Animation <> A_STAND));
5436 if (FModel.GetCurrentAnimation.Played or ((not FActionChanged) and (FModel.Animation = A_WALK)))
5437 then SetAction(A_STAND, True);
5439 if not ((FModel.Animation = A_WALK) and (Abs(FObj.Vel.X) < 4) and not FModel.Fire) then FModel.Update;
5441 for b := Low(FKeys) to High(FKeys) do
5442 if FKeys[b].Time = 0 then FKeys[b].Pressed := False else Dec(FKeys[b].Time);
5443 end;
5446 procedure TPlayer.getMapBox (out x, y, w, h: Integer); inline;
5447 begin
5448 x := FObj.X+PLAYER_RECT.X;
5449 y := FObj.Y+PLAYER_RECT.Y;
5450 w := PLAYER_RECT.Width;
5451 h := PLAYER_RECT.Height;
5452 end;
5455 procedure TPlayer.moveBy (dx, dy: Integer); inline;
5456 begin
5457 if (dx <> 0) or (dy <> 0) then
5458 begin
5459 FObj.X += dx;
5460 FObj.Y += dy;
5461 positionChanged();
5462 end;
5463 end;
5466 function TPlayer.Collide(X, Y: Integer; Width, Height: Word): Boolean;
5467 begin
5468 Result := g_Collide(FObj.X+PLAYER_RECT.X,
5469 FObj.Y+PLAYER_RECT.Y,
5470 PLAYER_RECT.Width,
5471 PLAYER_RECT.Height,
5472 X, Y,
5473 Width, Height);
5474 end;
5476 function TPlayer.Collide(Panel: TPanel): Boolean;
5477 begin
5478 Result := g_Collide(FObj.X+PLAYER_RECT.X,
5479 FObj.Y+PLAYER_RECT.Y,
5480 PLAYER_RECT.Width,
5481 PLAYER_RECT.Height,
5482 Panel.X, Panel.Y,
5483 Panel.Width, Panel.Height);
5484 end;
5486 function TPlayer.Collide(X, Y: Integer): Boolean;
5487 begin
5488 X := X-FObj.X-PLAYER_RECT.X;
5489 Y := Y-FObj.Y-PLAYER_RECT.Y;
5490 Result := (x >= 0) and (x <= PLAYER_RECT.Width) and
5491 (y >= 0) and (y <= PLAYER_RECT.Height);
5492 end;
5494 function g_Player_ValidName(Name: string): Boolean;
5496 a: Integer;
5497 begin
5498 Result := True;
5500 if gPlayers = nil then Exit;
5502 for a := 0 to High(gPlayers) do
5503 if gPlayers[a] <> nil then
5504 if LowerCase(Name) = LowerCase(gPlayers[a].FName) then
5505 begin
5506 Result := False;
5507 Exit;
5508 end;
5509 end;
5511 procedure TPlayer.SetDirection(Direction: TDirection);
5513 d: TDirection;
5514 begin
5515 d := FModel.Direction;
5517 FModel.Direction := Direction;
5518 if d <> Direction then FModel.ChangeAnimation(FModel.Animation, True);
5520 FDirection := Direction;
5521 end;
5523 function TPlayer.GetKeys(): Byte;
5524 begin
5525 Result := 0;
5527 if R_KEY_RED in FRulez then Result := KEY_RED;
5528 if R_KEY_GREEN in FRulez then Result := Result or KEY_GREEN;
5529 if R_KEY_BLUE in FRulez then Result := Result or KEY_BLUE;
5531 if FTeam = TEAM_RED then Result := Result or KEY_REDTEAM;
5532 if FTeam = TEAM_BLUE then Result := Result or KEY_BLUETEAM;
5533 end;
5535 procedure TPlayer.Use();
5537 a: Integer;
5538 begin
5539 if FTime[T_USE] > gTime then Exit;
5541 g_Triggers_PressR(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
5542 PLAYER_RECT.Height, FUID, ACTIVATE_PLAYERPRESS);
5544 for a := 0 to High(gPlayers) do
5545 if (gPlayers[a] <> nil) and (gPlayers[a] <> Self) and
5546 gPlayers[a].alive and SameTeam(FUID, gPlayers[a].FUID) and
5547 g_Obj_Collide(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y,
5548 FObj.Rect.Width, FObj.Rect.Height, @gPlayers[a].FObj) then
5549 begin
5550 gPlayers[a].Touch();
5551 if g_Game_IsNet and g_Game_IsServer then
5552 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH, gPlayers[a].FUID);
5553 end;
5555 FTime[T_USE] := gTime+120;
5556 end;
5558 procedure TPlayer.NetFire(Wpn: Byte; X, Y, AX, AY: Integer; WID: Integer = -1);
5560 locObj: TObj;
5561 F: Boolean;
5562 WX, WY, XD, YD: Integer;
5563 begin
5564 F := False;
5565 WX := X;
5566 WY := Y;
5567 XD := AX;
5568 YD := AY;
5570 case FCurrWeap of
5571 WEAPON_KASTET:
5572 begin
5573 DoPunch();
5574 if R_BERSERK in FRulez then
5575 begin
5576 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5577 locobj.X := FObj.X+FObj.Rect.X;
5578 locobj.Y := FObj.Y+FObj.Rect.Y;
5579 locobj.rect.X := 0;
5580 locobj.rect.Y := 0;
5581 locobj.rect.Width := 39;
5582 locobj.rect.Height := 52;
5583 locobj.Vel.X := (xd-wx) div 2;
5584 locobj.Vel.Y := (yd-wy) div 2;
5585 locobj.Accel.X := xd-wx;
5586 locobj.Accel.y := yd-wy;
5588 if g_Weapon_Hit(@locobj, 50, FUID, HIT_SOME) <> 0 then
5589 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj.X, FObj.Y)
5590 else
5591 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj.X, FObj.Y);
5593 if gFlash = 1 then
5594 if FPain < 50 then
5595 FPain := min(FPain + 25, 50);
5596 end else
5597 g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 3, FUID);
5598 end;
5600 WEAPON_SAW:
5601 begin
5602 if g_Weapon_chainsaw(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y,
5603 IfThen(gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF], 9, 3), FUID) <> 0 then
5604 begin
5605 FSawSoundSelect.Stop();
5606 FSawSound.Stop();
5607 FSawSoundHit.PlayAt(FObj.X, FObj.Y);
5609 else if not FSawSoundHit.IsPlaying() then
5610 begin
5611 FSawSoundSelect.Stop();
5612 FSawSound.PlayAt(FObj.X, FObj.Y);
5613 end;
5614 f := True;
5615 end;
5617 WEAPON_PISTOL:
5618 begin
5619 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX, Gamey);
5620 FFireAngle := FAngle;
5621 f := True;
5622 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
5623 GameVelX, GameVelY-2, SHELL_BULLET);
5624 end;
5626 WEAPON_SHOTGUN1:
5627 begin
5628 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex, Gamey);
5629 FFireAngle := FAngle;
5630 f := True;
5631 FShellTimer := 10;
5632 FShellType := SHELL_SHELL;
5633 end;
5635 WEAPON_SHOTGUN2:
5636 begin
5637 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex, Gamey);
5638 FFireAngle := FAngle;
5639 f := True;
5640 FShellTimer := 13;
5641 FShellType := SHELL_DBLSHELL;
5642 end;
5644 WEAPON_CHAINGUN:
5645 begin
5646 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex, Gamey);
5647 FFireAngle := FAngle;
5648 f := True;
5649 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
5650 GameVelX, GameVelY-2, SHELL_BULLET);
5651 end;
5653 WEAPON_ROCKETLAUNCHER:
5654 begin
5655 g_Weapon_Rocket(wx, wy, xd, yd, FUID, WID);
5656 FFireAngle := FAngle;
5657 f := True;
5658 end;
5660 WEAPON_PLASMA:
5661 begin
5662 g_Weapon_Plasma(wx, wy, xd, yd, FUID, WID);
5663 FFireAngle := FAngle;
5664 f := True;
5665 end;
5667 WEAPON_BFG:
5668 begin
5669 g_Weapon_BFGShot(wx, wy, xd, yd, FUID, WID);
5670 FFireAngle := FAngle;
5671 f := True;
5672 end;
5674 WEAPON_SUPERPULEMET:
5675 begin
5676 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex, Gamey);
5677 FFireAngle := FAngle;
5678 f := True;
5679 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
5680 GameVelX, GameVelY-2, SHELL_SHELL);
5681 end;
5683 WEAPON_FLAMETHROWER:
5684 begin
5685 g_Weapon_flame(wx, wy, xd, yd, FUID, WID);
5686 FFireAngle := FAngle;
5687 f := True;
5688 end;
5689 end;
5691 if not f then Exit;
5693 if (FAngle = 0) or (FAngle = 180) then SetAction(A_ATTACK)
5694 else if (FAngle = ANGLE_LEFTDOWN) or (FAngle = ANGLE_RIGHTDOWN) then SetAction(A_ATTACKDOWN)
5695 else if (FAngle = ANGLE_LEFTUP) or (FAngle = ANGLE_RIGHTUP) then SetAction(A_ATTACKUP);
5696 end;
5698 procedure TPlayer.DoLerp(Level: Integer = 2);
5699 begin
5700 if FObj.X <> FXTo then FObj.X := Lerp(FObj.X, FXTo, Level);
5701 if FObj.Y <> FYTo then FObj.Y := Lerp(FObj.Y, FYTo, Level);
5702 end;
5704 procedure TPlayer.SetLerp(XTo, YTo: Integer);
5706 AX, AY: Integer;
5707 begin
5708 if NetInterpLevel < 1 then
5709 begin
5710 FObj.X := XTo;
5711 FObj.Y := YTo;
5713 else
5714 begin
5715 FXTo := XTo;
5716 FYTo := YTo;
5718 AX := Abs(FXTo - FObj.X);
5719 AY := Abs(FYTo - FObj.Y);
5720 if (AX > 32) or (AX <= NetInterpLevel) then
5721 FObj.X := FXTo;
5722 if (AY > 32) or (AY <= NetInterpLevel) then
5723 FObj.Y := FYTo;
5724 end;
5725 end;
5727 function TPlayer.FullInLift(XInc, YInc: Integer): Integer;
5728 begin
5729 if g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc,
5730 PLAYER_RECT.Width, PLAYER_RECT.Height-8,
5731 PANEL_LIFTUP, False) then Result := -1
5732 else
5733 if g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc,
5734 PLAYER_RECT.Width, PLAYER_RECT.Height-8,
5735 PANEL_LIFTDOWN, False) then Result := 1
5736 else Result := 0;
5737 end;
5739 function TPlayer.GetFlag(Flag: Byte): Boolean;
5741 s, ts: String;
5742 evtype: Byte;
5743 begin
5744 Result := False;
5746 if Flag = FLAG_NONE then
5747 Exit;
5749 if not g_Game_IsServer then Exit;
5751 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5752 if (Flag = FTeam) and
5753 (gFlags[Flag].State = FLAG_STATE_NORMAL) and
5754 (FFlag <> FLAG_NONE) then
5755 begin
5756 if FFlag = FLAG_RED then
5757 s := _lc[I_PLAYER_FLAG_RED]
5758 else
5759 s := _lc[I_PLAYER_FLAG_BLUE];
5761 evtype := FLAG_STATE_SCORED;
5763 ts := Format('%.4d', [gFlags[FFlag].CaptureTime]);
5764 Insert('.', ts, Length(ts) + 1 - 3);
5765 g_Console_Add(Format(_lc[I_PLAYER_FLAG_CAPTURE], [FName, s, ts]), True);
5767 g_Map_ResetFlag(FFlag);
5768 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_CAPTURE], [AnsiUpperCase(s)]), 144);
5770 gTeamStat[FTeam].Goals := gTeamStat[FTeam].Goals + 1;
5772 Result := True;
5773 if g_Game_IsNet then
5774 begin
5775 MH_SEND_FlagEvent(evtype, FFlag, FUID, False);
5776 MH_SEND_GameStats;
5777 end;
5779 gFlags[FFlag].CaptureTime := 0;
5780 SetFlag(FLAG_NONE);
5781 Exit;
5782 end;
5784 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5785 if (Flag = FTeam) and
5786 (gFlags[Flag].State = FLAG_STATE_DROPPED) then
5787 begin
5788 if Flag = FLAG_RED then
5789 s := _lc[I_PLAYER_FLAG_RED]
5790 else
5791 s := _lc[I_PLAYER_FLAG_BLUE];
5793 evtype := FLAG_STATE_RETURNED;
5794 gFlags[Flag].CaptureTime := 0;
5796 g_Console_Add(Format(_lc[I_PLAYER_FLAG_RETURN], [FName, s]), True);
5798 g_Map_ResetFlag(Flag);
5799 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_RETURN], [AnsiUpperCase(s)]), 144);
5801 Result := True;
5802 if g_Game_IsNet then
5803 begin
5804 MH_SEND_FlagEvent(evtype, Flag, FUID, False);
5805 MH_SEND_GameStats;
5806 end;
5807 Exit;
5808 end;
5810 // Ïîäîáðàë ÷óæîé ôëàã:
5811 if (Flag <> FTeam) and (FTime[T_FLAGCAP] <= gTime) then
5812 begin
5813 SetFlag(Flag);
5815 if Flag = FLAG_RED then
5816 s := _lc[I_PLAYER_FLAG_RED]
5817 else
5818 s := _lc[I_PLAYER_FLAG_BLUE];
5820 evtype := FLAG_STATE_CAPTURED;
5822 g_Console_Add(Format(_lc[I_PLAYER_FLAG_GET], [FName, s]), True);
5824 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_GET], [AnsiUpperCase(s)]), 144);
5826 gFlags[Flag].State := FLAG_STATE_CAPTURED;
5828 Result := True;
5829 if g_Game_IsNet then
5830 begin
5831 MH_SEND_FlagEvent(evtype, Flag, FUID, False);
5832 MH_SEND_GameStats;
5833 end;
5834 end;
5835 end;
5837 procedure TPlayer.SetFlag(Flag: Byte);
5838 begin
5839 FFlag := Flag;
5840 if FModel <> nil then
5841 FModel.SetFlag(FFlag);
5842 end;
5844 function TPlayer.DropFlag(): Boolean;
5846 s: String;
5847 begin
5848 Result := False;
5849 if (not g_Game_IsServer) or (FFlag = FLAG_NONE) then
5850 Exit;
5851 FTime[T_FLAGCAP] := gTime + 2000;
5852 with gFlags[FFlag] do
5853 begin
5854 Obj.X := FObj.X;
5855 Obj.Y := FObj.Y;
5856 Direction := FDirection;
5857 State := FLAG_STATE_DROPPED;
5858 Count := FLAG_TIME;
5859 g_Obj_Push(@Obj, (FObj.Vel.X div 2)-2+Random(5),
5860 (FObj.Vel.Y div 2)-2+Random(5));
5861 positionChanged(); // this updates spatial accelerators
5863 if FFlag = FLAG_RED then
5864 s := _lc[I_PLAYER_FLAG_RED]
5865 else
5866 s := _lc[I_PLAYER_FLAG_BLUE];
5868 g_Console_Add(Format(_lc[I_PLAYER_FLAG_DROP], [FName, s]), True);
5869 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_DROP], [AnsiUpperCase(s)]), 144);
5871 if g_Game_IsNet then
5872 MH_SEND_FlagEvent(FLAG_STATE_DROPPED, Flag, FUID, False);
5873 end;
5874 SetFlag(FLAG_NONE);
5875 Result := True;
5876 end;
5878 procedure TPlayer.GetSecret();
5879 begin
5880 Inc(FSecrets);
5881 end;
5883 procedure TPlayer.PressKey(Key: Byte; Time: Word = 1);
5884 begin
5885 Assert(Key <= High(FKeys));
5887 FKeys[Key].Pressed := True;
5888 FKeys[Key].Time := Time;
5889 end;
5891 function TPlayer.IsKeyPressed(K: Byte): Boolean;
5892 begin
5893 Result := FKeys[K].Pressed;
5894 end;
5896 procedure TPlayer.ReleaseKeys();
5898 a: Integer;
5899 begin
5900 for a := Low(FKeys) to High(FKeys) do
5901 begin
5902 FKeys[a].Pressed := False;
5903 FKeys[a].Time := 0;
5904 end;
5905 end;
5907 procedure TPlayer.ReleaseKeysNoWeapon();
5909 a: Integer;
5910 begin
5911 for a := Low(FKeys) to High(FKeys) do
5912 begin
5913 if (a = KEY_PREVWEAPON) or (a = KEY_NEXTWEAPON) then continue;
5914 FKeys[a].Pressed := False;
5915 FKeys[a].Time := 0;
5916 end;
5917 end;
5919 procedure TPlayer.OnDamage(Angle: SmallInt);
5920 begin
5921 end;
5923 function TPlayer.firediry(): Integer;
5924 begin
5925 if FKeys[KEY_UP].Pressed then Result := -42
5926 else if FKeys[KEY_DOWN].Pressed then Result := 19
5927 else Result := 0;
5928 end;
5930 procedure TPlayer.RememberState();
5932 i: Integer;
5933 begin
5934 FSavedState.Health := FHealth;
5935 FSavedState.Armor := FArmor;
5936 FSavedState.Air := FAir;
5937 FSavedState.JetFuel := FJetFuel;
5938 FSavedState.CurrWeap := FCurrWeap;
5939 FSavedState.NextWeap := FNextWeap;
5940 FSavedState.NextWeapDelay := FNextWeapDelay;
5942 for i := 0 to 3 do
5943 FSavedState.Ammo[i] := FAmmo[i];
5944 for i := 0 to 3 do
5945 FSavedState.MaxAmmo[i] := FMaxAmmo[i];
5947 FSavedState.Rulez := FRulez;
5948 FSavedState.WaitRecall := True;
5949 end;
5951 procedure TPlayer.RecallState();
5953 i: Integer;
5954 begin
5955 if not FSavedState.WaitRecall then Exit;
5957 FHealth := FSavedState.Health;
5958 FArmor := FSavedState.Armor;
5959 FAir := FSavedState.Air;
5960 FJetFuel := FSavedState.JetFuel;
5961 FCurrWeap := FSavedState.CurrWeap;
5962 //FNetForceWeap := FCurrWeap;
5963 FNextWeap := FSavedState.NextWeap;
5964 FNextWeapDelay := FSavedState.NextWeapDelay;
5966 for i := 0 to 3 do
5967 FAmmo[i] := FSavedState.Ammo[i];
5968 for i := 0 to 3 do
5969 FMaxAmmo[i] := FSavedState.MaxAmmo[i];
5971 FRulez := FSavedState.Rulez;
5972 FSavedState.WaitRecall := False;
5974 if gGameSettings.GameType = GT_SERVER then
5975 MH_SEND_PlayerStats(FUID);
5976 end;
5978 procedure TPlayer.SaveState (st: TStream);
5980 i: Integer;
5981 b: Byte;
5982 begin
5983 // Ñèãíàòóðà èãðîêà
5984 utils.writeSign(st, 'PLYR');
5985 utils.writeInt(st, Byte(PLR_SAVE_VERSION)); // version
5986 // Áîò èëè ÷åëîâåê
5987 utils.writeBool(st, FIamBot);
5988 // UID èãðîêà
5989 utils.writeInt(st, Word(FUID));
5990 // Èìÿ èãðîêà
5991 utils.writeStr(st, FName);
5992 // Êîìàíäà
5993 utils.writeInt(st, Byte(FTeam));
5994 // Æèâ ëè
5995 utils.writeBool(st, FAlive);
5996 // Èçðàñõîäîâàë ëè âñå æèçíè
5997 utils.writeBool(st, FNoRespawn);
5998 // Íàïðàâëåíèå
5999 if FDirection = TDirection.D_LEFT then b := 1 else b := 2; // D_RIGHT
6000 utils.writeInt(st, Byte(b));
6001 // Çäîðîâüå
6002 utils.writeInt(st, LongInt(FHealth));
6003 // Æèçíè
6004 utils.writeInt(st, Byte(FLives));
6005 // Áðîíÿ
6006 utils.writeInt(st, LongInt(FArmor));
6007 // Çàïàñ âîçäóõà
6008 utils.writeInt(st, LongInt(FAir));
6009 // Çàïàñ ãîðþ÷åãî
6010 utils.writeInt(st, LongInt(FJetFuel));
6011 // Áîëü
6012 utils.writeInt(st, LongInt(FPain));
6013 // Óáèë
6014 utils.writeInt(st, LongInt(FKills));
6015 // Óáèë ìîíñòðîâ
6016 utils.writeInt(st, LongInt(FMonsterKills));
6017 // Ôðàãîâ
6018 utils.writeInt(st, LongInt(FFrags));
6019 // Ôðàãîâ ïîäðÿä
6020 utils.writeInt(st, Byte(FFragCombo));
6021 // Âðåìÿ ïîñëåäíåãî ôðàãà
6022 utils.writeInt(st, LongWord(FLastFrag));
6023 // Ñìåðòåé
6024 utils.writeInt(st, LongInt(FDeath));
6025 // Êàêîé ôëàã íåñåò
6026 utils.writeInt(st, Byte(FFlag));
6027 // Íàøåë ñåêðåòîâ
6028 utils.writeInt(st, LongInt(FSecrets));
6029 // Òåêóùåå îðóæèå
6030 utils.writeInt(st, Byte(FCurrWeap));
6031 // Æåëàåìîå îðóæèå
6032 utils.writeInt(st, Word(FNextWeap));
6033 // ...è ïàóçà
6034 utils.writeInt(st, Byte(FNextWeapDelay));
6035 // Âðåìÿ çàðÿäêè BFG
6036 utils.writeInt(st, SmallInt(FBFGFireCounter));
6037 // Áóôåð óðîíà
6038 utils.writeInt(st, LongInt(FDamageBuffer));
6039 // Ïîñëåäíèé óäàðèâøèé
6040 utils.writeInt(st, Word(FLastSpawnerUID));
6041 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6042 utils.writeInt(st, Byte(FLastHit));
6043 // Îáúåêò èãðîêà
6044 Obj_SaveState(st, @FObj);
6045 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6046 for i := A_BULLETS to A_HIGH do utils.writeInt(st, Word(FAmmo[i]));
6047 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6048 for i := A_BULLETS to A_HIGH do utils.writeInt(st, Word(FMaxAmmo[i]));
6049 // Íàëè÷èå îðóæèÿ
6050 for i := WP_FIRST to WP_LAST do utils.writeBool(st, FWeapon[i]);
6051 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6052 for i := WP_FIRST to WP_LAST do utils.writeInt(st, Word(FReloading[i]));
6053 // Íàëè÷èå ðþêçàêà
6054 utils.writeBool(st, (R_ITEM_BACKPACK in FRulez));
6055 // Íàëè÷èå êðàñíîãî êëþ÷à
6056 utils.writeBool(st, (R_KEY_RED in FRulez));
6057 // Íàëè÷èå çåëåíîãî êëþ÷à
6058 utils.writeBool(st, (R_KEY_GREEN in FRulez));
6059 // Íàëè÷èå ñèíåãî êëþ÷à
6060 utils.writeBool(st, (R_KEY_BLUE in FRulez));
6061 // Íàëè÷èå áåðñåðêà
6062 utils.writeBool(st, (R_BERSERK in FRulez));
6063 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6064 for i := MR_SUIT to MR_MAX do utils.writeInt(st, LongWord(FMegaRulez[i]));
6065 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6066 for i := T_RESPAWN to T_FLAGCAP do utils.writeInt(st, LongWord(FTime[i]));
6067 // Íàçâàíèå ìîäåëè
6068 utils.writeStr(st, FModel.Name);
6069 // Öâåò ìîäåëè
6070 utils.writeInt(st, Byte(FColor.R));
6071 utils.writeInt(st, Byte(FColor.G));
6072 utils.writeInt(st, Byte(FColor.B));
6073 end;
6076 procedure TPlayer.LoadState (st: TStream);
6078 i: Integer;
6079 str: String;
6080 b: Byte;
6081 begin
6082 assert(st <> nil);
6084 // Ñèãíàòóðà èãðîêà
6085 if not utils.checkSign(st, 'PLYR') then raise XStreamError.Create('invalid player signature');
6086 if (utils.readByte(st) <> PLR_SAVE_VERSION) then raise XStreamError.Create('invalid player version');
6087 // Áîò èëè ÷åëîâåê:
6088 FIamBot := utils.readBool(st);
6089 // UID èãðîêà
6090 FUID := utils.readWord(st);
6091 // Èìÿ èãðîêà
6092 str := utils.readStr(st);
6093 if (self <> gPlayer1) and (self <> gPlayer2) then FName := str;
6094 // Êîìàíäà
6095 FTeam := utils.readByte(st);
6096 // Æèâ ëè
6097 FAlive := utils.readBool(st);
6098 // Èçðàñõîäîâàë ëè âñå æèçíè
6099 FNoRespawn := utils.readBool(st);
6100 // Íàïðàâëåíèå
6101 b := utils.readByte(st);
6102 if b = 1 then FDirection := TDirection.D_LEFT else FDirection := TDirection.D_RIGHT; // b = 2
6103 // Çäîðîâüå
6104 FHealth := utils.readLongInt(st);
6105 // Æèçíè
6106 FLives := utils.readByte(st);
6107 // Áðîíÿ
6108 FArmor := utils.readLongInt(st);
6109 // Çàïàñ âîçäóõà
6110 FAir := utils.readLongInt(st);
6111 // Çàïàñ ãîðþ÷åãî
6112 FJetFuel := utils.readLongInt(st);
6113 // Áîëü
6114 FPain := utils.readLongInt(st);
6115 // Óáèë
6116 FKills := utils.readLongInt(st);
6117 // Óáèë ìîíñòðîâ
6118 FMonsterKills := utils.readLongInt(st);
6119 // Ôðàãîâ
6120 FFrags := utils.readLongInt(st);
6121 // Ôðàãîâ ïîäðÿä
6122 FFragCombo := utils.readByte(st);
6123 // Âðåìÿ ïîñëåäíåãî ôðàãà
6124 FLastFrag := utils.readLongWord(st);
6125 // Ñìåðòåé
6126 FDeath := utils.readLongInt(st);
6127 // Êàêîé ôëàã íåñåò
6128 FFlag := utils.readByte(st);
6129 // Íàøåë ñåêðåòîâ
6130 FSecrets := utils.readLongInt(st);
6131 // Òåêóùåå îðóæèå
6132 FCurrWeap := utils.readByte(st);
6133 //FNetForceWeap := FCurrWeap;
6134 // Æåëàåìîå îðóæèå
6135 FNextWeap := utils.readWord(st);
6136 // ...è ïàóçà
6137 FNextWeapDelay := utils.readByte(st);
6138 // Âðåìÿ çàðÿäêè BFG
6139 FBFGFireCounter := utils.readSmallInt(st);
6140 // Áóôåð óðîíà
6141 FDamageBuffer := utils.readLongInt(st);
6142 // Ïîñëåäíèé óäàðèâøèé
6143 FLastSpawnerUID := utils.readWord(st);
6144 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6145 FLastHit := utils.readByte(st);
6146 // Îáúåêò èãðîêà
6147 Obj_LoadState(@FObj, st);
6148 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6149 for i := A_BULLETS to A_HIGH do FAmmo[i] := utils.readWord(st);
6150 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6151 for i := A_BULLETS to A_HIGH do FMaxAmmo[i] := utils.readWord(st);
6152 // Íàëè÷èå îðóæèÿ
6153 for i := WP_FIRST to WP_LAST do FWeapon[i] := utils.readBool(st);
6154 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6155 for i := WP_FIRST to WP_LAST do FReloading[i] := utils.readWord(st);
6156 // Íàëè÷èå ðþêçàêà
6157 if utils.readBool(st) then Include(FRulez, R_ITEM_BACKPACK);
6158 // Íàëè÷èå êðàñíîãî êëþ÷à
6159 if utils.readBool(st) then Include(FRulez, R_KEY_RED);
6160 // Íàëè÷èå çåëåíîãî êëþ÷à
6161 if utils.readBool(st) then Include(FRulez, R_KEY_GREEN);
6162 // Íàëè÷èå ñèíåãî êëþ÷à
6163 if utils.readBool(st) then Include(FRulez, R_KEY_BLUE);
6164 // Íàëè÷èå áåðñåðêà
6165 if utils.readBool(st) then Include(FRulez, R_BERSERK);
6166 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6167 for i := MR_SUIT to MR_MAX do FMegaRulez[i] := utils.readLongWord(st);
6168 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6169 for i := T_RESPAWN to T_FLAGCAP do FTime[i] := utils.readLongWord(st);
6170 // Íàçâàíèå ìîäåëè
6171 str := utils.readStr(st);
6172 // Öâåò ìîäåëè
6173 FColor.R := utils.readByte(st);
6174 FColor.G := utils.readByte(st);
6175 FColor.B := utils.readByte(st);
6176 if (self = gPlayer1) then
6177 begin
6178 str := gPlayer1Settings.Model;
6179 FColor := gPlayer1Settings.Color;
6181 else if (self = gPlayer2) then
6182 begin
6183 str := gPlayer2Settings.Model;
6184 FColor := gPlayer2Settings.Color;
6185 end;
6186 // Îáíîâëÿåì ìîäåëü èãðîêà
6187 SetModel(str);
6188 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
6189 FModel.Color := TEAMCOLOR[FTeam]
6190 else
6191 FModel.Color := FColor;
6192 end;
6195 procedure TPlayer.AllRulez(Health: Boolean);
6197 a: Integer;
6198 begin
6199 if Health then
6200 begin
6201 FHealth := PLAYER_HP_LIMIT;
6202 FArmor := PLAYER_AP_LIMIT;
6203 Exit;
6204 end;
6206 for a := WP_FIRST to WP_LAST do FWeapon[a] := True;
6207 for a := A_BULLETS to A_HIGH do FAmmo[a] := 30000;
6208 FRulez := FRulez+[R_KEY_RED, R_KEY_GREEN, R_KEY_BLUE];
6209 end;
6211 procedure TPlayer.RestoreHealthArmor();
6212 begin
6213 FHealth := PLAYER_HP_LIMIT;
6214 FArmor := PLAYER_AP_LIMIT;
6215 end;
6217 procedure TPlayer.FragCombo();
6219 Param: Integer;
6220 begin
6221 if (gGameSettings.GameMode in [GM_COOP, GM_SINGLE]) or g_Game_IsClient then
6222 Exit;
6223 if gTime - FLastFrag < FRAG_COMBO_TIME then
6224 begin
6225 if FFragCombo < 5 then
6226 Inc(FFragCombo);
6227 Param := FUID or (FFragCombo shl 16);
6228 if (FComboEvnt >= Low(gDelayedEvents)) and
6229 (FComboEvnt <= High(gDelayedEvents)) and
6230 gDelayedEvents[FComboEvnt].Pending and
6231 (gDelayedEvents[FComboEvnt].DEType = DE_KILLCOMBO) and
6232 (gDelayedEvents[FComboEvnt].DENum and $FFFF = FUID) then
6233 begin
6234 gDelayedEvents[FComboEvnt].Time := gTime + 500;
6235 gDelayedEvents[FComboEvnt].DENum := Param;
6237 else
6238 FComboEvnt := g_Game_DelayEvent(DE_KILLCOMBO, 500, Param);
6240 else
6241 FFragCombo := 1;
6243 FLastFrag := gTime;
6244 end;
6246 procedure TPlayer.GiveItem(ItemType: Byte);
6247 begin
6248 case ItemType of
6249 ITEM_SUIT:
6250 if FMegaRulez[MR_SUIT] < gTime+PLAYER_SUIT_TIME then
6251 begin
6252 FMegaRulez[MR_SUIT] := gTime+PLAYER_SUIT_TIME;
6253 end;
6255 ITEM_OXYGEN:
6256 if FAir < AIR_MAX then
6257 begin
6258 FAir := AIR_MAX;
6259 end;
6261 ITEM_MEDKIT_BLACK:
6262 begin
6263 if not (R_BERSERK in FRulez) then
6264 begin
6265 Include(FRulez, R_BERSERK);
6266 if FBFGFireCounter < 1 then
6267 begin
6268 FCurrWeap := WEAPON_KASTET;
6269 //FNetForceWeap := FCurrWeap;
6270 FNetForceWeapFIdx := 0;
6271 resetWeaponQueue();
6272 FModel.SetWeapon(WEAPON_KASTET);
6273 end;
6274 if gFlash <> 0 then
6275 Inc(FPain, 100);
6276 FBerserk := gTime+30000;
6277 end;
6278 if FHealth < PLAYER_HP_SOFT then
6279 begin
6280 FHealth := PLAYER_HP_SOFT;
6281 FBerserk := gTime+30000;
6282 end;
6283 end;
6285 ITEM_INVUL:
6286 if FMegaRulez[MR_INVUL] < gTime+PLAYER_INVUL_TIME then
6287 begin
6288 FMegaRulez[MR_INVUL] := gTime+PLAYER_INVUL_TIME;
6289 end;
6291 ITEM_INVIS:
6292 if FMegaRulez[MR_INVIS] < gTime+PLAYER_INVIS_TIME then
6293 begin
6294 FMegaRulez[MR_INVIS] := gTime+PLAYER_INVIS_TIME;
6295 end;
6297 ITEM_JETPACK:
6298 if FJetFuel < JET_MAX then
6299 begin
6300 FJetFuel := JET_MAX;
6301 end;
6303 ITEM_MEDKIT_SMALL: if FHealth < PLAYER_HP_SOFT then IncMax(FHealth, 10, PLAYER_HP_SOFT);
6304 ITEM_MEDKIT_LARGE: if FHealth < PLAYER_HP_SOFT then IncMax(FHealth, 25, PLAYER_HP_SOFT);
6306 ITEM_ARMOR_GREEN: if FArmor < PLAYER_AP_SOFT then FArmor := PLAYER_AP_SOFT;
6307 ITEM_ARMOR_BLUE: if FArmor < PLAYER_AP_LIMIT then FArmor := PLAYER_AP_LIMIT;
6309 ITEM_SPHERE_BLUE: if FHealth < PLAYER_HP_LIMIT then IncMax(FHealth, 100, PLAYER_HP_LIMIT);
6310 ITEM_SPHERE_WHITE:
6311 if (FHealth < PLAYER_HP_LIMIT) or (FArmor < PLAYER_AP_LIMIT) then
6312 begin
6313 if FHealth < PLAYER_HP_LIMIT then FHealth := PLAYER_HP_LIMIT;
6314 if FArmor < PLAYER_AP_LIMIT then FArmor := PLAYER_AP_LIMIT;
6315 end;
6317 ITEM_WEAPON_SAW: FWeapon[WEAPON_SAW] := True;
6318 ITEM_WEAPON_SHOTGUN1: FWeapon[WEAPON_SHOTGUN1] := True;
6319 ITEM_WEAPON_SHOTGUN2: FWeapon[WEAPON_SHOTGUN2] := True;
6320 ITEM_WEAPON_CHAINGUN: FWeapon[WEAPON_CHAINGUN] := True;
6321 ITEM_WEAPON_ROCKETLAUNCHER: FWeapon[WEAPON_ROCKETLAUNCHER] := True;
6322 ITEM_WEAPON_PLASMA: FWeapon[WEAPON_PLASMA] := True;
6323 ITEM_WEAPON_BFG: FWeapon[WEAPON_BFG] := True;
6324 ITEM_WEAPON_SUPERPULEMET: FWeapon[WEAPON_SUPERPULEMET] := True;
6325 ITEM_WEAPON_FLAMETHROWER: FWeapon[WEAPON_FLAMETHROWER] := True;
6327 ITEM_AMMO_BULLETS: if FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS] then IncMax(FAmmo[A_BULLETS], 10, FMaxAmmo[A_BULLETS]);
6328 ITEM_AMMO_BULLETS_BOX: if FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS] then IncMax(FAmmo[A_BULLETS], 50, FMaxAmmo[A_BULLETS]);
6329 ITEM_AMMO_SHELLS: if FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS] then IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
6330 ITEM_AMMO_SHELLS_BOX: if FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS] then IncMax(FAmmo[A_SHELLS], 25, FMaxAmmo[A_SHELLS]);
6331 ITEM_AMMO_ROCKET: if FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS] then IncMax(FAmmo[A_ROCKETS], 1, FMaxAmmo[A_ROCKETS]);
6332 ITEM_AMMO_ROCKET_BOX: if FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS] then IncMax(FAmmo[A_ROCKETS], 5, FMaxAmmo[A_ROCKETS]);
6333 ITEM_AMMO_CELL: if FAmmo[A_CELLS] < FMaxAmmo[A_CELLS] then IncMax(FAmmo[A_CELLS], 40, FMaxAmmo[A_CELLS]);
6334 ITEM_AMMO_CELL_BIG: if FAmmo[A_CELLS] < FMaxAmmo[A_CELLS] then IncMax(FAmmo[A_CELLS], 100, FMaxAmmo[A_CELLS]);
6335 ITEM_AMMO_FUELCAN: if FAmmo[A_FUEL] < FMaxAmmo[A_FUEL] then IncMax(FAmmo[A_FUEL], 100, FMaxAmmo[A_FUEL]);
6337 ITEM_AMMO_BACKPACK:
6338 if (FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS]) or
6339 (FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS]) or
6340 (FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS]) or
6341 (FAmmo[A_CELLS] < FMaxAmmo[A_CELLS]) or
6342 (FMaxAmmo[A_FUEL] < AmmoLimits[1, A_FUEL]) then
6343 begin
6344 FMaxAmmo[A_BULLETS] := AmmoLimits[1, A_BULLETS];
6345 FMaxAmmo[A_SHELLS] := AmmoLimits[1, A_SHELLS];
6346 FMaxAmmo[A_ROCKETS] := AmmoLimits[1, A_ROCKETS];
6347 FMaxAmmo[A_CELLS] := AmmoLimits[1, A_CELLS];
6348 FMaxAmmo[A_FUEL] := AmmoLimits[1, A_FUEL];
6350 if FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS] then IncMax(FAmmo[A_BULLETS], 10, FMaxAmmo[A_BULLETS]);
6351 if FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS] then IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
6352 if FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS] then IncMax(FAmmo[A_ROCKETS], 1, FMaxAmmo[A_ROCKETS]);
6353 if FAmmo[A_CELLS] < FMaxAmmo[A_CELLS] then IncMax(FAmmo[A_CELLS], 40, FMaxAmmo[A_CELLS]);
6355 FRulez := FRulez + [R_ITEM_BACKPACK];
6356 end;
6358 ITEM_KEY_RED: if not (R_KEY_RED in FRulez) then Include(FRulez, R_KEY_RED);
6359 ITEM_KEY_GREEN: if not (R_KEY_GREEN in FRulez) then Include(FRulez, R_KEY_GREEN);
6360 ITEM_KEY_BLUE: if not (R_KEY_BLUE in FRulez) then Include(FRulez, R_KEY_BLUE);
6362 ITEM_BOTTLE: if FHealth < PLAYER_HP_LIMIT then IncMax(FHealth, 4, PLAYER_HP_LIMIT);
6363 ITEM_HELMET: if FArmor < PLAYER_AP_LIMIT then IncMax(FArmor, 5, PLAYER_AP_LIMIT);
6365 else
6366 Exit;
6367 end;
6368 if g_Game_IsNet and g_Game_IsServer then
6369 MH_SEND_PlayerStats(FUID);
6370 end;
6372 procedure TPlayer.FlySmoke(Times: DWORD = 1);
6374 id, i: DWORD;
6375 Anim: TAnimation;
6376 begin
6377 if (Random(5) = 1) and (Times = 1) then
6378 Exit;
6380 if BodyInLiquid(0, 0) then
6381 begin
6382 g_GFX_Bubbles(Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2)+Random(3)-1,
6383 Obj.Y+Obj.Rect.Height+8, 1, 8, 4);
6384 if Random(2) = 0 then
6385 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj.X, FObj.Y)
6386 else
6387 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj.X, FObj.Y);
6388 Exit;
6389 end;
6391 if g_Frames_Get(id, 'FRAMES_SMOKE') then
6392 begin
6393 for i := 1 to Times do
6394 begin
6395 Anim := TAnimation.Create(id, False, 3);
6396 Anim.Alpha := 150;
6397 g_GFX_OnceAnim(Obj.X+Obj.Rect.X+Random(Obj.Rect.Width+Times*2)-(Anim.Width div 2),
6398 Obj.Y+Obj.Rect.Height-4+Random(8+Times*2), Anim, ONCEANIM_SMOKE);
6399 Anim.Free();
6400 end;
6401 end;
6402 end;
6404 procedure TPlayer.OnFireFlame(Times: DWORD = 1);
6406 id, i: DWORD;
6407 Anim: TAnimation;
6408 begin
6409 if (Random(10) = 1) and (Times = 1) then
6410 Exit;
6412 if g_Frames_Get(id, 'FRAMES_FLAME') then
6413 begin
6414 for i := 1 to Times do
6415 begin
6416 Anim := TAnimation.Create(id, False, 3);
6417 Anim.Alpha := 0;
6418 g_GFX_OnceAnim(Obj.X+Obj.Rect.X+Random(Obj.Rect.Width+Times*2)-(Anim.Width div 2),
6419 Obj.Y+8+Random(8+Times*2), Anim, ONCEANIM_SMOKE);
6420 Anim.Free();
6421 end;
6422 end;
6423 end;
6425 procedure TPlayer.PauseSounds(Enable: Boolean);
6426 begin
6427 FSawSound.Pause(Enable);
6428 FSawSoundIdle.Pause(Enable);
6429 FSawSoundHit.Pause(Enable);
6430 FSawSoundSelect.Pause(Enable);
6431 end;
6433 { T C o r p s e : }
6435 constructor TCorpse.Create(X, Y: Integer; ModelName: String; aMess: Boolean);
6436 begin
6437 g_Obj_Init(@FObj);
6438 FObj.X := X;
6439 FObj.Y := Y;
6440 FObj.Rect := PLAYER_CORPSERECT;
6441 FModelName := ModelName;
6442 FMess := aMess;
6444 if FMess then
6445 begin
6446 FState := CORPSE_STATE_MESS;
6447 g_PlayerModel_GetAnim(ModelName, A_DIE2, FAnimation, FAnimationMask);
6449 else
6450 begin
6451 FState := CORPSE_STATE_NORMAL;
6452 g_PlayerModel_GetAnim(ModelName, A_DIE1, FAnimation, FAnimationMask);
6453 end;
6454 end;
6456 destructor TCorpse.Destroy();
6457 begin
6458 FAnimation.Free();
6460 inherited;
6461 end;
6463 function TCorpse.ObjPtr (): PObj; inline; begin result := @FObj; end;
6465 procedure TCorpse.positionChanged (); inline; begin end;
6467 procedure TCorpse.moveBy (dx, dy: Integer); inline;
6468 begin
6469 if (dx <> 0) or (dy <> 0) then
6470 begin
6471 FObj.X += dx;
6472 FObj.Y += dy;
6473 positionChanged();
6474 end;
6475 end;
6478 procedure TCorpse.getMapBox (out x, y, w, h: Integer); inline;
6479 begin
6480 x := FObj.X+PLAYER_CORPSERECT.X;
6481 y := FObj.Y+PLAYER_CORPSERECT.Y;
6482 w := PLAYER_CORPSERECT.Width;
6483 h := PLAYER_CORPSERECT.Height;
6484 end;
6487 procedure TCorpse.Damage(Value: Word; vx, vy: Integer);
6489 pm: TPlayerModel;
6490 Blood: TModelBlood;
6491 begin
6492 if FState = CORPSE_STATE_REMOVEME then
6493 Exit;
6495 FDamage := FDamage + Value;
6497 if FDamage > 150 then
6498 begin
6499 if FAnimation <> nil then
6500 begin
6501 FAnimation.Free();
6502 FAnimation := nil;
6504 FState := CORPSE_STATE_REMOVEME;
6506 g_Player_CreateGibs(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
6507 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
6508 FModelName, FColor);
6509 // Çâóê ìÿñà îò òðóïà:
6510 pm := g_PlayerModel_Get(FModelName);
6511 pm.PlaySound(MODELSOUND_DIE, 5, FObj.X, FObj.Y);
6512 pm.Free;
6514 // Çëîâåùèé ñìåõ:
6515 if (gBodyKillEvent <> -1)
6516 and gDelayedEvents[gBodyKillEvent].Pending then
6517 gDelayedEvents[gBodyKillEvent].Pending := False;
6518 gBodyKillEvent := g_Game_DelayEvent(DE_BODYKILL, 1050, 0);
6519 end;
6521 else
6522 begin
6523 Blood := g_PlayerModel_GetBlood(FModelName);
6524 FObj.Vel.X := FObj.Vel.X + vx;
6525 FObj.Vel.Y := FObj.Vel.Y + vy;
6526 g_GFX_Blood(FObj.X+PLAYER_CORPSERECT.X+(PLAYER_CORPSERECT.Width div 2),
6527 FObj.Y+PLAYER_CORPSERECT.Y+(PLAYER_CORPSERECT.Height div 2),
6528 Value, vx, vy, 16, (PLAYER_CORPSERECT.Height*2) div 3,
6529 Blood.R, Blood.G, Blood.B, Blood.Kind);
6530 end;
6531 end;
6533 procedure TCorpse.Draw();
6534 begin
6535 if FState = CORPSE_STATE_REMOVEME then
6536 Exit;
6538 if FAnimation <> nil then
6539 FAnimation.Draw(FObj.X, FObj.Y, TMirrorType.None);
6541 if FAnimationMask <> nil then
6542 begin
6543 e_Colors := FColor;
6544 FAnimationMask.Draw(FObj.X, FObj.Y, TMirrorType.None);
6545 e_Colors.R := 255;
6546 e_Colors.G := 255;
6547 e_Colors.B := 255;
6548 end;
6549 end;
6551 procedure TCorpse.Update();
6553 st: Word;
6554 begin
6555 if FState = CORPSE_STATE_REMOVEME then
6556 Exit;
6558 if gTime mod (GAME_TICK*2) <> 0 then
6559 begin
6560 g_Obj_Move(@FObj, True, True, True);
6561 positionChanged(); // this updates spatial accelerators
6562 Exit;
6563 end;
6565 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6566 FObj.Vel.X := z_dec(FObj.Vel.X, 1);
6568 st := g_Obj_Move(@FObj, True, True, True);
6569 positionChanged(); // this updates spatial accelerators
6571 if WordBool(st and MOVE_FALLOUT) then
6572 begin
6573 FState := CORPSE_STATE_REMOVEME;
6574 Exit;
6575 end;
6577 if FAnimation <> nil then
6578 FAnimation.Update();
6579 if FAnimationMask <> nil then
6580 FAnimationMask.Update();
6581 end;
6584 procedure TCorpse.SaveState (st: TStream);
6586 anim: Boolean;
6587 begin
6588 assert(st <> nil);
6590 // Ñèãíàòóðà òðóïà
6591 utils.writeSign(st, 'CORP');
6592 utils.writeInt(st, Byte(0));
6593 // Ñîñòîÿíèå
6594 utils.writeInt(st, Byte(FState));
6595 // Íàêîïëåííûé óðîí
6596 utils.writeInt(st, Byte(FDamage));
6597 // Öâåò
6598 utils.writeInt(st, Byte(FColor.R));
6599 utils.writeInt(st, Byte(FColor.G));
6600 utils.writeInt(st, Byte(FColor.B));
6601 // Îáúåêò òðóïà
6602 Obj_SaveState(st, @FObj);
6603 utils.writeInt(st, Word(FPlayerUID));
6604 // Åñòü ëè àíèìàöèÿ
6605 anim := (FAnimation <> nil);
6606 utils.writeBool(st, anim);
6607 // Åñëè åñòü - ñîõðàíÿåì
6608 if anim then FAnimation.SaveState(st);
6609 // Åñòü ëè ìàñêà àíèìàöèè
6610 anim := (FAnimationMask <> nil);
6611 utils.writeBool(st, anim);
6612 // Åñëè åñòü - ñîõðàíÿåì
6613 if anim then FAnimationMask.SaveState(st);
6614 end;
6617 procedure TCorpse.LoadState (st: TStream);
6619 anim: Boolean;
6620 begin
6621 assert(st <> nil);
6623 // Ñèãíàòóðà òðóïà
6624 if not utils.checkSign(st, 'CORP') then raise XStreamError.Create('invalid corpse signature');
6625 if (utils.readByte(st) <> 0) then raise XStreamError.Create('invalid corpse version');
6626 // Ñîñòîÿíèå
6627 FState := utils.readByte(st);
6628 // Íàêîïëåííûé óðîí
6629 FDamage := utils.readByte(st);
6630 // Öâåò
6631 FColor.R := utils.readByte(st);
6632 FColor.G := utils.readByte(st);
6633 FColor.B := utils.readByte(st);
6634 // Îáúåêò òðóïà
6635 Obj_LoadState(@FObj, st);
6636 FPlayerUID := utils.readWord(st);
6637 // Åñòü ëè àíèìàöèÿ
6638 anim := utils.readBool(st);
6639 // Åñëè åñòü - çàãðóæàåì
6640 if anim then
6641 begin
6642 Assert(FAnimation <> nil, 'TCorpse.LoadState: no FAnimation');
6643 FAnimation.LoadState(st);
6644 end;
6645 // Åñòü ëè ìàñêà àíèìàöèè
6646 anim := utils.readBool(st);
6647 // Åñëè åñòü - çàãðóæàåì
6648 if anim then
6649 begin
6650 Assert(FAnimationMask <> nil, 'TCorpse.LoadState: no FAnimationMask');
6651 FAnimationMask.LoadState(st);
6652 end;
6653 end;
6655 { T B o t : }
6657 constructor TBot.Create();
6659 a: Integer;
6660 begin
6661 inherited Create();
6663 FPhysics := True;
6664 FSpectator := False;
6665 FGhost := False;
6667 FIamBot := True;
6669 Inc(gNumBots);
6671 for a := WP_FIRST to WP_LAST do
6672 begin
6673 FDifficult.WeaponPrior[a] := WEAPON_PRIOR1[a];
6674 FDifficult.CloseWeaponPrior[a] := WEAPON_PRIOR2[a];
6675 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6676 end;
6677 end;
6679 destructor TBot.Destroy();
6680 begin
6681 Dec(gNumBots);
6682 inherited Destroy();
6683 end;
6685 procedure TBot.Draw();
6686 begin
6687 inherited Draw();
6689 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6690 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6691 end;
6693 procedure TBot.Respawn(Silent: Boolean; Force: Boolean = False);
6694 begin
6695 inherited Respawn(Silent, Force);
6697 FAIFlags := nil;
6698 FSelectedWeapon := FCurrWeap;
6699 FNetForceWeapFIdx := 0;
6700 resetWeaponQueue();
6701 FTargetUID := 0;
6702 end;
6704 procedure TBot.UpdateCombat();
6705 type
6706 TTarget = record
6707 UID: Word;
6708 X, Y: Integer;
6709 Rect: TRectWH;
6710 cX, cY: Integer;
6711 Dist: Word;
6712 Line: Boolean;
6713 Visible: Boolean;
6714 IsPlayer: Boolean;
6715 end;
6717 TTargetRecord = array of TTarget;
6719 function Compare(a, b: TTarget): Integer;
6720 begin
6721 if a.Line and not b.Line then // A íà ëèíèè îãíÿ
6722 Result := -1
6723 else
6724 if not a.Line and b.Line then // B íà ëèíèè îãíÿ
6725 Result := 1
6726 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6727 if (a.Line and b.Line) or ((not a.Line) and (not b.Line)) then
6728 begin
6729 if a.Dist > b.Dist then // B áëèæå
6730 Result := 1
6731 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6732 Result := -1;
6734 else // Ñòðàííî -> A
6735 Result := -1;
6736 end;
6739 a, x1, y1, x2, y2: Integer;
6740 targets: TTargetRecord;
6741 ammo: Word;
6742 Target, BestTarget: TTarget;
6743 firew, fireh: Integer;
6744 angle: SmallInt;
6745 mon: TMonster;
6746 pla, tpla: TPlayer;
6747 vsPlayer, vsMonster, ok: Boolean;
6750 function monsUpdate (mon: TMonster): Boolean;
6751 begin
6752 result := false; // don't stop
6753 if mon.alive and (mon.MonsterType <> MONSTER_BARREL) then
6754 begin
6755 if not TargetOnScreen(mon.Obj.X+mon.Obj.Rect.X, mon.Obj.Y+mon.Obj.Rect.Y) then exit;
6757 x2 := mon.Obj.X+mon.Obj.Rect.X+(mon.Obj.Rect.Width div 2);
6758 y2 := mon.Obj.Y+mon.Obj.Rect.Y+(mon.Obj.Rect.Height div 2);
6760 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6761 if g_TraceVector(x1, y1, x2, y2) then
6762 begin
6763 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6764 SetLength(targets, Length(targets)+1);
6765 with targets[High(targets)] do
6766 begin
6767 UID := mon.UID;
6768 X := mon.Obj.X;
6769 Y := mon.Obj.Y;
6770 cX := x2;
6771 cY := y2;
6772 Rect := mon.Obj.Rect;
6773 Dist := g_PatchLength(x1, y1, x2, y2);
6774 Line := (y1+4 < Target.Y + mon.Obj.Rect.Y + mon.Obj.Rect.Height) and
6775 (y1-4 > Target.Y + mon.Obj.Rect.Y);
6776 Visible := True;
6777 IsPlayer := False;
6778 end;
6779 end;
6780 end;
6781 end;
6783 begin
6784 vsPlayer := LongBool(gGameSettings.Options and GAME_OPTION_BOTVSPLAYER);
6785 vsMonster := LongBool(gGameSettings.Options and GAME_OPTION_BOTVSMONSTER);
6787 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6788 if FCurrWeap <> FSelectedWeapon then
6789 NextWeapon();
6791 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6792 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap = FSelectedWeapon) then
6793 begin
6794 RemoveAIFlag('NEEDFIRE');
6796 case FCurrWeap of
6797 WEAPON_PLASMA, WEAPON_SUPERPULEMET, WEAPON_CHAINGUN: PressKey(KEY_FIRE, 20);
6798 WEAPON_SAW, WEAPON_KASTET, WEAPON_FLAMETHROWER: PressKey(KEY_FIRE, 40);
6799 else PressKey(KEY_FIRE);
6800 end;
6801 end;
6803 // Êîîðäèíàòû ñòâîëà:
6804 x1 := FObj.X + WEAPONPOINT[FDirection].X;
6805 y1 := FObj.Y + WEAPONPOINT[FDirection].Y;
6807 Target.UID := FTargetUID;
6809 ok := False;
6810 if Target.UID <> 0 then
6811 begin // Öåëü åñòü - íàñòðàèâàåì
6812 if (g_GetUIDType(Target.UID) = UID_PLAYER) and
6813 vsPlayer then
6814 begin // Èãðîê
6815 tpla := g_Player_Get(Target.UID);
6816 if tpla <> nil then
6817 with tpla do
6818 begin
6819 if (@FObj) <> nil then
6820 begin
6821 Target.X := FObj.X;
6822 Target.Y := FObj.Y;
6823 end;
6824 end;
6826 Target.cX := Target.X + PLAYER_RECT_CX;
6827 Target.cY := Target.Y + PLAYER_RECT_CY;
6828 Target.Rect := PLAYER_RECT;
6829 Target.Visible := g_TraceVector(x1, y1, Target.cX, Target.cY);
6830 Target.Line := (y1+4 < Target.Y+PLAYER_RECT.Y+PLAYER_RECT.Height) and
6831 (y1-4 > Target.Y+PLAYER_RECT.Y);
6832 Target.IsPlayer := True;
6833 ok := True;
6835 else
6836 if (g_GetUIDType(Target.UID) = UID_MONSTER) and
6837 vsMonster then
6838 begin // Ìîíñòð
6839 mon := g_Monsters_ByUID(Target.UID);
6840 if mon <> nil then
6841 begin
6842 Target.X := mon.Obj.X;
6843 Target.Y := mon.Obj.Y;
6845 Target.cX := Target.X + mon.Obj.Rect.X + (mon.Obj.Rect.Width div 2);
6846 Target.cY := Target.Y + mon.Obj.Rect.Y + (mon.Obj.Rect.Height div 2);
6847 Target.Rect := mon.Obj.Rect;
6848 Target.Visible := g_TraceVector(x1, y1, Target.cX, Target.cY);
6849 Target.Line := (y1+4 < Target.Y + mon.Obj.Rect.Y + mon.Obj.Rect.Height) and
6850 (y1-4 > Target.Y + mon.Obj.Rect.Y);
6851 Target.IsPlayer := False;
6852 ok := True;
6853 end;
6854 end;
6855 end;
6857 if not ok then
6858 begin // Öåëè íåò - îáíóëÿåì
6859 Target.X := 0;
6860 Target.Y := 0;
6861 Target.cX := 0;
6862 Target.cY := 0;
6863 Target.Visible := False;
6864 Target.Line := False;
6865 Target.IsPlayer := False;
6866 end;
6868 targets := nil;
6870 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6871 if (not Target.Line) or (not Target.Visible) then
6872 begin
6873 // Èãðîêè:
6874 if vsPlayer then
6875 for a := 0 to High(gPlayers) do
6876 if (gPlayers[a] <> nil) and (gPlayers[a].alive) and
6877 (gPlayers[a].FUID <> FUID) and
6878 (not SameTeam(FUID, gPlayers[a].FUID)) and
6879 (not gPlayers[a].NoTarget) and
6880 (gPlayers[a].FMegaRulez[MR_INVIS] < gTime) then
6881 begin
6882 if not TargetOnScreen(gPlayers[a].FObj.X + PLAYER_RECT.X,
6883 gPlayers[a].FObj.Y + PLAYER_RECT.Y) then
6884 Continue;
6886 x2 := gPlayers[a].FObj.X + PLAYER_RECT_CX;
6887 y2 := gPlayers[a].FObj.Y + PLAYER_RECT_CY;
6889 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6890 if g_TraceVector(x1, y1, x2, y2) then
6891 begin
6892 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6893 SetLength(targets, Length(targets)+1);
6894 with targets[High(targets)] do
6895 begin
6896 UID := gPlayers[a].FUID;
6897 X := gPlayers[a].FObj.X;
6898 Y := gPlayers[a].FObj.Y;
6899 cX := x2;
6900 cY := y2;
6901 Rect := PLAYER_RECT;
6902 Dist := g_PatchLength(x1, y1, x2, y2);
6903 Line := (y1+4 < Target.Y+PLAYER_RECT.Y+PLAYER_RECT.Height) and
6904 (y1-4 > Target.Y+PLAYER_RECT.Y);
6905 Visible := True;
6906 IsPlayer := True;
6907 end;
6908 end;
6909 end;
6911 // Ìîíñòðû:
6912 if vsMonster then g_Mons_ForEach(monsUpdate);
6913 end;
6915 // Åñëè åñòü âîçìîæíûå öåëè:
6916 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6917 if targets <> nil then
6918 begin
6919 // Âûáèðàåì íàèëó÷øóþ öåëü:
6920 BestTarget := targets[0];
6921 if Length(targets) > 1 then
6922 for a := 1 to High(targets) do
6923 if Compare(BestTarget, targets[a]) = 1 then
6924 BestTarget := targets[a];
6926 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6927 if ((not Target.Visible) and BestTarget.Visible and (Target.UID <> BestTarget.UID)) or
6928 ((not Target.Line) and BestTarget.Line and BestTarget.Visible) then
6929 begin
6930 Target := BestTarget;
6932 if (Healthy() = 3) or ((Healthy() = 2)) then
6933 begin // Åñëè çäîðîâû - äîãîíÿåì
6934 if ((RunDirection() = TDirection.D_LEFT) and (Target.X > FObj.X)) then
6935 SetAIFlag('GORIGHT', '1');
6936 if ((RunDirection() = TDirection.D_RIGHT) and (Target.X < FObj.X)) then
6937 SetAIFlag('GOLEFT', '1');
6939 else
6940 begin // Åñëè ïîáèòû - óáåãàåì
6941 if ((RunDirection() = TDirection.D_LEFT) and (Target.X < FObj.X)) then
6942 SetAIFlag('GORIGHT', '1');
6943 if ((RunDirection() = TDirection.D_RIGHT) and (Target.X > FObj.X)) then
6944 SetAIFlag('GOLEFT', '1');
6945 end;
6947 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6948 SelectWeapon(Abs(x1-Target.cX));
6949 end;
6950 end;
6952 // Åñëè åñòü öåëü:
6953 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6954 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6955 if Target.UID <> 0 then
6956 begin
6957 if not TargetOnScreen(Target.X + Target.Rect.X,
6958 Target.Y + Target.Rect.Y) then
6959 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6960 if (Healthy() = 3) or ((Healthy() = 2)) then
6961 begin // Åñëè çäîðîâû - äîãîíÿåì
6962 if ((RunDirection() = TDirection.D_LEFT) and (Target.X > FObj.X)) then
6963 SetAIFlag('GORIGHT', '1');
6964 if ((RunDirection() = TDirection.D_RIGHT) and (Target.X < FObj.X)) then
6965 SetAIFlag('GOLEFT', '1');
6967 else
6968 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6969 Target.UID := 0;
6970 if ((RunDirection() = TDirection.D_LEFT) and (Target.X < FObj.X)) then
6971 SetAIFlag('GORIGHT', '1');
6972 if ((RunDirection() = TDirection.D_RIGHT) and (Target.X > FObj.X)) then
6973 SetAIFlag('GOLEFT', '1');
6974 end;
6976 else
6977 begin // Öåëü ïîêà íà "ýêðàíå"
6978 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
6979 if g_TraceVector(x1, y1, Target.cX, Target.cY) then
6980 FLastVisible := gTime;
6981 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
6982 if (Abs(FObj.Y-Target.Y) <= 128) then
6983 begin
6984 if ((RunDirection() = TDirection.D_LEFT) and (Target.X > FObj.X)) then
6985 SetAIFlag('GORIGHT', '1');
6986 if ((RunDirection() = TDirection.D_RIGHT) and (Target.X < FObj.X)) then
6987 SetAIFlag('GOLEFT', '1');
6988 end;
6989 end;
6991 // Âûáèðàåì óãîë ââåðõ:
6992 if FDirection = TDirection.D_LEFT then
6993 angle := ANGLE_LEFTUP
6994 else
6995 angle := ANGLE_RIGHTUP;
6997 firew := Trunc(Cos(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
6998 fireh := Trunc(Sin(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
7000 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
7001 if g_CollideLine(x1, y1, x1+firew, y1+fireh,
7002 Target.X+Target.Rect.X+GetInterval(FDifficult.DiagPrecision, 128), //96
7003 Target.Y+Target.Rect.Y+GetInterval(FDifficult.DiagPrecision, 128),
7004 Target.Rect.Width, Target.Rect.Height) and
7005 g_TraceVector(x1, y1, Target.cX, Target.cY) then
7006 begin // òî íóæíî ñòðåëÿòü ââåðõ
7007 SetAIFlag('NEEDFIRE', '1');
7008 SetAIFlag('NEEDSEEUP', '1');
7009 end;
7011 // Âûáèðàåì óãîë âíèç:
7012 if FDirection = TDirection.D_LEFT then
7013 angle := ANGLE_LEFTDOWN
7014 else
7015 angle := ANGLE_RIGHTDOWN;
7017 firew := Trunc(Cos(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
7018 fireh := Trunc(Sin(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
7020 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
7021 if g_CollideLine(x1, y1, x1+firew, y1+fireh,
7022 Target.X+Target.Rect.X+GetInterval(FDifficult.DiagPrecision, 128),
7023 Target.Y+Target.Rect.Y+GetInterval(FDifficult.DiagPrecision, 128),
7024 Target.Rect.Width, Target.Rect.Height) and
7025 g_TraceVector(x1, y1, Target.cX, Target.cY) then
7026 begin // òî íóæíî ñòðåëÿòü âíèç
7027 SetAIFlag('NEEDFIRE', '1');
7028 SetAIFlag('NEEDSEEDOWN', '1');
7029 end;
7031 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
7032 if Target.Visible and
7033 (y1+4 < Target.Y+Target.Rect.Y+Target.Rect.Height) and
7034 (y1-4 > Target.Y+Target.Rect.Y) then
7035 begin
7036 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
7037 if ((FDirection = TDirection.D_LEFT) and (Target.X < FObj.X)) or
7038 ((FDirection = TDirection.D_RIGHT) and (Target.X > FObj.X)) then
7039 begin // òî íóæíî ñòðåëÿòü âïåðåä
7040 SetAIFlag('NEEDFIRE', '1');
7041 SetAIFlag('NEEDSEEDOWN', '');
7042 SetAIFlag('NEEDSEEUP', '');
7043 end;
7044 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
7045 if Abs(FObj.X-Target.X) < Trunc(gPlayerScreenSize.X*0.75) then
7046 if GetRnd(FDifficult.CloseJump) then
7047 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
7048 if Abs(FObj.X-Target.X) < 128 then
7049 a := 4
7050 else
7051 a := 30;
7052 if Random(a) = 0 then
7053 SetAIFlag('NEEDJUMP', '1');
7054 end;
7055 end;
7057 // Åñëè öåëü âñå åùå åñòü:
7058 if Target.UID <> 0 then
7059 if gTime-FLastVisible > 2000 then // Åñëè âèäåëè äàâíî
7060 Target.UID := 0 // òî çàáûòü öåëü
7061 else // Åñëè âèäåëè íåäàâíî
7062 begin // íî öåëü óáèëè
7063 if Target.IsPlayer then
7064 begin // Öåëü - èãðîê
7065 pla := g_Player_Get(Target.UID);
7066 if (pla = nil) or (not pla.alive) or pla.NoTarget or
7067 (pla.FMegaRulez[MR_INVIS] >= gTime) then
7068 Target.UID := 0; // òî çàáûòü öåëü
7070 else
7071 begin // Öåëü - ìîíñòð
7072 mon := g_Monsters_ByUID(Target.UID);
7073 if (mon = nil) or (not mon.alive) then
7074 Target.UID := 0; // òî çàáûòü öåëü
7075 end;
7076 end;
7077 end; // if Target.UID <> 0
7079 FTargetUID := Target.UID;
7081 // Åñëè âîçìîæíûõ öåëåé íåò:
7082 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
7083 if targets = nil then
7084 if GetAIFlag('ATTACKLEFT') <> '' then
7085 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
7086 RemoveAIFlag('ATTACKLEFT');
7088 SetAIFlag('NEEDJUMP', '1');
7090 if RunDirection() = TDirection.D_RIGHT then
7091 begin // Èäåì íå â òó ñòîðîíó
7092 if (Healthy() > 1) and GetRnd(FDifficult.InvisFire) then
7093 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
7094 SetAIFlag('NEEDFIRE', '1');
7095 SetAIFlag('GOLEFT', '1');
7096 end;
7098 else
7099 begin // Èäåì â íóæíóþ ñòîðîíó
7100 if GetRnd(FDifficult.InvisFire) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7101 SetAIFlag('NEEDFIRE', '1');
7102 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7103 SetAIFlag('GORIGHT', '1');
7104 end;
7106 else
7107 if GetAIFlag('ATTACKRIGHT') <> '' then
7108 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
7109 RemoveAIFlag('ATTACKRIGHT');
7111 SetAIFlag('NEEDJUMP', '1');
7113 if RunDirection() = TDirection.D_LEFT then
7114 begin // Èäåì íå â òó ñòîðîíó
7115 if (Healthy() > 1) and GetRnd(FDifficult.InvisFire) then
7116 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
7117 SetAIFlag('NEEDFIRE', '1');
7118 SetAIFlag('GORIGHT', '1');
7119 end;
7121 else
7122 begin
7123 if GetRnd(FDifficult.InvisFire) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7124 SetAIFlag('NEEDFIRE', '1');
7125 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7126 SetAIFlag('GOLEFT', '1');
7127 end;
7128 end;
7130 //HACK! (does it belong there?)
7131 RealizeCurrentWeapon();
7133 // Åñëè åñòü âîçìîæíûå öåëè:
7134 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
7135 if (targets <> nil) and (GetAIFlag('NEEDFIRE') <> '') then
7136 for a := 0 to High(targets) do
7137 begin
7138 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
7139 if GetRnd(FDifficult.DiagFire) then
7140 begin
7141 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
7142 if FDirection = TDirection.D_LEFT then
7143 angle := ANGLE_LEFTUP
7144 else
7145 angle := ANGLE_RIGHTUP;
7147 firew := Trunc(Cos(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
7148 fireh := Trunc(Sin(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
7150 if g_CollideLine(x1, y1, x1+firew, y1+fireh,
7151 targets[a].X+targets[a].Rect.X+GetInterval(FDifficult.DiagPrecision, 128),
7152 targets[a].Y+targets[a].Rect.Y+GetInterval(FDifficult.DiagPrecision, 128),
7153 targets[a].Rect.Width, targets[a].Rect.Height) and
7154 g_TraceVector(x1, y1, targets[a].cX, targets[a].cY) then
7155 begin
7156 SetAIFlag('NEEDFIRE', '1');
7157 SetAIFlag('NEEDSEEUP', '1');
7158 end;
7160 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
7161 if FDirection = TDirection.D_LEFT then
7162 angle := ANGLE_LEFTDOWN
7163 else
7164 angle := ANGLE_RIGHTDOWN;
7166 firew := Trunc(Cos(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
7167 fireh := Trunc(Sin(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
7169 if g_CollideLine(x1, y1, x1+firew, y1+fireh,
7170 targets[a].X+targets[a].Rect.X+GetInterval(FDifficult.DiagPrecision, 128),
7171 targets[a].Y+targets[a].Rect.Y+GetInterval(FDifficult.DiagPrecision, 128),
7172 targets[a].Rect.Width, targets[a].Rect.Height) and
7173 g_TraceVector(x1, y1, targets[a].cX, targets[a].cY) then
7174 begin
7175 SetAIFlag('NEEDFIRE', '1');
7176 SetAIFlag('NEEDSEEDOWN', '1');
7177 end;
7178 end;
7180 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
7181 if targets[a].Line and targets[a].Visible and
7182 (((FDirection = TDirection.D_LEFT) and (targets[a].X < FObj.X)) or
7183 ((FDirection = TDirection.D_RIGHT) and (targets[a].X > FObj.X))) then
7184 begin
7185 SetAIFlag('NEEDFIRE', '1');
7186 Break;
7187 end;
7188 end;
7190 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
7191 if g_Weapon_Danger(FUID, FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y,
7192 PLAYER_RECT.Width, PLAYER_RECT.Height,
7193 40+GetInterval(FDifficult.Cover, 40)) then
7194 SetAIFlag('NEEDJUMP', '1');
7196 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
7197 ammo := GetAmmoByWeapon(FCurrWeap);
7198 if ((FCurrWeap = WEAPON_SHOTGUN2) and (ammo < 2)) or
7199 ((FCurrWeap = WEAPON_BFG) and (ammo < 40)) or
7200 (ammo = 0) then
7201 SetAIFlag('SELECTWEAPON', '1');
7203 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
7204 if GetAIFlag('SELECTWEAPON') = '1' then
7205 begin
7206 SelectWeapon(-1);
7207 RemoveAIFlag('SELECTWEAPON');
7208 end;
7209 end;
7211 procedure TBot.Update();
7213 EnableAI: Boolean;
7214 begin
7215 if not FAlive then
7216 begin // Respawn
7217 ReleaseKeys();
7218 PressKey(KEY_UP);
7220 else
7221 begin
7222 EnableAI := True;
7224 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
7225 if (g_debug_BotAIOff = 1) and (Team = TEAM_RED) then
7226 EnableAI := False;
7227 if (g_debug_BotAIOff = 2) and (Team = TEAM_BLUE) then
7228 EnableAI := False;
7229 if g_debug_BotAIOff = 3 then
7230 EnableAI := False;
7232 if EnableAI then
7233 begin
7234 UpdateMove();
7235 UpdateCombat();
7237 else
7238 begin
7239 RealizeCurrentWeapon();
7240 end;
7241 end;
7243 inherited Update();
7244 end;
7246 procedure TBot.ReleaseKey(Key: Byte);
7247 begin
7248 with FKeys[Key] do
7249 begin
7250 Pressed := False;
7251 Time := 0;
7252 end;
7253 end;
7255 function TBot.KeyPressed(Key: Word): Boolean;
7256 begin
7257 Result := FKeys[Key].Pressed;
7258 end;
7260 function TBot.GetAIFlag(aName: String20): String20;
7262 a: Integer;
7263 begin
7264 Result := '';
7266 aName := LowerCase(aName);
7268 if FAIFlags <> nil then
7269 for a := 0 to High(FAIFlags) do
7270 if LowerCase(FAIFlags[a].Name) = aName then
7271 begin
7272 Result := FAIFlags[a].Value;
7273 Break;
7274 end;
7275 end;
7277 procedure TBot.RemoveAIFlag(aName: String20);
7279 a, b: Integer;
7280 begin
7281 if FAIFlags = nil then Exit;
7283 aName := LowerCase(aName);
7285 for a := 0 to High(FAIFlags) do
7286 if LowerCase(FAIFlags[a].Name) = aName then
7287 begin
7288 if a <> High(FAIFlags) then
7289 for b := a to High(FAIFlags)-1 do
7290 FAIFlags[b] := FAIFlags[b+1];
7292 SetLength(FAIFlags, Length(FAIFlags)-1);
7293 Break;
7294 end;
7295 end;
7297 procedure TBot.SetAIFlag(aName, fValue: String20);
7299 a: Integer;
7300 ok: Boolean;
7301 begin
7302 a := 0;
7303 ok := False;
7305 aName := LowerCase(aName);
7307 if FAIFlags <> nil then
7308 for a := 0 to High(FAIFlags) do
7309 if LowerCase(FAIFlags[a].Name) = aName then
7310 begin
7311 ok := True;
7312 Break;
7313 end;
7315 if ok then FAIFlags[a].Value := fValue
7316 else
7317 begin
7318 SetLength(FAIFlags, Length(FAIFlags)+1);
7319 with FAIFlags[High(FAIFlags)] do
7320 begin
7321 Name := aName;
7322 Value := fValue;
7323 end;
7324 end;
7325 end;
7327 procedure TBot.UpdateMove;
7329 procedure GoLeft(Time: Word = 1);
7330 begin
7331 ReleaseKey(KEY_LEFT);
7332 ReleaseKey(KEY_RIGHT);
7333 PressKey(KEY_LEFT, Time);
7334 SetDirection(TDirection.D_LEFT);
7335 end;
7337 procedure GoRight(Time: Word = 1);
7338 begin
7339 ReleaseKey(KEY_LEFT);
7340 ReleaseKey(KEY_RIGHT);
7341 PressKey(KEY_RIGHT, Time);
7342 SetDirection(TDirection.D_RIGHT);
7343 end;
7345 function Rnd(a: Word): Boolean;
7346 begin
7347 Result := Random(a) = 0;
7348 end;
7350 procedure Turn(Time: Word = 1200);
7351 begin
7352 if RunDirection() = TDirection.D_LEFT then GoRight(Time) else GoLeft(Time);
7353 end;
7355 procedure Stop();
7356 begin
7357 ReleaseKey(KEY_LEFT);
7358 ReleaseKey(KEY_RIGHT);
7359 end;
7361 function CanRunLeft(): Boolean;
7362 begin
7363 Result := not CollideLevel(-1, 0);
7364 end;
7366 function CanRunRight(): Boolean;
7367 begin
7368 Result := not CollideLevel(1, 0);
7369 end;
7371 function CanRun(): Boolean;
7372 begin
7373 if RunDirection() = TDirection.D_LEFT then Result := CanRunLeft() else Result := CanRunRight();
7374 end;
7376 procedure Jump(Time: Word = 30);
7377 begin
7378 PressKey(KEY_JUMP, Time);
7379 end;
7381 function NearHole(): Boolean;
7383 x, sx: Integer;
7384 begin
7385 { TODO 5 : Ëåñòíèöû }
7386 sx := IfThen(RunDirection() = TDirection.D_LEFT, -1, 1);
7387 for x := 1 to PLAYER_RECT.Width do
7388 if (not StayOnStep(x*sx, 0)) and
7389 (not CollideLevel(x*sx, PLAYER_RECT.Height)) and
7390 (not CollideLevel(x*sx, PLAYER_RECT.Height*2)) then
7391 begin
7392 Result := True;
7393 Exit;
7394 end;
7396 Result := False;
7397 end;
7399 function BorderHole(): Boolean;
7401 x, sx, xx: Integer;
7402 begin
7403 { TODO 5 : Ëåñòíèöû }
7404 sx := IfThen(RunDirection() = TDirection.D_LEFT, -1, 1);
7405 for x := 1 to PLAYER_RECT.Width do
7406 if (not StayOnStep(x*sx, 0)) and
7407 (not CollideLevel(x*sx, PLAYER_RECT.Height)) and
7408 (not CollideLevel(x*sx, PLAYER_RECT.Height*2)) then
7409 begin
7410 for xx := x to x+32 do
7411 if CollideLevel(xx*sx, PLAYER_RECT.Height) then
7412 begin
7413 Result := True;
7414 Exit;
7415 end;
7416 end;
7418 Result := False;
7419 end;
7421 function NearDeepHole(): Boolean;
7423 x, sx, y: Integer;
7424 begin
7425 Result := False;
7427 sx := IfThen(RunDirection() = TDirection.D_LEFT, -1, 1);
7428 y := 3;
7430 for x := 1 to PLAYER_RECT.Width do
7431 if (not StayOnStep(x*sx, 0)) and
7432 (not CollideLevel(x*sx, PLAYER_RECT.Height)) and
7433 (not CollideLevel(x*sx, PLAYER_RECT.Height*2)) then
7434 begin
7435 while FObj.Y+y*PLAYER_RECT.Height < gMapInfo.Height do
7436 begin
7437 if CollideLevel(x*sx, PLAYER_RECT.Height*y) then Exit;
7438 y := y+1;
7439 end;
7441 Result := True;
7442 end else Result := False;
7443 end;
7445 function OverDeepHole(): Boolean;
7447 y: Integer;
7448 begin
7449 Result := False;
7451 y := 1;
7452 while FObj.Y+y*PLAYER_RECT.Height < gMapInfo.Height do
7453 begin
7454 if CollideLevel(0, PLAYER_RECT.Height*y) then Exit;
7455 y := y+1;
7456 end;
7458 Result := True;
7459 end;
7461 function OnGround(): Boolean;
7462 begin
7463 Result := StayOnStep(0, 0) or CollideLevel(0, 1);
7464 end;
7466 function OnLadder(): Boolean;
7467 begin
7468 Result := FullInStep(0, 0);
7469 end;
7471 function BelowLadder(): Boolean;
7472 begin
7473 Result := (FullInStep(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -PLAYER_RECT.Height) and
7474 not CollideLevel(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -PLAYER_RECT.Height)) or
7475 (FullInStep(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -BOT_MAXJUMP) and
7476 not CollideLevel(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -BOT_MAXJUMP));
7477 end;
7479 function BelowLiftUp(): Boolean;
7480 begin
7481 Result := ((FullInLift(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -PLAYER_RECT.Height) = -1) and
7482 not CollideLevel(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -PLAYER_RECT.Height)) or
7483 ((FullInLift(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -BOT_MAXJUMP) = -1) and
7484 not CollideLevel(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -BOT_MAXJUMP));
7485 end;
7487 function OnTopLift(): Boolean;
7488 begin
7489 Result := (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7490 end;
7492 function CanJumpOver(): Boolean;
7494 sx, y: Integer;
7495 begin
7496 sx := IfThen(RunDirection() = TDirection.D_LEFT, -1, 1);
7498 Result := False;
7500 if not CollideLevel(sx, 0) then Exit;
7502 for y := 1 to BOT_MAXJUMP do
7503 if CollideLevel(0, -y) then Exit else
7504 if not CollideLevel(sx, -y) then
7505 begin
7506 Result := True;
7507 Exit;
7508 end;
7509 end;
7511 function CanJumpUp(Dist: ShortInt): Boolean;
7513 y, yy: Integer;
7514 c: Boolean;
7515 begin
7516 Result := False;
7518 if CollideLevel(Dist, 0) then Exit;
7520 c := False;
7521 for y := 0 to BOT_MAXJUMP do
7522 if CollideLevel(Dist, -y) then
7523 begin
7524 c := True;
7525 Break;
7526 end;
7528 if not c then Exit;
7530 c := False;
7531 for yy := y+1 to BOT_MAXJUMP do
7532 if not CollideLevel(Dist, -yy) then
7533 begin
7534 c := True;
7535 Break;
7536 end;
7538 if not c then Exit;
7540 c := False;
7541 for y := 0 to BOT_MAXJUMP do
7542 if CollideLevel(0, -y) then
7543 begin
7544 c := True;
7545 Break;
7546 end;
7548 if c then Exit;
7550 if y < yy then Exit;
7552 Result := True;
7553 end;
7555 function IsSafeTrigger(): Boolean;
7557 a: Integer;
7558 begin
7559 Result := True;
7560 if gTriggers = nil then
7561 Exit;
7562 for a := 0 to High(gTriggers) do
7563 if Collide(gTriggers[a].X,
7564 gTriggers[a].Y,
7565 gTriggers[a].Width,
7566 gTriggers[a].Height) and
7567 (gTriggers[a].TriggerType in [TRIGGER_EXIT, TRIGGER_CLOSEDOOR,
7568 TRIGGER_CLOSETRAP, TRIGGER_TRAP,
7569 TRIGGER_PRESS, TRIGGER_ON, TRIGGER_OFF,
7570 TRIGGER_ONOFF, TRIGGER_SPAWNMONSTER,
7571 TRIGGER_DAMAGE, TRIGGER_SHOT]) then
7572 Result := False;
7573 end;
7575 begin
7576 // Âîçìîæíî, íàæèìàåì êíîïêó:
7577 if Rnd(16) and IsSafeTrigger() then
7578 PressKey(KEY_OPEN);
7580 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7581 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7582 begin
7583 ReleaseKey(KEY_LEFT);
7584 ReleaseKey(KEY_RIGHT);
7585 Jump();
7586 end;
7588 // Èäåì âëåâî, åñëè íàäî áûëî:
7589 if GetAIFlag('GOLEFT') <> '' then
7590 begin
7591 RemoveAIFlag('GOLEFT');
7592 if CanRunLeft() then
7593 GoLeft(360);
7594 end;
7596 // Èäåì âïðàâî, åñëè íàäî áûëî:
7597 if GetAIFlag('GORIGHT') <> '' then
7598 begin
7599 RemoveAIFlag('GORIGHT');
7600 if CanRunRight() then
7601 GoRight(360);
7602 end;
7604 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7605 if FObj.X < -32 then
7606 GoRight(360)
7607 else
7608 if FObj.X+32 > gMapInfo.Width then
7609 GoLeft(360);
7611 // Ïðûãàåì, åñëè íàäî áûëî:
7612 if GetAIFlag('NEEDJUMP') <> '' then
7613 begin
7614 Jump(0);
7615 RemoveAIFlag('NEEDJUMP');
7616 end;
7618 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7619 if GetAIFlag('NEEDSEEUP') <> '' then
7620 begin
7621 ReleaseKey(KEY_UP);
7622 ReleaseKey(KEY_DOWN);
7623 PressKey(KEY_UP, 20);
7624 RemoveAIFlag('NEEDSEEUP');
7625 end;
7627 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7628 if GetAIFlag('NEEDSEEDOWN') <> '' then
7629 begin
7630 ReleaseKey(KEY_UP);
7631 ReleaseKey(KEY_DOWN);
7632 PressKey(KEY_DOWN, 20);
7633 RemoveAIFlag('NEEDSEEDOWN');
7634 end;
7636 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7637 if GetAIFlag('GOINHOLE') <> '' then
7638 if not OnGround() then
7639 begin
7640 ReleaseKey(KEY_LEFT);
7641 ReleaseKey(KEY_RIGHT);
7642 RemoveAIFlag('GOINHOLE');
7643 SetAIFlag('FALLINHOLE', '1');
7644 end;
7646 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7647 if GetAIFlag('FALLINHOLE') <> '' then
7648 if OnGround() then
7649 RemoveAIFlag('FALLINHOLE');
7651 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7652 if not (KeyPressed(KEY_LEFT) or KeyPressed(KEY_RIGHT)) then
7653 if GetAIFlag('FALLINHOLE') = '' then
7654 if (not OnLadder()) or (FObj.Vel.Y >= 0) or (OnTopLift()) then
7655 if Rnd(2) then
7656 GoLeft(360)
7657 else
7658 GoRight(360);
7660 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7661 if OnGround() and
7662 CanJumpUp(IfThen(RunDirection() = TDirection.D_LEFT, -1, 1)*32) and
7663 Rnd(8) then
7664 Jump();
7666 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7667 if OnGround() and NearHole() then
7668 if NearDeepHole() then // Åñëè ýòî áåçäíà
7669 case Random(6) of
7670 0..3: Turn(); // Áåæèì îáðàòíî
7671 4: Jump(); // Ïðûãàåì
7672 5: begin // Ïðûãàåì îáðàòíî
7673 Turn();
7674 Jump();
7675 end;
7677 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7678 if GetAIFlag('GOINHOLE') = '' then
7679 case Random(6) of
7680 0: Turn(); // Íå íóæíî òóäà
7681 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7682 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7683 if BorderHole() then
7684 SetAIFlag('GOINHOLE', '1');
7685 end;
7687 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7688 if (not CanRun()) and OnGround() then
7689 begin
7690 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7691 if CanJumpOver() or OnLadder() then
7692 Jump()
7693 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7694 if Random(2) = 0 then
7695 begin
7696 if IsSafeTrigger() then
7697 PressKey(KEY_OPEN);
7698 end else
7699 Turn();
7700 end;
7702 // Îñòàëîñü ìàëî âîçäóõà:
7703 if FAir < 36 * 2 then
7704 Jump(20);
7706 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7707 if (FMegaRulez[MR_SUIT] < gTime) and ((FLastHit = HIT_ACID) or (Healthy() <= 1)) then
7708 if BodyInAcid(0, 0) then
7709 Jump();
7710 end;
7712 function TBot.FullInStep(XInc, YInc: Integer): Boolean;
7713 begin
7714 Result := g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc,
7715 PLAYER_RECT.Width, PLAYER_RECT.Height, PANEL_STEP, False);
7716 end;
7718 {function TBot.NeedItem(Item: Byte): Byte;
7719 begin
7720 Result := 4;
7721 end;}
7723 procedure TBot.SelectWeapon(Dist: Integer);
7725 a: Integer;
7727 function HaveAmmo(weapon: Byte): Boolean;
7728 begin
7729 case weapon of
7730 WEAPON_PISTOL: Result := FAmmo[A_BULLETS] >= 1;
7731 WEAPON_SHOTGUN1: Result := FAmmo[A_SHELLS] >= 1;
7732 WEAPON_SHOTGUN2: Result := FAmmo[A_SHELLS] >= 2;
7733 WEAPON_CHAINGUN: Result := FAmmo[A_BULLETS] >= 10;
7734 WEAPON_ROCKETLAUNCHER: Result := FAmmo[A_ROCKETS] >= 1;
7735 WEAPON_PLASMA: Result := FAmmo[A_CELLS] >= 10;
7736 WEAPON_BFG: Result := FAmmo[A_CELLS] >= 40;
7737 WEAPON_SUPERPULEMET: Result := FAmmo[A_SHELLS] >= 1;
7738 WEAPON_FLAMETHROWER: Result := FAmmo[A_FUEL] >= 1;
7739 else Result := True;
7740 end;
7741 end;
7743 begin
7744 if Dist = -1 then Dist := BOT_LONGDIST;
7746 if Dist > BOT_LONGDIST then
7747 begin // Äàëüíèé áîé
7748 for a := 0 to 9 do
7749 if FWeapon[FDifficult.WeaponPrior[a]] and HaveAmmo(FDifficult.WeaponPrior[a]) then
7750 begin
7751 FSelectedWeapon := FDifficult.WeaponPrior[a];
7752 Break;
7753 end;
7755 else //if Dist > BOT_UNSAFEDIST then
7756 begin // Áëèæíèé áîé
7757 for a := 0 to 9 do
7758 if FWeapon[FDifficult.CloseWeaponPrior[a]] and HaveAmmo(FDifficult.CloseWeaponPrior[a]) then
7759 begin
7760 FSelectedWeapon := FDifficult.CloseWeaponPrior[a];
7761 Break;
7762 end;
7763 end;
7764 { else
7765 begin
7766 for a := 0 to 9 do
7767 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7768 begin
7769 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7770 Break;
7771 end;
7772 end;}
7773 end;
7775 function TBot.PickItem(ItemType: Byte; force: Boolean; var remove: Boolean): Boolean;
7776 begin
7777 Result := inherited PickItem(ItemType, force, remove);
7779 if Result then SetAIFlag('SELECTWEAPON', '1');
7780 end;
7782 function TBot.Heal(value: Word; Soft: Boolean): Boolean;
7783 begin
7784 Result := inherited Heal(value, Soft);
7785 end;
7787 function TBot.Healthy(): Byte;
7788 begin
7789 if FMegaRulez[MR_INVUL] >= gTime then Result := 3
7790 else if (FHealth > 80) or ((FHealth > 50) and (FArmor > 20)) then Result := 3
7791 else if (FHealth > 50) then Result := 2
7792 else if (FHealth > 20) then Result := 1
7793 else Result := 0;
7794 end;
7796 function TBot.TargetOnScreen(TX, TY: Integer): Boolean;
7797 begin
7798 Result := (Abs(FObj.X-TX) <= Trunc(gPlayerScreenSize.X*0.6)) and
7799 (Abs(FObj.Y-TY) <= Trunc(gPlayerScreenSize.Y*0.6));
7800 end;
7802 procedure TBot.OnDamage(Angle: SmallInt);
7804 pla: TPlayer;
7805 mon: TMonster;
7806 ok: Boolean;
7807 begin
7808 inherited;
7810 if (Angle = 0) or (Angle = 180) then
7811 begin
7812 ok := False;
7813 if (g_GetUIDType(FLastSpawnerUID) = UID_PLAYER) and
7814 LongBool(gGameSettings.Options and GAME_OPTION_BOTVSPLAYER) then
7815 begin // Èãðîê
7816 pla := g_Player_Get(FLastSpawnerUID);
7817 ok := not TargetOnScreen(pla.FObj.X + PLAYER_RECT.X,
7818 pla.FObj.Y + PLAYER_RECT.Y);
7820 else
7821 if (g_GetUIDType(FLastSpawnerUID) = UID_MONSTER) and
7822 LongBool(gGameSettings.Options and GAME_OPTION_BOTVSMONSTER) then
7823 begin // Ìîíñòð
7824 mon := g_Monsters_ByUID(FLastSpawnerUID);
7825 ok := not TargetOnScreen(mon.Obj.X + mon.Obj.Rect.X,
7826 mon.Obj.Y + mon.Obj.Rect.Y);
7827 end;
7829 if ok then
7830 if Angle = 0 then
7831 SetAIFlag('ATTACKLEFT', '1')
7832 else
7833 SetAIFlag('ATTACKRIGHT', '1');
7834 end;
7835 end;
7837 function TBot.RunDirection(): TDirection;
7838 begin
7839 if Abs(Vel.X) >= 1 then
7840 begin
7841 if Vel.X > 0 then Result := TDirection.D_RIGHT else Result := TDirection.D_LEFT;
7842 end else
7843 Result := FDirection;
7844 end;
7846 function TBot.GetRnd(a: Byte): Boolean;
7847 begin
7848 if a = 0 then Result := False
7849 else if a = 255 then Result := True
7850 else Result := Random(256) > 255-a;
7851 end;
7853 function TBot.GetInterval(a: Byte; radius: SmallInt): SmallInt;
7854 begin
7855 Result := Round((255-a)/255*radius*(Random(2)-1));
7856 end;
7859 procedure TDifficult.save (st: TStream);
7860 begin
7861 utils.writeInt(st, Byte(DiagFire));
7862 utils.writeInt(st, Byte(InvisFire));
7863 utils.writeInt(st, Byte(DiagPrecision));
7864 utils.writeInt(st, Byte(FlyPrecision));
7865 utils.writeInt(st, Byte(Cover));
7866 utils.writeInt(st, Byte(CloseJump));
7867 st.WriteBuffer(WeaponPrior[Low(WeaponPrior)], sizeof(WeaponPrior));
7868 st.WriteBuffer(CloseWeaponPrior[Low(CloseWeaponPrior)], sizeof(CloseWeaponPrior));
7869 end;
7871 procedure TDifficult.load (st: TStream);
7872 begin
7873 DiagFire := utils.readByte(st);
7874 InvisFire := utils.readByte(st);
7875 DiagPrecision := utils.readByte(st);
7876 FlyPrecision := utils.readByte(st);
7877 Cover := utils.readByte(st);
7878 CloseJump := utils.readByte(st);
7879 st.ReadBuffer(WeaponPrior[Low(WeaponPrior)], sizeof(WeaponPrior));
7880 st.ReadBuffer(CloseWeaponPrior[Low(CloseWeaponPrior)], sizeof(CloseWeaponPrior));
7881 end;
7884 procedure TBot.SaveState (st: TStream);
7886 i: Integer;
7887 dw: Integer;
7888 begin
7889 inherited SaveState(st);
7890 utils.writeSign(st, 'BOT0');
7891 // Âûáðàííîå îðóæèå
7892 utils.writeInt(st, Byte(FSelectedWeapon));
7893 // UID öåëè
7894 utils.writeInt(st, Word(FTargetUID));
7895 // Âðåìÿ ïîòåðè öåëè
7896 utils.writeInt(st, LongWord(FLastVisible));
7897 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7898 dw := Length(FAIFlags);
7899 utils.writeInt(st, LongInt(dw));
7900 // Ôëàãè ÈÈ
7901 for i := 0 to dw-1 do
7902 begin
7903 utils.writeStr(st, FAIFlags[i].Name, 20);
7904 utils.writeStr(st, FAIFlags[i].Value, 20);
7905 end;
7906 // Íàñòðîéêè ñëîæíîñòè
7907 FDifficult.save(st);
7908 end;
7911 procedure TBot.LoadState (st: TStream);
7913 i: Integer;
7914 dw: Integer;
7915 begin
7916 inherited LoadState(st);
7917 if not utils.checkSign(st, 'BOT0') then raise XStreamError.Create('invalid bot signature');
7918 // Âûáðàííîå îðóæèå
7919 FSelectedWeapon := utils.readByte(st);
7920 // UID öåëè
7921 FTargetUID := utils.readWord(st);
7922 // Âðåìÿ ïîòåðè öåëè
7923 FLastVisible := utils.readLongWord(st);
7924 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7925 dw := utils.readLongInt(st);
7926 if (dw < 0) or (dw > 16384) then raise XStreamError.Create('invalid number of bot AI flags');
7927 SetLength(FAIFlags, dw);
7928 // Ôëàãè ÈÈ
7929 for i := 0 to dw-1 do
7930 begin
7931 FAIFlags[i].Name := utils.readStr(st, 20);
7932 FAIFlags[i].Value := utils.readStr(st, 20);
7933 end;
7934 // Íàñòðîéêè ñëîæíîñòè
7935 FDifficult.load(st);
7936 end;
7939 begin
7940 conRegVar('cheat_berserk_autoswitch', @gBerserkAutoswitch, 'autoswitch to fist when berserk pack taken', '', true, true);
7941 end.