DEADSOFTWARE

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