DEADSOFTWARE

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