DEADSOFTWARE

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