DEADSOFTWARE

alot of debugging code
[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, either version 3 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *)
16 {$INCLUDE ../shared/a_modes.inc}
17 unit g_player;
19 interface
21 uses
22 e_graphics, g_playermodel, g_basic, g_textures,
23 g_weapons, g_phys, g_sound, g_saveload, MAPSTRUCT,
24 BinEditor, g_panel;
26 const
27 KEY_LEFT = 1;
28 KEY_RIGHT = 2;
29 KEY_UP = 3;
30 KEY_DOWN = 4;
31 KEY_FIRE = 5;
32 KEY_NEXTWEAPON = 6;
33 KEY_PREVWEAPON = 7;
34 KEY_OPEN = 8;
35 KEY_JUMP = 9;
36 KEY_CHAT = 10;
38 R_ITEM_BACKPACK = 0;
39 R_KEY_RED = 1;
40 R_KEY_GREEN = 2;
41 R_KEY_BLUE = 3;
42 R_BERSERK = 4;
44 MR_SUIT = 0;
45 MR_INVUL = 1;
46 MR_INVIS = 2;
47 MR_MAX = 2;
49 A_BULLETS = 0;
50 A_SHELLS = 1;
51 A_ROCKETS = 2;
52 A_CELLS = 3;
53 A_FUEL = 4;
54 A_HIGH = 4;
56 AmmoLimits: Array [0..1] of Array [A_BULLETS..A_HIGH] of Word =
57 ((200, 50, 50, 300, 100),
58 (400, 100, 100, 600, 200));
60 K_SIMPLEKILL = 0;
61 K_HARDKILL = 1;
62 K_EXTRAHARDKILL = 2;
63 K_FALLKILL = 3;
65 T_RESPAWN = 0;
66 T_SWITCH = 1;
67 T_USE = 2;
68 T_FLAGCAP = 3;
70 TEAM_NONE = 0;
71 TEAM_RED = 1;
72 TEAM_BLUE = 2;
73 TEAM_COOP = 3;
75 SHELL_BULLET = 0;
76 SHELL_SHELL = 1;
77 SHELL_DBLSHELL = 2;
79 ANGLE_NONE = Low(SmallInt);
81 CORPSE_STATE_REMOVEME = 0;
82 CORPSE_STATE_NORMAL = 1;
83 CORPSE_STATE_MESS = 2;
85 PLAYER_RECT: TRectWH = (X:15; Y:12; Width:34; Height:52);
86 PLAYER_RECT_CX = 15+(34 div 2);
87 PLAYER_RECT_CY = 12+(52 div 2);
88 PLAYER_CORPSERECT: TRectWH = (X:15; Y:48; Width:34; Height:16);
90 PLAYER_HP_SOFT = 100;
91 PLAYER_HP_LIMIT = 200;
92 PLAYER_AP_SOFT = 100;
93 PLAYER_AP_LIMIT = 200;
94 SUICIDE_DAMAGE = 112;
96 PLAYER1_DEF_COLOR: TRGB = (R:64; G:175; B:48);
97 PLAYER2_DEF_COLOR: TRGB = (R:96; G:96; B:96);
99 type
100 TPlayerStat = record
101 Ping: Word;
102 Loss: Byte;
103 Name: String;
104 Team: Byte;
105 Frags: SmallInt;
106 Deaths: SmallInt;
107 Lives: Byte;
108 Kills: Word;
109 Color: TRGB;
110 Spectator: Boolean;
111 end;
113 TPlayerStatArray = Array of TPlayerStat;
115 TPlayerSavedState = record
116 Health: Integer;
117 Armor: Integer;
118 Air: Integer;
119 JetFuel: Integer;
120 CurrWeap: Byte;
121 NextWeap: WORD;
122 NextWeapDelay: Byte;
123 Ammo: Array [A_BULLETS..A_HIGH] of Word;
124 MaxAmmo: Array [A_BULLETS..A_HIGH] of Word;
125 Weapon: Array [WP_FIRST..WP_LAST] of Boolean;
126 Rulez: Set of R_ITEM_BACKPACK..R_BERSERK;
127 WaitRecall: Boolean;
128 end;
130 TKeyState = record
131 Pressed: Boolean;
132 Time: Word;
133 end;
135 TPlayer = class (TObject)
136 private
137 FIamBot: Boolean;
138 FUID: Word;
139 FName: String;
140 FTeam: Byte;
141 FLive: Boolean;
142 FSpawned: Boolean;
143 FDirection: TDirection;
144 FHealth: Integer;
145 FLives: Byte;
146 FArmor: Integer;
147 FAir: Integer;
148 FPain: Integer;
149 FPickup: Integer;
150 FKills: Integer;
151 FMonsterKills: Integer;
152 FFrags: Integer;
153 FFragCombo: Byte;
154 FLastFrag: LongWord;
155 FComboEvnt: Integer;
156 FDeath: Integer;
157 FCanJetpack: Boolean;
158 FJetFuel: Integer;
159 FFlag: Byte;
160 FSecrets: Integer;
161 FCurrWeap: Byte;
162 FNextWeap: WORD;
163 FNextWeapDelay: Byte; // frames
164 FBFGFireCounter: SmallInt;
165 FLastSpawnerUID: Word;
166 FLastHit: Byte;
167 FObj: TObj;
168 FXTo, FYTo: Integer;
169 FSpectatePlayer: Integer;
170 FFirePainTime: Integer;
171 FFireAttacker: Word;
173 FSavedState: TPlayerSavedState;
175 FModel: TPlayerModel;
176 FActionPrior: Byte;
177 FActionAnim: Byte;
178 FActionForce: Boolean;
179 FActionChanged: Boolean;
180 FAngle: SmallInt;
181 FFireAngle: SmallInt;
182 FIncCam: Integer;
183 FShellTimer: Integer;
184 FShellType: Byte;
185 FSawSound: TPlayableSound;
186 FSawSoundIdle: TPlayableSound;
187 FSawSoundHit: TPlayableSound;
188 FSawSoundSelect: TPlayableSound;
189 FJetSoundOn: TPlayableSound;
190 FJetSoundOff: TPlayableSound;
191 FJetSoundFly: TPlayableSound;
192 FGodMode: Boolean;
193 FNoTarget: Boolean;
194 FNoReload: Boolean;
195 FJustTeleported: Boolean;
196 FNetTime: LongWord;
198 function CollideLevel(XInc, YInc: Integer): Boolean;
199 function StayOnStep(XInc, YInc: Integer): Boolean;
200 function HeadInLiquid(XInc, YInc: Integer): Boolean;
201 function BodyInLiquid(XInc, YInc: Integer): Boolean;
202 function BodyInAcid(XInc, YInc: Integer): Boolean;
203 function FullInLift(XInc, YInc: Integer): Integer;
204 {procedure CollideItem();}
205 procedure FlySmoke(Times: DWORD = 1);
206 procedure OnFireFlame(Times: DWORD = 1);
207 function GetAmmoByWeapon(Weapon: Byte): Word;
208 procedure SetAction(Action: Byte; Force: Boolean = False);
209 procedure OnDamage(Angle: SmallInt); virtual;
210 function firediry(): Integer;
212 procedure Run(Direction: TDirection);
213 procedure NextWeapon();
214 procedure PrevWeapon();
215 procedure SeeUp();
216 procedure SeeDown();
217 procedure Fire();
218 procedure Jump();
219 procedure Use();
221 function getNextWeaponIndex (): Byte; // return 255 for "no switch"
222 procedure resetWeaponQueue ();
223 function hasAmmoForWeapon (weapon: Byte): Boolean;
225 public
226 FDamageBuffer: Integer;
228 FAmmo: Array [A_BULLETS..A_HIGH] of Word;
229 FMaxAmmo: Array [A_BULLETS..A_HIGH] of Word;
230 FWeapon: Array [WP_FIRST..WP_LAST] of Boolean;
231 FRulez: Set of R_ITEM_BACKPACK..R_BERSERK;
232 FBerserk: Integer;
233 FMegaRulez: Array [MR_SUIT..MR_MAX] of DWORD;
234 FReloading: Array [WP_FIRST..WP_LAST] of Word;
235 FTime: Array [T_RESPAWN..T_FLAGCAP] of DWORD;
236 FKeys: Array [KEY_LEFT..KEY_CHAT] of TKeyState;
237 FColor: TRGB;
238 FPreferredTeam: Byte;
239 FSpectator: Boolean;
240 FNoRespawn: Boolean;
241 FWantsInGame: Boolean;
242 FGhost: Boolean;
243 FPhysics: Boolean;
244 FJetpack: Boolean;
245 FActualModelName: string;
246 FClientID: SmallInt;
247 FPing: Word;
248 FLoss: Byte;
249 FDummy: Boolean;
250 FFireTime: Integer;
252 // debug: viewport offset
253 viewPortX, viewPortY, viewPortW, viewPortH: Integer;
255 function isValidViewPort (): Boolean; inline;
257 constructor Create(); virtual;
258 destructor Destroy(); override;
259 procedure Respawn(Silent: Boolean; Force: Boolean = False); virtual;
260 function GetRespawnPoint(): Byte;
261 procedure PressKey(Key: Byte; Time: Word = 1);
262 procedure ReleaseKeys();
263 procedure SetModel(ModelName: String);
264 procedure SetColor(Color: TRGB);
265 procedure SetWeapon(W: Byte);
266 function IsKeyPressed(K: Byte): Boolean;
267 function GetKeys(): Byte;
268 function PickItem(ItemType: Byte; arespawn: Boolean; var remove: Boolean): Boolean; virtual;
269 function Collide(X, Y: Integer; Width, Height: Word): Boolean; overload;
270 function Collide(Panel: TPanel): Boolean; overload;
271 function Collide(X, Y: Integer): Boolean; overload;
272 procedure SetDirection(Direction: TDirection);
273 procedure GetSecret();
274 function TeleportTo(X, Y: Integer; silent: Boolean; dir: Byte): Boolean;
275 procedure Touch();
276 procedure Push(vx, vy: Integer);
277 procedure ChangeModel(ModelName: String);
278 procedure SwitchTeam;
279 procedure ChangeTeam(Team: Byte);
280 procedure BFGHit();
281 function GetFlag(Flag: Byte): Boolean;
282 procedure SetFlag(Flag: Byte);
283 function DropFlag(): Boolean;
284 procedure AllRulez(Health: Boolean);
285 procedure RestoreHealthArmor();
286 procedure FragCombo();
287 procedure GiveItem(ItemType: Byte);
288 procedure Damage(value: Word; SpawnerUID: Word; vx, vy: Integer; t: Byte); virtual;
289 function Heal(value: Word; Soft: Boolean): Boolean; virtual;
290 procedure MakeBloodVector(Count: Word; VelX, VelY: Integer);
291 procedure MakeBloodSimple(Count: Word);
292 procedure Kill(KillType: Byte; SpawnerUID: Word; t: Byte);
293 procedure Reset(Force: Boolean);
294 procedure Spectate(NoMove: Boolean = False);
295 procedure SwitchNoClip;
296 procedure SoftReset();
297 procedure Draw(); virtual;
298 procedure DrawPain();
299 procedure DrawPickup();
300 procedure DrawRulez();
301 procedure DrawAim();
302 procedure DrawBubble();
303 procedure DrawGUI();
304 procedure Update(); virtual;
305 procedure RememberState();
306 procedure RecallState();
307 procedure SaveState(var Mem: TBinMemoryWriter); virtual;
308 procedure LoadState(var Mem: TBinMemoryReader); virtual;
309 procedure PauseSounds(Enable: Boolean);
310 procedure NetFire(Wpn: Byte; X, Y, AX, AY: Integer; WID: Integer = -1);
311 procedure DoLerp(Level: Integer = 2);
312 procedure SetLerp(XTo, YTo: Integer);
313 procedure QueueWeaponSwitch(Weapon: Byte);
314 procedure RealizeCurrentWeapon();
315 procedure JetpackOn;
316 procedure JetpackOff;
317 procedure CatchFire(Attacker: Word);
319 //WARNING! this does nothing for now, but still call it!
320 procedure positionChanged (); //WARNING! call this after monster position was changed, or coldet will not work right!
322 procedure getMapBox (out x, y, w, h: Integer); inline;
324 property Name: String read FName write FName;
325 property Model: TPlayerModel read FModel;
326 property Health: Integer read FHealth write FHealth;
327 property Lives: Byte read FLives write FLives;
328 property Armor: Integer read FArmor write FArmor;
329 property Air: Integer read FAir write FAir;
330 property JetFuel: Integer read FJetFuel write FJetFuel;
331 property Frags: Integer read FFrags write FFrags;
332 property Death: Integer read FDeath write FDeath;
333 property Kills: Integer read FKills write FKills;
334 property CurrWeap: Byte read FCurrWeap write FCurrWeap;
335 property MonsterKills: Integer read FMonsterKills write FMonsterKills;
336 property Secrets: Integer read FSecrets;
337 property GodMode: Boolean read FGodMode write FGodMode;
338 property NoTarget: Boolean read FNoTarget write FNoTarget;
339 property NoReload: Boolean read FNoReload write FNoReload;
340 property Live: Boolean read FLive write FLive;
341 property Flag: Byte read FFlag;
342 property Team: Byte read FTeam write FTeam;
343 property Direction: TDirection read FDirection;
344 property GameX: Integer read FObj.X write FObj.X;
345 property GameY: Integer read FObj.Y write FObj.Y;
346 property GameVelX: Integer read FObj.Vel.X write FObj.Vel.X;
347 property GameVelY: Integer read FObj.Vel.Y write FObj.Vel.Y;
348 property GameAccelX: Integer read FObj.Accel.X write FObj.Accel.X;
349 property GameAccelY: Integer read FObj.Accel.Y write FObj.Accel.Y;
350 property Vel: TPoint2i read FObj.Vel;
351 property Obj: TObj read FObj;
352 property IncCam: Integer read FIncCam write FIncCam;
353 property UID: Word read FUID write FUID;
354 property JustTeleported: Boolean read FJustTeleported write FJustTeleported;
355 property NetTime: LongWord read FNetTime write FNetTime;
356 end;
358 TDifficult = record
359 DiagFire: Byte;
360 InvisFire: Byte;
361 DiagPrecision: Byte;
362 FlyPrecision: Byte;
363 Cover: Byte;
364 CloseJump: Byte;
365 WeaponPrior: Array [WP_FIRST..WP_LAST] of Byte;
366 CloseWeaponPrior: Array [WP_FIRST..WP_LAST] of Byte;
367 //SafeWeaponPrior: Array [WP_FIRST..WP_LAST] of Byte;
368 end;
370 TAIFlag = record
371 Name: String;
372 Value: String;
373 end;
375 TBot = class (TPlayer)
376 private
377 FSelectedWeapon: Byte;
378 FTargetUID: Word;
379 FLastVisible: DWORD;
380 FAIFlags: Array of TAIFlag;
381 FDifficult: TDifficult;
383 function GetRnd(a: Byte): Boolean;
384 function GetInterval(a: Byte; radius: SmallInt): SmallInt;
385 function RunDirection(): TDirection;
386 function FullInStep(XInc, YInc: Integer): Boolean;
387 //function NeedItem(Item: Byte): Byte;
388 procedure SelectWeapon(Dist: Integer);
389 procedure SetAIFlag(aName, fValue: String20);
390 function GetAIFlag(aName: String20): String20;
391 procedure RemoveAIFlag(aName: String20);
392 function Healthy(): Byte;
393 procedure UpdateMove();
394 procedure UpdateCombat();
395 function KeyPressed(Key: Word): Boolean;
396 procedure ReleaseKey(Key: Byte);
397 function TargetOnScreen(TX, TY: Integer): Boolean;
398 procedure OnDamage(Angle: SmallInt); override;
400 public
401 procedure Respawn(Silent: Boolean; Force: Boolean = False); override;
402 constructor Create(); override;
403 destructor Destroy(); override;
404 procedure Draw(); override;
405 function PickItem(ItemType: Byte; force: Boolean; var remove: Boolean): Boolean; override;
406 function Heal(value: Word; Soft: Boolean): Boolean; override;
407 procedure Update(); override;
408 procedure SaveState(var Mem: TBinMemoryWriter); override;
409 procedure LoadState(var Mem: TBinMemoryReader); override;
410 end;
412 TGib = record
413 Live: Boolean;
414 ID: DWORD;
415 MaskID: DWORD;
416 RAngle: Integer;
417 Color: TRGB;
418 Obj: TObj;
420 procedure positionChanged (); //WARNING! call this after monster position was changed, or coldet will not work right!
421 end;
424 TShell = record
425 SpriteID: DWORD;
426 Live: Boolean;
427 SType: Byte;
428 RAngle: Integer;
429 Timeout: Cardinal;
430 CX, CY: Integer;
431 Obj: TObj;
433 procedure positionChanged (); //WARNING! call this after monster position was changed, or coldet will not work right!
434 end;
436 TCorpse = class (TObject)
437 private
438 FModelName: String;
439 FMess: Boolean;
440 FState: Byte;
441 FDamage: Byte;
442 FColor: TRGB;
443 FObj: TObj;
444 FAnimation: TAnimation;
445 FAnimationMask: TAnimation;
447 public
448 constructor Create(X, Y: Integer; ModelName: String; aMess: Boolean);
449 destructor Destroy(); override;
450 procedure Damage(Value: Word; vx, vy: Integer);
451 procedure Update();
452 procedure Draw();
453 procedure SaveState(var Mem: TBinMemoryWriter);
454 procedure LoadState(var Mem: TBinMemoryReader);
456 procedure positionChanged (); //WARNING! call this after monster position was changed, or coldet will not work right!
458 property Obj: TObj read FObj;
459 property State: Byte read FState;
460 property Mess: Boolean read FMess;
461 end;
463 TTeamStat = Array [TEAM_RED..TEAM_BLUE] of
464 record
465 Goals: SmallInt;
466 end;
468 var
469 gPlayers: Array of TPlayer;
470 gCorpses: Array of TCorpse;
471 gGibs: Array of TGib;
472 gShells: Array of TShell;
473 gTeamStat: TTeamStat;
474 gFly: Boolean = False;
475 gAimLine: Boolean = False;
476 gChatBubble: Byte = 0;
477 gNumBots: Word = 0;
478 gLMSPID1: Word = 0;
479 gLMSPID2: Word = 0;
480 MAX_RUNVEL: Integer = 8;
481 VEL_JUMP: Integer = 10;
482 SHELL_TIMEOUT: Cardinal = 60000;
484 function Lerp(X, Y, Factor: Integer): Integer;
486 procedure g_Gibs_SetMax(Count: Word);
487 function g_Gibs_GetMax(): Word;
488 procedure g_Corpses_SetMax(Count: Word);
489 function g_Corpses_GetMax(): Word;
490 procedure g_Shells_SetMax(Count: Word);
491 function g_Shells_GetMax(): Word;
493 procedure g_Player_Init();
494 procedure g_Player_Free();
495 function g_Player_Create(ModelName: String; Color: TRGB; Team: Byte; Bot: Boolean): Word;
496 function g_Player_CreateFromState(var Mem: TBinMemoryReader): Word;
497 procedure g_Player_Remove(UID: Word);
498 procedure g_Player_ResetTeams();
499 procedure g_Player_UpdateAll();
500 procedure g_Player_DrawAll();
501 procedure g_Player_DrawDebug(p: TPlayer);
502 procedure g_Player_DrawHealth();
503 procedure g_Player_RememberAll();
504 procedure g_Player_ResetAll(Force, Silent: Boolean);
505 function g_Player_Get(UID: Word): TPlayer;
506 function g_Player_GetCount(): Byte;
507 function g_Player_GetStats(): TPlayerStatArray;
508 function g_Player_ValidName(Name: String): Boolean;
509 procedure g_Player_CreateCorpse(Player: TPlayer);
510 procedure g_Player_CreateGibs(fX, fY: Integer; ModelName: String; fColor: TRGB);
511 procedure g_Player_CreateShell(fX, fY, dX, dY: Integer; T: Byte);
512 procedure g_Player_UpdatePhysicalObjects();
513 procedure g_Player_DrawCorpses();
514 procedure g_Player_DrawShells();
515 procedure g_Player_RemoveAllCorpses();
516 procedure g_Player_Corpses_SaveState(var Mem: TBinMemoryWriter);
517 procedure g_Player_Corpses_LoadState(var Mem: TBinMemoryReader);
518 procedure g_Bot_Add(Team, Difficult: Byte);
519 procedure g_Bot_AddList(Team: Byte; lname: ShortString; num: Integer = -1);
520 procedure g_Bot_MixNames();
521 procedure g_Bot_RemoveAll();
523 implementation
525 uses
526 e_log, g_map, g_items, g_console, SysUtils, g_gfx, Math,
527 g_options, g_triggers, g_menu, MAPDEF, g_game, g_grid,
528 wadreader, g_main, g_monsters, CONFIG, g_language,
529 g_net, g_netmsg, g_window, GL;
531 type
532 TBotProfile = record
533 name: ShortString;
534 model: ShortString;
535 team: Byte;
536 color: TRGB;
537 diag_fire: Byte;
538 invis_fire: Byte;
539 diag_precision: Byte;
540 fly_precision: Byte;
541 cover: Byte;
542 close_jump: Byte;
543 w_prior1: Array [WP_FIRST..WP_LAST] of Byte;
544 w_prior2: Array [WP_FIRST..WP_LAST] of Byte;
545 w_prior3: Array [WP_FIRST..WP_LAST] of Byte;
546 end;
548 const
549 TIME_RESPAWN1 = 1500;
550 TIME_RESPAWN2 = 2000;
551 TIME_RESPAWN3 = 3000;
552 AIR_DEF = 360;
553 AIR_MAX = 1091;
554 JET_MAX = 540; // ~30 sec
555 PLAYER_SUIT_TIME = 30000;
556 PLAYER_INVUL_TIME = 30000;
557 PLAYER_INVIS_TIME = 35000;
558 FRAG_COMBO_TIME = 3000;
559 VEL_SW = 4;
560 VEL_FLY = 6;
561 ANGLE_RIGHTUP = 55;
562 ANGLE_RIGHTDOWN = -35;
563 ANGLE_LEFTUP = 125;
564 ANGLE_LEFTDOWN = -145;
565 PLAYER_HEADRECT: TRectWH = (X:24; Y:12; Width:20; Height:12);
566 WEAPONPOINT: Array [TDirection] of TPoint = ((X:16; Y:32), (X:47; Y:32));
567 BOT_MAXJUMP = 84;
568 BOT_LONGDIST = 300;
569 BOT_UNSAFEDIST = 128;
570 TEAMCOLOR: Array [TEAM_RED..TEAM_BLUE] of TRGB = ((R:255; G:0; B:0),
571 (R:0; G:0; B:255));
572 DIFFICULT_EASY: TDifficult = (DiagFire: 32; InvisFire: 32; DiagPrecision: 32;
573 FlyPrecision: 32; Cover: 32; CloseJump: 32;
574 WeaponPrior:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior:(0,0,0,0,0,0,0,0,0,0,0));
575 DIFFICULT_MEDIUM: TDifficult = (DiagFire: 127; InvisFire: 127; DiagPrecision: 127;
576 FlyPrecision: 127; Cover: 127; CloseJump: 127;
577 WeaponPrior:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior:(0,0,0,0,0,0,0,0,0,0,0));
578 DIFFICULT_HARD: TDifficult = (DiagFire: 255; InvisFire: 255; DiagPrecision: 255;
579 FlyPrecision: 255; Cover: 255; CloseJump: 255;
580 WeaponPrior:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior:(0,0,0,0,0,0,0,0,0,0,0));
581 WEAPON_PRIOR1: Array [WP_FIRST..WP_LAST] of Byte =
582 (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
583 WEAPON_SHOTGUN2, WEAPON_SHOTGUN1,
584 WEAPON_CHAINGUN, WEAPON_PLASMA, WEAPON_ROCKETLAUNCHER,
585 WEAPON_BFG, WEAPON_PISTOL, WEAPON_SAW, WEAPON_KASTET);
586 WEAPON_PRIOR2: Array [WP_FIRST..WP_LAST] of Byte =
587 (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
588 WEAPON_BFG, WEAPON_ROCKETLAUNCHER,
589 WEAPON_SHOTGUN2, WEAPON_PLASMA, WEAPON_SHOTGUN1,
590 WEAPON_CHAINGUN, WEAPON_PISTOL, WEAPON_SAW, WEAPON_KASTET);
591 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
592 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
593 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
594 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
595 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
596 WEAPON_RELOAD: Array [WP_FIRST..WP_LAST] of Byte =
597 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
599 PLAYER_SIGNATURE = $52594C50; // 'PLYR'
600 CORPSE_SIGNATURE = $50524F43; // 'CORP'
602 BOTNAMES_FILENAME = 'botnames.txt';
603 BOTLIST_FILENAME = 'botlist.txt';
605 var
606 MaxGibs: Word = 150;
607 MaxCorpses: Word = 20;
608 MaxShells: Word = 300;
609 CurrentGib: Integer = 0;
610 CurrentShell: Integer = 0;
611 BotNames: Array of String;
612 BotList: Array of TBotProfile;
615 procedure TGib.positionChanged (); begin end;
616 procedure TShell.positionChanged (); begin end;
619 function Lerp(X, Y, Factor: Integer): Integer;
620 begin
621 Result := X + ((Y - X) div Factor);
622 end;
624 function SameTeam(UID1, UID2: Word): Boolean;
625 begin
626 Result := False;
628 if (UID1 > UID_MAX_PLAYER) or (UID1 <= UID_MAX_GAME) or
629 (UID2 > UID_MAX_PLAYER) or (UID2 <= UID_MAX_GAME) then Exit;
631 if (g_Player_Get(UID1) = nil) or (g_Player_Get(UID2) = nil) then Exit;
633 if ((g_Player_Get(UID1).Team = TEAM_NONE) or
634 (g_Player_Get(UID2).Team = TEAM_NONE)) then Exit;
636 Result := g_Player_Get(UID1).FTeam = g_Player_Get(UID2).FTeam;
637 end;
639 procedure g_Gibs_SetMax(Count: Word);
640 begin
641 MaxGibs := Count;
642 SetLength(gGibs, Count);
644 if CurrentGib >= Count then
645 CurrentGib := 0;
646 end;
648 function g_Gibs_GetMax(): Word;
649 begin
650 Result := MaxGibs;
651 end;
653 procedure g_Shells_SetMax(Count: Word);
654 begin
655 MaxShells := Count;
656 SetLength(gShells, Count);
658 if CurrentShell >= Count then
659 CurrentShell := 0;
660 end;
662 function g_Shells_GetMax(): Word;
663 begin
664 Result := MaxShells;
665 end;
668 procedure g_Corpses_SetMax(Count: Word);
669 begin
670 MaxCorpses := Count;
671 SetLength(gCorpses, Count);
672 end;
674 function g_Corpses_GetMax(): Word;
675 begin
676 Result := MaxCorpses;
677 end;
679 function g_Player_Create(ModelName: String; Color: TRGB; Team: Byte; Bot: Boolean): Word;
680 var
681 a: Integer;
682 ok: Boolean;
683 begin
684 Result := 0;
686 ok := False;
687 a := 0;
689 // Åñòü ëè ìåñòî â gPlayers:
690 if gPlayers <> nil then
691 for a := 0 to High(gPlayers) do
692 if gPlayers[a] = nil then
693 begin
694 ok := True;
695 Break;
696 end;
698 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
699 if not ok then
700 begin
701 SetLength(gPlayers, Length(gPlayers)+1);
702 a := High(gPlayers);
703 end;
705 // Ñîçäàåì îáúåêò èãðîêà:
706 if Bot then
707 gPlayers[a] := TBot.Create()
708 else
709 gPlayers[a] := TPlayer.Create();
712 gPlayers[a].FActualModelName := ModelName;
713 gPlayers[a].SetModel(ModelName);
715 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
716 if gPlayers[a].FModel = nil then
717 begin
718 gPlayers[a].Free();
719 gPlayers[a] := nil;
720 g_FatalError(Format(_lc[I_GAME_ERROR_MODEL], [ModelName]));
721 Exit;
722 end;
724 if not (Team in [TEAM_RED, TEAM_BLUE]) then
725 if Random(2) = 0 then
726 Team := TEAM_RED
727 else
728 Team := TEAM_BLUE;
729 gPlayers[a].FPreferredTeam := Team;
731 case gGameSettings.GameMode of
732 GM_DM: gPlayers[a].FTeam := TEAM_NONE;
733 GM_TDM,
734 GM_CTF: gPlayers[a].FTeam := gPlayers[a].FPreferredTeam;
735 GM_SINGLE,
736 GM_COOP: gPlayers[a].FTeam := TEAM_COOP;
737 end;
739 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
740 gPlayers[a].FColor := Color;
741 if gPlayers[a].FTeam in [TEAM_RED, TEAM_BLUE] then
742 gPlayers[a].FModel.Color := TEAMCOLOR[gPlayers[a].FTeam]
743 else
744 gPlayers[a].FModel.Color := Color;
746 gPlayers[a].FUID := g_CreateUID(UID_PLAYER);
747 gPlayers[a].FLive := False;
749 Result := gPlayers[a].FUID;
750 end;
752 function g_Player_CreateFromState(var Mem: TBinMemoryReader): Word;
753 var
754 a, i: Integer;
755 ok, Bot: Boolean;
756 sig: DWORD;
757 b: Byte;
758 begin
759 Result := 0;
760 if Mem = nil then
761 Exit;
763 // Ñèãíàòóðà èãðîêà:
764 Mem.ReadDWORD(sig);
765 if sig <> PLAYER_SIGNATURE then // 'PLYR'
766 begin
767 raise EBinSizeError.Create('g_Player_CreateFromState: Wrong Player Signature');
768 end;
770 // Áîò èëè ÷åëîâåê:
771 Mem.ReadBoolean(Bot);
773 ok := False;
774 a := 0;
776 // Åñòü ëè ìåñòî â gPlayers:
777 if gPlayers <> nil then
778 for a := 0 to High(gPlayers) do
779 if gPlayers[a] = nil then
780 begin
781 ok := True;
782 Break;
783 end;
785 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
786 if not ok then
787 begin
788 SetLength(gPlayers, Length(gPlayers)+1);
789 a := High(gPlayers);
790 end;
792 // Ñîçäàåì îáúåêò èãðîêà:
793 if Bot then
794 gPlayers[a] := TBot.Create()
795 else
796 gPlayers[a] := TPlayer.Create();
797 gPlayers[a].FIamBot := Bot;
798 gPlayers[a].FPhysics := True;
800 // UID èãðîêà:
801 Mem.ReadWord(gPlayers[a].FUID);
802 // Èìÿ èãðîêà:
803 Mem.ReadString(gPlayers[a].FName);
804 // Êîìàíäà:
805 Mem.ReadByte(gPlayers[a].FTeam);
806 gPlayers[a].FPreferredTeam := gPlayers[a].FTeam;
807 // Æèâ ëè:
808 Mem.ReadBoolean(gPlayers[a].FLive);
809 // Èçðàñõîäîâàë ëè âñå æèçíè:
810 Mem.ReadBoolean(gPlayers[a].FNoRespawn);
811 // Íàïðàâëåíèå:
812 Mem.ReadByte(b);
813 if b = 1 then
814 gPlayers[a].FDirection := D_LEFT
815 else // b = 2
816 gPlayers[a].FDirection := D_RIGHT;
817 // Çäîðîâüå:
818 Mem.ReadInt(gPlayers[a].FHealth);
819 // Æèçíè:
820 Mem.ReadByte(gPlayers[a].FLives);
821 // Áðîíÿ:
822 Mem.ReadInt(gPlayers[a].FArmor);
823 // Çàïàñ âîçäóõà:
824 Mem.ReadInt(gPlayers[a].FAir);
825 // Çàïàñ ãîðþ÷åãî:
826 Mem.ReadInt(gPlayers[a].FJetFuel);
827 // Áîëü:
828 Mem.ReadInt(gPlayers[a].FPain);
829 // Óáèë:
830 Mem.ReadInt(gPlayers[a].FKills);
831 // Óáèë ìîíñòðîâ:
832 Mem.ReadInt(gPlayers[a].FMonsterKills);
833 // Ôðàãîâ:
834 Mem.ReadInt(gPlayers[a].FFrags);
835 // Ôðàãîâ ïîäðÿä:
836 Mem.ReadByte(gPlayers[a].FFragCombo);
837 // Âðåìÿ ïîñëåäíåãî ôðàãà:
838 Mem.ReadDWORD(gPlayers[a].FLastFrag);
839 // Ñìåðòåé:
840 Mem.ReadInt(gPlayers[a].FDeath);
841 // Êàêîé ôëàã íåñåò:
842 Mem.ReadByte(gPlayers[a].FFlag);
843 // Íàøåë ñåêðåòîâ:
844 Mem.ReadInt(gPlayers[a].FSecrets);
845 // Òåêóùåå îðóæèå:
846 Mem.ReadByte(gPlayers[a].FCurrWeap);
847 // Ñëåäóþùåå æåëàåìîå îðóæèå:
848 Mem.ReadWord(gPlayers[a].FNextWeap);
849 // ...è ïàóçà:
850 Mem.ReadByte(gPlayers[a].FNextWeapDelay);
851 // Âðåìÿ çàðÿäêè BFG:
852 Mem.ReadSmallInt(gPlayers[a].FBFGFireCounter);
853 // Áóôåð óðîíà:
854 Mem.ReadInt(gPlayers[a].FDamageBuffer);
855 // Ïîñëåäíèé óäàðèâøèé:
856 Mem.ReadWord(gPlayers[a].FLastSpawnerUID);
857 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
858 Mem.ReadByte(gPlayers[a].FLastHit);
859 // Îáúåêò èãðîêà:
860 Obj_LoadState(@gPlayers[a].FObj, Mem);
861 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
862 for i := A_BULLETS to A_HIGH do
863 Mem.ReadWord(gPlayers[a].FAmmo[i]);
864 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
865 for i := A_BULLETS to A_HIGH do
866 Mem.ReadWord(gPlayers[a].FMaxAmmo[i]);
867 // Íàëè÷èå îðóæèÿ:
868 for i := WP_FIRST to WP_LAST do
869 Mem.ReadBoolean(gPlayers[a].FWeapon[i]);
870 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
871 for i := WP_FIRST to WP_LAST do
872 Mem.ReadWord(gPlayers[a].FReloading[i]);
873 // Íàëè÷èå ðþêçàêà:
874 Mem.ReadByte(b);
875 if b = 1 then
876 Include(gPlayers[a].FRulez, R_ITEM_BACKPACK);
877 // Íàëè÷èå êðàñíîãî êëþ÷à:
878 Mem.ReadByte(b);
879 if b = 1 then
880 Include(gPlayers[a].FRulez, R_KEY_RED);
881 // Íàëè÷èå çåëåíîãî êëþ÷à:
882 Mem.ReadByte(b);
883 if b = 1 then
884 Include(gPlayers[a].FRulez, R_KEY_GREEN);
885 // Íàëè÷èå ñèíåãî êëþ÷à:
886 Mem.ReadByte(b);
887 if b = 1 then
888 Include(gPlayers[a].FRulez, R_KEY_BLUE);
889 // Íàëè÷èå áåðñåðêà:
890 Mem.ReadByte(b);
891 if b = 1 then
892 Include(gPlayers[a].FRulez, R_BERSERK);
893 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
894 for i := MR_SUIT to MR_MAX do
895 Mem.ReadDWORD(gPlayers[a].FMegaRulez[i]);
896 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
897 for i := T_RESPAWN to T_FLAGCAP do
898 Mem.ReadDWORD(gPlayers[a].FTime[i]);
900 // Íàçâàíèå ìîäåëè:
901 Mem.ReadString(gPlayers[a].FActualModelName);
902 // Öâåò ìîäåëè:
903 Mem.ReadByte(gPlayers[a].FColor.R);
904 Mem.ReadByte(gPlayers[a].FColor.G);
905 Mem.ReadByte(gPlayers[a].FColor.B);
906 // Îáíîâëÿåì ìîäåëü èãðîêà:
907 gPlayers[a].SetModel(gPlayers[a].FActualModelName);
909 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
910 if gPlayers[a].FModel = nil then
911 begin
912 gPlayers[a].Free();
913 gPlayers[a] := nil;
914 g_FatalError(Format(_lc[I_GAME_ERROR_MODEL], [gPlayers[a].FActualModelName]));
915 Exit;
916 end;
918 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
919 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
920 gPlayers[a].FModel.Color := TEAMCOLOR[gPlayers[a].FTeam]
921 else
922 gPlayers[a].FModel.Color := gPlayers[a].FColor;
924 Result := gPlayers[a].FUID;
925 end;
927 procedure g_Player_ResetTeams();
928 var
929 a: Integer;
930 begin
931 if g_Game_IsClient then
932 Exit;
933 if gPlayers = nil then
934 Exit;
935 for a := Low(gPlayers) to High(gPlayers) do
936 if gPlayers[a] <> nil then
937 case gGameSettings.GameMode of
938 GM_DM:
939 gPlayers[a].ChangeTeam(TEAM_NONE);
940 GM_TDM, GM_CTF:
941 if not (gPlayers[a].Team in [TEAM_RED, TEAM_BLUE]) then
942 if gPlayers[a].FPreferredTeam in [TEAM_RED, TEAM_BLUE] then
943 gPlayers[a].ChangeTeam(gPlayers[a].FPreferredTeam)
944 else
945 if a mod 2 = 0 then
946 gPlayers[a].ChangeTeam(TEAM_RED)
947 else
948 gPlayers[a].ChangeTeam(TEAM_BLUE);
949 GM_SINGLE,
950 GM_COOP:
951 gPlayers[a].ChangeTeam(TEAM_COOP);
952 end;
953 end;
955 procedure g_Bot_Add(Team, Difficult: Byte);
956 var
957 m: SArray;
958 _name, _model: String;
959 a, tr, tb: Integer;
960 begin
961 if not g_Game_IsServer then Exit;
963 // Ñïèñîê íàçâàíèé ìîäåëåé:
964 m := g_PlayerModel_GetNames();
965 if m = nil then
966 Exit;
968 // Êîìàíäà:
969 if (gGameSettings.GameType = GT_SINGLE) or (gGameSettings.GameMode = GM_COOP) then
970 Team := TEAM_COOP // COOP
971 else
972 if gGameSettings.GameMode = GM_DM then
973 Team := TEAM_NONE // DM
974 else
975 if Team = TEAM_NONE then // CTF / TDM
976 begin
977 // Àâòîáàëàíñ êîìàíä:
978 tr := 0;
979 tb := 0;
981 for a := 0 to High(gPlayers) do
982 if gPlayers[a] <> nil then
983 begin
984 if gPlayers[a].Team = TEAM_RED then
985 Inc(tr)
986 else
987 if gPlayers[a].Team = TEAM_BLUE then
988 Inc(tb);
989 end;
991 if tr > tb then
992 Team := TEAM_BLUE
993 else
994 if tb > tr then
995 Team := TEAM_RED
996 else // tr = tb
997 if Random(2) = 0 then
998 Team := TEAM_RED
999 else
1000 Team := TEAM_BLUE;
1001 end;
1003 // Âûáèðàåì áîòó èìÿ:
1004 _name := '';
1005 if BotNames <> nil then
1006 for a := 0 to High(BotNames) do
1007 if g_Player_ValidName(BotNames[a]) then
1008 begin
1009 _name := BotNames[a];
1010 Break;
1011 end;
1013 // Èìåíè íåò, çàäàåì ñëó÷àéíîå:
1014 if _name = '' then
1015 repeat
1016 _name := Format('DFBOT%.2d', [Random(100)]);
1017 until g_Player_ValidName(_name);
1019 // Âûáèðàåì ñëó÷àéíóþ ìîäåëü:
1020 _model := m[Random(Length(m))];
1022 // Ñîçäàåì áîòà:
1023 with g_Player_Get(g_Player_Create(_model,
1024 _RGB(Min(Random(9)*32, 255),
1025 Min(Random(9)*32, 255),
1026 Min(Random(9)*32, 255)),
1027 Team, True)) as TBot do
1028 begin
1029 Name := _name;
1031 case Difficult of
1032 1: FDifficult := DIFFICULT_EASY;
1033 2: FDifficult := DIFFICULT_MEDIUM;
1034 else FDifficult := DIFFICULT_HARD;
1035 end;
1037 for a := WP_FIRST to WP_LAST do
1038 begin
1039 FDifficult.WeaponPrior[a] := WEAPON_PRIOR1[a];
1040 FDifficult.CloseWeaponPrior[a] := WEAPON_PRIOR2[a];
1041 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1042 end;
1044 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [Name]), True);
1046 if g_Game_IsNet then MH_SEND_PlayerCreate(UID);
1047 if g_Game_IsServer and (gGameSettings.MaxLives > 0) then
1048 Spectate();
1049 end;
1050 end;
1052 procedure g_Bot_AddList(Team: Byte; lName: ShortString; num: Integer = -1);
1053 var
1054 m: SArray;
1055 _name, _model: String;
1056 a: Integer;
1057 begin
1058 if not g_Game_IsServer then Exit;
1060 // Ñïèñîê íàçâàíèé ìîäåëåé:
1061 m := g_PlayerModel_GetNames();
1062 if m = nil then
1063 Exit;
1065 // Êîìàíäà:
1066 if (gGameSettings.GameType = GT_SINGLE) or (gGameSettings.GameMode = GM_COOP) then
1067 Team := TEAM_COOP // COOP
1068 else
1069 if gGameSettings.GameMode = GM_DM then
1070 Team := TEAM_NONE // DM
1071 else
1072 if Team = TEAM_NONE then
1073 Team := BotList[num].team; // CTF / TDM
1075 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1076 lName := AnsiLowerCase(lName);
1077 if (num < 0) or (num > Length(BotList)-1) then
1078 num := -1;
1079 if (num = -1) and (lName <> '') and (BotList <> nil) then
1080 for a := 0 to High(BotList) do
1081 if AnsiLowerCase(BotList[a].name) = lName then
1082 begin
1083 num := a;
1084 Break;
1085 end;
1086 if num = -1 then
1087 Exit;
1089 // Èìÿ áîòà:
1090 _name := BotList[num].name;
1091 // Çàíÿòî - âûáèðàåì ñëó÷àéíîå:
1092 if not g_Player_ValidName(_name) then
1093 repeat
1094 _name := Format('DFBOT%.2d', [Random(100)]);
1095 until g_Player_ValidName(_name);
1097 // Ìîäåëü:
1098 _model := BotList[num].model;
1099 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1100 if not InSArray(_model, m) then
1101 _model := m[Random(Length(m))];
1103 // Ñîçäàåì áîòà:
1104 with g_Player_Get(g_Player_Create(_model, BotList[num].color, Team, True)) as TBot do
1105 begin
1106 Name := _name;
1108 FDifficult.DiagFire := BotList[num].diag_fire;
1109 FDifficult.InvisFire := BotList[num].invis_fire;
1110 FDifficult.DiagPrecision := BotList[num].diag_precision;
1111 FDifficult.FlyPrecision := BotList[num].fly_precision;
1112 FDifficult.Cover := BotList[num].cover;
1113 FDifficult.CloseJump := BotList[num].close_jump;
1115 for a := WP_FIRST to WP_LAST do
1116 begin
1117 FDifficult.WeaponPrior[a] := BotList[num].w_prior1[a];
1118 FDifficult.CloseWeaponPrior[a] := BotList[num].w_prior2[a];
1119 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1120 end;
1122 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [Name]), True);
1124 if g_Game_IsNet then MH_SEND_PlayerCreate(UID);
1125 end;
1126 end;
1128 procedure g_Bot_RemoveAll();
1129 var
1130 a: Integer;
1131 begin
1132 if not g_Game_IsServer then Exit;
1133 if gPlayers = nil then Exit;
1135 for a := 0 to High(gPlayers) do
1136 if gPlayers[a] <> nil then
1137 if gPlayers[a] is TBot then
1138 begin
1139 gPlayers[a].Lives := 0;
1140 gPlayers[a].Kill(K_SIMPLEKILL, 0, HIT_DISCON);
1141 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [gPlayers[a].Name]), True);
1142 g_Player_Remove(gPlayers[a].FUID);
1143 end;
1145 g_Bot_MixNames();
1146 end;
1148 procedure g_Bot_MixNames();
1149 var
1150 s: String;
1151 a, b: Integer;
1152 begin
1153 if BotNames <> nil then
1154 for a := 0 to High(BotNames) do
1155 begin
1156 b := Random(Length(BotNames));
1157 s := BotNames[a];
1158 Botnames[a] := BotNames[b];
1159 BotNames[b] := s;
1160 end;
1161 end;
1163 procedure g_Player_Remove(UID: Word);
1164 var
1165 i: Integer;
1166 begin
1167 if gPlayers = nil then Exit;
1169 if g_Game_IsServer and g_Game_IsNet then
1170 MH_SEND_PlayerDelete(UID);
1172 for i := 0 to High(gPlayers) do
1173 if gPlayers[i] <> nil then
1174 if gPlayers[i].FUID = UID then
1175 begin
1176 if gPlayers[i] is TPlayer then
1177 TPlayer(gPlayers[i]).Free()
1178 else
1179 TBot(gPlayers[i]).Free();
1180 gPlayers[i] := nil;
1181 Exit;
1182 end;
1183 end;
1185 procedure g_Player_Init();
1186 var
1187 F: TextFile;
1188 s: String;
1189 a, b: Integer;
1190 config: TConfig;
1191 sa: SArray;
1192 begin
1193 BotNames := nil;
1195 if not FileExists(DataDir + BOTNAMES_FILENAME) then
1196 Exit;
1198 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1199 AssignFile(F, DataDir + BOTNAMES_FILENAME);
1200 Reset(F);
1202 while not EOF(F) do
1203 begin
1204 ReadLn(F, s);
1206 s := Trim(s);
1207 if s = '' then
1208 Continue;
1210 SetLength(BotNames, Length(BotNames)+1);
1211 BotNames[High(BotNames)] := s;
1212 end;
1214 CloseFile(F);
1216 // Ïåðåìåøèâàåì èõ:
1217 g_Bot_MixNames();
1219 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1220 config := TConfig.CreateFile(DataDir + BOTLIST_FILENAME);
1221 BotList := nil;
1222 a := 0;
1224 while config.SectionExists(IntToStr(a)) do
1225 begin
1226 SetLength(BotList, Length(BotList)+1);
1228 with BotList[High(BotList)] do
1229 begin
1230 // Èìÿ áîòà:
1231 name := config.ReadStr(IntToStr(a), 'name', '');
1232 // Ìîäåëü:
1233 model := config.ReadStr(IntToStr(a), 'model', '');
1234 // Êîìàíäà:
1235 if config.ReadStr(IntToStr(a), 'team', 'red') = 'red' then
1236 team := TEAM_RED
1237 else
1238 team := TEAM_BLUE;
1239 // Öâåò ìîäåëè:
1240 sa := parse(config.ReadStr(IntToStr(a), 'color', ''));
1241 color.R := StrToIntDef(sa[0], 0);
1242 color.G := StrToIntDef(sa[1], 0);
1243 color.B := StrToIntDef(sa[2], 0);
1244 // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì:
1245 diag_fire := config.ReadInt(IntToStr(a), 'diag_fire', 0);
1246 // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó:
1247 invis_fire := config.ReadInt(IntToStr(a), 'invis_fire', 0);
1248 // Òî÷íîñòü ñòðåëüáû ïîä óãëîì:
1249 diag_precision := config.ReadInt(IntToStr(a), 'diag_precision', 0);
1250 // Òî÷íîñòü ñòðåëüáû â ïîëåòå:
1251 fly_precision := config.ReadInt(IntToStr(a), 'fly_precision', 0);
1252 // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ:
1253 cover := config.ReadInt(IntToStr(a), 'cover', 0);
1254 // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà:
1255 close_jump := config.ReadInt(IntToStr(a), 'close_jump', 0);
1256 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ:
1257 sa := parse(config.ReadStr(IntToStr(a), 'w_prior1', ''));
1258 if Length(sa) = 10 then
1259 for b := 0 to 9 do
1260 w_prior1[b] := EnsureRange(StrToInt(sa[b]), 0, 9);
1261 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ:
1262 sa := parse(config.ReadStr(IntToStr(a), 'w_prior2', ''));
1263 if Length(sa) = 10 then
1264 for b := 0 to 9 do
1265 w_prior2[b] := EnsureRange(StrToInt(sa[b]), 0, 9);
1267 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1268 if Length(sa) = 10 then
1269 for b := 0 to 9 do
1270 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1271 end;
1273 a := a + 1;
1274 end;
1276 config.Free();
1277 end;
1279 procedure g_Player_Free();
1280 var
1281 i: Integer;
1282 begin
1283 if gPlayers <> nil then
1284 begin
1285 for i := 0 to High(gPlayers) do
1286 if gPlayers[i] <> nil then
1287 begin
1288 if gPlayers[i] is TPlayer then
1289 TPlayer(gPlayers[i]).Free()
1290 else
1291 TBot(gPlayers[i]).Free();
1292 gPlayers[i] := nil;
1293 end;
1295 gPlayers := nil;
1296 end;
1298 gPlayer1 := nil;
1299 gPlayer2 := nil;
1300 end;
1302 procedure g_Player_UpdateAll();
1303 var
1304 i: Integer;
1305 begin
1306 if gPlayers = nil then Exit;
1308 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1309 for i := 0 to High(gPlayers) do
1310 begin
1311 if gPlayers[i] <> nil then
1312 begin
1313 if gPlayers[i] is TPlayer then
1314 begin
1315 gPlayers[i].Update();
1316 gPlayers[i].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1317 end
1318 else
1319 begin
1320 // bot updates weapons in `UpdateCombat()`
1321 TBot(gPlayers[i]).Update();
1322 end;
1323 end;
1324 end;
1325 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1326 end;
1328 procedure g_Player_DrawAll();
1329 var
1330 i: Integer;
1331 begin
1332 if gPlayers = nil then Exit;
1334 for i := 0 to High(gPlayers) do
1335 if gPlayers[i] <> nil then
1336 if gPlayers[i] is TPlayer then gPlayers[i].Draw()
1337 else TBot(gPlayers[i]).Draw();
1338 end;
1340 procedure g_Player_DrawDebug(p: TPlayer);
1341 var
1342 fW, fH: Byte;
1343 begin
1344 if p = nil then Exit;
1345 if (@p.FObj) = nil then Exit;
1347 e_TextureFontGetSize(gStdFont, fW, fH);
1349 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p.FObj.X), gStdFont);
1350 e_TextureFontPrint(0, fH , 'Pos Y: ' + IntToStr(p.FObj.Y), gStdFont);
1351 e_TextureFontPrint(0, fH * 2, 'Vel X: ' + IntToStr(p.FObj.Vel.X), gStdFont);
1352 e_TextureFontPrint(0, fH * 3, 'Vel Y: ' + IntToStr(p.FObj.Vel.Y), gStdFont);
1353 e_TextureFontPrint(0, fH * 4, 'Acc X: ' + IntToStr(p.FObj.Accel.X), gStdFont);
1354 e_TextureFontPrint(0, fH * 5, 'Acc Y: ' + IntToStr(p.FObj.Accel.Y), gStdFont);
1355 end;
1357 procedure g_Player_DrawHealth();
1358 var
1359 i: Integer;
1360 fW, fH: Byte;
1361 begin
1362 if gPlayers = nil then Exit;
1363 e_TextureFontGetSize(gStdFont, fW, fH);
1365 for i := 0 to High(gPlayers) do
1366 if gPlayers[i] <> nil then
1367 begin
1368 e_TextureFontPrint(gPlayers[i].FObj.X + gPlayers[i].FObj.Rect.X,
1369 gPlayers[i].FObj.Y + gPlayers[i].FObj.Rect.Y + gPlayers[i].FObj.Rect.Height - fH * 2,
1370 IntToStr(gPlayers[i].FHealth), gStdFont);
1371 e_TextureFontPrint(gPlayers[i].FObj.X + gPlayers[i].FObj.Rect.X,
1372 gPlayers[i].FObj.Y + gPlayers[i].FObj.Rect.Y + gPlayers[i].FObj.Rect.Height - fH,
1373 IntToStr(gPlayers[i].FArmor), gStdFont);
1374 end;
1375 end;
1377 function g_Player_Get(UID: Word): TPlayer;
1378 var
1379 a: Integer;
1380 begin
1381 Result := nil;
1383 if gPlayers = nil then
1384 Exit;
1386 for a := 0 to High(gPlayers) do
1387 if gPlayers[a] <> nil then
1388 if gPlayers[a].FUID = UID then
1389 begin
1390 Result := gPlayers[a];
1391 Exit;
1392 end;
1393 end;
1395 function g_Player_GetCount(): Byte;
1396 var
1397 a: Integer;
1398 begin
1399 Result := 0;
1401 if gPlayers = nil then
1402 Exit;
1404 for a := 0 to High(gPlayers) do
1405 if gPlayers[a] <> nil then
1406 Result := Result + 1;
1407 end;
1409 function g_Player_GetStats(): TPlayerStatArray;
1410 var
1411 a: Integer;
1412 begin
1413 Result := nil;
1415 if gPlayers = nil then Exit;
1417 for a := 0 to High(gPlayers) do
1418 if gPlayers[a] <> nil then
1419 begin
1420 SetLength(Result, Length(Result)+1);
1421 with Result[High(Result)] do
1422 begin
1423 Ping := gPlayers[a].FPing;
1424 Loss := gPlayers[a].FLoss;
1425 Name := gPlayers[a].FName;
1426 Team := gPlayers[a].FTeam;
1427 Frags := gPlayers[a].FFrags;
1428 Deaths := gPlayers[a].FDeath;
1429 Kills := gPlayers[a].FKills;
1430 Color := gPlayers[a].FModel.Color;
1431 Lives := gPlayers[a].FLives;
1432 Spectator := gPlayers[a].FSpectator;
1433 end;
1434 end;
1435 end;
1437 procedure g_Player_RememberAll;
1438 var
1439 i: Integer;
1440 begin
1441 for i := Low(gPlayers) to High(gPlayers) do
1442 if (gPlayers[i] <> nil) and gPlayers[i].Live then
1443 gPlayers[i].RememberState;
1444 end;
1446 procedure g_Player_ResetAll(Force, Silent: Boolean);
1447 var
1448 i: Integer;
1449 begin
1450 gTeamStat[TEAM_RED].Goals := 0;
1451 gTeamStat[TEAM_BLUE].Goals := 0;
1453 if gPlayers <> nil then
1454 for i := 0 to High(gPlayers) do
1455 if gPlayers[i] <> nil then
1456 begin
1457 gPlayers[i].Reset(Force);
1459 if gPlayers[i] is TPlayer then
1460 begin
1461 if (not gPlayers[i].FSpectator) or gPlayers[i].FWantsInGame then
1462 gPlayers[i].Respawn(Silent)
1463 else
1464 gPlayers[i].Spectate();
1465 end
1466 else
1467 TBot(gPlayers[i]).Respawn(Silent);
1468 end;
1469 end;
1471 procedure g_Player_CreateCorpse(Player: TPlayer);
1472 var
1473 find_id: DWORD;
1474 ok: Boolean;
1475 begin
1476 if Player.Live then
1477 Exit;
1478 if Player.FObj.Y >= gMapInfo.Height+128 then
1479 Exit;
1481 with Player do
1482 begin
1483 if (FHealth >= -50) or (gGibsCount = 0) then
1484 begin
1485 if (gCorpses = nil) or (Length(gCorpses) = 0) then
1486 Exit;
1488 ok := False;
1489 for find_id := 0 to High(gCorpses) do
1490 if gCorpses[find_id] = nil then
1491 begin
1492 ok := True;
1493 Break;
1494 end;
1496 if not ok then
1497 find_id := Random(Length(gCorpses));
1499 gCorpses[find_id] := TCorpse.Create(FObj.X, FObj.Y, FModel.Name, FHealth < -20);
1500 gCorpses[find_id].FColor := FModel.Color;
1501 gCorpses[find_id].FObj.Vel := FObj.Vel;
1502 gCorpses[find_id].FObj.Accel := FObj.Accel;
1503 end
1504 else
1505 g_Player_CreateGibs(FObj.X + PLAYER_RECT_CX,
1506 FObj.Y + PLAYER_RECT_CY,
1507 FModel.Name, FModel.Color);
1508 end;
1509 end;
1511 procedure g_Player_CreateShell(fX, fY, dX, dY: Integer; T: Byte);
1512 var
1513 SID: DWORD;
1514 begin
1515 if (gShells = nil) or (Length(gShells) = 0) then
1516 Exit;
1518 with gShells[CurrentShell] do
1519 begin
1520 SpriteID := 0;
1521 g_Obj_Init(@Obj);
1522 Obj.Rect.X := 0;
1523 Obj.Rect.Y := 0;
1524 if T = SHELL_BULLET then
1525 begin
1526 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID) then
1527 SpriteID := SID;
1528 CX := 2;
1529 CY := 1;
1530 Obj.Rect.Width := 4;
1531 Obj.Rect.Height := 2;
1532 end
1533 else
1534 begin
1535 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID) then
1536 SpriteID := SID;
1537 CX := 4;
1538 CY := 2;
1539 Obj.Rect.Width := 7;
1540 Obj.Rect.Height := 3;
1541 end;
1542 SType := T;
1543 Live := True;
1544 Obj.X := fX;
1545 Obj.Y := fY;
1546 g_Obj_Push(@Obj, dX + Random(4)-Random(4), dY-Random(4));
1547 positionChanged(); // this updates spatial accelerators
1548 RAngle := Random(360);
1549 Timeout := gTime + SHELL_TIMEOUT;
1551 if CurrentShell >= High(gShells) then
1552 CurrentShell := 0
1553 else
1554 Inc(CurrentShell);
1555 end;
1556 end;
1558 procedure g_Player_CreateGibs(fX, fY: Integer; ModelName: string; fColor: TRGB);
1559 var
1560 a: Integer;
1561 GibsArray: TGibsArray;
1562 begin
1563 if (gGibs = nil) or (Length(gGibs) = 0) then
1564 Exit;
1565 if not g_PlayerModel_GetGibs(ModelName, GibsArray) then
1566 Exit;
1568 for a := 0 to High(GibsArray) do
1569 with gGibs[CurrentGib] do
1570 begin
1571 Color := fColor;
1572 ID := GibsArray[a].ID;
1573 MaskID := GibsArray[a].MaskID;
1574 Live := True;
1575 g_Obj_Init(@Obj);
1576 Obj.Rect := GibsArray[a].Rect;
1577 Obj.X := fX-GibsArray[a].Rect.X-(GibsArray[a].Rect.Width div 2);
1578 Obj.Y := fY-GibsArray[a].Rect.Y-(GibsArray[a].Rect.Height div 2);
1579 g_Obj_PushA(@Obj, 25 + Random(10), Random(361));
1580 positionChanged(); // this updates spatial accelerators
1581 RAngle := Random(360);
1583 if gBloodCount > 0 then
1584 g_GFX_Blood(fX, fY, 16*gBloodCount+Random(5*gBloodCount), -16+Random(33), -16+Random(33),
1585 Random(48), Random(48), 150, 0, 0);
1587 if CurrentGib >= High(gGibs) then
1588 CurrentGib := 0
1589 else
1590 Inc(CurrentGib);
1591 end;
1592 end;
1594 procedure g_Player_UpdatePhysicalObjects();
1595 var
1596 i: Integer;
1597 vel: TPoint2i;
1598 mr: Word;
1600 procedure ShellSound_Bounce(X, Y: Integer; T: Byte);
1601 var
1602 k: Integer;
1603 begin
1604 k := 1 + Random(2);
1605 if T = SHELL_BULLET then
1606 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k), X, Y)
1607 else
1608 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k), X, Y);
1609 end;
1611 begin
1612 // Êóñêè ìÿñà:
1613 if gGibs <> nil then
1614 for i := 0 to High(gGibs) do
1615 if gGibs[i].Live then
1616 with gGibs[i] do
1617 begin
1618 vel := Obj.Vel;
1619 mr := g_Obj_Move(@Obj, True, False, True);
1620 positionChanged(); // this updates spatial accelerators
1622 if WordBool(mr and MOVE_FALLOUT) then
1623 begin
1624 Live := False;
1625 Continue;
1626 end;
1628 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1629 if WordBool(mr and MOVE_HITWALL) then
1630 Obj.Vel.X := -(vel.X div 2);
1631 if WordBool(mr and (MOVE_HITCEIL or MOVE_HITLAND)) then
1632 Obj.Vel.Y := -(vel.Y div 2);
1634 if (Obj.Vel.X >= 0) then
1635 begin // Clockwise
1636 RAngle := RAngle + Abs(Obj.Vel.X)*6 + Abs(Obj.Vel.Y);
1637 if RAngle >= 360 then
1638 RAngle := RAngle mod 360;
1639 end else begin // Counter-clockwise
1640 RAngle := RAngle - Abs(Obj.Vel.X)*6 - Abs(Obj.Vel.Y);
1641 if RAngle < 0 then
1642 RAngle := (360 - (Abs(RAngle) mod 360)) mod 360;
1643 end;
1645 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1646 if gTime mod (GAME_TICK*3) = 0 then
1647 Obj.Vel.X := z_dec(Obj.Vel.X, 1);
1648 end;
1650 // Òðóïû:
1651 if gCorpses <> nil then
1652 for i := 0 to High(gCorpses) do
1653 if gCorpses[i] <> nil then
1654 if gCorpses[i].State = CORPSE_STATE_REMOVEME then
1655 begin
1656 gCorpses[i].Free();
1657 gCorpses[i] := nil;
1658 end
1659 else
1660 gCorpses[i].Update();
1662 // Ãèëüçû:
1663 if gShells <> nil then
1664 for i := 0 to High(gShells) do
1665 if gShells[i].Live then
1666 with gShells[i] do
1667 begin
1668 vel := Obj.Vel;
1669 mr := g_Obj_Move(@Obj, True, False, True);
1670 positionChanged(); // this updates spatial accelerators
1672 if WordBool(mr and MOVE_FALLOUT) or (gShells[i].Timeout < gTime) then
1673 begin
1674 Live := False;
1675 Continue;
1676 end;
1678 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1679 if WordBool(mr and MOVE_HITWALL) then
1680 begin
1681 Obj.Vel.X := -(vel.X div 2);
1682 if not WordBool(mr and MOVE_INWATER) then
1683 ShellSound_Bounce(Obj.X, Obj.Y, SType);
1684 end;
1685 if WordBool(mr and (MOVE_HITCEIL or MOVE_HITLAND)) then
1686 begin
1687 Obj.Vel.Y := -(vel.Y div 2);
1688 if Obj.Vel.X <> 0 then Obj.Vel.X := Obj.Vel.X div 2;
1689 if (Obj.Vel.X = 0) and (Obj.Vel.Y = 0) then
1690 begin
1691 if RAngle mod 90 <> 0 then
1692 RAngle := (RAngle div 90) * 90;
1693 end
1694 else if not WordBool(mr and MOVE_INWATER) then
1695 ShellSound_Bounce(Obj.X, Obj.Y, SType);
1696 end;
1698 if (Obj.Vel.X >= 0) then
1699 begin // Clockwise
1700 RAngle := RAngle + Abs(Obj.Vel.X)*8 + Abs(Obj.Vel.Y);
1701 if RAngle >= 360 then
1702 RAngle := RAngle mod 360;
1703 end else begin // Counter-clockwise
1704 RAngle := RAngle - Abs(Obj.Vel.X)*8 - Abs(Obj.Vel.Y);
1705 if RAngle < 0 then
1706 RAngle := (360 - (Abs(RAngle) mod 360)) mod 360;
1707 end;
1708 end;
1709 end;
1711 procedure g_Player_DrawCorpses();
1712 var
1713 i: Integer;
1714 a: TPoint;
1715 begin
1716 if gGibs <> nil then
1717 for i := 0 to High(gGibs) do
1718 if gGibs[i].Live then
1719 with gGibs[i] do
1720 begin
1721 if not g_Obj_Collide(sX, sY, sWidth, sHeight, @Obj) then
1722 Continue;
1724 a.X := Obj.Rect.X+(Obj.Rect.Width div 2);
1725 a.y := Obj.Rect.Y+(Obj.Rect.Height div 2);
1727 e_DrawAdv(ID, Obj.X, Obj.Y, 0, True, False, RAngle, @a, M_NONE);
1729 e_Colors := Color;
1730 e_DrawAdv(MaskID, Obj.X, Obj.Y, 0, True, False, RAngle, @a, M_NONE);
1731 e_Colors.R := 255;
1732 e_Colors.G := 255;
1733 e_Colors.B := 255;
1734 end;
1736 if gCorpses <> nil then
1737 for i := 0 to High(gCorpses) do
1738 if gCorpses[i] <> nil then
1739 gCorpses[i].Draw();
1740 end;
1742 procedure g_Player_DrawShells();
1743 var
1744 i: Integer;
1745 a: TPoint;
1746 begin
1747 if gShells <> nil then
1748 for i := 0 to High(gShells) do
1749 if gShells[i].Live then
1750 with gShells[i] do
1751 begin
1752 if not g_Obj_Collide(sX, sY, sWidth, sHeight, @Obj) then
1753 Continue;
1755 a.X := CX;
1756 a.Y := CY;
1758 e_DrawAdv(SpriteID, Obj.X, Obj.Y, 0, True, False, RAngle, @a, M_NONE);
1759 end;
1760 end;
1762 procedure g_Player_RemoveAllCorpses();
1763 var
1764 i: Integer;
1765 begin
1766 gGibs := nil;
1767 gShells := nil;
1768 SetLength(gGibs, MaxGibs);
1769 SetLength(gShells, MaxGibs);
1770 CurrentGib := 0;
1771 CurrentShell := 0;
1773 if gCorpses <> nil then
1774 for i := 0 to High(gCorpses) do
1775 gCorpses[i].Free();
1777 gCorpses := nil;
1778 SetLength(gCorpses, MaxCorpses);
1779 end;
1781 procedure g_Player_Corpses_SaveState(var Mem: TBinMemoryWriter);
1782 var
1783 count, i: Integer;
1784 b: Boolean;
1785 begin
1786 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ:
1787 count := 0;
1788 if gCorpses <> nil then
1789 for i := 0 to High(gCorpses) do
1790 if gCorpses[i] <> nil then
1791 count := count + 1;
1793 Mem := TBinMemoryWriter.Create((count+1) * 128);
1795 // Êîëè÷åñòâî òðóïîâ:
1796 Mem.WriteInt(count);
1798 if count = 0 then
1799 Exit;
1801 // Ñîõðàíÿåì òðóïû:
1802 for i := 0 to High(gCorpses) do
1803 if gCorpses[i] <> nil then
1804 begin
1805 // Íàçâàíèå ìîäåëè:
1806 Mem.WriteString(gCorpses[i].FModelName);
1807 // Òèï ñìåðòè:
1808 b := gCorpses[i].Mess;
1809 Mem.WriteBoolean(b);
1810 // Ñîõðàíÿåì äàííûå òðóïà:
1811 gCorpses[i].SaveState(Mem);
1812 end;
1813 end;
1815 procedure g_Player_Corpses_LoadState(var Mem: TBinMemoryReader);
1816 var
1817 count, i: Integer;
1818 str: String;
1819 b: Boolean;
1820 begin
1821 if Mem = nil then
1822 Exit;
1824 g_Player_RemoveAllCorpses();
1826 // Êîëè÷åñòâî òðóïîâ:
1827 Mem.ReadInt(count);
1829 if count > Length(gCorpses) then
1830 begin
1831 raise EBinSizeError.Create('g_Player_Corpses_LoadState: Too Many Corpses');
1832 end;
1834 if count = 0 then
1835 Exit;
1837 // Çàãðóæàåì òðóïû:
1838 for i := 0 to count-1 do
1839 begin
1840 // Íàçâàíèå ìîäåëè:
1841 Mem.ReadString(str);
1842 // Òèï ñìåðòè:
1843 Mem.ReadBoolean(b);
1844 // Ñîçäàåì òðóï:
1845 gCorpses[i] := TCorpse.Create(0, 0, str, b);
1846 // Çàãðóæàåì äàííûå òðóïà:
1847 gCorpses[i].LoadState(Mem);
1848 end;
1849 end;
1851 { T P l a y e r : }
1853 function TPlayer.isValidViewPort (): Boolean; inline; begin result := (viewPortW > 0) and (viewPortH > 0); end;
1855 procedure TPlayer.BFGHit();
1856 begin
1857 g_Weapon_BFGHit(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
1858 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2));
1859 if g_Game_IsServer and g_Game_IsNet then
1860 MH_SEND_Effect(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
1861 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
1862 0, NET_GFX_BFGHIT);
1863 end;
1865 procedure TPlayer.ChangeModel(ModelName: string);
1866 var
1867 locModel: TPlayerModel;
1868 begin
1869 locModel := g_PlayerModel_Get(ModelName);
1870 if locModel = nil then Exit;
1872 FModel.Free();
1873 FModel := locModel;
1874 end;
1876 procedure TPlayer.SetModel(ModelName: string);
1877 var
1878 m: TPlayerModel;
1879 begin
1880 m := g_PlayerModel_Get(ModelName);
1881 if m = nil then
1882 begin
1883 g_SimpleError(Format(_lc[I_GAME_ERROR_MODEL_FALLBACK], [ModelName]));
1884 m := g_PlayerModel_Get('doomer');
1885 if m = nil then
1886 begin
1887 g_FatalError(Format(_lc[I_GAME_ERROR_MODEL], ['doomer']));
1888 Exit;
1889 end;
1890 end;
1892 if FModel <> nil then
1893 FModel.Free();
1895 FModel := m;
1897 if not (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
1898 FModel.Color := FColor
1899 else
1900 FModel.Color := TEAMCOLOR[FTeam];
1901 FModel.SetWeapon(FCurrWeap);
1902 FModel.SetFlag(FFlag);
1903 SetDirection(FDirection);
1904 end;
1906 procedure TPlayer.SetColor(Color: TRGB);
1907 begin
1908 FColor := Color;
1909 if not (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
1910 if FModel <> nil then FModel.Color := Color;
1911 end;
1913 procedure TPlayer.SwitchTeam;
1914 begin
1915 if g_Game_IsClient then
1916 Exit;
1917 if not (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then Exit;
1919 if gGameOn and FLive then
1920 Kill(K_SIMPLEKILL, FUID, HIT_SELF);
1922 if FTeam = TEAM_RED then
1923 begin
1924 ChangeTeam(TEAM_BLUE);
1925 g_Console_Add(Format(_lc[I_PLAYER_CHTEAM_BLUE], [FName]), True);
1926 if g_Game_IsNet then
1927 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM, TEAM_BLUE, FName);
1928 end
1929 else
1930 begin
1931 ChangeTeam(TEAM_RED);
1932 g_Console_Add(Format(_lc[I_PLAYER_CHTEAM_RED], [FName]), True);
1933 if g_Game_IsNet then
1934 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM, TEAM_RED, FName);
1935 end;
1936 FPreferredTeam := FTeam;
1937 end;
1939 procedure TPlayer.ChangeTeam(Team: Byte);
1940 var
1941 OldTeam: Byte;
1942 begin
1943 OldTeam := FTeam;
1944 FTeam := Team;
1945 case Team of
1946 TEAM_RED, TEAM_BLUE:
1947 FModel.Color := TEAMCOLOR[Team];
1948 else
1949 FModel.Color := FColor;
1950 end;
1951 if (FTeam <> OldTeam) and g_Game_IsNet and g_Game_IsServer then
1952 MH_SEND_PlayerStats(FUID);
1953 end;
1956 procedure TPlayer.CollideItem();
1957 var
1958 i: Integer;
1959 r: Boolean;
1960 begin
1961 if gItems = nil then Exit;
1962 if not FLive then Exit;
1964 for i := 0 to High(gItems) do
1965 with gItems[i] do
1966 begin
1967 if (ItemType <> ITEM_NONE) and Live then
1968 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
1969 PLAYER_RECT.Height, @Obj) then
1970 begin
1971 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
1973 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
1974 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
1975 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
1976 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
1977 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
1979 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
1980 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
1981 (gGameSettings.GameType = GT_SINGLE) and
1982 (g_Player_GetCount() > 1)) then
1983 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
1984 end;
1985 end;
1986 end;
1989 function TPlayer.CollideLevel(XInc, YInc: Integer): Boolean;
1990 begin
1991 Result := g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc,
1992 PLAYER_RECT.Width, PLAYER_RECT.Height, PANEL_WALL,
1993 False);
1994 end;
1996 constructor TPlayer.Create();
1997 begin
1998 viewPortX := 0;
1999 viewPortY := 0;
2000 viewPortW := 0;
2001 viewPortH := 0;
2003 FIamBot := False;
2004 FDummy := False;
2005 FSpawned := False;
2007 FSawSound := TPlayableSound.Create();
2008 FSawSoundIdle := TPlayableSound.Create();
2009 FSawSoundHit := TPlayableSound.Create();
2010 FSawSoundSelect := TPlayableSound.Create();
2011 FJetSoundFly := TPlayableSound.Create();
2012 FJetSoundOn := TPlayableSound.Create();
2013 FJetSoundOff := TPlayableSound.Create();
2015 FSawSound.SetByName('SOUND_WEAPON_FIRESAW');
2016 FSawSoundIdle.SetByName('SOUND_WEAPON_IDLESAW');
2017 FSawSoundHit.SetByName('SOUND_WEAPON_HITSAW');
2018 FSawSoundSelect.SetByName('SOUND_WEAPON_SELECTSAW');
2019 FJetSoundFly.SetByName('SOUND_PLAYER_JETFLY');
2020 FJetSoundOn.SetByName('SOUND_PLAYER_JETON');
2021 FJetSoundOff.SetByName('SOUND_PLAYER_JETOFF');
2023 FSpectatePlayer := -1;
2024 FClientID := -1;
2025 FPing := 0;
2026 FLoss := 0;
2027 FSavedState.WaitRecall := False;
2028 FShellTimer := -1;
2029 FFireTime := 0;
2030 FFirePainTime := 0;
2031 FFireAttacker := 0;
2033 FActualModelName := 'doomer';
2035 g_Obj_Init(@FObj);
2036 FObj.Rect := PLAYER_RECT;
2038 FBFGFireCounter := -1;
2039 FJustTeleported := False;
2040 FNetTime := 0;
2042 resetWeaponQueue();
2043 end;
2045 procedure TPlayer.positionChanged ();
2046 begin
2047 end;
2049 procedure TPlayer.Damage(value: Word; SpawnerUID: Word; vx, vy: Integer; t: Byte);
2050 var
2051 c: Word;
2052 begin
2053 if (not g_Game_IsClient) and (not FLive) then
2054 Exit;
2056 FLastHit := t;
2058 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2059 if ((t = HIT_TRAP) or (t = HIT_SELF)) and (not FGodMode) then
2060 begin
2061 if not g_Game_IsClient then
2062 begin
2063 FArmor := 0;
2064 if t = HIT_TRAP then
2065 begin
2066 // Ëîâóøêà óáèâàåò ñðàçó:
2067 FHealth := -100;
2068 Kill(K_EXTRAHARDKILL, SpawnerUID, t);
2069 end;
2070 if t = HIT_SELF then
2071 begin
2072 // Ñàìîóáèéñòâî:
2073 FHealth := 0;
2074 Kill(K_SIMPLEKILL, SpawnerUID, t);
2075 end;
2076 end;
2077 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2078 FMegaRulez[MR_SUIT] := 0;
2079 FMegaRulez[MR_INVUL] := 0;
2080 FMegaRulez[MR_INVIS] := 0;
2081 FBerserk := 0;
2082 end;
2084 // Íî îò îñòàëüíîãî ñïàñàåò:
2085 if FMegaRulez[MR_INVUL] >= gTime then
2086 Exit;
2088 // ×èò-êîä "ÃÎÐÅÖ":
2089 if FGodMode then
2090 Exit;
2092 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2093 if LongBool(gGameSettings.Options and GAME_OPTION_TEAMDAMAGE) or
2094 (SpawnerUID = FUID) or
2095 (not SameTeam(FUID, SpawnerUID)) then
2096 begin
2097 FLastSpawnerUID := SpawnerUID;
2099 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2100 if gBloodCount > 0 then
2101 begin
2102 c := Min(value, 200)*gBloodCount + Random(Min(value, 200) div 2);
2103 if value div 4 <= c then
2104 c := c - (value div 4)
2105 else
2106 c := 0;
2108 if (t = HIT_SOME) and (vx = 0) and (vy = 0) then
2109 MakeBloodSimple(c)
2110 else
2111 case t of
2112 HIT_TRAP, HIT_ACID, HIT_FLAME, HIT_SELF: MakeBloodSimple(c);
2113 HIT_BFG, HIT_ROCKET, HIT_SOME: MakeBloodVector(c, vx, vy);
2114 end;
2116 if t = HIT_WATER then
2117 g_GFX_Bubbles(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2),
2118 FObj.Y+PLAYER_RECT.Y-4, value div 2, 8, 4);
2119 end;
2121 // Áóôåð óðîíà:
2122 if FLive then
2123 Inc(FDamageBuffer, value);
2125 // Âñïûøêà áîëè:
2126 if gFlash <> 0 then
2127 FPain := FPain + value;
2128 end;
2130 if g_Game_IsServer and g_Game_IsNet then
2131 begin
2132 MH_SEND_PlayerDamage(FUID, t, SpawnerUID, value, vx, vy);
2133 MH_SEND_PlayerStats(FUID);
2134 MH_SEND_PlayerPos(False, FUID);
2135 end;
2136 end;
2138 function TPlayer.Heal(value: Word; Soft: Boolean): Boolean;
2139 begin
2140 Result := False;
2141 if g_Game_IsClient then
2142 Exit;
2143 if not FLive then
2144 Exit;
2146 if Soft and (FHealth < PLAYER_HP_SOFT) then
2147 begin
2148 IncMax(FHealth, value, PLAYER_HP_SOFT);
2149 Result := True;
2150 end;
2151 if (not Soft) and (FHealth < PLAYER_HP_LIMIT) then
2152 begin
2153 IncMax(FHealth, value, PLAYER_HP_LIMIT);
2154 Result := True;
2155 end;
2157 if Result and g_Game_IsServer and g_Game_IsNet then
2158 MH_SEND_PlayerStats(FUID);
2159 end;
2161 destructor TPlayer.Destroy();
2162 begin
2163 if (gPlayer1 <> nil) and (gPlayer1.FUID = FUID) then
2164 gPlayer1 := nil;
2165 if (gPlayer2 <> nil) and (gPlayer2.FUID = FUID) then
2166 gPlayer2 := nil;
2168 FSawSound.Free();
2169 FSawSoundIdle.Free();
2170 FSawSoundHit.Free();
2171 FJetSoundFly.Free();
2172 FJetSoundOn.Free();
2173 FJetSoundOff.Free();
2174 FModel.Free();
2176 inherited;
2177 end;
2179 procedure TPlayer.DrawBubble();
2180 var
2181 bubX, bubY: Integer;
2182 ID: LongWord;
2183 Rb, Gb, Bb,
2184 Rw, Gw, Bw: SmallInt;
2185 Dot: Byte;
2186 begin
2187 bubX := FObj.X+FObj.Rect.X + IfThen(FDirection = D_LEFT, -4, 18);
2188 bubY := FObj.Y+FObj.Rect.Y - 18;
2189 Rb := 64;
2190 Gb := 64;
2191 Bb := 64;
2192 Rw := 240;
2193 Gw := 240;
2194 Bw := 240;
2195 case gChatBubble of
2196 1: // simple textual non-bubble
2197 begin
2198 bubX := FObj.X+FObj.Rect.X - 11;
2199 bubY := FObj.Y+FObj.Rect.Y - 17;
2200 e_TextureFontPrint(bubX, bubY, '[...]', gStdFont);
2201 Exit;
2202 end;
2203 2: // advanced pixel-perfect bubble
2204 begin
2205 if FTeam = TEAM_RED then
2206 Rb := 255
2207 else
2208 if FTeam = TEAM_BLUE then
2209 Bb := 255;
2210 end;
2211 3: // colored bubble
2212 begin
2213 Rb := FModel.Color.R;
2214 Gb := FModel.Color.G;
2215 Bb := FModel.Color.B;
2216 Rw := Min(Rb * 2 + 64, 255);
2217 Gw := Min(Gb * 2 + 64, 255);
2218 Bw := Min(Bb * 2 + 64, 255);
2219 if (Abs(Rw - Rb) < 32)
2220 or (Abs(Gw - Gb) < 32)
2221 or (Abs(Bw - Bb) < 32) then
2222 begin
2223 Rb := Max(Rw div 2 - 16, 0);
2224 Gb := Max(Gw div 2 - 16, 0);
2225 Bb := Max(Bw div 2 - 16, 0);
2226 end;
2227 end;
2228 4: // custom textured bubble
2229 begin
2230 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID) then
2231 if FDirection = D_RIGHT then
2232 e_Draw(ID, bubX - 6, bubY - 7, 0, True, False)
2233 else
2234 e_Draw(ID, bubX - 6, bubY - 7, 0, True, False, M_HORIZONTAL);
2235 Exit;
2236 end;
2237 end;
2239 // Outer borders
2240 e_DrawQuad(bubX + 1, bubY , bubX + 18, bubY + 13, Rb, Gb, Bb);
2241 e_DrawQuad(bubX , bubY + 1, bubX + 19, bubY + 12, Rb, Gb, Bb);
2242 // Inner box
2243 e_DrawFillQuad(bubX + 1, bubY + 1, bubX + 18, bubY + 12, Rw, Gw, Bw, 0);
2245 // Tail
2246 Dot := IfThen(FDirection = D_LEFT, 14, 5);
2247 e_DrawLine(1, bubX + Dot, bubY + 14, bubX + Dot, bubY + 16, Rb, Gb, Bb);
2248 e_DrawLine(1, bubX + IfThen(FDirection = D_LEFT, Dot - 1, Dot + 1), bubY + 13, bubX + IfThen(FDirection = D_LEFT, Dot - 1, Dot + 1), bubY + 15, Rw, Gw, Bw);
2249 e_DrawLine(1, bubX + IfThen(FDirection = D_LEFT, Dot - 2, Dot + 2), bubY + 13, bubX + IfThen(FDirection = D_LEFT, Dot - 2, Dot + 2), bubY + 14, Rw, Gw, Bw);
2250 e_DrawLine(1, bubX + IfThen(FDirection = D_LEFT, Dot - 3, Dot + 3), bubY + 13, bubX + IfThen(FDirection = D_LEFT, Dot - 3, Dot + 3), bubY + 13, Rw, Gw, Bw);
2251 e_DrawLine(1, bubX + IfThen(FDirection = D_LEFT, Dot - 3, Dot + 3), bubY + 14, bubX + IfThen(FDirection = D_LEFT, Dot - 1, Dot + 1), bubY + 16, Rb, Gb, Bb);
2253 // Dots
2254 Dot := 6;
2255 e_DrawFillQuad(bubX + Dot, bubY + 8, bubX + Dot + 1, bubY + 9, Rb, Gb, Bb, 0);
2256 e_DrawFillQuad(bubX + Dot + 3, bubY + 8, bubX + Dot + 4, bubY + 9, Rb, Gb, Bb, 0);
2257 e_DrawFillQuad(bubX + Dot + 6, bubY + 8, bubX + Dot + 7, bubY + 9, Rb, Gb, Bb, 0);
2258 end;
2260 procedure TPlayer.Draw();
2261 var
2262 ID: DWORD;
2263 w, h: Word;
2264 dr: Boolean;
2265 begin
2266 if FLive then
2267 begin
2268 if (FMegaRulez[MR_INVUL] > gTime) and (gPlayerDrawn <> Self) then
2269 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID) then
2270 begin
2271 e_GetTextureSize(ID, @w, @h);
2272 if FDirection = D_LEFT then
2273 e_Draw(ID, FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2)-(w div 2)+4,
2274 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2)-(h div 2)-7, 0, True, False)
2275 else
2276 e_Draw(ID, FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2)-(w div 2)-2,
2277 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2)-(h div 2)-7, 0, True, False);
2278 end;
2280 if FMegaRulez[MR_INVIS] > gTime then
2281 begin
2282 if (gPlayerDrawn <> nil) and ((Self = gPlayerDrawn) or
2283 ((FTeam = gPlayerDrawn.Team) and (gGameSettings.GameMode <> GM_DM))) then
2284 begin
2285 if (FMegaRulez[MR_INVIS] - gTime) <= 2100 then
2286 dr := not Odd((FMegaRulez[MR_INVIS] - gTime) div 300)
2287 else
2288 dr := True;
2289 if dr then
2290 FModel.Draw(FObj.X, FObj.Y, 200)
2291 else
2292 FModel.Draw(FObj.X, FObj.Y);
2293 end
2294 else
2295 FModel.Draw(FObj.X, FObj.Y, 254);
2296 end
2297 else
2298 FModel.Draw(FObj.X, FObj.Y);
2299 end;
2301 if g_debug_Frames then
2302 begin
2303 e_DrawQuad(FObj.X+FObj.Rect.X,
2304 FObj.Y+FObj.Rect.Y,
2305 FObj.X+FObj.Rect.X+FObj.Rect.Width-1,
2306 FObj.Y+FObj.Rect.Y+FObj.Rect.Height-1,
2307 0, 255, 0);
2308 end;
2310 if (gChatBubble > 0) and (FKeys[KEY_CHAT].Pressed) and not FGhost then
2311 DrawBubble();
2312 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2313 if gAimLine and Live and
2314 ((Self = gPlayer1) or (Self = gPlayer2)) then
2315 DrawAim();
2316 end;
2319 var
2320 plrMouseX: Integer = -666;
2321 plrMouseY: Integer = -666;
2322 vpx, vpy: Integer;
2323 //vpw, vph: Integer;
2324 laserX0, laserY0, laserX1, laserY1: Integer;
2325 monMarkedUID: Integer = -1;
2327 function pmsCurMapX (): Integer; inline; begin result := plrMouseX+vpx; end;
2328 function pmsCurMapY (): Integer; inline; begin result := plrMouseY+vpy; end;
2330 procedure plrDebugMouse (msx, msy, but: Integer; bstate: Integer);
2332 function wallToggle (pan: TPanel; tag: Integer): Boolean;
2333 begin
2334 result := false; // don't stop
2335 if pan.Enabled then g_Map_DisableWall(pan.arrIdx) else g_Map_EnableWall(pan.arrIdx);
2336 end;
2338 function monsAtDump (mon: TMonster; tag: Integer): Boolean;
2339 begin
2340 result := false; // don't stop
2341 e_WriteLog(Format('monster #%d; UID=%d', [mon.arrIdx, mon.UID]), MSG_NOTIFY);
2342 monMarkedUID := mon.UID;
2343 //if pan.Enabled then g_Map_DisableWall(pan.arrIdx) else g_Map_EnableWall(pan.arrIdx);
2344 end;
2346 begin
2347 plrMouseX := msx;
2348 plrMouseY := msy;
2349 //e_WriteLog(Format('mouse: x=%d; y=%d; but=%d; bstate=%d', [msx, msy, but, bstate]), MSG_NOTIFY);
2350 if (gPlayer1 = nil) then exit;
2352 if (but = MouseLeft) then
2353 begin
2354 mapGrid.forEachAtPoint(pmsCurMapX, pmsCurMapY, wallToggle, (GridTagWall or GridTagDoor));
2355 exit;
2356 end;
2358 if (but = MouseRight) then
2359 begin
2360 monMarkedUID := -1;
2361 e_WriteLog('===========================', MSG_NOTIFY);
2362 monsGrid.forEachAtPoint(pmsCurMapX, pmsCurMapY, monsAtDump);
2363 e_WriteLog('---------------------------', MSG_NOTIFY);
2364 exit;
2365 end;
2366 end;
2369 procedure plrDebugDrawMouse ();
2371 function monsCollector (mon: TMonster; tag: Integer): Boolean;
2372 var
2373 ex, ey: Integer;
2374 mx, my, mw, mh: Integer;
2375 begin
2376 result := false;
2377 mon.getMapBox(mx, my, mw, mh);
2378 e_DrawQuad(mx, my, mx+mw-1, my+mh-1, 255, 255, 0, 96);
2379 if lineAABBIntersects(laserX0, laserY0, laserX1, laserY1, mx, my, mw, mh, ex, ey) then
2380 begin
2381 e_DrawPoint(8, ex, ey, 0, 255, 0);
2382 end;
2383 end;
2385 var
2386 mon: TMonster;
2387 mx, my, mw, mh: Integer;
2388 begin
2389 e_DrawPoint(4, plrMouseX, plrMouseY, 255, 0, 255);
2390 if (gPlayer1 = nil) then exit;
2392 //e_WriteLog(Format('(%d,%d)-(%d,%d)', [laserX0, laserY0, laserX1, laserY1]), MSG_NOTIFY);
2394 glPushMatrix();
2395 glTranslatef(-vpx, -vpy, 0);
2397 g_Mons_AlongLine(laserX0, laserY0, laserX1, laserY1, monsCollector, true);
2399 if (monMarkedUID <> -1) then
2400 begin
2401 mon := g_Monsters_ByUID(monMarkedUID);
2402 if (mon <> nil) then
2403 begin
2404 mon.getMapBox(mx, my, mw, mh);
2405 e_DrawQuad(mx, my, mx+mw-1, my+mh-1, 255, 0, 0, 30);
2406 end;
2407 end;
2409 //e_DrawPoint(16, laserX0, laserY0, 255, 255, 255);
2411 glPopMatrix();
2412 end;
2415 procedure TPlayer.DrawAim();
2416 procedure drawCast (sz: Integer; ax0, ay0, ax1, ay1: Integer);
2418 procedure drawTileGrid ();
2419 var
2420 x, y: Integer;
2421 begin
2422 y := mapGrid.gridY0;
2423 while (y < mapGrid.gridY0+mapGrid.gridHeight) do
2424 begin
2425 x := mapGrid.gridX0;
2426 while (x < mapGrid.gridX0+mapGrid.gridWidth) do
2427 begin
2428 if (x+mapGrid.tileSize > viewPortX) and (y+mapGrid.tileSize > viewPortY) and
2429 (x < viewPortX+viewPortW) and (y < viewPortY+viewPortH) then
2430 begin
2431 e_DrawQuad(x, y, x+mapGrid.tileSize-1, y+mapGrid.tileSize-1, 96, 96, 96, 96);
2432 end;
2433 Inc(x, mapGrid.tileSize);
2434 end;
2435 Inc(y, mapGrid.tileSize);
2436 end;
2437 end;
2439 var
2440 ex, ey: Integer;
2441 //mon: TMonster;
2442 //mx, my, mw, mh: Integer;
2443 begin
2444 if isValidViewPort and (self = gPlayer1) then
2445 begin
2446 vpx := viewPortX;
2447 vpy := viewPortY;
2448 //vpw := viewPortW;
2449 //vpy := viewPortH;
2450 evMouseCB := plrDebugMouse;
2451 postdrawMouse := plrDebugDrawMouse;
2452 end;
2454 laserX0 := ax0;
2455 laserY0 := ay0;
2456 laserX1 := ax1;
2457 laserY1 := ay1;
2459 e_DrawLine(sz, ax0, ay0, ax1, ay1, 255, 0, 0, 96);
2460 if (g_Map_traceToNearestWall(ax0, ay0, ax1, ay1, @ex, @ey) <> nil) then
2461 begin
2462 e_DrawLine(sz, ax0, ay0, ex, ey, 0, 255, 0, 96);
2463 end
2464 else
2465 begin
2466 e_DrawLine(sz, ax0, ay0, ex, ey, 0, 0, 255, 96);
2467 end;
2470 mon := g_Mons_ByIdx(0);
2471 mon.getMapBox(mx, my, mw, mh);
2472 ax1 := mx+mw div 2;
2473 ay1 := my+mh div 2;
2474 e_DrawLine(2, ax0, ay0, ax1, ay1, 0, 96, 96, 96);
2476 if lineAABBIntersects(ax0, ay0, ax1, ay1, mx, my, mw, mh, ex, ey) then
2477 begin
2478 e_DrawLine(2, ax0, ay0, ex, ey, 255, 255, 0, 96);
2479 end
2480 else
2481 begin
2482 e_DrawLine(2, ax0, ay0, ex, ey, 255, 127, 0, 96);
2483 end;
2486 drawTileGrid();
2487 end;
2489 var
2490 wx, wy, xx, yy: Integer;
2491 angle: SmallInt;
2492 sz, len: Word;
2493 begin
2494 wx := FObj.X + WEAPONPOINT[FDirection].X + IfThen(FDirection = D_LEFT, 7, -7);
2495 wy := FObj.Y + WEAPONPOINT[FDirection].Y;
2496 angle := FAngle;
2497 len := 1024;
2498 sz := 2;
2499 case FCurrWeap of
2500 0: begin // Punch
2501 len := 12;
2502 sz := 4;
2503 end;
2504 1: begin // Chainsaw
2505 len := 24;
2506 sz := 6;
2507 end;
2508 2: begin // Pistol
2509 len := 1024;
2510 sz := 2;
2511 if angle = ANGLE_RIGHTUP then Dec(angle, 2);
2512 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2513 if angle = ANGLE_LEFTUP then Inc(angle, 2);
2514 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2515 end;
2516 3: begin // Shotgun
2517 len := 1024;
2518 sz := 3;
2519 if angle = ANGLE_RIGHTUP then Dec(angle, 2);
2520 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2521 if angle = ANGLE_LEFTUP then Inc(angle, 2);
2522 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2523 end;
2524 4: begin // Double Shotgun
2525 len := 1024;
2526 sz := 4;
2527 if angle = ANGLE_RIGHTUP then Dec(angle, 2);
2528 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2529 if angle = ANGLE_LEFTUP then Inc(angle, 2);
2530 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2531 end;
2532 5: begin // Chaingun
2533 len := 1024;
2534 sz := 3;
2535 if angle = ANGLE_RIGHTUP then Dec(angle, 2);
2536 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2537 if angle = ANGLE_LEFTUP then Inc(angle, 2);
2538 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2539 end;
2540 6: begin // Rocket Launcher
2541 len := 1024;
2542 sz := 7;
2543 if angle = ANGLE_RIGHTUP then Inc(angle, 2);
2544 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2545 if angle = ANGLE_LEFTUP then Dec(angle, 2);
2546 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2547 end;
2548 7: begin // Plasmagun
2549 len := 1024;
2550 sz := 5;
2551 if angle = ANGLE_RIGHTUP then Inc(angle);
2552 if angle = ANGLE_RIGHTDOWN then Inc(angle, 3);
2553 if angle = ANGLE_LEFTUP then Dec(angle);
2554 if angle = ANGLE_LEFTDOWN then Dec(angle, 3);
2555 end;
2556 8: begin // BFG
2557 len := 1024;
2558 sz := 12;
2559 if angle = ANGLE_RIGHTUP then Inc(angle, 1);
2560 if angle = ANGLE_RIGHTDOWN then Inc(angle, 2);
2561 if angle = ANGLE_LEFTUP then Dec(angle, 1);
2562 if angle = ANGLE_LEFTDOWN then Dec(angle, 2);
2563 end;
2564 9: begin // Super Chaingun
2565 len := 1024;
2566 sz := 4;
2567 if angle = ANGLE_RIGHTUP then Dec(angle, 2);
2568 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2569 if angle = ANGLE_LEFTUP then Inc(angle, 2);
2570 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2571 end;
2572 end;
2573 xx := Trunc(Cos(-DegToRad(angle)) * len) + wx;
2574 yy := Trunc(Sin(-DegToRad(angle)) * len) + wy;
2575 {$IF DEFINED(D2F_DEBUG)}
2576 drawCast(sz, wx, wy, xx, yy);
2577 {$ELSE}
2578 e_DrawLine(sz, wx, wy, xx, yy, 255, 0, 0, 96);
2579 {$ENDIF}
2580 end;
2582 procedure TPlayer.DrawGUI();
2583 var
2584 ID: DWORD;
2585 X, Y, SY, a, p, m: Integer;
2586 tw, th: Word;
2587 cw, ch: Byte;
2588 s: string;
2589 stat: TPlayerStatArray;
2590 begin
2591 X := gPlayerScreenSize.X;
2592 SY := gPlayerScreenSize.Y;
2593 Y := 0;
2595 if gShowGoals and (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
2596 begin
2597 if gGameSettings.GameMode = GM_CTF then
2598 a := 32 + 8
2599 else
2600 a := 0;
2601 if gGameSettings.GameMode = GM_CTF then
2602 begin
2603 s := 'TEXTURE_PLAYER_REDFLAG';
2604 if gFlags[FLAG_RED].State = FLAG_STATE_CAPTURED then
2605 s := 'TEXTURE_PLAYER_REDFLAG_S';
2606 if gFlags[FLAG_RED].State = FLAG_STATE_DROPPED then
2607 s := 'TEXTURE_PLAYER_REDFLAG_D';
2608 if g_Texture_Get(s, ID) then
2609 e_Draw(ID, X-16-32, 240-72-4, 0, True, False);
2610 end;
2612 s := IntToStr(gTeamStat[TEAM_RED].Goals);
2613 e_CharFont_GetSize(gMenuFont, s, tw, th);
2614 e_CharFont_PrintEx(gMenuFont, X-16-a-tw, 240-72-4, s, TEAMCOLOR[TEAM_RED]);
2616 if gGameSettings.GameMode = GM_CTF then
2617 begin
2618 s := 'TEXTURE_PLAYER_BLUEFLAG';
2619 if gFlags[FLAG_BLUE].State = FLAG_STATE_CAPTURED then
2620 s := 'TEXTURE_PLAYER_BLUEFLAG_S';
2621 if gFlags[FLAG_BLUE].State = FLAG_STATE_DROPPED then
2622 s := 'TEXTURE_PLAYER_BLUEFLAG_D';
2623 if g_Texture_Get(s, ID) then
2624 e_Draw(ID, X-16-32, 240-32-4, 0, True, False);
2625 end;
2627 s := IntToStr(gTeamStat[TEAM_BLUE].Goals);
2628 e_CharFont_GetSize(gMenuFont, s, tw, th);
2629 e_CharFont_PrintEx(gMenuFont, X-16-a-tw, 240-32-4, s, TEAMCOLOR[TEAM_BLUE]);
2630 end;
2632 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID) then
2633 e_DrawFill(ID, X, 0, 1, (gPlayerScreenSize.Y div 256)+IfThen(gPlayerScreenSize.Y mod 256 > 0, 1, 0),
2634 0, False, False);
2636 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID) then
2637 e_Draw(ID, X+2, Y, 0, True, False);
2639 if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
2640 begin
2641 if gShowStat then
2642 begin
2643 s := IntToStr(Frags);
2644 e_CharFont_GetSize(gMenuFont, s, tw, th);
2645 e_CharFont_PrintEx(gMenuFont, X-16-tw, Y, s, _RGB(255, 0, 0));
2647 s := '';
2648 p := 1;
2649 m := 0;
2650 stat := g_Player_GetStats();
2651 if stat <> nil then
2652 begin
2653 p := 1;
2655 for a := 0 to High(stat) do
2656 if stat[a].Name <> Name then
2657 begin
2658 if stat[a].Frags > m then m := stat[a].Frags;
2659 if stat[a].Frags > Frags then p := p+1;
2660 end;
2661 end;
2663 s := IntToStr(p)+' / '+IntToStr(Length(stat))+' ';
2664 if Frags >= m then s := s+'+' else s := s+'-';
2665 s := s+IntToStr(Abs(Frags-m));
2667 e_CharFont_GetSize(gMenuSmallFont, s, tw, th);
2668 e_CharFont_PrintEx(gMenuSmallFont, X-16-tw, Y+32, s, _RGB(255, 0, 0));
2669 end;
2671 if gShowLives and (gGameSettings.MaxLives > 0) then
2672 begin
2673 s := IntToStr(Lives);
2674 e_CharFont_GetSize(gMenuFont, s, tw, th);
2675 e_CharFont_PrintEx(gMenuFont, X-16-tw, SY-32, s, _RGB(0, 255, 0));
2676 end;
2677 end;
2679 e_CharFont_GetSize(gMenuSmallFont, FName, tw, th);
2680 e_CharFont_PrintEx(gMenuSmallFont, X+98-(tw div 2), Y+8, FName, _RGB(255, 0, 0));
2682 if R_BERSERK in FRulez then
2683 e_Draw(gItemsTexturesID[ITEM_MEDKIT_BLACK], X+37, Y+45, 0, True, False)
2684 else
2685 e_Draw(gItemsTexturesID[ITEM_MEDKIT_LARGE], X+37, Y+45, 0, True, False);
2687 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID) then
2688 e_Draw(ID, X+36, Y+77, 0, True, False);
2690 s := IntToStr(IfThen(FHealth > 0, FHealth, 0));
2691 e_CharFont_GetSize(gMenuFont, s, tw, th);
2692 e_CharFont_PrintEx(gMenuFont, X+178-tw, Y+40, s, _RGB(255, 0, 0));
2694 s := IntToStr(FArmor);
2695 e_CharFont_GetSize(gMenuFont, s, tw, th);
2696 e_CharFont_PrintEx(gMenuFont, X+178-tw, Y+68, s, _RGB(255, 0, 0));
2698 s := IntToStr(GetAmmoByWeapon(FCurrWeap));
2700 case FCurrWeap of
2701 WEAPON_KASTET:
2702 begin
2703 s := '--';
2704 ID := gItemsTexturesID[ITEM_WEAPON_KASTET];
2705 end;
2706 WEAPON_SAW:
2707 begin
2708 s := '--';
2709 ID := gItemsTexturesID[ITEM_WEAPON_SAW];
2710 end;
2711 WEAPON_PISTOL: ID := gItemsTexturesID[ITEM_WEAPON_PISTOL];
2712 WEAPON_CHAINGUN: ID := gItemsTexturesID[ITEM_WEAPON_CHAINGUN];
2713 WEAPON_SHOTGUN1: ID := gItemsTexturesID[ITEM_WEAPON_SHOTGUN1];
2714 WEAPON_SHOTGUN2: ID := gItemsTexturesID[ITEM_WEAPON_SHOTGUN2];
2715 WEAPON_SUPERPULEMET: ID := gItemsTexturesID[ITEM_WEAPON_SUPERPULEMET];
2716 WEAPON_ROCKETLAUNCHER: ID := gItemsTexturesID[ITEM_WEAPON_ROCKETLAUNCHER];
2717 WEAPON_PLASMA: ID := gItemsTexturesID[ITEM_WEAPON_PLASMA];
2718 WEAPON_BFG: ID := gItemsTexturesID[ITEM_WEAPON_BFG];
2719 WEAPON_FLAMETHROWER: ID := gItemsTexturesID[ITEM_WEAPON_FLAMETHROWER];
2720 end;
2722 e_CharFont_GetSize(gMenuFont, s, tw, th);
2723 e_CharFont_PrintEx(gMenuFont, X+178-tw, Y+158, s, _RGB(255, 0, 0));
2724 e_Draw(ID, X+20, Y+160, 0, True, False);
2726 if R_KEY_RED in FRulez then
2727 e_Draw(gItemsTexturesID[ITEM_KEY_RED], X+78, Y+214, 0, True, False);
2729 if R_KEY_GREEN in FRulez then
2730 e_Draw(gItemsTexturesID[ITEM_KEY_GREEN], X+95, Y+214, 0, True, False);
2732 if R_KEY_BLUE in FRulez then
2733 e_Draw(gItemsTexturesID[ITEM_KEY_BLUE], X+112, Y+214, 0, True, False);
2735 if FJetFuel > 0 then
2736 begin
2737 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID) then
2738 e_Draw(ID, X+2, Y+116, 0, True, False);
2739 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID) then
2740 e_Draw(ID, X+2, Y+126, 0, True, False);
2741 e_DrawLine(4, X+16, Y+122, X+16+Trunc(168*IfThen(FAir > 0, FAir, 0)/AIR_MAX), Y+122, 0, 0, 196);
2742 e_DrawLine(4, X+16, Y+132, X+16+Trunc(168*FJetFuel/JET_MAX), Y+132, 208, 0, 0);
2743 end
2744 else
2745 begin
2746 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID) then
2747 e_Draw(ID, X+2, Y+124, 0, True, False);
2748 e_DrawLine(4, X+16, Y+130, X+16+Trunc(168*IfThen(FAir > 0, FAir, 0)/AIR_MAX), Y+130, 0, 0, 196);
2749 end;
2751 if gShowPing and g_Game_IsClient then
2752 begin
2753 s := _lc[I_GAME_PING_HUD] + IntToStr(NetPeer.lastRoundTripTime) + _lc[I_NET_SLIST_PING_MS];
2754 e_TextureFontPrint(X + 4, Y + 242, s, gStdFont);
2755 Y := Y + 16;
2756 end;
2758 if FSpectator then
2759 begin
2760 e_TextureFontPrint(X + 4, Y + 242, _lc[I_PLAYER_SPECT], gStdFont);
2761 e_TextureFontPrint(X + 4, Y + 258, _lc[I_PLAYER_SPECT2], gStdFont);
2762 e_TextureFontPrint(X + 4, Y + 274, _lc[I_PLAYER_SPECT1], gStdFont);
2763 if FNoRespawn then
2764 begin
2765 e_TextureFontGetSize(gStdFont, cw, ch);
2766 s := _lc[I_PLAYER_SPECT4];
2767 e_TextureFontPrintEx(gScreenWidth div 2 - cw*(Length(s) div 2),
2768 gScreenHeight-4-ch, s, gStdFont, 255, 255, 255, 1, True);
2769 e_TextureFontPrint(X + 4, Y + 290, _lc[I_PLAYER_SPECT1S], gStdFont);
2770 end;
2772 end;
2773 end;
2775 procedure TPlayer.DrawRulez();
2776 var
2777 dr: Boolean;
2778 begin
2779 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2780 if FMegaRulez[MR_INVUL] >= gTime then
2781 begin
2782 if (FMegaRulez[MR_INVUL]-gTime) <= 2100 then
2783 dr := not Odd((FMegaRulez[MR_INVUL]-gTime) div 300)
2784 else
2785 dr := True;
2787 if dr then
2788 e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1,
2789 191, 191, 191, 0, B_INVERT);
2790 end;
2792 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2793 if FMegaRulez[MR_SUIT] >= gTime then
2794 begin
2795 if (FMegaRulez[MR_SUIT]-gTime) <= 2100 then
2796 dr := not Odd((FMegaRulez[MR_SUIT]-gTime) div 300)
2797 else
2798 dr := True;
2800 if dr then
2801 e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1,
2802 0, 96, 0, 200, B_NONE);
2803 end;
2805 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2806 if (FBerserk >= 0) and (LongWord(FBerserk) >= gTime) and (gFlash = 2) then
2807 begin
2808 e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1,
2809 255, 0, 0, 200, B_NONE);
2810 end;
2811 end;
2813 procedure TPlayer.DrawPain();
2814 var
2815 a, h: Integer;
2816 begin
2817 if FPain = 0 then Exit;
2819 a := FPain;
2821 if a < 15 then h := 0
2822 else if a < 35 then h := 1
2823 else if a < 55 then h := 2
2824 else if a < 75 then h := 3
2825 else if a < 95 then h := 4
2826 else h := 5;
2828 //if a > 255 then a := 255;
2830 e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255, 0, 0, 255-h*50);
2831 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2832 end;
2834 procedure TPlayer.DrawPickup();
2835 var
2836 a, h: Integer;
2837 begin
2838 if FPickup = 0 then Exit;
2840 a := FPickup;
2842 if a < 15 then h := 1
2843 else if a < 35 then h := 2
2844 else if a < 55 then h := 3
2845 else if a < 75 then h := 4
2846 else h := 5;
2848 e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 150, 200, 150, 255-h*50);
2849 end;
2851 procedure TPlayer.Fire();
2852 var
2853 f, DidFire: Boolean;
2854 wx, wy, xd, yd: Integer;
2855 locobj: TObj;
2856 begin
2857 if g_Game_IsClient then Exit;
2858 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
2859 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
2861 if FSpectator then
2862 begin
2863 Respawn(False);
2864 Exit;
2865 end;
2867 if FReloading[FCurrWeap] <> 0 then Exit;
2869 DidFire := False;
2871 f := False;
2872 wx := FObj.X+WEAPONPOINT[FDirection].X;
2873 wy := FObj.Y+WEAPONPOINT[FDirection].Y;
2874 xd := wx+IfThen(FDirection = D_LEFT, -30, 30);
2875 yd := wy+firediry();
2877 case FCurrWeap of
2878 WEAPON_KASTET:
2879 begin
2880 if R_BERSERK in FRulez then
2881 begin
2882 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2883 locobj.X := FObj.X+FObj.Rect.X;
2884 locobj.Y := FObj.Y+FObj.Rect.Y;
2885 locobj.rect.X := 0;
2886 locobj.rect.Y := 0;
2887 locobj.rect.Width := 39;
2888 locobj.rect.Height := 52;
2889 locobj.Vel.X := (xd-wx) div 2;
2890 locobj.Vel.Y := (yd-wy) div 2;
2891 locobj.Accel.X := xd-wx;
2892 locobj.Accel.y := yd-wy;
2894 if g_Weapon_Hit(@locobj, 50, FUID, HIT_SOME) <> 0 then
2895 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj.X, FObj.Y)
2896 else
2897 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj.X, FObj.Y);
2899 if gFlash = 1 then
2900 if FPain < 50 then
2901 FPain := min(FPain + 25, 50);
2902 end else g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 3, FUID);
2904 DidFire := True;
2905 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
2906 end;
2908 WEAPON_SAW:
2909 begin
2910 if g_Weapon_chainsaw(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y,
2911 IfThen(gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF], 9, 3), FUID) <> 0 then
2912 begin
2913 FSawSoundSelect.Stop();
2914 FSawSound.Stop();
2915 FSawSoundHit.PlayAt(FObj.X, FObj.Y);
2916 end
2917 else if not FSawSoundHit.IsPlaying() then
2918 begin
2919 FSawSoundSelect.Stop();
2920 FSawSound.PlayAt(FObj.X, FObj.Y);
2921 end;
2923 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
2924 DidFire := True;
2925 f := True;
2926 end;
2928 WEAPON_PISTOL:
2929 if FAmmo[A_BULLETS] > 0 then
2930 begin
2931 g_Weapon_pistol(wx, wy, xd, yd, FUID);
2932 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
2933 Dec(FAmmo[A_BULLETS]);
2934 FFireAngle := FAngle;
2935 f := True;
2936 DidFire := True;
2937 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
2938 GameVelX, GameVelY-2, SHELL_BULLET);
2939 end;
2941 WEAPON_SHOTGUN1:
2942 if FAmmo[A_SHELLS] > 0 then
2943 begin
2944 g_Weapon_shotgun(wx, wy, xd, yd, FUID);
2945 if not gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx, wy);
2946 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
2947 Dec(FAmmo[A_SHELLS]);
2948 FFireAngle := FAngle;
2949 f := True;
2950 DidFire := True;
2951 FShellTimer := 10;
2952 FShellType := SHELL_SHELL;
2953 end;
2955 WEAPON_SHOTGUN2:
2956 if FAmmo[A_SHELLS] >= 2 then
2957 begin
2958 g_Weapon_dshotgun(wx, wy, xd, yd, FUID);
2959 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
2960 Dec(FAmmo[A_SHELLS], 2);
2961 FFireAngle := FAngle;
2962 f := True;
2963 DidFire := True;
2964 FShellTimer := 13;
2965 FShellType := SHELL_DBLSHELL;
2966 end;
2968 WEAPON_CHAINGUN:
2969 if FAmmo[A_BULLETS] > 0 then
2970 begin
2971 g_Weapon_mgun(wx, wy, xd, yd, FUID);
2972 if not gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx, wy);
2973 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
2974 Dec(FAmmo[A_BULLETS]);
2975 FFireAngle := FAngle;
2976 f := True;
2977 DidFire := True;
2978 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
2979 GameVelX, GameVelY-2, SHELL_BULLET);
2980 end;
2982 WEAPON_ROCKETLAUNCHER:
2983 if FAmmo[A_ROCKETS] > 0 then
2984 begin
2985 g_Weapon_rocket(wx, wy, xd, yd, FUID);
2986 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
2987 Dec(FAmmo[A_ROCKETS]);
2988 FFireAngle := FAngle;
2989 f := True;
2990 DidFire := True;
2991 end;
2993 WEAPON_PLASMA:
2994 if FAmmo[A_CELLS] > 0 then
2995 begin
2996 g_Weapon_plasma(wx, wy, xd, yd, FUID);
2997 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
2998 Dec(FAmmo[A_CELLS]);
2999 FFireAngle := FAngle;
3000 f := True;
3001 DidFire := True;
3002 end;
3004 WEAPON_BFG:
3005 if (FAmmo[A_CELLS] >= 40) and (FBFGFireCounter = -1) then
3006 begin
3007 FBFGFireCounter := 17;
3008 if not FNoReload then
3009 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj.X, FObj.Y);
3010 Dec(FAmmo[A_CELLS], 40);
3011 DidFire := True;
3012 end;
3014 WEAPON_SUPERPULEMET:
3015 if FAmmo[A_SHELLS] > 0 then
3016 begin
3017 g_Weapon_shotgun(wx, wy, xd, yd, FUID);
3018 if not gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx, wy);
3019 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3020 Dec(FAmmo[A_SHELLS]);
3021 FFireAngle := FAngle;
3022 f := True;
3023 DidFire := True;
3024 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
3025 GameVelX, GameVelY-2, SHELL_SHELL);
3026 end;
3028 WEAPON_FLAMETHROWER:
3029 if FAmmo[A_FUEL] > 0 then
3030 begin
3031 g_Weapon_flame(wx, wy, xd, yd, FUID);
3032 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
3033 Dec(FAmmo[A_FUEL]);
3034 FFireAngle := FAngle;
3035 f := True;
3036 DidFire := True;
3037 end;
3038 end;
3040 if g_Game_IsNet then
3041 begin
3042 if DidFire then
3043 begin
3044 if FCurrWeap <> WEAPON_BFG then
3045 MH_SEND_PlayerFire(FUID, FCurrWeap, wx, wy, xd, yd, LastShotID)
3046 else
3047 if not FNoReload then
3048 MH_SEND_Sound(FObj.X, FObj.Y, 'SOUND_WEAPON_STARTFIREBFG');
3049 end;
3051 MH_SEND_PlayerStats(FUID);
3052 end;
3054 if not f then Exit;
3056 if (FAngle = 0) or (FAngle = 180) then SetAction(A_ATTACK)
3057 else if (FAngle = ANGLE_LEFTDOWN) or (FAngle = ANGLE_RIGHTDOWN) then SetAction(A_ATTACKDOWN)
3058 else if (FAngle = ANGLE_LEFTUP) or (FAngle = ANGLE_RIGHTUP) then SetAction(A_ATTACKUP);
3059 end;
3061 function TPlayer.GetAmmoByWeapon(Weapon: Byte): Word;
3062 begin
3063 case Weapon of
3064 WEAPON_PISTOL, WEAPON_CHAINGUN: Result := FAmmo[A_BULLETS];
3065 WEAPON_SHOTGUN1, WEAPON_SHOTGUN2, WEAPON_SUPERPULEMET: Result := FAmmo[A_SHELLS];
3066 WEAPON_ROCKETLAUNCHER: Result := FAmmo[A_ROCKETS];
3067 WEAPON_PLASMA, WEAPON_BFG: Result := FAmmo[A_CELLS];
3068 WEAPON_FLAMETHROWER: Result := FAmmo[A_FUEL];
3069 else Result := 0;
3070 end;
3071 end;
3073 function TPlayer.HeadInLiquid(XInc, YInc: Integer): Boolean;
3074 begin
3075 Result := g_Map_CollidePanel(FObj.X+PLAYER_HEADRECT.X+XInc, FObj.Y+PLAYER_HEADRECT.Y+YInc,
3076 PLAYER_HEADRECT.Width, PLAYER_HEADRECT.Height,
3077 PANEL_WATER or PANEL_ACID1 or PANEL_ACID2, True);
3078 end;
3080 procedure TPlayer.JetpackOn;
3081 begin
3082 FJetSoundFly.Stop;
3083 FJetSoundOff.Stop;
3084 FJetSoundOn.SetPosition(0);
3085 FJetSoundOn.PlayAt(FObj.X, FObj.Y);
3086 FlySmoke(8);
3087 end;
3089 procedure TPlayer.JetpackOff;
3090 begin
3091 FJetSoundFly.Stop;
3092 FJetSoundOn.Stop;
3093 FJetSoundOff.SetPosition(0);
3094 FJetSoundOff.PlayAt(FObj.X, FObj.Y);
3095 end;
3097 procedure TPlayer.CatchFire(Attacker: Word);
3098 begin
3099 FFireTime := 100;
3100 FFireAttacker := Attacker;
3101 if g_Game_IsNet and g_Game_IsServer then
3102 MH_SEND_PlayerStats(FUID);
3103 end;
3105 procedure TPlayer.Jump();
3106 begin
3107 if gFly or FJetpack then
3108 begin
3109 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
3110 if FObj.Vel.Y > -VEL_FLY then
3111 FObj.Vel.Y := FObj.Vel.Y - 3;
3112 if FJetpack then
3113 begin
3114 if FJetFuel > 0 then
3115 Dec(FJetFuel);
3116 if (FJetFuel < 1) and g_Game_IsServer then
3117 begin
3118 FJetpack := False;
3119 JetpackOff;
3120 if g_Game_IsNet then
3121 MH_SEND_PlayerStats(FUID);
3122 end;
3123 end;
3124 Exit;
3125 end;
3127 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
3128 if FGhost then
3129 FCanJetpack := False;
3131 // Ïðûãàåì èëè âñïëûâàåì:
3132 if (CollideLevel(0, 1) or
3133 g_Map_CollidePanel(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y+36, PLAYER_RECT.Width,
3134 PLAYER_RECT.Height-33, PANEL_STEP, False)
3135 ) and (FObj.Accel.Y = 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
3136 begin
3137 FObj.Vel.Y := -VEL_JUMP;
3138 FCanJetpack := False;
3139 end
3140 else
3141 begin
3142 if BodyInLiquid(0, 0) then
3143 FObj.Vel.Y := -VEL_SW
3144 else if (FJetFuel > 0) and FCanJetpack and
3145 g_Game_IsServer and (not g_Obj_CollideLiquid(@FObj, 0, 0)) then
3146 begin
3147 FJetpack := True;
3148 JetpackOn;
3149 if g_Game_IsNet then
3150 MH_SEND_PlayerStats(FUID);
3151 end;
3152 end;
3153 end;
3155 procedure TPlayer.Kill(KillType: Byte; SpawnerUID: Word; t: Byte);
3156 var
3157 a, i, k, ab, ar: Byte;
3158 s: String;
3159 mon: TMonster;
3160 plr: TPlayer;
3161 srv, netsrv: Boolean;
3162 DoFrags: Boolean;
3163 OldLR: Byte;
3164 KP: TPlayer;
3165 it: PItem;
3167 procedure PushItem(t: Byte);
3168 var
3169 id: DWORD;
3170 begin
3171 id := g_Items_Create(FObj.X, FObj.Y, t, True, False);
3172 it := g_Items_ByIdx(id);
3173 if KillType = K_EXTRAHARDKILL then // -7..+7; -8..0
3174 begin
3175 g_Obj_Push(@it.Obj, (FObj.Vel.X div 2)-7+Random(15),
3176 (FObj.Vel.Y div 2)-Random(9));
3177 it.positionChanged(); // this updates spatial accelerators
3178 end
3179 else
3180 begin
3181 if KillType = K_HARDKILL then // -5..+5; -5..0
3182 begin
3183 g_Obj_Push(@it.Obj, (FObj.Vel.X div 2)-5+Random(11),
3184 (FObj.Vel.Y div 2)-Random(6));
3185 end
3186 else // -3..+3; -3..0
3187 begin
3188 g_Obj_Push(@it.Obj, (FObj.Vel.X div 2)-3+Random(7),
3189 (FObj.Vel.Y div 2)-Random(4));
3190 end;
3191 it.positionChanged(); // this updates spatial accelerators
3192 end;
3194 if g_Game_IsNet and g_Game_IsServer then
3195 MH_SEND_ItemSpawn(True, id);
3196 end;
3198 begin
3199 DoFrags := (gGameSettings.MaxLives = 0) or (gGameSettings.GameMode = GM_COOP);
3200 Srv := g_Game_IsServer;
3201 Netsrv := g_Game_IsServer and g_Game_IsNet;
3202 if Srv then FDeath := FDeath + 1;
3203 if FLive then
3204 begin
3205 if FGhost then
3206 FGhost := False;
3207 if not FPhysics then
3208 FPhysics := True;
3209 FLive := False;
3210 end;
3211 FShellTimer := -1;
3213 if (gGameSettings.MaxLives > 0) and Srv and (gLMSRespawn = LMS_RESPAWN_NONE) then
3214 begin
3215 if FLives > 0 then FLives := FLives - 1;
3216 if FLives = 0 then FNoRespawn := True;
3217 end;
3219 // Íîìåð òèïà ñìåðòè:
3220 a := 1;
3221 case KillType of
3222 K_SIMPLEKILL: a := 1;
3223 K_HARDKILL: a := 2;
3224 K_EXTRAHARDKILL: a := 3;
3225 K_FALLKILL: a := 4;
3226 end;
3228 // Çâóê ñìåðòè:
3229 if not FModel.PlaySound(MODELSOUND_DIE, a, FObj.X, FObj.Y) then
3230 for i := 1 to 3 do
3231 if FModel.PlaySound(MODELSOUND_DIE, i, FObj.X, FObj.Y) then
3232 Break;
3234 // Âðåìÿ ðåñïàóíà:
3235 if Srv then
3236 case KillType of
3237 K_SIMPLEKILL:
3238 FTime[T_RESPAWN] := gTime + TIME_RESPAWN1;
3239 K_HARDKILL:
3240 FTime[T_RESPAWN] := gTime + TIME_RESPAWN2;
3241 K_EXTRAHARDKILL, K_FALLKILL:
3242 FTime[T_RESPAWN] := gTime + TIME_RESPAWN3;
3243 end;
3245 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3246 case KillType of
3247 K_SIMPLEKILL:
3248 SetAction(A_DIE1);
3249 K_HARDKILL, K_EXTRAHARDKILL:
3250 SetAction(A_DIE2);
3251 end;
3253 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3254 if (KillType <> K_FALLKILL) and (Srv) then
3255 g_Monsters_killedp();
3257 if SpawnerUID = FUID then
3258 begin // Ñàìîóáèëñÿ
3259 if Srv and (DoFrags or (gGameSettings.GameMode = GM_TDM)) then
3260 begin
3261 Dec(FFrags);
3262 FLastFrag := 0;
3263 end;
3264 g_Console_Add(Format(_lc[I_PLAYER_KILL_SELF], [FName]), True);
3265 end
3266 else
3267 if g_GetUIDType(SpawnerUID) = UID_PLAYER then
3268 begin // Óáèò äðóãèì èãðîêîì
3269 KP := g_Player_Get(SpawnerUID);
3270 if (KP <> nil) and Srv then
3271 begin
3272 if (DoFrags or (gGameSettings.GameMode = GM_TDM)) then
3273 if SameTeam(FUID, SpawnerUID) then
3274 begin
3275 Dec(KP.FFrags);
3276 KP.FLastFrag := 0;
3277 end else
3278 begin
3279 Inc(KP.FFrags);
3280 KP.FragCombo();
3281 end;
3283 if (gGameSettings.GameMode = GM_TDM) and DoFrags then
3284 Inc(gTeamStat[KP.Team].Goals,
3285 IfThen(SameTeam(FUID, SpawnerUID), -1, 1));
3287 if netsrv then MH_SEND_PlayerStats(SpawnerUID);
3288 end;
3290 plr := g_Player_Get(SpawnerUID);
3291 if plr = nil then
3292 s := '?'
3293 else
3294 s := plr.FName;
3296 case KillType of
3297 K_HARDKILL:
3298 g_Console_Add(Format(_lc[I_PLAYER_KILL_EXTRAHARD_2],
3299 [FName, s]),
3300 gShowKillMsg);
3301 K_EXTRAHARDKILL:
3302 g_Console_Add(Format(_lc[I_PLAYER_KILL_EXTRAHARD_1],
3303 [FName, s]),
3304 gShowKillMsg);
3305 else
3306 g_Console_Add(Format(_lc[I_PLAYER_KILL],
3307 [FName, s]),
3308 gShowKillMsg);
3309 end;
3310 end
3311 else if g_GetUIDType(SpawnerUID) = UID_MONSTER then
3312 begin // Óáèò ìîíñòðîì
3313 mon := g_Monsters_ByUID(SpawnerUID);
3314 if mon = nil then
3315 s := '?'
3316 else
3317 s := g_Monsters_GetKilledBy(mon.MonsterType);
3319 case KillType of
3320 K_HARDKILL:
3321 g_Console_Add(Format(_lc[I_PLAYER_KILL_EXTRAHARD_2],
3322 [FName, s]),
3323 gShowKillMsg);
3324 K_EXTRAHARDKILL:
3325 g_Console_Add(Format(_lc[I_PLAYER_KILL_EXTRAHARD_1],
3326 [FName, s]),
3327 gShowKillMsg);
3328 else
3329 g_Console_Add(Format(_lc[I_PLAYER_KILL],
3330 [FName, s]),
3331 gShowKillMsg);
3332 end;
3333 end
3334 else // Îñîáûå òèïû ñìåðòè
3335 case t of
3336 HIT_DISCON: ;
3337 HIT_SELF: g_Console_Add(Format(_lc[I_PLAYER_KILL_SELF], [FName]), True);
3338 HIT_FALL: g_Console_Add(Format(_lc[I_PLAYER_KILL_FALL], [FName]), True);
3339 HIT_WATER: g_Console_Add(Format(_lc[I_PLAYER_KILL_WATER], [FName]), True);
3340 HIT_ACID: g_Console_Add(Format(_lc[I_PLAYER_KILL_ACID], [FName]), True);
3341 HIT_TRAP: g_Console_Add(Format(_lc[I_PLAYER_KILL_TRAP], [FName]), True);
3342 else g_Console_Add(Format(_lc[I_PLAYER_DIED], [FName]), True);
3343 end;
3345 if Srv then
3346 begin
3347 // Âûáðîñ îðóæèÿ:
3348 for a := WP_FIRST to WP_LAST do
3349 if FWeapon[a] then
3350 begin
3351 case a of
3352 WEAPON_SAW: i := ITEM_WEAPON_SAW;
3353 WEAPON_SHOTGUN1: i := ITEM_WEAPON_SHOTGUN1;
3354 WEAPON_SHOTGUN2: i := ITEM_WEAPON_SHOTGUN2;
3355 WEAPON_CHAINGUN: i := ITEM_WEAPON_CHAINGUN;
3356 WEAPON_ROCKETLAUNCHER: i := ITEM_WEAPON_ROCKETLAUNCHER;
3357 WEAPON_PLASMA: i := ITEM_WEAPON_PLASMA;
3358 WEAPON_BFG: i := ITEM_WEAPON_BFG;
3359 WEAPON_SUPERPULEMET: i := ITEM_WEAPON_SUPERPULEMET;
3360 WEAPON_FLAMETHROWER: i := ITEM_WEAPON_FLAMETHROWER;
3361 else i := 0;
3362 end;
3364 if i <> 0 then
3365 PushItem(i);
3366 end;
3368 // Âûáðîñ ðþêçàêà:
3369 if R_ITEM_BACKPACK in FRulez then
3370 PushItem(ITEM_AMMO_BACKPACK);
3372 // Âûáðîñ ðàêåòíîãî ðàíöà:
3373 if FJetFuel > 0 then
3374 PushItem(ITEM_JETPACK);
3376 // Âûáðîñ êëþ÷åé:
3377 if not (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF]) then
3378 begin
3379 if R_KEY_RED in FRulez then
3380 PushItem(ITEM_KEY_RED);
3382 if R_KEY_GREEN in FRulez then
3383 PushItem(ITEM_KEY_GREEN);
3385 if R_KEY_BLUE in FRulez then
3386 PushItem(ITEM_KEY_BLUE);
3387 end;
3389 // Âûáðîñ ôëàãà:
3390 DropFlag();
3391 end;
3393 g_Player_CreateCorpse(Self);
3395 if Srv and (gGameSettings.MaxLives > 0) and FNoRespawn and
3396 (gLMSRespawn = LMS_RESPAWN_NONE) then
3397 begin
3398 a := 0;
3399 k := 0;
3400 ar := 0;
3401 ab := 0;
3402 for i := Low(gPlayers) to High(gPlayers) do
3403 begin
3404 if gPlayers[i] = nil then continue;
3405 if (not gPlayers[i].FNoRespawn) and (not gPlayers[i].FSpectator) then
3406 begin
3407 Inc(a);
3408 if gPlayers[i].FTeam = TEAM_RED then Inc(ar)
3409 else if gPlayers[i].FTeam = TEAM_BLUE then Inc(ab);
3410 k := i;
3411 end;
3412 end;
3414 OldLR := gLMSRespawn;
3415 if (gGameSettings.GameMode = GM_COOP) then
3416 begin
3417 if (a = 0) then
3418 begin
3419 // everyone is dead, restart the map
3420 g_Game_Message(_lc[I_MESSAGE_LMS_LOSE], 144);
3421 if Netsrv then
3422 MH_SEND_GameEvent(NET_EV_LMS_LOSE);
3423 gLMSRespawn := LMS_RESPAWN_FINAL;
3424 gLMSRespawnTime := gTime + 5000;
3425 end
3426 else if (a = 1) then
3427 begin
3428 if (gPlayers[k] <> nil) and not (gPlayers[k] is TBot) then
3429 if (gPlayers[k] = gPlayer1) or
3430 (gPlayers[k] = gPlayer2) then
3431 g_Console_Add('*** ' + _lc[I_MESSAGE_LMS_SURVIVOR] + ' ***', True)
3432 else if Netsrv and (gPlayers[k].FClientID >= 0) then
3433 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR, 0, 'N', gPlayers[k].FClientID);
3434 end;
3435 end
3436 else if (gGameSettings.GameMode = GM_TDM) then
3437 begin
3438 if (ab = 0) and (ar <> 0) then
3439 begin
3440 // blu team ded
3441 g_Game_Message(Format(_lc[I_MESSAGE_TLMS_WIN], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 144);
3442 if Netsrv then
3443 MH_SEND_GameEvent(NET_EV_TLMS_WIN, TEAM_RED);
3444 Inc(gTeamStat[TEAM_RED].Goals);
3445 gLMSRespawn := LMS_RESPAWN_FINAL;
3446 gLMSRespawnTime := gTime + 5000;
3447 end
3448 else if (ar = 0) and (ab <> 0) then
3449 begin
3450 // red team ded
3451 g_Game_Message(Format(_lc[I_MESSAGE_TLMS_WIN], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 144);
3452 if Netsrv then
3453 MH_SEND_GameEvent(NET_EV_TLMS_WIN, TEAM_BLUE);
3454 Inc(gTeamStat[TEAM_BLUE].Goals);
3455 gLMSRespawn := LMS_RESPAWN_FINAL;
3456 gLMSRespawnTime := gTime + 5000;
3457 end
3458 else if (ar = 0) and (ab = 0) then
3459 begin
3460 // everyone ded
3461 g_Game_Message(_lc[I_GAME_WIN_DRAW], 144);
3462 if Netsrv then
3463 MH_SEND_GameEvent(NET_EV_LMS_DRAW, 0, FName);
3464 gLMSRespawn := LMS_RESPAWN_FINAL;
3465 gLMSRespawnTime := gTime + 5000;
3466 end;
3467 end
3468 else if (gGameSettings.GameMode = GM_DM) then
3469 begin
3470 if (a = 1) then
3471 begin
3472 if gPlayers[k] <> nil then
3473 with gPlayers[k] do
3474 begin
3475 // survivor is the winner
3476 g_Game_Message(Format(_lc[I_MESSAGE_LMS_WIN], [AnsiUpperCase(FName)]), 144);
3477 if Netsrv then
3478 MH_SEND_GameEvent(NET_EV_LMS_WIN, 0, FName);
3479 Inc(FFrags);
3480 end;
3481 gLMSRespawn := LMS_RESPAWN_FINAL;
3482 gLMSRespawnTime := gTime + 5000;
3483 end
3484 else if (a = 0) then
3485 begin
3486 // everyone is dead, restart the map
3487 g_Game_Message(_lc[I_GAME_WIN_DRAW], 144);
3488 if Netsrv then
3489 MH_SEND_GameEvent(NET_EV_LMS_DRAW, 0, FName);
3490 gLMSRespawn := LMS_RESPAWN_FINAL;
3491 gLMSRespawnTime := gTime + 5000;
3492 end;
3493 end;
3494 if srv and (OldLR = LMS_RESPAWN_NONE) and (gLMSRespawn > LMS_RESPAWN_NONE) then
3495 begin
3496 if NetMode = NET_SERVER then
3497 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, (gLMSRespawnTime - gTime) div 1000)
3498 else
3499 g_Console_Add(Format(_lc[I_MSG_WARMUP_START], [(gLMSRespawnTime - gTime) div 1000]), True);
3500 end;
3501 end;
3503 if Netsrv then
3504 begin
3505 MH_SEND_PlayerStats(FUID);
3506 MH_SEND_PlayerDeath(FUID, KillType, t, SpawnerUID);
3507 if gGameSettings.GameMode = GM_TDM then MH_SEND_GameStats;
3508 end;
3510 if srv and FNoRespawn then Spectate(True);
3511 FWantsInGame := True;
3512 end;
3514 function TPlayer.BodyInLiquid(XInc, YInc: Integer): Boolean;
3515 begin
3516 Result := g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc, PLAYER_RECT.Width,
3517 PLAYER_RECT.Height-20, PANEL_WATER or PANEL_ACID1 or PANEL_ACID2, False);
3518 end;
3520 function TPlayer.BodyInAcid(XInc, YInc: Integer): Boolean;
3521 begin
3522 Result := g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc, PLAYER_RECT.Width,
3523 PLAYER_RECT.Height-20, PANEL_ACID1 or PANEL_ACID2, False);
3524 end;
3526 procedure TPlayer.MakeBloodSimple(Count: Word);
3527 begin
3528 g_GFX_Blood(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)+8,
3529 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2),
3530 Count div 2, 3, -1, 16, (PLAYER_RECT.Height*2 div 3),
3531 150, 0, 0);
3532 g_GFX_Blood(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-8,
3533 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2),
3534 Count div 2, -3, -1, 16, (PLAYER_RECT.Height*2) div 3,
3535 150, 0, 0);
3536 end;
3538 procedure TPlayer.MakeBloodVector(Count: Word; VelX, VelY: Integer);
3539 begin
3540 g_GFX_Blood(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2),
3541 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2),
3542 Count, VelX, VelY, 16, (PLAYER_RECT.Height*2) div 3,
3543 150, 0, 0);
3544 end;
3546 procedure TPlayer.QueueWeaponSwitch(Weapon: Byte);
3547 begin
3548 if g_Game_IsClient then Exit;
3549 if Weapon > High(FWeapon) then Exit;
3550 FNextWeap := FNextWeap or (1 shl Weapon);
3551 end;
3553 procedure TPlayer.resetWeaponQueue ();
3554 begin
3555 FNextWeap := 0;
3556 FNextWeapDelay := 0;
3557 end;
3559 function TPlayer.hasAmmoForWeapon (weapon: Byte): Boolean;
3560 begin
3561 result := false;
3562 case weapon of
3563 WEAPON_KASTET, WEAPON_SAW: result := true;
3564 WEAPON_SHOTGUN1, WEAPON_SHOTGUN2: result := (FAmmo[A_SHELLS] > 0);
3565 WEAPON_PISTOL, WEAPON_CHAINGUN, WEAPON_SUPERPULEMET: result := (FAmmo[A_BULLETS] > 0);
3566 WEAPON_ROCKETLAUNCHER: result := (FAmmo[A_ROCKETS] > 0);
3567 WEAPON_PLASMA, WEAPON_BFG: result := (FAmmo[A_CELLS] > 0);
3568 WEAPON_FLAMETHROWER: result := (FAmmo[A_FUEL] > 0);
3569 else result := (weapon < length(FWeapon));
3570 end;
3571 end;
3573 // return 255 for "no switch"
3574 function TPlayer.getNextWeaponIndex (): Byte;
3575 var
3576 i: Word;
3577 wantThisWeapon: array[0..64] of Boolean;
3578 wwc: Integer = 0; //HACK!
3579 dir, cwi: Integer;
3580 begin
3581 result := 255; // default result: "no switch"
3582 // had weapon cycling on previous frame? remove that flag
3583 if (FNextWeap and $2000) <> 0 then
3584 begin
3585 FNextWeap := FNextWeap and $1FFF;
3586 FNextWeapDelay := 0;
3587 end;
3588 // cycling has priority
3589 if (FNextWeap and $C000) <> 0 then
3590 begin
3591 if (FNextWeap and $8000) <> 0 then
3592 dir := 1
3593 else
3594 dir := -1;
3595 FNextWeap := FNextWeap or $2000; // we need this
3596 if FNextWeapDelay > 0 then
3597 exit; // cooldown time
3598 cwi := FCurrWeap;
3599 for i := 0 to High(FWeapon) do
3600 begin
3601 cwi := (cwi+length(FWeapon)+dir) mod length(FWeapon);
3602 if FWeapon[cwi] then
3603 begin
3604 //e_WriteLog(Format(' SWITCH: cur=%d; new=%d', [FCurrWeap, cwi]), MSG_WARNING);
3605 result := Byte(cwi);
3606 FNextWeapDelay := 10;
3607 exit;
3608 end;
3609 end;
3610 resetWeaponQueue();
3611 exit;
3612 end;
3613 // no cycling
3614 for i := 0 to High(wantThisWeapon) do
3615 wantThisWeapon[i] := false;
3616 for i := 0 to High(FWeapon) do
3617 if (FNextWeap and (1 shl i)) <> 0 then
3618 begin
3619 wantThisWeapon[i] := true;
3620 Inc(wwc);
3621 end;
3622 // exclude currently selected weapon from the set
3623 wantThisWeapon[FCurrWeap] := false;
3624 // slow down alterations a little
3625 if wwc > 1 then
3626 begin
3627 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3628 // more than one weapon requested, assume "alteration" and check alteration delay
3629 if FNextWeapDelay > 0 then
3630 begin
3631 FNextWeap := 0;
3632 exit;
3633 end; // yeah
3634 end;
3635 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3636 // but clear all counters if no weapon should be switched
3637 if wwc < 1 then
3638 begin
3639 resetWeaponQueue();
3640 exit;
3641 end;
3642 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3643 // try weapons in descending order
3644 for i := High(FWeapon) downto 0 do
3645 begin
3646 if wantThisWeapon[i] and FWeapon[i] and ((wwc = 1) or hasAmmoForWeapon(i)) then
3647 begin
3648 // i found her!
3649 result := Byte(i);
3650 resetWeaponQueue();
3651 FNextWeapDelay := 10; // anyway, 'cause why not
3652 exit;
3653 end;
3654 end;
3655 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3656 resetWeaponQueue();
3657 end;
3659 procedure TPlayer.RealizeCurrentWeapon();
3660 function switchAllowed (): Boolean;
3661 var
3662 i: Byte;
3663 begin
3664 result := false;
3665 if FBFGFireCounter <> -1 then
3666 exit;
3667 if FTime[T_SWITCH] > gTime then
3668 exit;
3669 for i := WP_FIRST to WP_LAST do
3670 if FReloading[i] > 0 then
3671 exit;
3672 result := true;
3673 end;
3675 var
3676 nw: Byte;
3677 begin
3678 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3679 //FNextWeap := FNextWeap and $1FFF;
3680 if FNextWeapDelay > 0 then Dec(FNextWeapDelay); // "alteration delay"
3682 if not switchAllowed then
3683 begin
3684 //HACK for weapon cycling
3685 if (FNextWeap and $7000) <> 0 then FNextWeap := 0;
3686 exit;
3687 end;
3689 nw := getNextWeaponIndex();
3690 if nw = 255 then exit; // don't reset anything here
3691 if nw > High(FWeapon) then
3692 begin
3693 // don't forget to reset queue here!
3694 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
3695 resetWeaponQueue();
3696 exit;
3697 end;
3699 if FWeapon[nw] then
3700 begin
3701 FCurrWeap := nw;
3702 FTime[T_SWITCH] := gTime+156;
3703 if FCurrWeap = WEAPON_SAW then FSawSoundSelect.PlayAt(FObj.X, FObj.Y);
3704 FModel.SetWeapon(FCurrWeap);
3705 if g_Game_IsNet then MH_SEND_PlayerStats(FUID);
3706 end;
3707 end;
3709 procedure TPlayer.NextWeapon();
3710 begin
3711 if g_Game_IsClient then Exit;
3712 FNextWeap := $8000;
3713 end;
3715 procedure TPlayer.PrevWeapon();
3716 begin
3717 if g_Game_IsClient then Exit;
3718 FNextWeap := $4000;
3719 end;
3721 procedure TPlayer.SetWeapon(W: Byte);
3722 begin
3723 if FCurrWeap <> W then
3724 if W = WEAPON_SAW then
3725 FSawSoundSelect.PlayAt(FObj.X, FObj.Y);
3727 FCurrWeap := W;
3728 FModel.SetWeapon(CurrWeap);
3729 resetWeaponQueue();
3730 end;
3732 function TPlayer.PickItem(ItemType: Byte; arespawn: Boolean; var remove: Boolean): Boolean;
3733 var
3734 a: Boolean;
3735 begin
3736 Result := False;
3737 if g_Game_IsClient then Exit;
3739 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3740 a := LongBool(gGameSettings.Options and GAME_OPTION_WEAPONSTAY) and arespawn;
3741 remove := not a;
3743 case ItemType of
3744 ITEM_MEDKIT_SMALL:
3745 if FHealth < PLAYER_HP_SOFT then
3746 begin
3747 IncMax(FHealth, 10, PLAYER_HP_SOFT);
3748 Result := True;
3749 remove := True;
3750 FFireTime := 0;
3751 if gFlash = 2 then Inc(FPickup, 5);
3752 end;
3754 ITEM_MEDKIT_LARGE:
3755 if FHealth < PLAYER_HP_SOFT then
3756 begin
3757 IncMax(FHealth, 25, PLAYER_HP_SOFT);
3758 Result := True;
3759 remove := True;
3760 FFireTime := 0;
3761 if gFlash = 2 then Inc(FPickup, 5);
3762 end;
3764 ITEM_ARMOR_GREEN:
3765 if FArmor < PLAYER_AP_SOFT then
3766 begin
3767 FArmor := PLAYER_AP_SOFT;
3768 Result := True;
3769 remove := True;
3770 if gFlash = 2 then Inc(FPickup, 5);
3771 end;
3773 ITEM_ARMOR_BLUE:
3774 if FArmor < PLAYER_AP_LIMIT then
3775 begin
3776 FArmor := PLAYER_AP_LIMIT;
3777 Result := True;
3778 remove := True;
3779 if gFlash = 2 then Inc(FPickup, 5);
3780 end;
3782 ITEM_SPHERE_BLUE:
3783 if FHealth < PLAYER_HP_LIMIT then
3784 begin
3785 IncMax(FHealth, 100, PLAYER_HP_LIMIT);
3786 Result := True;
3787 remove := True;
3788 FFireTime := 0;
3789 if gFlash = 2 then Inc(FPickup, 5);
3790 end;
3792 ITEM_SPHERE_WHITE:
3793 if (FHealth < PLAYER_HP_LIMIT) or (FArmor < PLAYER_AP_LIMIT) then
3794 begin
3795 if FHealth < PLAYER_HP_LIMIT then
3796 FHealth := PLAYER_HP_LIMIT;
3797 if FArmor < PLAYER_AP_LIMIT then
3798 FArmor := PLAYER_AP_LIMIT;
3799 Result := True;
3800 remove := True;
3801 FFireTime := 0;
3802 if gFlash = 2 then Inc(FPickup, 5);
3803 end;
3805 ITEM_WEAPON_SAW:
3806 if (not FWeapon[WEAPON_SAW]) or ((not arespawn) and (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF])) then
3807 begin
3808 FWeapon[WEAPON_SAW] := True;
3809 Result := True;
3810 if gFlash = 2 then Inc(FPickup, 5);
3811 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
3812 end;
3814 ITEM_WEAPON_SHOTGUN1:
3815 if (FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS]) or not FWeapon[WEAPON_SHOTGUN1] then
3816 begin
3817 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
3818 if a and FWeapon[WEAPON_SHOTGUN1] then Exit;
3820 IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
3821 FWeapon[WEAPON_SHOTGUN1] := True;
3822 Result := True;
3823 if gFlash = 2 then Inc(FPickup, 5);
3824 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
3825 end;
3827 ITEM_WEAPON_SHOTGUN2:
3828 if (FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS]) or not FWeapon[WEAPON_SHOTGUN2] then
3829 begin
3830 if a and FWeapon[WEAPON_SHOTGUN2] then Exit;
3832 IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
3833 FWeapon[WEAPON_SHOTGUN2] := True;
3834 Result := True;
3835 if gFlash = 2 then Inc(FPickup, 5);
3836 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
3837 end;
3839 ITEM_WEAPON_CHAINGUN:
3840 if (FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS]) or not FWeapon[WEAPON_CHAINGUN] then
3841 begin
3842 if a and FWeapon[WEAPON_CHAINGUN] then Exit;
3844 IncMax(FAmmo[A_BULLETS], 50, FMaxAmmo[A_BULLETS]);
3845 FWeapon[WEAPON_CHAINGUN] := True;
3846 Result := True;
3847 if gFlash = 2 then Inc(FPickup, 5);
3848 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
3849 end;
3851 ITEM_WEAPON_ROCKETLAUNCHER:
3852 if (FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS]) or not FWeapon[WEAPON_ROCKETLAUNCHER] then
3853 begin
3854 if a and FWeapon[WEAPON_ROCKETLAUNCHER] then Exit;
3856 IncMax(FAmmo[A_ROCKETS], 2, FMaxAmmo[A_ROCKETS]);
3857 FWeapon[WEAPON_ROCKETLAUNCHER] := True;
3858 Result := True;
3859 if gFlash = 2 then Inc(FPickup, 5);
3860 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
3861 end;
3863 ITEM_WEAPON_PLASMA:
3864 if (FAmmo[A_CELLS] < FMaxAmmo[A_CELLS]) or not FWeapon[WEAPON_PLASMA] then
3865 begin
3866 if a and FWeapon[WEAPON_PLASMA] then Exit;
3868 IncMax(FAmmo[A_CELLS], 40, FMaxAmmo[A_CELLS]);
3869 FWeapon[WEAPON_PLASMA] := True;
3870 Result := True;
3871 if gFlash = 2 then Inc(FPickup, 5);
3872 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
3873 end;
3875 ITEM_WEAPON_BFG:
3876 if (FAmmo[A_CELLS] < FMaxAmmo[A_CELLS]) or not FWeapon[WEAPON_BFG] then
3877 begin
3878 if a and FWeapon[WEAPON_BFG] then Exit;
3880 IncMax(FAmmo[A_CELLS], 40, FMaxAmmo[A_CELLS]);
3881 FWeapon[WEAPON_BFG] := True;
3882 Result := True;
3883 if gFlash = 2 then Inc(FPickup, 5);
3884 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
3885 end;
3887 ITEM_WEAPON_SUPERPULEMET:
3888 if (FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS]) or not FWeapon[WEAPON_SUPERPULEMET] then
3889 begin
3890 if a and FWeapon[WEAPON_SUPERPULEMET] then Exit;
3892 IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
3893 FWeapon[WEAPON_SUPERPULEMET] := True;
3894 Result := True;
3895 if gFlash = 2 then Inc(FPickup, 5);
3896 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
3897 end;
3899 ITEM_WEAPON_FLAMETHROWER:
3900 if (FAmmo[A_FUEL] < FMaxAmmo[A_FUEL]) or not FWeapon[WEAPON_FLAMETHROWER] then
3901 begin
3902 if a and FWeapon[WEAPON_FLAMETHROWER] then Exit;
3904 IncMax(FAmmo[A_FUEL], 100, FMaxAmmo[A_FUEL]);
3905 FWeapon[WEAPON_FLAMETHROWER] := True;
3906 Result := True;
3907 if gFlash = 2 then Inc(FPickup, 5);
3908 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
3909 end;
3911 ITEM_AMMO_BULLETS:
3912 if FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS] then
3913 begin
3914 IncMax(FAmmo[A_BULLETS], 10, FMaxAmmo[A_BULLETS]);
3915 Result := True;
3916 remove := True;
3917 if gFlash = 2 then Inc(FPickup, 5);
3918 end;
3920 ITEM_AMMO_BULLETS_BOX:
3921 if FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS] then
3922 begin
3923 IncMax(FAmmo[A_BULLETS], 50, FMaxAmmo[A_BULLETS]);
3924 Result := True;
3925 remove := True;
3926 if gFlash = 2 then Inc(FPickup, 5);
3927 end;
3929 ITEM_AMMO_SHELLS:
3930 if FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS] then
3931 begin
3932 IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
3933 Result := True;
3934 remove := True;
3935 if gFlash = 2 then Inc(FPickup, 5);
3936 end;
3938 ITEM_AMMO_SHELLS_BOX:
3939 if FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS] then
3940 begin
3941 IncMax(FAmmo[A_SHELLS], 25, FMaxAmmo[A_SHELLS]);
3942 Result := True;
3943 remove := True;
3944 if gFlash = 2 then Inc(FPickup, 5);
3945 end;
3947 ITEM_AMMO_ROCKET:
3948 if FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS] then
3949 begin
3950 IncMax(FAmmo[A_ROCKETS], 1, FMaxAmmo[A_ROCKETS]);
3951 Result := True;
3952 remove := True;
3953 if gFlash = 2 then Inc(FPickup, 5);
3954 end;
3956 ITEM_AMMO_ROCKET_BOX:
3957 if FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS] then
3958 begin
3959 IncMax(FAmmo[A_ROCKETS], 5, FMaxAmmo[A_ROCKETS]);
3960 Result := True;
3961 remove := True;
3962 if gFlash = 2 then Inc(FPickup, 5);
3963 end;
3965 ITEM_AMMO_CELL:
3966 if FAmmo[A_CELLS] < FMaxAmmo[A_CELLS] then
3967 begin
3968 IncMax(FAmmo[A_CELLS], 40, FMaxAmmo[A_CELLS]);
3969 Result := True;
3970 remove := True;
3971 if gFlash = 2 then Inc(FPickup, 5);
3972 end;
3974 ITEM_AMMO_CELL_BIG:
3975 if FAmmo[A_CELLS] < FMaxAmmo[A_CELLS] then
3976 begin
3977 IncMax(FAmmo[A_CELLS], 100, FMaxAmmo[A_CELLS]);
3978 Result := True;
3979 remove := True;
3980 if gFlash = 2 then Inc(FPickup, 5);
3981 end;
3983 ITEM_AMMO_FUELCAN:
3984 if FAmmo[A_FUEL] < FMaxAmmo[A_FUEL] then
3985 begin
3986 IncMax(FAmmo[A_FUEL], 100, FMaxAmmo[A_FUEL]);
3987 Result := True;
3988 remove := True;
3989 if gFlash = 2 then Inc(FPickup, 5);
3990 end;
3992 ITEM_AMMO_BACKPACK:
3993 if not(R_ITEM_BACKPACK in FRulez) or
3994 (FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS]) or
3995 (FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS]) or
3996 (FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS]) or
3997 (FAmmo[A_CELLS] < FMaxAmmo[A_CELLS]) or
3998 (FMaxAmmo[A_FUEL] < AmmoLimits[1, A_FUEL]) then
3999 begin
4000 FMaxAmmo[A_BULLETS] := AmmoLimits[1, A_BULLETS];
4001 FMaxAmmo[A_SHELLS] := AmmoLimits[1, A_SHELLS];
4002 FMaxAmmo[A_ROCKETS] := AmmoLimits[1, A_ROCKETS];
4003 FMaxAmmo[A_CELLS] := AmmoLimits[1, A_CELLS];
4004 FMaxAmmo[A_FUEL] := AmmoLimits[1, A_FUEL];
4006 if FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS] then
4007 IncMax(FAmmo[A_BULLETS], 10, FMaxAmmo[A_BULLETS]);
4008 if FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS] then
4009 IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
4010 if FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS] then
4011 IncMax(FAmmo[A_ROCKETS], 1, FMaxAmmo[A_ROCKETS]);
4012 if FAmmo[A_CELLS] < FMaxAmmo[A_CELLS] then
4013 IncMax(FAmmo[A_CELLS], 40, FMaxAmmo[A_CELLS]);
4015 FRulez := FRulez + [R_ITEM_BACKPACK];
4016 Result := True;
4017 remove := True;
4018 if gFlash = 2 then Inc(FPickup, 5);
4019 end;
4021 ITEM_KEY_RED:
4022 if not(R_KEY_RED in FRulez) then
4023 begin
4024 Include(FRulez, R_KEY_RED);
4025 Result := True;
4026 remove := (gGameSettings.GameMode <> GM_COOP) and (g_Player_GetCount() < 2);
4027 if gFlash = 2 then Inc(FPickup, 5);
4028 if (not remove) and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETITEM');
4029 end;
4031 ITEM_KEY_GREEN:
4032 if not(R_KEY_GREEN in FRulez) then
4033 begin
4034 Include(FRulez, R_KEY_GREEN);
4035 Result := True;
4036 remove := (gGameSettings.GameMode <> GM_COOP) and (g_Player_GetCount() < 2);
4037 if gFlash = 2 then Inc(FPickup, 5);
4038 if (not remove) and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETITEM');
4039 end;
4041 ITEM_KEY_BLUE:
4042 if not(R_KEY_BLUE in FRulez) then
4043 begin
4044 Include(FRulez, R_KEY_BLUE);
4045 Result := True;
4046 remove := (gGameSettings.GameMode <> GM_COOP) and (g_Player_GetCount() < 2);
4047 if gFlash = 2 then Inc(FPickup, 5);
4048 if (not remove) and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETITEM');
4049 end;
4051 ITEM_SUIT:
4052 if FMegaRulez[MR_SUIT] < gTime+PLAYER_SUIT_TIME then
4053 begin
4054 FMegaRulez[MR_SUIT] := gTime+PLAYER_SUIT_TIME;
4055 Result := True;
4056 remove := True;
4057 FFireTime := 0;
4058 if gFlash = 2 then Inc(FPickup, 5);
4059 end;
4061 ITEM_OXYGEN:
4062 if FAir < AIR_MAX then
4063 begin
4064 FAir := AIR_MAX;
4065 Result := True;
4066 remove := True;
4067 if gFlash = 2 then Inc(FPickup, 5);
4068 end;
4070 ITEM_MEDKIT_BLACK:
4071 begin
4072 if not (R_BERSERK in FRulez) then
4073 begin
4074 Include(FRulez, R_BERSERK);
4075 if FBFGFireCounter = -1 then
4076 begin
4077 FCurrWeap := WEAPON_KASTET;
4078 resetWeaponQueue();
4079 FModel.SetWeapon(WEAPON_KASTET);
4080 end;
4081 if gFlash <> 0 then
4082 Inc(FPain, 100);
4083 if gFlash = 2 then Inc(FPickup, 5);
4084 FBerserk := gTime+30000;
4085 Result := True;
4086 remove := True;
4087 FFireTime := 0;
4088 end;
4089 if FHealth < PLAYER_HP_SOFT then
4090 begin
4091 FHealth := PLAYER_HP_SOFT;
4092 FBerserk := gTime+30000;
4093 Result := True;
4094 remove := True;
4095 FFireTime := 0;
4096 end;
4097 end;
4099 ITEM_INVUL:
4100 if FMegaRulez[MR_INVUL] < gTime+PLAYER_INVUL_TIME then
4101 begin
4102 FMegaRulez[MR_INVUL] := gTime+PLAYER_INVUL_TIME;
4103 Result := True;
4104 remove := True;
4105 if gFlash = 2 then Inc(FPickup, 5);
4106 end;
4108 ITEM_BOTTLE:
4109 if FHealth < PLAYER_HP_LIMIT then
4110 begin
4111 IncMax(FHealth, 4, PLAYER_HP_LIMIT);
4112 Result := True;
4113 remove := True;
4114 FFireTime := 0;
4115 if gFlash = 2 then Inc(FPickup, 5);
4116 end;
4118 ITEM_HELMET:
4119 if FArmor < PLAYER_AP_LIMIT then
4120 begin
4121 IncMax(FArmor, 5, PLAYER_AP_LIMIT);
4122 Result := True;
4123 remove := True;
4124 if gFlash = 2 then Inc(FPickup, 5);
4125 end;
4127 ITEM_JETPACK:
4128 if FJetFuel < JET_MAX then
4129 begin
4130 FJetFuel := JET_MAX;
4131 Result := True;
4132 remove := True;
4133 if gFlash = 2 then Inc(FPickup, 5);
4134 end;
4136 ITEM_INVIS:
4137 if FMegaRulez[MR_INVIS] < gTime+PLAYER_INVIS_TIME then
4138 begin
4139 FMegaRulez[MR_INVIS] := gTime+PLAYER_INVIS_TIME;
4140 Result := True;
4141 remove := True;
4142 if gFlash = 2 then Inc(FPickup, 5);
4143 end;
4144 end;
4145 end;
4147 procedure TPlayer.Touch();
4148 begin
4149 if not FLive then
4150 Exit;
4151 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4152 if FIamBot then
4153 begin
4154 // Áðîñèòü ôëàã òîâàðèùó:
4155 if gGameSettings.GameMode = GM_CTF then
4156 DropFlag();
4157 end;
4158 end;
4160 procedure TPlayer.Push(vx, vy: Integer);
4161 begin
4162 if (not FPhysics) and FGhost then
4163 Exit;
4164 FObj.Accel.X := FObj.Accel.X + vx;
4165 FObj.Accel.Y := FObj.Accel.Y + vy;
4166 if g_Game_IsNet and g_Game_IsServer then
4167 MH_SEND_PlayerPos(True, FUID, NET_EVERYONE);
4168 end;
4170 procedure TPlayer.Reset(Force: Boolean);
4171 begin
4172 if Force then
4173 FLive := False;
4175 FSpawned := False;
4176 FTime[T_RESPAWN] := 0;
4177 FTime[T_FLAGCAP] := 0;
4178 FGodMode := False;
4179 FNoTarget := False;
4180 FNoReload := False;
4181 FFrags := 0;
4182 FLastFrag := 0;
4183 FComboEvnt := -1;
4184 FKills := 0;
4185 FMonsterKills := 0;
4186 FDeath := 0;
4187 FSecrets := 0;
4188 if FNoRespawn then
4189 begin
4190 FSpectator := False;
4191 FGhost := False;
4192 FPhysics := True;
4193 FSpectatePlayer := -1;
4194 FNoRespawn := False;
4195 end;
4196 FLives := gGameSettings.MaxLives;
4198 SetFlag(FLAG_NONE);
4199 end;
4201 procedure TPlayer.SoftReset();
4202 begin
4203 ReleaseKeys();
4205 FDamageBuffer := 0;
4206 FIncCam := 0;
4207 FBFGFireCounter := -1;
4208 FShellTimer := -1;
4209 FPain := 0;
4210 FLastHit := 0;
4211 FLastFrag := 0;
4212 FComboEvnt := -1;
4214 SetFlag(FLAG_NONE);
4215 SetAction(A_STAND, True);
4216 end;
4218 function TPlayer.GetRespawnPoint(): Byte;
4219 var
4220 c: Byte;
4221 begin
4222 Result := 255;
4223 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4225 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4226 if gGameSettings.GameMode in [GM_COOP, GM_SINGLE] then
4227 begin
4228 if (Self = gPlayer1) or (Self = gPlayer2) then
4229 begin
4230 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
4231 if Self = gPlayer1 then
4232 c := RESPAWNPOINT_PLAYER1
4233 else
4234 c := RESPAWNPOINT_PLAYER2;
4235 if g_Map_GetPointCount(c) > 0 then
4236 begin
4237 Result := c;
4238 Exit;
4239 end;
4241 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
4242 if Self = gPlayer1 then
4243 c := RESPAWNPOINT_PLAYER2
4244 else
4245 c := RESPAWNPOINT_PLAYER1;
4246 if g_Map_GetPointCount(c) > 0 then
4247 begin
4248 Result := c;
4249 Exit;
4250 end;
4251 end else
4252 begin
4253 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
4254 if Random(2) = 0 then
4255 c := RESPAWNPOINT_PLAYER1
4256 else
4257 c := RESPAWNPOINT_PLAYER2;
4258 if g_Map_GetPointCount(c) > 0 then
4259 begin
4260 Result := c;
4261 Exit;
4262 end;
4263 end;
4265 // Òî÷êà ëþáîé èç êîìàíä
4266 if Random(2) = 0 then
4267 c := RESPAWNPOINT_RED
4268 else
4269 c := RESPAWNPOINT_BLUE;
4270 if g_Map_GetPointCount(c) > 0 then
4271 begin
4272 Result := c;
4273 Exit;
4274 end;
4276 // Òî÷êà DM
4277 c := RESPAWNPOINT_DM;
4278 if g_Map_GetPointCount(c) > 0 then
4279 begin
4280 Result := c;
4281 Exit;
4282 end;
4283 end;
4285 // Ìÿñîïîâàë
4286 if gGameSettings.GameMode = GM_DM then
4287 begin
4288 // Òî÷êà DM
4289 c := RESPAWNPOINT_DM;
4290 if g_Map_GetPointCount(c) > 0 then
4291 begin
4292 Result := c;
4293 Exit;
4294 end;
4296 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4297 if Random(2) = 0 then
4298 c := RESPAWNPOINT_PLAYER1
4299 else
4300 c := RESPAWNPOINT_PLAYER2;
4301 if g_Map_GetPointCount(c) > 0 then
4302 begin
4303 Result := c;
4304 Exit;
4305 end;
4307 // Òî÷êà ëþáîé èç êîìàíä
4308 if Random(2) = 0 then
4309 c := RESPAWNPOINT_RED
4310 else
4311 c := RESPAWNPOINT_BLUE;
4312 if g_Map_GetPointCount(c) > 0 then
4313 begin
4314 Result := c;
4315 Exit;
4316 end;
4317 end;
4319 // Êîìàíäíûå
4320 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
4321 begin
4322 // Òî÷êà ñâîåé êîìàíäû
4323 c := RESPAWNPOINT_DM;
4324 if FTeam = TEAM_RED then
4325 c := RESPAWNPOINT_RED;
4326 if FTeam = TEAM_BLUE then
4327 c := RESPAWNPOINT_BLUE;
4328 if g_Map_GetPointCount(c) > 0 then
4329 begin
4330 Result := c;
4331 Exit;
4332 end;
4334 // Òî÷êà DM
4335 c := RESPAWNPOINT_DM;
4336 if g_Map_GetPointCount(c) > 0 then
4337 begin
4338 Result := c;
4339 Exit;
4340 end;
4342 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4343 if Random(2) = 0 then
4344 c := RESPAWNPOINT_PLAYER1
4345 else
4346 c := RESPAWNPOINT_PLAYER2;
4347 if g_Map_GetPointCount(c) > 0 then
4348 begin
4349 Result := c;
4350 Exit;
4351 end;
4353 // Òî÷êà äðóãîé êîìàíäû
4354 c := RESPAWNPOINT_DM;
4355 if FTeam = TEAM_RED then
4356 c := RESPAWNPOINT_BLUE;
4357 if FTeam = TEAM_BLUE then
4358 c := RESPAWNPOINT_RED;
4359 if g_Map_GetPointCount(c) > 0 then
4360 begin
4361 Result := c;
4362 Exit;
4363 end;
4364 end;
4365 end;
4367 procedure TPlayer.Respawn(Silent: Boolean; Force: Boolean = False);
4368 var
4369 RespawnPoint: TRespawnPoint;
4370 a, b, c: Byte;
4371 Anim: TAnimation;
4372 ID: DWORD;
4373 begin
4374 if not g_Game_IsServer then
4375 Exit;
4376 if FDummy then
4377 Exit;
4378 FWantsInGame := True;
4379 FJustTeleported := True;
4380 if Force then
4381 begin
4382 FTime[T_RESPAWN] := 0;
4383 FLive := False;
4384 end;
4385 FNetTime := 0;
4386 // if server changes MaxLives we gotta be ready
4387 if gGameSettings.MaxLives = 0 then FNoRespawn := False;
4389 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4390 if FTime[T_RESPAWN] > gTime then
4391 Exit;
4393 // Ïðîñðàë âñå æèçíè:
4394 if FNoRespawn then
4395 begin
4396 if not FSpectator then Spectate(True);
4397 FWantsInGame := True;
4398 Exit;
4399 end;
4401 if (gGameSettings.GameType <> GT_SINGLE) and (gGameSettings.GameMode <> GM_COOP) then
4402 begin // "Ñâîÿ èãðà"
4403 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4404 FRulez := FRulez-[R_BERSERK];
4405 end
4406 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4407 begin
4408 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4409 FRulez := FRulez-[R_KEY_RED, R_KEY_GREEN, R_KEY_BLUE, R_BERSERK];
4410 end;
4412 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4413 c := GetRespawnPoint();
4415 ReleaseKeys();
4416 SetFlag(FLAG_NONE);
4418 // Âîñêðåøåíèå áåç îðóæèÿ:
4419 if not FLive then
4420 begin
4421 FHealth := PLAYER_HP_SOFT;
4422 FArmor := 0;
4423 FLive := True;
4424 FAir := AIR_DEF;
4425 FJetFuel := 0;
4427 for a := WP_FIRST to WP_LAST do
4428 begin
4429 FWeapon[a] := False;
4430 FReloading[a] := 0;
4431 end;
4433 FWeapon[WEAPON_PISTOL] := True;
4434 FWeapon[WEAPON_KASTET] := True;
4435 FCurrWeap := WEAPON_PISTOL;
4436 resetWeaponQueue();
4438 FModel.SetWeapon(FCurrWeap);
4440 for b := A_BULLETS to A_HIGH do
4441 FAmmo[b] := 0;
4443 FAmmo[A_BULLETS] := 50;
4445 FMaxAmmo[A_BULLETS] := AmmoLimits[0, A_BULLETS];
4446 FMaxAmmo[A_SHELLS] := AmmoLimits[0, A_SHELLS];
4447 FMaxAmmo[A_ROCKETS] := AmmoLimits[0, A_SHELLS];
4448 FMaxAmmo[A_CELLS] := AmmoLimits[0, A_CELLS];
4449 FMaxAmmo[A_FUEL] := AmmoLimits[0, A_FUEL];
4451 if gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF] then
4452 FRulez := [R_KEY_RED, R_KEY_GREEN, R_KEY_BLUE]
4453 else
4454 FRulez := [];
4455 end;
4457 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4458 if not g_Map_GetPoint(c, RespawnPoint) then
4459 begin
4460 g_FatalError(_lc[I_GAME_ERROR_GET_SPAWN]);
4461 Exit;
4462 end;
4464 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4465 FObj.X := RespawnPoint.X-PLAYER_RECT.X;
4466 FObj.Y := RespawnPoint.Y-PLAYER_RECT.Y;
4467 FObj.Vel.X := 0;
4468 FObj.Vel.Y := 0;
4469 FObj.Accel.X := 0;
4470 FObj.Accel.Y := 0;
4472 FDirection := RespawnPoint.Direction;
4473 if FDirection = D_LEFT then
4474 FAngle := 180
4475 else
4476 FAngle := 0;
4478 FIncCam := 0;
4479 FBFGFireCounter := -1;
4480 FShellTimer := -1;
4481 FPain := 0;
4482 FLastHit := 0;
4484 SetAction(A_STAND, True);
4485 FModel.Direction := FDirection;
4487 for a := Low(FTime) to High(FTime) do
4488 FTime[a] := 0;
4490 for a := Low(FMegaRulez) to High(FMegaRulez) do
4491 FMegaRulez[a] := 0;
4493 FDamageBuffer := 0;
4494 FJetpack := False;
4495 FCanJetpack := False;
4496 FFireTime := 0;
4497 FFirePainTime := 0;
4498 FFireAttacker := 0;
4500 // Àíèìàöèÿ âîçðîæäåíèÿ:
4501 if (not gLoadGameMode) and (not Silent) then
4502 if g_Frames_Get(ID, 'FRAMES_TELEPORT') then
4503 begin
4504 Anim := TAnimation.Create(ID, False, 3);
4505 g_GFX_OnceAnim(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
4506 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32, Anim);
4507 Anim.Free();
4508 end;
4510 FSpectator := False;
4511 FGhost := False;
4512 FPhysics := True;
4513 FSpectatePlayer := -1;
4514 FSpawned := True;
4516 if g_Game_IsNet then
4517 begin
4518 MH_SEND_PlayerPos(True, FUID, NET_EVERYONE);
4519 MH_SEND_PlayerStats(FUID, NET_EVERYONE);
4520 if not Silent then
4521 MH_SEND_Effect(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
4522 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32,
4523 0, NET_GFX_TELE);
4524 end;
4525 end;
4527 procedure TPlayer.Spectate(NoMove: Boolean = False);
4528 begin
4529 if FLive then
4530 Kill(K_EXTRAHARDKILL, FUID, HIT_SOME)
4531 else if (not NoMove) then
4532 begin
4533 GameX := gMapInfo.Width div 2;
4534 GameY := gMapInfo.Height div 2;
4535 end;
4536 FXTo := GameX;
4537 FYTo := GameY;
4539 FLive := False;
4540 FSpectator := True;
4541 FGhost := True;
4542 FPhysics := False;
4543 FWantsInGame := False;
4544 FSpawned := False;
4546 if FNoRespawn then
4547 begin
4548 if Self = gPlayer1 then
4549 begin
4550 gLMSPID1 := FUID;
4551 gPlayer1 := nil;
4552 end;
4553 if Self = gPlayer2 then
4554 begin
4555 gLMSPID2 := FUID;
4556 gPlayer2 := nil;
4557 end;
4558 end;
4560 if g_Game_IsNet then
4561 MH_SEND_PlayerStats(FUID);
4562 end;
4564 procedure TPlayer.SwitchNoClip;
4565 begin
4566 if not FLive then
4567 Exit;
4568 FGhost := not FGhost;
4569 FPhysics := not FGhost;
4570 if FGhost then
4571 begin
4572 FXTo := FObj.X;
4573 FYTo := FObj.Y;
4574 end else
4575 begin
4576 FObj.Accel.X := 0;
4577 FObj.Accel.Y := 0;
4578 end;
4579 end;
4581 procedure TPlayer.Run(Direction: TDirection);
4582 var
4583 a, b: Integer;
4584 begin
4585 if MAX_RUNVEL > 8 then
4586 FlySmoke();
4588 // Áåæèì:
4589 if Direction = D_LEFT then
4590 begin
4591 if FObj.Vel.X > -MAX_RUNVEL then
4592 FObj.Vel.X := FObj.Vel.X - (MAX_RUNVEL shr 3);
4593 end
4594 else
4595 if FObj.Vel.X < MAX_RUNVEL then
4596 FObj.Vel.X := FObj.Vel.X + (MAX_RUNVEL shr 3);
4598 // Âîçìîæíî, ïèíàåì êóñêè:
4599 if (FObj.Vel.X <> 0) and (gGibs <> nil) then
4600 begin
4601 b := Abs(FObj.Vel.X);
4602 if b > 1 then b := b * (Random(8 div b) + 1);
4603 for a := 0 to High(gGibs) do
4604 begin
4605 if gGibs[a].Live and
4606 g_Obj_Collide(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y+FObj.Rect.Height-4,
4607 FObj.Rect.Width, 8, @gGibs[a].Obj) and (Random(3) = 0) then
4608 begin
4609 // Ïèíàåì êóñêè
4610 if FObj.Vel.X < 0 then
4611 begin
4612 g_Obj_PushA(@gGibs[a].Obj, b, Random(61)+120) // íàëåâî
4613 end
4614 else
4615 begin
4616 g_Obj_PushA(@gGibs[a].Obj, b, Random(61)); // íàïðàâî
4617 end;
4618 gGibs[a].positionChanged(); // this updates spatial accelerators
4619 end;
4620 end;
4621 end;
4623 SetAction(A_WALK);
4624 end;
4626 procedure TPlayer.SeeDown();
4627 begin
4628 SetAction(A_SEEDOWN);
4630 if FDirection = D_LEFT then FAngle := ANGLE_LEFTDOWN else FAngle := ANGLE_RIGHTDOWN;
4632 if FIncCam > -120 then DecMin(FIncCam, 5, -120);
4633 end;
4635 procedure TPlayer.SeeUp();
4636 begin
4637 SetAction(A_SEEUP);
4639 if FDirection = D_LEFT then FAngle := ANGLE_LEFTUP else FAngle := ANGLE_RIGHTUP;
4641 if FIncCam < 120 then IncMax(FIncCam, 5, 120);
4642 end;
4644 procedure TPlayer.SetAction(Action: Byte; Force: Boolean = False);
4645 var
4646 Prior: Byte;
4647 begin
4648 case Action of
4649 A_WALK: Prior := 3;
4650 A_DIE1: Prior := 5;
4651 A_DIE2: Prior := 5;
4652 A_ATTACK: Prior := 2;
4653 A_SEEUP: Prior := 1;
4654 A_SEEDOWN: Prior := 1;
4655 A_ATTACKUP: Prior := 2;
4656 A_ATTACKDOWN: Prior := 2;
4657 A_PAIN: Prior := 4;
4658 else Prior := 0;
4659 end;
4661 if (Prior > FActionPrior) or Force then
4662 if not ((Prior = 2) and (FCurrWeap = WEAPON_SAW)) then
4663 begin
4664 FActionPrior := Prior;
4665 FActionAnim := Action;
4666 FActionForce := Force;
4667 FActionChanged := True;
4668 end;
4670 if Action in [A_ATTACK, A_ATTACKUP, A_ATTACKDOWN] then FModel.SetFire(True);
4671 end;
4673 function TPlayer.StayOnStep(XInc, YInc: Integer): Boolean;
4674 begin
4675 Result := not g_Map_CollidePanel(FObj.X+PLAYER_RECT.X, FObj.Y+YInc+PLAYER_RECT.Y+PLAYER_RECT.Height-1,
4676 PLAYER_RECT.Width, 1, PANEL_STEP, False)
4677 and g_Map_CollidePanel(FObj.X+PLAYER_RECT.X, FObj.Y+YInc+PLAYER_RECT.Y+PLAYER_RECT.Height,
4678 PLAYER_RECT.Width, 1, PANEL_STEP, False);
4679 end;
4681 function TPlayer.TeleportTo(X, Y: Integer; silent: Boolean; dir: Byte): Boolean;
4682 var
4683 Anim: TAnimation;
4684 ID: DWORD;
4685 begin
4686 Result := False;
4688 if g_CollideLevel(X, Y, PLAYER_RECT.Width, PLAYER_RECT.Height) then
4689 begin
4690 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj.X, FObj.Y);
4691 if g_Game_IsServer and g_Game_IsNet then
4692 MH_SEND_Sound(FObj.X, FObj.Y, 'SOUND_GAME_NOTELEPORT');
4693 Exit;
4694 end;
4696 FJustTeleported := True;
4698 Anim := nil;
4699 if not silent then
4700 begin
4701 if g_Frames_Get(ID, 'FRAMES_TELEPORT') then
4702 begin
4703 Anim := TAnimation.Create(ID, False, 3);
4704 end;
4706 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj.X, FObj.Y);
4707 g_GFX_OnceAnim(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
4708 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32, Anim);
4709 if g_Game_IsServer and g_Game_IsNet then
4710 MH_SEND_Effect(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
4711 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32, 1,
4712 NET_GFX_TELE);
4713 end;
4715 FObj.X := X-PLAYER_RECT.X;
4716 FObj.Y := Y-PLAYER_RECT.Y;
4717 if FLive and FGhost then
4718 begin
4719 FXTo := FObj.X;
4720 FYTo := FObj.Y;
4721 end;
4723 if not g_Game_IsNet then
4724 begin
4725 if dir = 1 then
4726 begin
4727 SetDirection(D_LEFT);
4728 FAngle := 180;
4729 end
4730 else
4731 if dir = 2 then
4732 begin
4733 SetDirection(D_RIGHT);
4734 FAngle := 0;
4735 end
4736 else
4737 if dir = 3 then
4738 begin // îáðàòíîå
4739 if FDirection = D_RIGHT then
4740 begin
4741 SetDirection(D_LEFT);
4742 FAngle := 180;
4743 end
4744 else
4745 begin
4746 SetDirection(D_RIGHT);
4747 FAngle := 0;
4748 end;
4749 end;
4750 end;
4752 if not silent and (Anim <> nil) then
4753 begin
4754 g_GFX_OnceAnim(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
4755 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32, Anim);
4756 Anim.Free();
4758 if g_Game_IsServer and g_Game_IsNet then
4759 MH_SEND_Effect(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
4760 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32, 0,
4761 NET_GFX_TELE);
4762 end;
4764 Result := True;
4765 end;
4767 function nonz(a: Single): Single;
4768 begin
4769 if a <> 0 then
4770 Result := a
4771 else
4772 Result := 1;
4773 end;
4775 procedure TPlayer.Update();
4776 var
4777 b: Byte;
4778 i, ii, wx, wy, xd, yd, k: Integer;
4779 blockmon, headwater, dospawn: Boolean;
4780 NetServer: Boolean;
4781 AnyServer: Boolean;
4782 SetSpect: Boolean;
4783 begin
4784 NetServer := g_Game_IsNet and g_Game_IsServer;
4785 AnyServer := g_Game_IsServer;
4787 if g_Game_IsClient and (NetInterpLevel > 0) then
4788 DoLerp(NetInterpLevel + 1)
4789 else
4790 if FGhost then
4791 DoLerp(4);
4793 if NetServer then
4794 if FClientID >= 0 then
4795 begin
4796 FPing := NetClients[FClientID].Peer^.lastRoundTripTime;
4797 if NetClients[FClientID].Peer^.packetsSent > 0 then
4798 FLoss := Round(100*NetClients[FClientID].Peer^.packetsLost/NetClients[FClientID].Peer^.packetsSent)
4799 else
4800 FLoss := 0;
4801 end else
4802 begin
4803 FPing := 0;
4804 FLoss := 0;
4805 end;
4807 if FLive and (gFly or FJetpack) then
4808 FlySmoke();
4810 if FDirection = D_LEFT then
4811 FAngle := 180
4812 else
4813 FAngle := 0;
4815 if FLive and (not FGhost) then
4816 begin
4817 if FKeys[KEY_UP].Pressed then
4818 SeeUp();
4819 if FKeys[KEY_DOWN].Pressed then
4820 SeeDown();
4821 end;
4823 if (not (FKeys[KEY_UP].Pressed or FKeys[KEY_DOWN].Pressed)) and
4824 (FIncCam <> 0) then
4825 begin
4826 i := g_basic.Sign(FIncCam);
4827 FIncCam := Abs(FIncCam);
4828 DecMin(FIncCam, 5, 0);
4829 FIncCam := FIncCam*i;
4830 end;
4832 // no need to do that each second frame, weapon queue will take care of it
4833 if FLive and FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
4834 if FLive and FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
4836 if gTime mod (GAME_TICK*2) <> 0 then
4837 begin
4838 if (FObj.Vel.X = 0) and FLive then
4839 begin
4840 if FKeys[KEY_LEFT].Pressed then
4841 Run(D_LEFT);
4842 if FKeys[KEY_RIGHT].Pressed then
4843 Run(D_RIGHT);
4844 end;
4846 if FPhysics then
4847 begin
4848 g_Obj_Move(@FObj, True, True, True);
4849 positionChanged(); // this updates spatial accelerators
4850 end;
4852 Exit;
4853 end;
4855 FActionChanged := False;
4857 if FLive then
4858 begin
4859 // Let alive player do some actions
4860 if FKeys[KEY_LEFT].Pressed then Run(D_LEFT);
4861 if FKeys[KEY_RIGHT].Pressed then Run(D_RIGHT);
4862 //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
4863 //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
4864 if FKeys[KEY_FIRE].Pressed and AnyServer then Fire();
4865 if FKeys[KEY_OPEN].Pressed and AnyServer then Use();
4866 if FKeys[KEY_JUMP].Pressed then Jump()
4867 else
4868 begin
4869 if AnyServer and FJetpack then
4870 begin
4871 FJetpack := False;
4872 JetpackOff;
4873 if NetServer then MH_SEND_PlayerStats(FUID);
4874 end;
4875 FCanJetpack := True;
4876 end;
4877 end
4878 else // Dead
4879 begin
4880 dospawn := False;
4881 if not FGhost then
4882 for k := Low(FKeys) to KEY_CHAT-1 do
4883 begin
4884 if FKeys[k].Pressed then
4885 begin
4886 dospawn := True;
4887 break;
4888 end;
4889 end;
4890 if dospawn then
4891 begin
4892 if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
4893 Respawn(False)
4894 else // Single
4895 if (FTime[T_RESPAWN] <= gTime) and
4896 gGameOn and (not FLive) then
4897 begin
4898 if (g_Player_GetCount() > 1) then
4899 Respawn(False)
4900 else
4901 begin
4902 gExit := EXIT_RESTART;
4903 Exit;
4904 end;
4905 end;
4906 end;
4907 // Dead spectator actions
4908 if FGhost then
4909 begin
4910 if FKeys[KEY_OPEN].Pressed and AnyServer then Fire();
4911 if FKeys[KEY_FIRE].Pressed and AnyServer then
4912 begin
4913 if FSpectator then
4914 begin
4915 if (FSpectatePlayer >= High(gPlayers)) then
4916 FSpectatePlayer := -1
4917 else
4918 begin
4919 SetSpect := False;
4920 for I := FSpectatePlayer + 1 to High(gPlayers) do
4921 if gPlayers[I] <> nil then
4922 if gPlayers[I].Live then
4923 if gPlayers[I].UID <> FUID then
4924 begin
4925 FSpectatePlayer := I;
4926 SetSpect := True;
4927 break;
4928 end;
4930 if not SetSpect then FSpectatePlayer := -1;
4931 end;
4933 ReleaseKeys;
4934 end;
4935 end;
4936 end;
4937 end;
4938 // No clipping
4939 if FGhost then
4940 begin
4941 if FKeys[KEY_UP].Pressed or FKeys[KEY_JUMP].Pressed then
4942 begin
4943 FYTo := FObj.Y - 32;
4944 FSpectatePlayer := -1;
4945 end;
4946 if FKeys[KEY_DOWN].Pressed then
4947 begin
4948 FYTo := FObj.Y + 32;
4949 FSpectatePlayer := -1;
4950 end;
4951 if FKeys[KEY_LEFT].Pressed then
4952 begin
4953 FXTo := FObj.X - 32;
4954 FSpectatePlayer := -1;
4955 end;
4956 if FKeys[KEY_RIGHT].Pressed then
4957 begin
4958 FXTo := FObj.X + 32;
4959 FSpectatePlayer := -1;
4960 end;
4962 if (FXTo < -64) then
4963 FXTo := -64
4964 else if (FXTo > gMapInfo.Width + 32) then
4965 FXTo := gMapInfo.Width + 32;
4966 if (FYTo < -72) then
4967 FYTo := -72
4968 else if (FYTo > gMapInfo.Height + 32) then
4969 FYTo := gMapInfo.Height + 32;
4970 end;
4972 if FPhysics then
4973 begin
4974 g_Obj_Move(@FObj, True, True, True);
4975 positionChanged(); // this updates spatial accelerators
4976 end
4977 else
4978 begin
4979 FObj.Vel.X := 0;
4980 FObj.Vel.Y := 0;
4981 if FSpectator then
4982 if (FSpectatePlayer <= High(gPlayers)) and (FSpectatePlayer >= 0) then
4983 if gPlayers[FSpectatePlayer] <> nil then
4984 if gPlayers[FSpectatePlayer].Live then
4985 begin
4986 FXTo := gPlayers[FSpectatePlayer].GameX;
4987 FYTo := gPlayers[FSpectatePlayer].GameY;
4988 end;
4989 end;
4991 blockmon := g_Map_CollidePanel(FObj.X+PLAYER_HEADRECT.X, FObj.Y+PLAYER_HEADRECT.Y,
4992 PLAYER_HEADRECT.Width, PLAYER_HEADRECT.Height,
4993 PANEL_BLOCKMON, True);
4994 headwater := HeadInLiquid(0, 0);
4996 // Ñîïðîòèâëåíèå âîçäóõà:
4997 if (not FLive) or not (FKeys[KEY_LEFT].Pressed or FKeys[KEY_RIGHT].Pressed) then
4998 if FObj.Vel.X <> 0 then
4999 FObj.Vel.X := z_dec(FObj.Vel.X, 1);
5001 if (FLastHit = HIT_TRAP) and (FPain > 90) then FPain := 90;
5002 DecMin(FPain, 5, 0);
5003 DecMin(FPickup, 1, 0);
5005 if FLive and (FObj.Y > Integer(gMapInfo.Height)+128) and AnyServer then
5006 begin
5007 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
5008 FMegaRulez[MR_SUIT] := 0;
5009 FMegaRulez[MR_INVUL] := 0;
5010 FMegaRulez[MR_INVIS] := 0;
5011 Kill(K_FALLKILL, 0, HIT_FALL);
5012 end;
5014 i := 9;
5016 if FLive then
5017 begin
5018 if FCurrWeap = WEAPON_SAW then
5019 if not (FSawSound.IsPlaying() or FSawSoundHit.IsPlaying() or
5020 FSawSoundSelect.IsPlaying()) then
5021 FSawSoundIdle.PlayAt(FObj.X, FObj.Y);
5023 if FJetpack then
5024 if (not FJetSoundFly.IsPlaying()) and (not FJetSoundOn.IsPlaying()) and
5025 (not FJetSoundOff.IsPlaying()) then
5026 begin
5027 FJetSoundFly.SetPosition(0);
5028 FJetSoundFly.PlayAt(FObj.X, FObj.Y);
5029 end;
5031 for b := WP_FIRST to WP_LAST do
5032 if FReloading[b] > 0 then
5033 if FNoReload then
5034 FReloading[b] := 0
5035 else
5036 Dec(FReloading[b]);
5038 if FShellTimer > -1 then
5039 if FShellTimer = 0 then
5040 begin
5041 if FShellType = SHELL_SHELL then
5042 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
5043 GameVelX, GameVelY-2, SHELL_SHELL)
5044 else if FShellType = SHELL_DBLSHELL then
5045 begin
5046 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
5047 GameVelX+1, GameVelY-2, SHELL_SHELL);
5048 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
5049 GameVelX-1, GameVelY-2, SHELL_SHELL);
5050 end;
5051 FShellTimer := -1;
5052 end else Dec(FShellTimer);
5054 if (FBFGFireCounter > -1) then
5055 if FBFGFireCounter = 0 then
5056 begin
5057 if AnyServer then
5058 begin
5059 wx := FObj.X+WEAPONPOINT[FDirection].X;
5060 wy := FObj.Y+WEAPONPOINT[FDirection].Y;
5061 xd := wx+IfThen(FDirection = D_LEFT, -30, 30);
5062 yd := wy+firediry();
5063 g_Weapon_bfgshot(wx, wy, xd, yd, FUID);
5064 if NetServer then MH_SEND_PlayerFire(FUID, WEAPON_BFG, wx, wy, xd, yd);
5065 if (FAngle = 0) or (FAngle = 180) then SetAction(A_ATTACK)
5066 else if (FAngle = ANGLE_LEFTDOWN) or (FAngle = ANGLE_RIGHTDOWN) then SetAction(A_ATTACKDOWN)
5067 else if (FAngle = ANGLE_LEFTUP) or (FAngle = ANGLE_RIGHTUP) then SetAction(A_ATTACKUP);
5068 end;
5070 FReloading[WEAPON_BFG] := WEAPON_RELOAD[WEAPON_BFG];
5071 FBFGFireCounter := -1;
5072 end else
5073 if FNoReload then
5074 FBFGFireCounter := 0
5075 else
5076 Dec(FBFGFireCounter);
5078 if (FMegaRulez[MR_SUIT] < gTime) and AnyServer then
5079 begin
5080 b := g_GetAcidHit(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width, PLAYER_RECT.Height);
5082 if (b > 0) and (gTime mod (15*GAME_TICK) = 0) then Damage(b, 0, 0, 0, HIT_ACID);
5083 end;
5085 if (headwater or blockmon) then
5086 begin
5087 Dec(FAir);
5089 if FAir < -9 then
5090 begin
5091 if AnyServer then Damage(10, 0, 0, 0, HIT_WATER);
5092 FAir := 0;
5093 end
5094 else if (FAir mod 31 = 0) and not blockmon then
5095 begin
5096 g_GFX_Bubbles(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2), FObj.Y+PLAYER_RECT.Y-4, 5+Random(6), 8, 4);
5097 if Random(2) = 0 then
5098 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj.X, FObj.Y)
5099 else
5100 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj.X, FObj.Y);
5101 end;
5102 end else if FAir < AIR_DEF then
5103 FAir := AIR_DEF;
5105 if FFireTime > 0 then
5106 begin
5107 if BodyInLiquid(0, 0) then
5108 begin
5109 FFireTime := 0;
5110 FFirePainTime := 0;
5111 end
5112 else if FMegaRulez[MR_SUIT] >= gTime then
5113 begin
5114 if FMegaRulez[MR_SUIT] = gTime then
5115 FFireTime := 1;
5116 FFirePainTime := 0;
5117 end
5118 else
5119 begin
5120 OnFireFlame(1);
5121 if FFirePainTime <= 0 then
5122 begin
5123 if g_Game_IsServer then
5124 Damage(5, FFireAttacker, 0, 0, HIT_FLAME);
5125 FFirePainTime := 18;
5126 end;
5127 FFirePainTime := FFirePainTime - 1;
5128 FFireTime := FFireTime - 1;
5129 if (FFireTime = 0) and g_Game_IsNet and g_Game_IsServer then
5130 MH_SEND_PlayerStats(FUID);
5131 end;
5132 end;
5134 if FDamageBuffer > 0 then
5135 begin
5136 if FDamageBuffer >= 9 then
5137 begin
5138 SetAction(A_PAIN);
5140 if FDamageBuffer < 30 then i := 9
5141 else if FDamageBuffer < 100 then i := 18
5142 else i := 27;
5143 end;
5145 ii := Round(FDamageBuffer*FHealth / nonz(FArmor*(3/4)+FHealth));
5146 FArmor := FArmor-(FDamageBuffer-ii);
5147 FHealth := FHealth-ii;
5148 if FArmor < 0 then
5149 begin
5150 FHealth := FHealth+FArmor;
5151 FArmor := 0;
5152 end;
5154 if AnyServer then
5155 if FHealth <= 0 then
5156 if FHealth > -30 then Kill(K_SIMPLEKILL, FLastSpawnerUID, FLastHit)
5157 else if FHealth > -50 then Kill(K_HARDKILL, FLastSpawnerUID, FLastHit)
5158 else Kill(K_EXTRAHARDKILL, FLastSpawnerUID, FLastHit);
5160 if FLive then
5161 begin
5162 if FDamageBuffer <= 20 then FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y)
5163 else if FDamageBuffer <= 55 then FModel.PlaySound(MODELSOUND_PAIN, 2, FObj.X, FObj.Y)
5164 else if FDamageBuffer <= 120 then FModel.PlaySound(MODELSOUND_PAIN, 3, FObj.X, FObj.Y)
5165 else FModel.PlaySound(MODELSOUND_PAIN, 4, FObj.X, FObj.Y);
5166 end;
5168 FDamageBuffer := 0;
5169 end;
5171 {CollideItem();}
5172 end; // if FLive then ...
5174 if (FActionAnim = A_PAIN) and (FModel.Animation <> A_PAIN) then
5175 begin
5176 FModel.ChangeAnimation(FActionAnim, FActionForce);
5177 FModel.GetCurrentAnimation.MinLength := i;
5178 FModel.GetCurrentAnimationMask.MinLength := i;
5179 end else FModel.ChangeAnimation(FActionAnim, FActionForce and (FModel.Animation <> A_STAND));
5181 if (FModel.GetCurrentAnimation.Played or ((not FActionChanged) and (FModel.Animation = A_WALK)))
5182 then SetAction(A_STAND, True);
5184 if not ((FModel.Animation = A_WALK) and (Abs(FObj.Vel.X) < 4) and not FModel.Fire) then FModel.Update;
5186 for b := Low(FKeys) to High(FKeys) do
5187 if FKeys[b].Time = 0 then FKeys[b].Pressed := False else Dec(FKeys[b].Time);
5188 end;
5190 procedure TPlayer.getMapBox (out x, y, w, h: Integer); inline;
5191 begin
5192 x := FObj.X+PLAYER_RECT.X;
5193 y := FObj.Y+PLAYER_RECT.Y;
5194 w := PLAYER_RECT.Width;
5195 h := PLAYER_RECT.Height;
5196 end;
5198 function TPlayer.Collide(X, Y: Integer; Width, Height: Word): Boolean;
5199 begin
5200 Result := g_Collide(FObj.X+PLAYER_RECT.X,
5201 FObj.Y+PLAYER_RECT.Y,
5202 PLAYER_RECT.Width,
5203 PLAYER_RECT.Height,
5204 X, Y,
5205 Width, Height);
5206 end;
5208 function TPlayer.Collide(Panel: TPanel): Boolean;
5209 begin
5210 Result := g_Collide(FObj.X+PLAYER_RECT.X,
5211 FObj.Y+PLAYER_RECT.Y,
5212 PLAYER_RECT.Width,
5213 PLAYER_RECT.Height,
5214 Panel.X, Panel.Y,
5215 Panel.Width, Panel.Height);
5216 end;
5218 function TPlayer.Collide(X, Y: Integer): Boolean;
5219 begin
5220 X := X-FObj.X-PLAYER_RECT.X;
5221 Y := Y-FObj.Y-PLAYER_RECT.Y;
5222 Result := (x >= 0) and (x <= PLAYER_RECT.Width) and
5223 (y >= 0) and (y <= PLAYER_RECT.Height);
5224 end;
5226 function g_Player_ValidName(Name: string): Boolean;
5227 var
5228 a: Integer;
5229 begin
5230 Result := True;
5232 if gPlayers = nil then Exit;
5234 for a := 0 to High(gPlayers) do
5235 if gPlayers[a] <> nil then
5236 if LowerCase(Name) = LowerCase(gPlayers[a].FName) then
5237 begin
5238 Result := False;
5239 Exit;
5240 end;
5241 end;
5243 procedure TPlayer.SetDirection(Direction: TDirection);
5244 var
5245 d: TDirection;
5246 begin
5247 d := FModel.Direction;
5249 FModel.Direction := Direction;
5250 if d <> Direction then FModel.ChangeAnimation(FModel.Animation, True);
5252 FDirection := Direction;
5253 end;
5255 function TPlayer.GetKeys(): Byte;
5256 begin
5257 Result := 0;
5259 if R_KEY_RED in FRulez then Result := KEY_RED;
5260 if R_KEY_GREEN in FRulez then Result := Result or KEY_GREEN;
5261 if R_KEY_BLUE in FRulez then Result := Result or KEY_BLUE;
5263 if FTeam = TEAM_RED then Result := Result or KEY_REDTEAM;
5264 if FTeam = TEAM_BLUE then Result := Result or KEY_BLUETEAM;
5265 end;
5267 procedure TPlayer.Use();
5268 var
5269 a: Integer;
5270 begin
5271 if FTime[T_USE] > gTime then Exit;
5273 g_Triggers_PressR(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
5274 PLAYER_RECT.Height, FUID, ACTIVATE_PLAYERPRESS);
5276 for a := 0 to High(gPlayers) do
5277 if (gPlayers[a] <> nil) and (gPlayers[a] <> Self) and
5278 gPlayers[a].Live and SameTeam(FUID, gPlayers[a].FUID) and
5279 g_Obj_Collide(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y,
5280 FObj.Rect.Width, FObj.Rect.Height, @gPlayers[a].FObj) then
5281 begin
5282 gPlayers[a].Touch();
5283 if g_Game_IsNet and g_Game_IsServer then
5284 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH, gPlayers[a].FUID);
5285 end;
5287 FTime[T_USE] := gTime+120;
5288 end;
5290 procedure TPlayer.NetFire(Wpn: Byte; X, Y, AX, AY: Integer; WID: Integer = -1);
5291 var
5292 locObj: TObj;
5293 F: Boolean;
5294 WX, WY, XD, YD: Integer;
5295 begin
5296 F := False;
5297 WX := X;
5298 WY := Y;
5299 XD := AX;
5300 YD := AY;
5302 case FCurrWeap of
5303 WEAPON_KASTET:
5304 begin
5305 if R_BERSERK in FRulez then
5306 begin
5307 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5308 locobj.X := FObj.X+FObj.Rect.X;
5309 locobj.Y := FObj.Y+FObj.Rect.Y;
5310 locobj.rect.X := 0;
5311 locobj.rect.Y := 0;
5312 locobj.rect.Width := 39;
5313 locobj.rect.Height := 52;
5314 locobj.Vel.X := (xd-wx) div 2;
5315 locobj.Vel.Y := (yd-wy) div 2;
5316 locobj.Accel.X := xd-wx;
5317 locobj.Accel.y := yd-wy;
5319 if g_Weapon_Hit(@locobj, 50, FUID, HIT_SOME) <> 0 then
5320 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj.X, FObj.Y)
5321 else
5322 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj.X, FObj.Y);
5324 if gFlash = 1 then
5325 if FPain < 50 then
5326 FPain := min(FPain + 25, 50);
5327 end else
5328 g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 3, FUID);
5329 end;
5331 WEAPON_SAW:
5332 begin
5333 if g_Weapon_chainsaw(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y,
5334 IfThen(gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF], 9, 3), FUID) <> 0 then
5335 begin
5336 FSawSoundSelect.Stop();
5337 FSawSound.Stop();
5338 FSawSoundHit.PlayAt(FObj.X, FObj.Y);
5339 end
5340 else if not FSawSoundHit.IsPlaying() then
5341 begin
5342 FSawSoundSelect.Stop();
5343 FSawSound.PlayAt(FObj.X, FObj.Y);
5344 end;
5345 f := True;
5346 end;
5348 WEAPON_PISTOL:
5349 begin
5350 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX, Gamey);
5351 FFireAngle := FAngle;
5352 f := True;
5353 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
5354 GameVelX, GameVelY-2, SHELL_BULLET);
5355 end;
5357 WEAPON_SHOTGUN1:
5358 begin
5359 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex, Gamey);
5360 FFireAngle := FAngle;
5361 f := True;
5362 FShellTimer := 10;
5363 FShellType := SHELL_SHELL;
5364 end;
5366 WEAPON_SHOTGUN2:
5367 begin
5368 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex, Gamey);
5369 FFireAngle := FAngle;
5370 f := True;
5371 FShellTimer := 13;
5372 FShellType := SHELL_DBLSHELL;
5373 end;
5375 WEAPON_CHAINGUN:
5376 begin
5377 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex, Gamey);
5378 FFireAngle := FAngle;
5379 f := True;
5380 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
5381 GameVelX, GameVelY-2, SHELL_BULLET);
5382 end;
5384 WEAPON_ROCKETLAUNCHER:
5385 begin
5386 g_Weapon_Rocket(wx, wy, xd, yd, FUID, WID);
5387 FFireAngle := FAngle;
5388 f := True;
5389 end;
5391 WEAPON_PLASMA:
5392 begin
5393 g_Weapon_Plasma(wx, wy, xd, yd, FUID, WID);
5394 FFireAngle := FAngle;
5395 f := True;
5396 end;
5398 WEAPON_BFG:
5399 begin
5400 g_Weapon_BFGShot(wx, wy, xd, yd, FUID, WID);
5401 FFireAngle := FAngle;
5402 f := True;
5403 end;
5405 WEAPON_SUPERPULEMET:
5406 begin
5407 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex, Gamey);
5408 FFireAngle := FAngle;
5409 f := True;
5410 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
5411 GameVelX, GameVelY-2, SHELL_SHELL);
5412 end;
5414 WEAPON_FLAMETHROWER:
5415 begin
5416 g_Weapon_flame(wx, wy, xd, yd, FUID, WID);
5417 FFireAngle := FAngle;
5418 f := True;
5419 end;
5420 end;
5422 if not f then Exit;
5424 if (FAngle = 0) or (FAngle = 180) then SetAction(A_ATTACK)
5425 else if (FAngle = ANGLE_LEFTDOWN) or (FAngle = ANGLE_RIGHTDOWN) then SetAction(A_ATTACKDOWN)
5426 else if (FAngle = ANGLE_LEFTUP) or (FAngle = ANGLE_RIGHTUP) then SetAction(A_ATTACKUP);
5427 end;
5429 procedure TPlayer.DoLerp(Level: Integer = 2);
5430 begin
5431 if FObj.X <> FXTo then FObj.X := Lerp(FObj.X, FXTo, Level);
5432 if FObj.Y <> FYTo then FObj.Y := Lerp(FObj.Y, FYTo, Level);
5433 end;
5435 procedure TPlayer.SetLerp(XTo, YTo: Integer);
5436 var
5437 AX, AY: Integer;
5438 begin
5439 if NetInterpLevel < 1 then
5440 begin
5441 FObj.X := XTo;
5442 FObj.Y := YTo;
5443 end
5444 else
5445 begin
5446 FXTo := XTo;
5447 FYTo := YTo;
5449 AX := Abs(FXTo - FObj.X);
5450 AY := Abs(FYTo - FObj.Y);
5451 if (AX > 32) or (AX <= NetInterpLevel) then
5452 FObj.X := FXTo;
5453 if (AY > 32) or (AY <= NetInterpLevel) then
5454 FObj.Y := FYTo;
5455 end;
5456 end;
5458 function TPlayer.FullInLift(XInc, YInc: Integer): Integer;
5459 begin
5460 if g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc,
5461 PLAYER_RECT.Width, PLAYER_RECT.Height-8,
5462 PANEL_LIFTUP, False) then Result := -1
5463 else
5464 if g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc,
5465 PLAYER_RECT.Width, PLAYER_RECT.Height-8,
5466 PANEL_LIFTDOWN, False) then Result := 1
5467 else Result := 0;
5468 end;
5470 function TPlayer.GetFlag(Flag: Byte): Boolean;
5471 var
5472 s, ts: String;
5473 evtype: Byte;
5474 begin
5475 Result := False;
5477 if Flag = FLAG_NONE then
5478 Exit;
5480 if not g_Game_IsServer then Exit;
5482 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5483 if (Flag = FTeam) and
5484 (gFlags[Flag].State = FLAG_STATE_NORMAL) and
5485 (FFlag <> FLAG_NONE) then
5486 begin
5487 if FFlag = FLAG_RED then
5488 s := _lc[I_PLAYER_FLAG_RED]
5489 else
5490 s := _lc[I_PLAYER_FLAG_BLUE];
5492 evtype := FLAG_STATE_SCORED;
5494 ts := Format('%.4d', [gFlags[FFlag].CaptureTime]);
5495 Insert('.', ts, Length(ts) + 1 - 3);
5496 g_Console_Add(Format(_lc[I_PLAYER_FLAG_CAPTURE], [FName, s, ts]), True);
5498 g_Map_ResetFlag(FFlag);
5499 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_CAPTURE], [AnsiUpperCase(s)]), 144);
5501 gTeamStat[FTeam].Goals := gTeamStat[FTeam].Goals + 1;
5503 Result := True;
5504 if g_Game_IsNet then
5505 begin
5506 MH_SEND_FlagEvent(evtype, FFlag, FUID, False);
5507 MH_SEND_GameStats;
5508 end;
5510 gFlags[FFlag].CaptureTime := 0;
5511 SetFlag(FLAG_NONE);
5512 Exit;
5513 end;
5515 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5516 if (Flag = FTeam) and
5517 (gFlags[Flag].State = FLAG_STATE_DROPPED) then
5518 begin
5519 if Flag = FLAG_RED then
5520 s := _lc[I_PLAYER_FLAG_RED]
5521 else
5522 s := _lc[I_PLAYER_FLAG_BLUE];
5524 evtype := FLAG_STATE_RETURNED;
5525 gFlags[Flag].CaptureTime := 0;
5527 g_Console_Add(Format(_lc[I_PLAYER_FLAG_RETURN], [FName, s]), True);
5529 g_Map_ResetFlag(Flag);
5530 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_RETURN], [AnsiUpperCase(s)]), 144);
5532 Result := True;
5533 if g_Game_IsNet then
5534 begin
5535 MH_SEND_FlagEvent(evtype, Flag, FUID, False);
5536 MH_SEND_GameStats;
5537 end;
5538 Exit;
5539 end;
5541 // Ïîäîáðàë ÷óæîé ôëàã:
5542 if (Flag <> FTeam) and (FTime[T_FLAGCAP] <= gTime) then
5543 begin
5544 SetFlag(Flag);
5546 if Flag = FLAG_RED then
5547 s := _lc[I_PLAYER_FLAG_RED]
5548 else
5549 s := _lc[I_PLAYER_FLAG_BLUE];
5551 evtype := FLAG_STATE_CAPTURED;
5553 g_Console_Add(Format(_lc[I_PLAYER_FLAG_GET], [FName, s]), True);
5555 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_GET], [AnsiUpperCase(s)]), 144);
5557 gFlags[Flag].State := FLAG_STATE_CAPTURED;
5559 Result := True;
5560 if g_Game_IsNet then
5561 begin
5562 MH_SEND_FlagEvent(evtype, Flag, FUID, False);
5563 MH_SEND_GameStats;
5564 end;
5565 end;
5566 end;
5568 procedure TPlayer.SetFlag(Flag: Byte);
5569 begin
5570 FFlag := Flag;
5571 if FModel <> nil then
5572 FModel.SetFlag(FFlag);
5573 end;
5575 function TPlayer.DropFlag(): Boolean;
5576 var
5577 s: String;
5578 begin
5579 Result := False;
5580 if (not g_Game_IsServer) or (FFlag = FLAG_NONE) then
5581 Exit;
5582 FTime[T_FLAGCAP] := gTime + 2000;
5583 with gFlags[FFlag] do
5584 begin
5585 Obj.X := FObj.X;
5586 Obj.Y := FObj.Y;
5587 Direction := FDirection;
5588 State := FLAG_STATE_DROPPED;
5589 Count := FLAG_TIME;
5590 g_Obj_Push(@Obj, (FObj.Vel.X div 2)-2+Random(5),
5591 (FObj.Vel.Y div 2)-2+Random(5));
5592 positionChanged(); // this updates spatial accelerators
5594 if FFlag = FLAG_RED then
5595 s := _lc[I_PLAYER_FLAG_RED]
5596 else
5597 s := _lc[I_PLAYER_FLAG_BLUE];
5599 g_Console_Add(Format(_lc[I_PLAYER_FLAG_DROP], [FName, s]), True);
5600 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_DROP], [AnsiUpperCase(s)]), 144);
5602 if g_Game_IsNet then
5603 MH_SEND_FlagEvent(FLAG_STATE_DROPPED, Flag, FUID, False);
5604 end;
5605 SetFlag(FLAG_NONE);
5606 Result := True;
5607 end;
5609 procedure TPlayer.GetSecret();
5610 begin
5611 Inc(FSecrets);
5612 end;
5614 procedure TPlayer.PressKey(Key: Byte; Time: Word = 1);
5615 begin
5616 Assert(Key <= High(FKeys));
5618 FKeys[Key].Pressed := True;
5619 FKeys[Key].Time := Time;
5620 end;
5622 function TPlayer.IsKeyPressed(K: Byte): Boolean;
5623 begin
5624 Result := FKeys[K].Pressed;
5625 end;
5627 procedure TPlayer.ReleaseKeys();
5628 var
5629 a: Integer;
5630 begin
5631 for a := Low(FKeys) to High(FKeys) do
5632 begin
5633 FKeys[a].Pressed := False;
5634 FKeys[a].Time := 0;
5635 end;
5636 end;
5638 procedure TPlayer.OnDamage(Angle: SmallInt);
5639 begin
5640 end;
5642 function TPlayer.firediry(): Integer;
5643 begin
5644 if FKeys[KEY_UP].Pressed then Result := -42
5645 else if FKeys[KEY_DOWN].Pressed then Result := 19
5646 else Result := 0;
5647 end;
5649 procedure TPlayer.RememberState();
5650 var
5651 i: Integer;
5652 begin
5653 FSavedState.Health := FHealth;
5654 FSavedState.Armor := FArmor;
5655 FSavedState.Air := FAir;
5656 FSavedState.JetFuel := FJetFuel;
5657 FSavedState.CurrWeap := FCurrWeap;
5658 FSavedState.NextWeap := FNextWeap;
5659 FSavedState.NextWeapDelay := FNextWeapDelay;
5661 for i := 0 to 3 do
5662 FSavedState.Ammo[i] := FAmmo[i];
5663 for i := 0 to 3 do
5664 FSavedState.MaxAmmo[i] := FMaxAmmo[i];
5666 FSavedState.Rulez := FRulez;
5667 FSavedState.WaitRecall := True;
5668 end;
5670 procedure TPlayer.RecallState();
5671 var
5672 i: Integer;
5673 begin
5674 if not FSavedState.WaitRecall then Exit;
5676 FHealth := FSavedState.Health;
5677 FArmor := FSavedState.Armor;
5678 FAir := FSavedState.Air;
5679 FJetFuel := FSavedState.JetFuel;
5680 FCurrWeap := FSavedState.CurrWeap;
5681 FNextWeap := FSavedState.NextWeap;
5682 FNextWeapDelay := FSavedState.NextWeapDelay;
5684 for i := 0 to 3 do
5685 FAmmo[i] := FSavedState.Ammo[i];
5686 for i := 0 to 3 do
5687 FMaxAmmo[i] := FSavedState.MaxAmmo[i];
5689 FRulez := FSavedState.Rulez;
5690 FSavedState.WaitRecall := False;
5692 if gGameSettings.GameType = GT_SERVER then
5693 MH_SEND_PlayerStats(FUID);
5694 end;
5696 procedure TPlayer.SaveState(var Mem: TBinMemoryWriter);
5697 var
5698 i: Integer;
5699 sig: DWORD;
5700 str: String;
5701 b: Byte;
5702 begin
5703 if FIamBot then
5704 i := 512
5705 else
5706 i := 256;
5708 Mem := TBinMemoryWriter.Create(i);
5710 // Ñèãíàòóðà èãðîêà:
5711 sig := PLAYER_SIGNATURE; // 'PLYR'
5712 Mem.WriteDWORD(sig);
5713 // Áîò èëè ÷åëîâåê:
5714 Mem.WriteBoolean(FIamBot);
5715 // UID èãðîêà:
5716 Mem.WriteWord(FUID);
5717 // Èìÿ èãðîêà:
5718 Mem.WriteString(FName, 32);
5719 // Êîìàíäà:
5720 Mem.WriteByte(FTeam);
5721 // Æèâ ëè:
5722 Mem.WriteBoolean(FLive);
5723 // Èçðàñõîäîâàë ëè âñå æèçíè:
5724 Mem.WriteBoolean(FNoRespawn);
5725 // Íàïðàâëåíèå:
5726 if FDirection = D_LEFT then
5727 b := 1
5728 else // D_RIGHT
5729 b := 2;
5730 Mem.WriteByte(b);
5731 // Çäîðîâüå:
5732 Mem.WriteInt(FHealth);
5733 // Æèçíè:
5734 Mem.WriteByte(FLives);
5735 // Áðîíÿ:
5736 Mem.WriteInt(FArmor);
5737 // Çàïàñ âîçäóõà:
5738 Mem.WriteInt(FAir);
5739 // Çàïàñ ãîðþ÷åãî:
5740 Mem.WriteInt(FJetFuel);
5741 // Áîëü:
5742 Mem.WriteInt(FPain);
5743 // Óáèë:
5744 Mem.WriteInt(FKills);
5745 // Óáèë ìîíñòðîâ:
5746 Mem.WriteInt(FMonsterKills);
5747 // Ôðàãîâ:
5748 Mem.WriteInt(FFrags);
5749 // Ôðàãîâ ïîäðÿä:
5750 Mem.WriteByte(FFragCombo);
5751 // Âðåìÿ ïîñëåäíåãî ôðàãà:
5752 Mem.WriteDWORD(FLastFrag);
5753 // Ñìåðòåé:
5754 Mem.WriteInt(FDeath);
5755 // Êàêîé ôëàã íåñåò:
5756 Mem.WriteByte(FFlag);
5757 // Íàøåë ñåêðåòîâ:
5758 Mem.WriteInt(FSecrets);
5759 // Òåêóùåå îðóæèå:
5760 Mem.WriteByte(FCurrWeap);
5761 // Æåëàåìîå îðóæèå:
5762 Mem.WriteWord(FNextWeap);
5763 // ...è ïàóçà
5764 Mem.WriteByte(FNextWeapDelay);
5765 // Âðåìÿ çàðÿäêè BFG:
5766 Mem.WriteSmallInt(FBFGFireCounter);
5767 // Áóôåð óðîíà:
5768 Mem.WriteInt(FDamageBuffer);
5769 // Ïîñëåäíèé óäàðèâøèé:
5770 Mem.WriteWord(FLastSpawnerUID);
5771 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
5772 Mem.WriteByte(FLastHit);
5773 // Îáúåêò èãðîêà:
5774 Obj_SaveState(@FObj, Mem);
5775 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
5776 for i := A_BULLETS to A_HIGH do
5777 Mem.WriteWord(FAmmo[i]);
5778 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
5779 for i := A_BULLETS to A_HIGH do
5780 Mem.WriteWord(FMaxAmmo[i]);
5781 // Íàëè÷èå îðóæèÿ:
5782 for i := WP_FIRST to WP_LAST do
5783 Mem.WriteBoolean(FWeapon[i]);
5784 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
5785 for i := WP_FIRST to WP_LAST do
5786 Mem.WriteWord(FReloading[i]);
5787 // Íàëè÷èå ðþêçàêà:
5788 if R_ITEM_BACKPACK in FRulez then
5789 b := 1
5790 else
5791 b := 0;
5792 Mem.WriteByte(b);
5793 // Íàëè÷èå êðàñíîãî êëþ÷à:
5794 if R_KEY_RED in FRulez then
5795 b := 1
5796 else
5797 b := 0;
5798 Mem.WriteByte(b);
5799 // Íàëè÷èå çåëåíîãî êëþ÷à:
5800 if R_KEY_GREEN in FRulez then
5801 b := 1
5802 else
5803 b := 0;
5804 Mem.WriteByte(b);
5805 // Íàëè÷èå ñèíåãî êëþ÷à:
5806 if R_KEY_BLUE in FRulez then
5807 b := 1
5808 else
5809 b := 0;
5810 Mem.WriteByte(b);
5811 // Íàëè÷èå áåðñåðêà:
5812 if R_BERSERK in FRulez then
5813 b := 1
5814 else
5815 b := 0;
5816 Mem.WriteByte(b);
5817 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
5818 for i := MR_SUIT to MR_MAX do
5819 Mem.WriteDWORD(FMegaRulez[i]);
5820 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
5821 for i := T_RESPAWN to T_FLAGCAP do
5822 Mem.WriteDWORD(FTime[i]);
5823 // Íàçâàíèå ìîäåëè:
5824 str := FModel.Name;
5825 Mem.WriteString(str);
5826 // Öâåò ìîäåëè:
5827 b := FColor.R;
5828 Mem.WriteByte(b);
5829 b := FColor.G;
5830 Mem.WriteByte(b);
5831 b := FColor.B;
5832 Mem.WriteByte(b);
5833 end;
5835 procedure TPlayer.LoadState(var Mem: TBinMemoryReader);
5836 var
5837 i: Integer;
5838 sig: DWORD;
5839 str: String;
5840 b: Byte;
5841 begin
5842 if Mem = nil then
5843 Exit;
5845 // Ñèãíàòóðà èãðîêà:
5846 Mem.ReadDWORD(sig);
5847 if sig <> PLAYER_SIGNATURE then // 'PLYR'
5848 begin
5849 raise EBinSizeError.Create('TPlayer.LoadState: Wrong Player Signature');
5850 end;
5851 // Áîò èëè ÷åëîâåê:
5852 Mem.ReadBoolean(FIamBot);
5853 // UID èãðîêà:
5854 Mem.ReadWord(FUID);
5855 // Èìÿ èãðîêà:
5856 Mem.ReadString(str);
5857 if (Self <> gPlayer1) and (Self <> gPlayer2) then
5858 FName := str;
5859 // Êîìàíäà:
5860 Mem.ReadByte(FTeam);
5861 // Æèâ ëè:
5862 Mem.ReadBoolean(FLive);
5863 // Èçðàñõîäîâàë ëè âñå æèçíè:
5864 Mem.ReadBoolean(FNoRespawn);
5865 // Íàïðàâëåíèå:
5866 Mem.ReadByte(b);
5867 if b = 1 then
5868 FDirection := D_LEFT
5869 else // b = 2
5870 FDirection := D_RIGHT;
5871 // Çäîðîâüå:
5872 Mem.ReadInt(FHealth);
5873 // Æèçíè:
5874 Mem.ReadByte(FLives);
5875 // Áðîíÿ:
5876 Mem.ReadInt(FArmor);
5877 // Çàïàñ âîçäóõà:
5878 Mem.ReadInt(FAir);
5879 // Çàïàñ ãîðþ÷åãî:
5880 Mem.ReadInt(FJetFuel);
5881 // Áîëü:
5882 Mem.ReadInt(FPain);
5883 // Óáèë:
5884 Mem.ReadInt(FKills);
5885 // Óáèë ìîíñòðîâ:
5886 Mem.ReadInt(FMonsterKills);
5887 // Ôðàãîâ:
5888 Mem.ReadInt(FFrags);
5889 // Ôðàãîâ ïîäðÿä:
5890 Mem.ReadByte(FFragCombo);
5891 // Âðåìÿ ïîñëåäíåãî ôðàãà:
5892 Mem.ReadDWORD(FLastFrag);
5893 // Ñìåðòåé:
5894 Mem.ReadInt(FDeath);
5895 // Êàêîé ôëàã íåñåò:
5896 Mem.ReadByte(FFlag);
5897 // Íàøåë ñåêðåòîâ:
5898 Mem.ReadInt(FSecrets);
5899 // Òåêóùåå îðóæèå:
5900 Mem.ReadByte(FCurrWeap);
5901 // Æåëàåìîå îðóæèå:
5902 Mem.ReadWord(FNextWeap);
5903 // ...è ïàóçà
5904 Mem.ReadByte(FNextWeapDelay);
5905 // Âðåìÿ çàðÿäêè BFG:
5906 Mem.ReadSmallInt(FBFGFireCounter);
5907 // Áóôåð óðîíà:
5908 Mem.ReadInt(FDamageBuffer);
5909 // Ïîñëåäíèé óäàðèâøèé:
5910 Mem.ReadWord(FLastSpawnerUID);
5911 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
5912 Mem.ReadByte(FLastHit);
5913 // Îáúåêò èãðîêà:
5914 Obj_LoadState(@FObj, Mem);
5915 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
5916 for i := A_BULLETS to A_HIGH do
5917 Mem.ReadWord(FAmmo[i]);
5918 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
5919 for i := A_BULLETS to A_HIGH do
5920 Mem.ReadWord(FMaxAmmo[i]);
5921 // Íàëè÷èå îðóæèÿ:
5922 for i := WP_FIRST to WP_LAST do
5923 Mem.ReadBoolean(FWeapon[i]);
5924 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
5925 for i := WP_FIRST to WP_LAST do
5926 Mem.ReadWord(FReloading[i]);
5927 // Íàëè÷èå ðþêçàêà:
5928 Mem.ReadByte(b);
5929 if b = 1 then
5930 Include(FRulez, R_ITEM_BACKPACK);
5931 // Íàëè÷èå êðàñíîãî êëþ÷à:
5932 Mem.ReadByte(b);
5933 if b = 1 then
5934 Include(FRulez, R_KEY_RED);
5935 // Íàëè÷èå çåëåíîãî êëþ÷à:
5936 Mem.ReadByte(b);
5937 if b = 1 then
5938 Include(FRulez, R_KEY_GREEN);
5939 // Íàëè÷èå ñèíåãî êëþ÷à:
5940 Mem.ReadByte(b);
5941 if b = 1 then
5942 Include(FRulez, R_KEY_BLUE);
5943 // Íàëè÷èå áåðñåðêà:
5944 Mem.ReadByte(b);
5945 if b = 1 then
5946 Include(FRulez, R_BERSERK);
5947 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
5948 for i := MR_SUIT to MR_MAX do
5949 Mem.ReadDWORD(FMegaRulez[i]);
5950 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
5951 for i := T_RESPAWN to T_FLAGCAP do
5952 Mem.ReadDWORD(FTime[i]);
5953 // Íàçâàíèå ìîäåëè:
5954 Mem.ReadString(str);
5955 // Öâåò ìîäåëè:
5956 Mem.ReadByte(FColor.R);
5957 Mem.ReadByte(FColor.G);
5958 Mem.ReadByte(FColor.B);
5959 if Self = gPlayer1 then
5960 begin
5961 str := gPlayer1Settings.Model;
5962 FColor := gPlayer1Settings.Color;
5963 end;
5964 if Self = gPlayer2 then
5965 begin
5966 str := gPlayer2Settings.Model;
5967 FColor := gPlayer2Settings.Color;
5968 end;
5969 // Îáíîâëÿåì ìîäåëü èãðîêà:
5970 SetModel(str);
5971 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
5972 FModel.Color := TEAMCOLOR[FTeam]
5973 else
5974 FModel.Color := FColor;
5975 end;
5977 procedure TPlayer.AllRulez(Health: Boolean);
5978 var
5979 a: Integer;
5980 begin
5981 if Health then
5982 begin
5983 FHealth := PLAYER_HP_LIMIT;
5984 FArmor := PLAYER_AP_LIMIT;
5985 Exit;
5986 end;
5988 for a := WP_FIRST to WP_LAST do FWeapon[a] := True;
5989 for a := A_BULLETS to A_HIGH do FAmmo[a] := 30000;
5990 FRulez := FRulez+[R_KEY_RED, R_KEY_GREEN, R_KEY_BLUE];
5991 end;
5993 procedure TPlayer.RestoreHealthArmor();
5994 begin
5995 FHealth := PLAYER_HP_LIMIT;
5996 FArmor := PLAYER_AP_LIMIT;
5997 end;
5999 procedure TPlayer.FragCombo();
6000 var
6001 Param: Integer;
6002 begin
6003 if (gGameSettings.GameMode in [GM_COOP, GM_SINGLE]) or g_Game_IsClient then
6004 Exit;
6005 if gTime - FLastFrag < FRAG_COMBO_TIME then
6006 begin
6007 if FFragCombo < 5 then
6008 Inc(FFragCombo);
6009 Param := FUID or (FFragCombo shl 16);
6010 if (FComboEvnt >= Low(gDelayedEvents)) and
6011 (FComboEvnt <= High(gDelayedEvents)) and
6012 gDelayedEvents[FComboEvnt].Pending and
6013 (gDelayedEvents[FComboEvnt].DEType = DE_KILLCOMBO) and
6014 (gDelayedEvents[FComboEvnt].DENum and $FFFF = FUID) then
6015 begin
6016 gDelayedEvents[FComboEvnt].Time := gTime + 500;
6017 gDelayedEvents[FComboEvnt].DENum := Param;
6018 end
6019 else
6020 FComboEvnt := g_Game_DelayEvent(DE_KILLCOMBO, 500, Param);
6021 end
6022 else
6023 FFragCombo := 1;
6025 FLastFrag := gTime;
6026 end;
6028 procedure TPlayer.GiveItem(ItemType: Byte);
6029 begin
6030 case ItemType of
6031 ITEM_SUIT:
6032 if FMegaRulez[MR_SUIT] < gTime+PLAYER_SUIT_TIME then
6033 begin
6034 FMegaRulez[MR_SUIT] := gTime+PLAYER_SUIT_TIME;
6035 end;
6037 ITEM_OXYGEN:
6038 if FAir < AIR_MAX then
6039 begin
6040 FAir := AIR_MAX;
6041 end;
6043 ITEM_MEDKIT_BLACK:
6044 begin
6045 if not (R_BERSERK in FRulez) then
6046 begin
6047 Include(FRulez, R_BERSERK);
6048 if FBFGFireCounter < 1 then
6049 begin
6050 FCurrWeap := WEAPON_KASTET;
6051 resetWeaponQueue();
6052 FModel.SetWeapon(WEAPON_KASTET);
6053 end;
6054 if gFlash <> 0 then
6055 Inc(FPain, 100);
6056 FBerserk := gTime+30000;
6057 end;
6058 if FHealth < PLAYER_HP_SOFT then
6059 begin
6060 FHealth := PLAYER_HP_SOFT;
6061 FBerserk := gTime+30000;
6062 end;
6063 end;
6065 ITEM_INVUL:
6066 if FMegaRulez[MR_INVUL] < gTime+PLAYER_INVUL_TIME then
6067 begin
6068 FMegaRulez[MR_INVUL] := gTime+PLAYER_INVUL_TIME;
6069 end;
6071 ITEM_INVIS:
6072 if FMegaRulez[MR_INVIS] < gTime+PLAYER_INVIS_TIME then
6073 begin
6074 FMegaRulez[MR_INVIS] := gTime+PLAYER_INVIS_TIME;
6075 end;
6077 ITEM_JETPACK:
6078 if FJetFuel < JET_MAX then
6079 begin
6080 FJetFuel := JET_MAX;
6081 end;
6083 ITEM_MEDKIT_SMALL: if FHealth < PLAYER_HP_SOFT then IncMax(FHealth, 10, PLAYER_HP_SOFT);
6084 ITEM_MEDKIT_LARGE: if FHealth < PLAYER_HP_SOFT then IncMax(FHealth, 25, PLAYER_HP_SOFT);
6086 ITEM_ARMOR_GREEN: if FArmor < PLAYER_AP_SOFT then FArmor := PLAYER_AP_SOFT;
6087 ITEM_ARMOR_BLUE: if FArmor < PLAYER_AP_LIMIT then FArmor := PLAYER_AP_LIMIT;
6089 ITEM_SPHERE_BLUE: if FHealth < PLAYER_HP_LIMIT then IncMax(FHealth, 100, PLAYER_HP_LIMIT);
6090 ITEM_SPHERE_WHITE:
6091 if (FHealth < PLAYER_HP_LIMIT) or (FArmor < PLAYER_AP_LIMIT) then
6092 begin
6093 if FHealth < PLAYER_HP_LIMIT then FHealth := PLAYER_HP_LIMIT;
6094 if FArmor < PLAYER_AP_LIMIT then FArmor := PLAYER_AP_LIMIT;
6095 end;
6097 ITEM_WEAPON_SAW: FWeapon[WEAPON_SAW] := True;
6098 ITEM_WEAPON_SHOTGUN1: FWeapon[WEAPON_SHOTGUN1] := True;
6099 ITEM_WEAPON_SHOTGUN2: FWeapon[WEAPON_SHOTGUN2] := True;
6100 ITEM_WEAPON_CHAINGUN: FWeapon[WEAPON_CHAINGUN] := True;
6101 ITEM_WEAPON_ROCKETLAUNCHER: FWeapon[WEAPON_ROCKETLAUNCHER] := True;
6102 ITEM_WEAPON_PLASMA: FWeapon[WEAPON_PLASMA] := True;
6103 ITEM_WEAPON_BFG: FWeapon[WEAPON_BFG] := True;
6104 ITEM_WEAPON_SUPERPULEMET: FWeapon[WEAPON_SUPERPULEMET] := True;
6105 ITEM_WEAPON_FLAMETHROWER: FWeapon[WEAPON_FLAMETHROWER] := True;
6107 ITEM_AMMO_BULLETS: if FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS] then IncMax(FAmmo[A_BULLETS], 10, FMaxAmmo[A_BULLETS]);
6108 ITEM_AMMO_BULLETS_BOX: if FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS] then IncMax(FAmmo[A_BULLETS], 50, FMaxAmmo[A_BULLETS]);
6109 ITEM_AMMO_SHELLS: if FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS] then IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
6110 ITEM_AMMO_SHELLS_BOX: if FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS] then IncMax(FAmmo[A_SHELLS], 25, FMaxAmmo[A_SHELLS]);
6111 ITEM_AMMO_ROCKET: if FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS] then IncMax(FAmmo[A_ROCKETS], 1, FMaxAmmo[A_ROCKETS]);
6112 ITEM_AMMO_ROCKET_BOX: if FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS] then IncMax(FAmmo[A_ROCKETS], 5, FMaxAmmo[A_ROCKETS]);
6113 ITEM_AMMO_CELL: if FAmmo[A_CELLS] < FMaxAmmo[A_CELLS] then IncMax(FAmmo[A_CELLS], 40, FMaxAmmo[A_CELLS]);
6114 ITEM_AMMO_CELL_BIG: if FAmmo[A_CELLS] < FMaxAmmo[A_CELLS] then IncMax(FAmmo[A_CELLS], 100, FMaxAmmo[A_CELLS]);
6115 ITEM_AMMO_FUELCAN: if FAmmo[A_FUEL] < FMaxAmmo[A_FUEL] then IncMax(FAmmo[A_FUEL], 100, FMaxAmmo[A_FUEL]);
6117 ITEM_AMMO_BACKPACK:
6118 if (FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS]) or
6119 (FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS]) or
6120 (FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS]) or
6121 (FAmmo[A_CELLS] < FMaxAmmo[A_CELLS]) or
6122 (FMaxAmmo[A_FUEL] < AmmoLimits[1, A_FUEL]) then
6123 begin
6124 FMaxAmmo[A_BULLETS] := AmmoLimits[1, A_BULLETS];
6125 FMaxAmmo[A_SHELLS] := AmmoLimits[1, A_SHELLS];
6126 FMaxAmmo[A_ROCKETS] := AmmoLimits[1, A_ROCKETS];
6127 FMaxAmmo[A_CELLS] := AmmoLimits[1, A_CELLS];
6128 FMaxAmmo[A_FUEL] := AmmoLimits[1, A_FUEL];
6130 if FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS] then IncMax(FAmmo[A_BULLETS], 10, FMaxAmmo[A_BULLETS]);
6131 if FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS] then IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
6132 if FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS] then IncMax(FAmmo[A_ROCKETS], 1, FMaxAmmo[A_ROCKETS]);
6133 if FAmmo[A_CELLS] < FMaxAmmo[A_CELLS] then IncMax(FAmmo[A_CELLS], 40, FMaxAmmo[A_CELLS]);
6135 FRulez := FRulez + [R_ITEM_BACKPACK];
6136 end;
6138 ITEM_KEY_RED: if not (R_KEY_RED in FRulez) then Include(FRulez, R_KEY_RED);
6139 ITEM_KEY_GREEN: if not (R_KEY_GREEN in FRulez) then Include(FRulez, R_KEY_GREEN);
6140 ITEM_KEY_BLUE: if not (R_KEY_BLUE in FRulez) then Include(FRulez, R_KEY_BLUE);
6142 ITEM_BOTTLE: if FHealth < PLAYER_HP_LIMIT then IncMax(FHealth, 4, PLAYER_HP_LIMIT);
6143 ITEM_HELMET: if FArmor < PLAYER_AP_LIMIT then IncMax(FArmor, 5, PLAYER_AP_LIMIT);
6145 else
6146 Exit;
6147 end;
6148 if g_Game_IsNet and g_Game_IsServer then
6149 MH_SEND_PlayerStats(FUID);
6150 end;
6152 procedure TPlayer.FlySmoke(Times: DWORD = 1);
6153 var
6154 id, i: DWORD;
6155 Anim: TAnimation;
6156 begin
6157 if (Random(5) = 1) and (Times = 1) then
6158 Exit;
6160 if BodyInLiquid(0, 0) then
6161 begin
6162 g_GFX_Bubbles(Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2)+Random(3)-1,
6163 Obj.Y+Obj.Rect.Height+8, 1, 8, 4);
6164 if Random(2) = 0 then
6165 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj.X, FObj.Y)
6166 else
6167 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj.X, FObj.Y);
6168 Exit;
6169 end;
6171 if g_Frames_Get(id, 'FRAMES_SMOKE') then
6172 begin
6173 for i := 1 to Times do
6174 begin
6175 Anim := TAnimation.Create(id, False, 3);
6176 Anim.Alpha := 150;
6177 g_GFX_OnceAnim(Obj.X+Obj.Rect.X+Random(Obj.Rect.Width+Times*2)-(Anim.Width div 2),
6178 Obj.Y+Obj.Rect.Height-4+Random(8+Times*2), Anim, ONCEANIM_SMOKE);
6179 Anim.Free();
6180 end;
6181 end;
6182 end;
6184 procedure TPlayer.OnFireFlame(Times: DWORD = 1);
6185 var
6186 id, i: DWORD;
6187 Anim: TAnimation;
6188 begin
6189 if (Random(10) = 1) and (Times = 1) then
6190 Exit;
6192 if g_Frames_Get(id, 'FRAMES_FLAME') then
6193 begin
6194 for i := 1 to Times do
6195 begin
6196 Anim := TAnimation.Create(id, False, 3);
6197 Anim.Alpha := 0;
6198 g_GFX_OnceAnim(Obj.X+Obj.Rect.X+Random(Obj.Rect.Width+Times*2)-(Anim.Width div 2),
6199 Obj.Y+8+Random(8+Times*2), Anim, ONCEANIM_SMOKE);
6200 Anim.Free();
6201 end;
6202 end;
6203 end;
6205 procedure TPlayer.PauseSounds(Enable: Boolean);
6206 begin
6207 FSawSound.Pause(Enable);
6208 FSawSoundIdle.Pause(Enable);
6209 FSawSoundHit.Pause(Enable);
6210 FSawSoundSelect.Pause(Enable);
6211 end;
6213 { T C o r p s e : }
6215 constructor TCorpse.Create(X, Y: Integer; ModelName: String; aMess: Boolean);
6216 begin
6217 g_Obj_Init(@FObj);
6218 FObj.X := X;
6219 FObj.Y := Y;
6220 FObj.Rect := PLAYER_CORPSERECT;
6221 FModelName := ModelName;
6222 FMess := aMess;
6224 if FMess then
6225 begin
6226 FState := CORPSE_STATE_MESS;
6227 g_PlayerModel_GetAnim(ModelName, A_DIE2, FAnimation, FAnimationMask);
6228 end
6229 else
6230 begin
6231 FState := CORPSE_STATE_NORMAL;
6232 g_PlayerModel_GetAnim(ModelName, A_DIE1, FAnimation, FAnimationMask);
6233 end;
6234 end;
6236 destructor TCorpse.Destroy();
6237 begin
6238 FAnimation.Free();
6240 inherited;
6241 end;
6243 procedure TCorpse.positionChanged (); begin end;
6245 procedure TCorpse.Damage(Value: Word; vx, vy: Integer);
6246 var
6247 pm: TPlayerModel;
6248 begin
6249 if FState = CORPSE_STATE_REMOVEME then
6250 Exit;
6252 FDamage := FDamage + Value;
6254 if FDamage > 150 then
6255 begin
6256 if FAnimation <> nil then
6257 begin
6258 FAnimation.Free();
6259 FAnimation := nil;
6261 FState := CORPSE_STATE_REMOVEME;
6263 g_Player_CreateGibs(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
6264 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
6265 FModelName, FColor);
6266 // Çâóê ìÿñà îò òðóïà:
6267 pm := g_PlayerModel_Get(FModelName);
6268 pm.PlaySound(MODELSOUND_DIE, 5, FObj.X, FObj.Y);
6269 pm.Free;
6270 end;
6271 end
6272 else
6273 begin
6274 FObj.Vel.X := FObj.Vel.X + vx;
6275 FObj.Vel.Y := FObj.Vel.Y + vy;
6276 g_GFX_Blood(FObj.X+PLAYER_CORPSERECT.X+(PLAYER_CORPSERECT.Width div 2),
6277 FObj.Y+PLAYER_CORPSERECT.Y+(PLAYER_CORPSERECT.Height div 2),
6278 Value, vx, vy, 16, (PLAYER_CORPSERECT.Height*2) div 3,
6279 150, 0, 0);
6280 end;
6281 end;
6283 procedure TCorpse.Draw();
6284 begin
6285 if FState = CORPSE_STATE_REMOVEME then
6286 Exit;
6288 if FAnimation <> nil then
6289 FAnimation.Draw(FObj.X, FObj.Y, M_NONE);
6291 if FAnimationMask <> nil then
6292 begin
6293 e_Colors := FColor;
6294 FAnimationMask.Draw(FObj.X, FObj.Y, M_NONE);
6295 e_Colors.R := 255;
6296 e_Colors.G := 255;
6297 e_Colors.B := 255;
6298 end;
6299 end;
6301 procedure TCorpse.Update();
6302 var
6303 st: Word;
6304 begin
6305 if FState = CORPSE_STATE_REMOVEME then
6306 Exit;
6308 if gTime mod (GAME_TICK*2) <> 0 then
6309 begin
6310 g_Obj_Move(@FObj, True, True, True);
6311 positionChanged(); // this updates spatial accelerators
6312 Exit;
6313 end;
6315 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6316 FObj.Vel.X := z_dec(FObj.Vel.X, 1);
6318 st := g_Obj_Move(@FObj, True, True, True);
6319 positionChanged(); // this updates spatial accelerators
6321 if WordBool(st and MOVE_FALLOUT) then
6322 begin
6323 FState := CORPSE_STATE_REMOVEME;
6324 Exit;
6325 end;
6327 if FAnimation <> nil then
6328 FAnimation.Update();
6329 if FAnimationMask <> nil then
6330 FAnimationMask.Update();
6331 end;
6333 procedure TCorpse.SaveState(var Mem: TBinMemoryWriter);
6334 var
6335 sig: DWORD;
6336 anim: Boolean;
6337 begin
6338 if Mem = nil then
6339 Exit;
6341 // Ñèãíàòóðà òðóïà:
6342 sig := CORPSE_SIGNATURE; // 'CORP'
6343 Mem.WriteDWORD(sig);
6344 // Ñîñòîÿíèå:
6345 Mem.WriteByte(FState);
6346 // Íàêîïëåííûé óðîí:
6347 Mem.WriteByte(FDamage);
6348 // Öâåò:
6349 Mem.WriteByte(FColor.R);
6350 Mem.WriteByte(FColor.G);
6351 Mem.WriteByte(FColor.B);
6352 // Îáúåêò òðóïà:
6353 Obj_SaveState(@FObj, Mem);
6354 // Åñòü ëè àíèìàöèÿ:
6355 anim := FAnimation <> nil;
6356 Mem.WriteBoolean(anim);
6357 // Åñëè åñòü - ñîõðàíÿåì:
6358 if anim then
6359 FAnimation.SaveState(Mem);
6360 // Åñòü ëè ìàñêà àíèìàöèè:
6361 anim := FAnimationMask <> nil;
6362 Mem.WriteBoolean(anim);
6363 // Åñëè åñòü - ñîõðàíÿåì:
6364 if anim then
6365 FAnimationMask.SaveState(Mem);
6366 end;
6368 procedure TCorpse.LoadState(var Mem: TBinMemoryReader);
6369 var
6370 sig: DWORD;
6371 anim: Boolean;
6372 begin
6373 if Mem = nil then
6374 Exit;
6376 // Ñèãíàòóðà òðóïà:
6377 Mem.ReadDWORD(sig);
6378 if sig <> CORPSE_SIGNATURE then // 'CORP'
6379 begin
6380 raise EBinSizeError.Create('TCorpse.LoadState: Wrong Corpse Signature');
6381 end;
6382 // Ñîñòîÿíèå:
6383 Mem.ReadByte(FState);
6384 // Íàêîïëåííûé óðîí:
6385 Mem.ReadByte(FDamage);
6386 // Öâåò:
6387 Mem.ReadByte(FColor.R);
6388 Mem.ReadByte(FColor.G);
6389 Mem.ReadByte(FColor.B);
6390 // Îáúåêò òðóïà:
6391 Obj_LoadState(@FObj, Mem);
6392 // Åñòü ëè àíèìàöèÿ:
6393 Mem.ReadBoolean(anim);
6394 // Åñëè åñòü - çàãðóæàåì:
6395 if anim then
6396 begin
6397 Assert(FAnimation <> nil, 'TCorpse.LoadState: no FAnimation');
6398 FAnimation.LoadState(Mem);
6399 end;
6400 // Åñòü ëè ìàñêà àíèìàöèè:
6401 Mem.ReadBoolean(anim);
6402 // Åñëè åñòü - çàãðóæàåì:
6403 if anim then
6404 begin
6405 Assert(FAnimationMask <> nil, 'TCorpse.LoadState: no FAnimationMask');
6406 FAnimationMask.LoadState(Mem);
6407 end;
6408 end;
6410 { T B o t : }
6412 constructor TBot.Create();
6413 var
6414 a: Integer;
6415 begin
6416 inherited Create();
6418 FPhysics := True;
6419 FSpectator := False;
6420 FGhost := False;
6422 FIamBot := True;
6424 Inc(gNumBots);
6426 for a := WP_FIRST to WP_LAST do
6427 begin
6428 FDifficult.WeaponPrior[a] := WEAPON_PRIOR1[a];
6429 FDifficult.CloseWeaponPrior[a] := WEAPON_PRIOR2[a];
6430 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6431 end;
6432 end;
6434 destructor TBot.Destroy();
6435 begin
6436 Dec(gNumBots);
6437 inherited Destroy();
6438 end;
6440 procedure TBot.Draw();
6441 begin
6442 inherited Draw();
6444 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6445 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6446 end;
6448 procedure TBot.Respawn(Silent: Boolean; Force: Boolean = False);
6449 begin
6450 inherited Respawn(Silent, Force);
6452 FAIFlags := nil;
6453 FSelectedWeapon := FCurrWeap;
6454 resetWeaponQueue();
6455 FTargetUID := 0;
6456 end;
6458 procedure TBot.UpdateCombat();
6459 type
6460 TTarget = record
6461 UID: Word;
6462 X, Y: Integer;
6463 Rect: TRectWH;
6464 cX, cY: Integer;
6465 Dist: Word;
6466 Line: Boolean;
6467 Visible: Boolean;
6468 IsPlayer: Boolean;
6469 end;
6471 TTargetRecord = array of TTarget;
6473 function Compare(a, b: TTarget): Integer;
6474 begin
6475 if a.Line and not b.Line then // A íà ëèíèè îãíÿ
6476 Result := -1
6477 else
6478 if not a.Line and b.Line then // B íà ëèíèè îãíÿ
6479 Result := 1
6480 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6481 if (a.Line and b.Line) or ((not a.Line) and (not b.Line)) then
6482 begin
6483 if a.Dist > b.Dist then // B áëèæå
6484 Result := 1
6485 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6486 Result := -1;
6487 end
6488 else // Ñòðàííî -> A
6489 Result := -1;
6490 end;
6492 var
6493 a, x1, y1, x2, y2: Integer;
6494 targets: TTargetRecord;
6495 ammo: Word;
6496 Target, BestTarget: TTarget;
6497 firew, fireh: Integer;
6498 angle: SmallInt;
6499 mon: TMonster;
6500 pla, tpla: TPlayer;
6501 vsPlayer, vsMonster, ok: Boolean;
6504 function monsUpdate (mon: TMonster): Boolean;
6505 begin
6506 result := false; // don't stop
6507 if mon.Live and (mon.MonsterType <> MONSTER_BARREL) then
6508 begin
6509 if not TargetOnScreen(mon.Obj.X+mon.Obj.Rect.X, mon.Obj.Y+mon.Obj.Rect.Y) then exit;
6511 x2 := mon.Obj.X+mon.Obj.Rect.X+(mon.Obj.Rect.Width div 2);
6512 y2 := mon.Obj.Y+mon.Obj.Rect.Y+(mon.Obj.Rect.Height div 2);
6514 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6515 if g_TraceVector(x1, y1, x2, y2) then
6516 begin
6517 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6518 SetLength(targets, Length(targets)+1);
6519 with targets[High(targets)] do
6520 begin
6521 UID := mon.UID;
6522 X := mon.Obj.X;
6523 Y := mon.Obj.Y;
6524 cX := x2;
6525 cY := y2;
6526 Rect := mon.Obj.Rect;
6527 Dist := g_PatchLength(x1, y1, x2, y2);
6528 Line := (y1+4 < Target.Y + mon.Obj.Rect.Y + mon.Obj.Rect.Height) and
6529 (y1-4 > Target.Y + mon.Obj.Rect.Y);
6530 Visible := True;
6531 IsPlayer := False;
6532 end;
6533 end;
6534 end;
6535 end;
6537 begin
6538 vsPlayer := LongBool(gGameSettings.Options and GAME_OPTION_BOTVSPLAYER);
6539 vsMonster := LongBool(gGameSettings.Options and GAME_OPTION_BOTVSMONSTER);
6541 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6542 if FCurrWeap <> FSelectedWeapon then
6543 NextWeapon();
6545 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6546 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap = FSelectedWeapon) then
6547 begin
6548 RemoveAIFlag('NEEDFIRE');
6550 case FCurrWeap of
6551 WEAPON_PLASMA, WEAPON_SUPERPULEMET, WEAPON_CHAINGUN: PressKey(KEY_FIRE, 20);
6552 WEAPON_SAW, WEAPON_KASTET, WEAPON_FLAMETHROWER: PressKey(KEY_FIRE, 40);
6553 else PressKey(KEY_FIRE);
6554 end;
6555 end;
6557 // Êîîðäèíàòû ñòâîëà:
6558 x1 := FObj.X + WEAPONPOINT[FDirection].X;
6559 y1 := FObj.Y + WEAPONPOINT[FDirection].Y;
6561 Target.UID := FTargetUID;
6563 ok := False;
6564 if Target.UID <> 0 then
6565 begin // Öåëü åñòü - íàñòðàèâàåì
6566 if (g_GetUIDType(Target.UID) = UID_PLAYER) and
6567 vsPlayer then
6568 begin // Èãðîê
6569 tpla := g_Player_Get(Target.UID);
6570 if tpla <> nil then
6571 with tpla do
6572 begin
6573 if (@FObj) <> nil then
6574 begin
6575 Target.X := FObj.X;
6576 Target.Y := FObj.Y;
6577 end;
6578 end;
6580 Target.cX := Target.X + PLAYER_RECT_CX;
6581 Target.cY := Target.Y + PLAYER_RECT_CY;
6582 Target.Rect := PLAYER_RECT;
6583 Target.Visible := g_TraceVector(x1, y1, Target.cX, Target.cY);
6584 Target.Line := (y1+4 < Target.Y+PLAYER_RECT.Y+PLAYER_RECT.Height) and
6585 (y1-4 > Target.Y+PLAYER_RECT.Y);
6586 Target.IsPlayer := True;
6587 ok := True;
6588 end
6589 else
6590 if (g_GetUIDType(Target.UID) = UID_MONSTER) and
6591 vsMonster then
6592 begin // Ìîíñòð
6593 mon := g_Monsters_ByUID(Target.UID);
6594 if mon <> nil then
6595 begin
6596 Target.X := mon.Obj.X;
6597 Target.Y := mon.Obj.Y;
6599 Target.cX := Target.X + mon.Obj.Rect.X + (mon.Obj.Rect.Width div 2);
6600 Target.cY := Target.Y + mon.Obj.Rect.Y + (mon.Obj.Rect.Height div 2);
6601 Target.Rect := mon.Obj.Rect;
6602 Target.Visible := g_TraceVector(x1, y1, Target.cX, Target.cY);
6603 Target.Line := (y1+4 < Target.Y + mon.Obj.Rect.Y + mon.Obj.Rect.Height) and
6604 (y1-4 > Target.Y + mon.Obj.Rect.Y);
6605 Target.IsPlayer := False;
6606 ok := True;
6607 end;
6608 end;
6609 end;
6611 if not ok then
6612 begin // Öåëè íåò - îáíóëÿåì
6613 Target.X := 0;
6614 Target.Y := 0;
6615 Target.cX := 0;
6616 Target.cY := 0;
6617 Target.Visible := False;
6618 Target.Line := False;
6619 Target.IsPlayer := False;
6620 end;
6622 targets := nil;
6624 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6625 if (not Target.Line) or (not Target.Visible) then
6626 begin
6627 // Èãðîêè:
6628 if vsPlayer then
6629 for a := 0 to High(gPlayers) do
6630 if (gPlayers[a] <> nil) and (gPlayers[a].Live) and
6631 (gPlayers[a].FUID <> FUID) and
6632 (not SameTeam(FUID, gPlayers[a].FUID)) and
6633 (not gPlayers[a].NoTarget) and
6634 (gPlayers[a].FMegaRulez[MR_INVIS] < gTime) then
6635 begin
6636 if not TargetOnScreen(gPlayers[a].FObj.X + PLAYER_RECT.X,
6637 gPlayers[a].FObj.Y + PLAYER_RECT.Y) then
6638 Continue;
6640 x2 := gPlayers[a].FObj.X + PLAYER_RECT_CX;
6641 y2 := gPlayers[a].FObj.Y + PLAYER_RECT_CY;
6643 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6644 if g_TraceVector(x1, y1, x2, y2) then
6645 begin
6646 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6647 SetLength(targets, Length(targets)+1);
6648 with targets[High(targets)] do
6649 begin
6650 UID := gPlayers[a].FUID;
6651 X := gPlayers[a].FObj.X;
6652 Y := gPlayers[a].FObj.Y;
6653 cX := x2;
6654 cY := y2;
6655 Rect := PLAYER_RECT;
6656 Dist := g_PatchLength(x1, y1, x2, y2);
6657 Line := (y1+4 < Target.Y+PLAYER_RECT.Y+PLAYER_RECT.Height) and
6658 (y1-4 > Target.Y+PLAYER_RECT.Y);
6659 Visible := True;
6660 IsPlayer := True;
6661 end;
6662 end;
6663 end;
6665 // Ìîíñòðû:
6666 if vsMonster then g_Mons_ForEach(monsUpdate);
6667 end;
6669 // Åñëè åñòü âîçìîæíûå öåëè:
6670 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6671 if targets <> nil then
6672 begin
6673 // Âûáèðàåì íàèëó÷øóþ öåëü:
6674 BestTarget := targets[0];
6675 if Length(targets) > 1 then
6676 for a := 1 to High(targets) do
6677 if Compare(BestTarget, targets[a]) = 1 then
6678 BestTarget := targets[a];
6680 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6681 if ((not Target.Visible) and BestTarget.Visible and (Target.UID <> BestTarget.UID)) or
6682 ((not Target.Line) and BestTarget.Line and BestTarget.Visible) then
6683 begin
6684 Target := BestTarget;
6686 if (Healthy() = 3) or ((Healthy() = 2)) then
6687 begin // Åñëè çäîðîâû - äîãîíÿåì
6688 if ((RunDirection() = D_LEFT) and (Target.X > FObj.X)) then
6689 SetAIFlag('GORIGHT', '1');
6690 if ((RunDirection() = D_RIGHT) and (Target.X < FObj.X)) then
6691 SetAIFlag('GOLEFT', '1');
6692 end
6693 else
6694 begin // Åñëè ïîáèòû - óáåãàåì
6695 if ((RunDirection() = D_LEFT) and (Target.X < FObj.X)) then
6696 SetAIFlag('GORIGHT', '1');
6697 if ((RunDirection() = D_RIGHT) and (Target.X > FObj.X)) then
6698 SetAIFlag('GOLEFT', '1');
6699 end;
6701 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6702 SelectWeapon(Abs(x1-Target.cX));
6703 end;
6704 end;
6706 // Åñëè åñòü öåëü:
6707 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6708 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6709 if Target.UID <> 0 then
6710 begin
6711 if not TargetOnScreen(Target.X + Target.Rect.X,
6712 Target.Y + Target.Rect.Y) then
6713 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6714 if (Healthy() = 3) or ((Healthy() = 2)) then
6715 begin // Åñëè çäîðîâû - äîãîíÿåì
6716 if ((RunDirection() = D_LEFT) and (Target.X > FObj.X)) then
6717 SetAIFlag('GORIGHT', '1');
6718 if ((RunDirection() = D_RIGHT) and (Target.X < FObj.X)) then
6719 SetAIFlag('GOLEFT', '1');
6720 end
6721 else
6722 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6723 Target.UID := 0;
6724 if ((RunDirection() = D_LEFT) and (Target.X < FObj.X)) then
6725 SetAIFlag('GORIGHT', '1');
6726 if ((RunDirection() = D_RIGHT) and (Target.X > FObj.X)) then
6727 SetAIFlag('GOLEFT', '1');
6728 end;
6729 end
6730 else
6731 begin // Öåëü ïîêà íà "ýêðàíå"
6732 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
6733 if g_TraceVector(x1, y1, Target.cX, Target.cY) then
6734 FLastVisible := gTime;
6735 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
6736 if (Abs(FObj.Y-Target.Y) <= 128) then
6737 begin
6738 if ((RunDirection() = D_LEFT) and (Target.X > FObj.X)) then
6739 SetAIFlag('GORIGHT', '1');
6740 if ((RunDirection() = D_RIGHT) and (Target.X < FObj.X)) then
6741 SetAIFlag('GOLEFT', '1');
6742 end;
6743 end;
6745 // Âûáèðàåì óãîë ââåðõ:
6746 if FDirection = D_LEFT then
6747 angle := ANGLE_LEFTUP
6748 else
6749 angle := ANGLE_RIGHTUP;
6751 firew := Trunc(Cos(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
6752 fireh := Trunc(Sin(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
6754 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6755 if g_CollideLine(x1, y1, x1+firew, y1+fireh,
6756 Target.X+Target.Rect.X+GetInterval(FDifficult.DiagPrecision, 128), //96
6757 Target.Y+Target.Rect.Y+GetInterval(FDifficult.DiagPrecision, 128),
6758 Target.Rect.Width, Target.Rect.Height) and
6759 g_TraceVector(x1, y1, Target.cX, Target.cY) then
6760 begin // òî íóæíî ñòðåëÿòü ââåðõ
6761 SetAIFlag('NEEDFIRE', '1');
6762 SetAIFlag('NEEDSEEUP', '1');
6763 end;
6765 // Âûáèðàåì óãîë âíèç:
6766 if FDirection = D_LEFT then
6767 angle := ANGLE_LEFTDOWN
6768 else
6769 angle := ANGLE_RIGHTDOWN;
6771 firew := Trunc(Cos(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
6772 fireh := Trunc(Sin(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
6774 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6775 if g_CollideLine(x1, y1, x1+firew, y1+fireh,
6776 Target.X+Target.Rect.X+GetInterval(FDifficult.DiagPrecision, 128),
6777 Target.Y+Target.Rect.Y+GetInterval(FDifficult.DiagPrecision, 128),
6778 Target.Rect.Width, Target.Rect.Height) and
6779 g_TraceVector(x1, y1, Target.cX, Target.cY) then
6780 begin // òî íóæíî ñòðåëÿòü âíèç
6781 SetAIFlag('NEEDFIRE', '1');
6782 SetAIFlag('NEEDSEEDOWN', '1');
6783 end;
6785 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
6786 if Target.Visible and
6787 (y1+4 < Target.Y+Target.Rect.Y+Target.Rect.Height) and
6788 (y1-4 > Target.Y+Target.Rect.Y) then
6789 begin
6790 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
6791 if ((FDirection = D_LEFT) and (Target.X < FObj.X)) or
6792 ((FDirection = D_RIGHT) and (Target.X > FObj.X)) then
6793 begin // òî íóæíî ñòðåëÿòü âïåðåä
6794 SetAIFlag('NEEDFIRE', '1');
6795 SetAIFlag('NEEDSEEDOWN', '');
6796 SetAIFlag('NEEDSEEUP', '');
6797 end;
6798 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
6799 if Abs(FObj.X-Target.X) < Trunc(gPlayerScreenSize.X*0.75) then
6800 if GetRnd(FDifficult.CloseJump) then
6801 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
6802 if Abs(FObj.X-Target.X) < 128 then
6803 a := 4
6804 else
6805 a := 30;
6806 if Random(a) = 0 then
6807 SetAIFlag('NEEDJUMP', '1');
6808 end;
6809 end;
6811 // Åñëè öåëü âñå åùå åñòü:
6812 if Target.UID <> 0 then
6813 if gTime-FLastVisible > 2000 then // Åñëè âèäåëè äàâíî
6814 Target.UID := 0 // òî çàáûòü öåëü
6815 else // Åñëè âèäåëè íåäàâíî
6816 begin // íî öåëü óáèëè
6817 if Target.IsPlayer then
6818 begin // Öåëü - èãðîê
6819 pla := g_Player_Get(Target.UID);
6820 if (pla = nil) or (not pla.Live) or pla.NoTarget or
6821 (pla.FMegaRulez[MR_INVIS] >= gTime) then
6822 Target.UID := 0; // òî çàáûòü öåëü
6823 end
6824 else
6825 begin // Öåëü - ìîíñòð
6826 mon := g_Monsters_ByUID(Target.UID);
6827 if (mon = nil) or (not mon.Live) then
6828 Target.UID := 0; // òî çàáûòü öåëü
6829 end;
6830 end;
6831 end; // if Target.UID <> 0
6833 FTargetUID := Target.UID;
6835 // Åñëè âîçìîæíûõ öåëåé íåò:
6836 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
6837 if targets = nil then
6838 if GetAIFlag('ATTACKLEFT') <> '' then
6839 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
6840 RemoveAIFlag('ATTACKLEFT');
6842 SetAIFlag('NEEDJUMP', '1');
6844 if RunDirection() = D_RIGHT then
6845 begin // Èäåì íå â òó ñòîðîíó
6846 if (Healthy() > 1) and GetRnd(FDifficult.InvisFire) then
6847 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
6848 SetAIFlag('NEEDFIRE', '1');
6849 SetAIFlag('GOLEFT', '1');
6850 end;
6851 end
6852 else
6853 begin // Èäåì â íóæíóþ ñòîðîíó
6854 if GetRnd(FDifficult.InvisFire) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6855 SetAIFlag('NEEDFIRE', '1');
6856 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6857 SetAIFlag('GORIGHT', '1');
6858 end;
6859 end
6860 else
6861 if GetAIFlag('ATTACKRIGHT') <> '' then
6862 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
6863 RemoveAIFlag('ATTACKRIGHT');
6865 SetAIFlag('NEEDJUMP', '1');
6867 if RunDirection() = D_LEFT then
6868 begin // Èäåì íå â òó ñòîðîíó
6869 if (Healthy() > 1) and GetRnd(FDifficult.InvisFire) then
6870 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
6871 SetAIFlag('NEEDFIRE', '1');
6872 SetAIFlag('GORIGHT', '1');
6873 end;
6874 end
6875 else
6876 begin
6877 if GetRnd(FDifficult.InvisFire) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6878 SetAIFlag('NEEDFIRE', '1');
6879 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6880 SetAIFlag('GOLEFT', '1');
6881 end;
6882 end;
6884 //HACK! (does it belongs there?)
6885 RealizeCurrentWeapon();
6887 // Åñëè åñòü âîçìîæíûå öåëè:
6888 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
6889 if (targets <> nil) and (GetAIFlag('NEEDFIRE') <> '') then
6890 for a := 0 to High(targets) do
6891 begin
6892 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
6893 if GetRnd(FDifficult.DiagFire) then
6894 begin
6895 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
6896 if FDirection = D_LEFT then
6897 angle := ANGLE_LEFTUP
6898 else
6899 angle := ANGLE_RIGHTUP;
6901 firew := Trunc(Cos(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
6902 fireh := Trunc(Sin(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
6904 if g_CollideLine(x1, y1, x1+firew, y1+fireh,
6905 targets[a].X+targets[a].Rect.X+GetInterval(FDifficult.DiagPrecision, 128),
6906 targets[a].Y+targets[a].Rect.Y+GetInterval(FDifficult.DiagPrecision, 128),
6907 targets[a].Rect.Width, targets[a].Rect.Height) and
6908 g_TraceVector(x1, y1, targets[a].cX, targets[a].cY) then
6909 begin
6910 SetAIFlag('NEEDFIRE', '1');
6911 SetAIFlag('NEEDSEEUP', '1');
6912 end;
6914 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
6915 if FDirection = D_LEFT then
6916 angle := ANGLE_LEFTDOWN
6917 else
6918 angle := ANGLE_RIGHTDOWN;
6920 firew := Trunc(Cos(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
6921 fireh := Trunc(Sin(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
6923 if g_CollideLine(x1, y1, x1+firew, y1+fireh,
6924 targets[a].X+targets[a].Rect.X+GetInterval(FDifficult.DiagPrecision, 128),
6925 targets[a].Y+targets[a].Rect.Y+GetInterval(FDifficult.DiagPrecision, 128),
6926 targets[a].Rect.Width, targets[a].Rect.Height) and
6927 g_TraceVector(x1, y1, targets[a].cX, targets[a].cY) then
6928 begin
6929 SetAIFlag('NEEDFIRE', '1');
6930 SetAIFlag('NEEDSEEDOWN', '1');
6931 end;
6932 end;
6934 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
6935 if targets[a].Line and targets[a].Visible and
6936 (((FDirection = D_LEFT) and (targets[a].X < FObj.X)) or
6937 ((FDirection = D_RIGHT) and (targets[a].X > FObj.X))) then
6938 begin
6939 SetAIFlag('NEEDFIRE', '1');
6940 Break;
6941 end;
6942 end;
6944 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
6945 if g_Weapon_Danger(FUID, FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y,
6946 PLAYER_RECT.Width, PLAYER_RECT.Height,
6947 40+GetInterval(FDifficult.Cover, 40)) then
6948 SetAIFlag('NEEDJUMP', '1');
6950 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
6951 ammo := GetAmmoByWeapon(FCurrWeap);
6952 if ((FCurrWeap = WEAPON_SHOTGUN2) and (ammo < 2)) or
6953 ((FCurrWeap = WEAPON_BFG) and (ammo < 40)) or
6954 (ammo = 0) then
6955 SetAIFlag('SELECTWEAPON', '1');
6957 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
6958 if GetAIFlag('SELECTWEAPON') = '1' then
6959 begin
6960 SelectWeapon(-1);
6961 RemoveAIFlag('SELECTWEAPON');
6962 end;
6963 end;
6965 procedure TBot.Update();
6966 var
6967 EnableAI: Boolean;
6968 begin
6969 if not FLive then
6970 begin // Respawn
6971 ReleaseKeys();
6972 PressKey(KEY_UP);
6973 end
6974 else
6975 begin
6976 EnableAI := True;
6978 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
6979 if (g_debug_BotAIOff = 1) and (Team = TEAM_RED) then
6980 EnableAI := False;
6981 if (g_debug_BotAIOff = 2) and (Team = TEAM_BLUE) then
6982 EnableAI := False;
6983 if g_debug_BotAIOff = 3 then
6984 EnableAI := False;
6986 if EnableAI then
6987 begin
6988 UpdateMove();
6989 UpdateCombat();
6990 end
6991 else
6992 begin
6993 RealizeCurrentWeapon();
6994 end;
6995 end;
6997 inherited Update();
6998 end;
7000 procedure TBot.ReleaseKey(Key: Byte);
7001 begin
7002 with FKeys[Key] do
7003 begin
7004 Pressed := False;
7005 Time := 0;
7006 end;
7007 end;
7009 function TBot.KeyPressed(Key: Word): Boolean;
7010 begin
7011 Result := FKeys[Key].Pressed;
7012 end;
7014 function TBot.GetAIFlag(aName: String20): String20;
7015 var
7016 a: Integer;
7017 begin
7018 Result := '';
7020 aName := LowerCase(aName);
7022 if FAIFlags <> nil then
7023 for a := 0 to High(FAIFlags) do
7024 if LowerCase(FAIFlags[a].Name) = aName then
7025 begin
7026 Result := FAIFlags[a].Value;
7027 Break;
7028 end;
7029 end;
7031 procedure TBot.RemoveAIFlag(aName: String20);
7032 var
7033 a, b: Integer;
7034 begin
7035 if FAIFlags = nil then Exit;
7037 aName := LowerCase(aName);
7039 for a := 0 to High(FAIFlags) do
7040 if LowerCase(FAIFlags[a].Name) = aName then
7041 begin
7042 if a <> High(FAIFlags) then
7043 for b := a to High(FAIFlags)-1 do
7044 FAIFlags[b] := FAIFlags[b+1];
7046 SetLength(FAIFlags, Length(FAIFlags)-1);
7047 Break;
7048 end;
7049 end;
7051 procedure TBot.SetAIFlag(aName, fValue: String20);
7052 var
7053 a: Integer;
7054 ok: Boolean;
7055 begin
7056 a := 0;
7057 ok := False;
7059 aName := LowerCase(aName);
7061 if FAIFlags <> nil then
7062 for a := 0 to High(FAIFlags) do
7063 if LowerCase(FAIFlags[a].Name) = aName then
7064 begin
7065 ok := True;
7066 Break;
7067 end;
7069 if ok then FAIFlags[a].Value := fValue
7070 else
7071 begin
7072 SetLength(FAIFlags, Length(FAIFlags)+1);
7073 with FAIFlags[High(FAIFlags)] do
7074 begin
7075 Name := aName;
7076 Value := fValue;
7077 end;
7078 end;
7079 end;
7081 procedure TBot.UpdateMove;
7083 procedure GoLeft(Time: Word = 1);
7084 begin
7085 ReleaseKey(KEY_LEFT);
7086 ReleaseKey(KEY_RIGHT);
7087 PressKey(KEY_LEFT, Time);
7088 SetDirection(D_LEFT);
7089 end;
7091 procedure GoRight(Time: Word = 1);
7092 begin
7093 ReleaseKey(KEY_LEFT);
7094 ReleaseKey(KEY_RIGHT);
7095 PressKey(KEY_RIGHT, Time);
7096 SetDirection(D_RIGHT);
7097 end;
7099 function Rnd(a: Word): Boolean;
7100 begin
7101 Result := Random(a) = 0;
7102 end;
7104 procedure Turn(Time: Word = 1200);
7105 begin
7106 if RunDirection() = D_LEFT then GoRight(Time) else GoLeft(Time);
7107 end;
7109 procedure Stop();
7110 begin
7111 ReleaseKey(KEY_LEFT);
7112 ReleaseKey(KEY_RIGHT);
7113 end;
7115 function CanRunLeft(): Boolean;
7116 begin
7117 Result := not CollideLevel(-1, 0);
7118 end;
7120 function CanRunRight(): Boolean;
7121 begin
7122 Result := not CollideLevel(1, 0);
7123 end;
7125 function CanRun(): Boolean;
7126 begin
7127 if RunDirection() = D_LEFT then Result := CanRunLeft() else Result := CanRunRight();
7128 end;
7130 procedure Jump(Time: Word = 30);
7131 begin
7132 PressKey(KEY_JUMP, Time);
7133 end;
7135 function NearHole(): Boolean;
7136 var
7137 x, sx: Integer;
7138 begin
7139 { TODO 5 : Ëåñòíèöû }
7140 sx := IfThen(RunDirection() = D_LEFT, -1, 1);
7141 for x := 1 to PLAYER_RECT.Width do
7142 if (not StayOnStep(x*sx, 0)) and
7143 (not CollideLevel(x*sx, PLAYER_RECT.Height)) and
7144 (not CollideLevel(x*sx, PLAYER_RECT.Height*2)) then
7145 begin
7146 Result := True;
7147 Exit;
7148 end;
7150 Result := False;
7151 end;
7153 function BorderHole(): Boolean;
7154 var
7155 x, sx, xx: Integer;
7156 begin
7157 { TODO 5 : Ëåñòíèöû }
7158 sx := IfThen(RunDirection() = D_LEFT, -1, 1);
7159 for x := 1 to PLAYER_RECT.Width do
7160 if (not StayOnStep(x*sx, 0)) and
7161 (not CollideLevel(x*sx, PLAYER_RECT.Height)) and
7162 (not CollideLevel(x*sx, PLAYER_RECT.Height*2)) then
7163 begin
7164 for xx := x to x+32 do
7165 if CollideLevel(xx*sx, PLAYER_RECT.Height) then
7166 begin
7167 Result := True;
7168 Exit;
7169 end;
7170 end;
7172 Result := False;
7173 end;
7175 function NearDeepHole(): Boolean;
7176 var
7177 x, sx, y: Integer;
7178 begin
7179 Result := False;
7181 sx := IfThen(RunDirection() = D_LEFT, -1, 1);
7182 y := 3;
7184 for x := 1 to PLAYER_RECT.Width do
7185 if (not StayOnStep(x*sx, 0)) and
7186 (not CollideLevel(x*sx, PLAYER_RECT.Height)) and
7187 (not CollideLevel(x*sx, PLAYER_RECT.Height*2)) then
7188 begin
7189 while FObj.Y+y*PLAYER_RECT.Height < gMapInfo.Height do
7190 begin
7191 if CollideLevel(x*sx, PLAYER_RECT.Height*y) then Exit;
7192 y := y+1;
7193 end;
7195 Result := True;
7196 end else Result := False;
7197 end;
7199 function OverDeepHole(): Boolean;
7200 var
7201 y: Integer;
7202 begin
7203 Result := False;
7205 y := 1;
7206 while FObj.Y+y*PLAYER_RECT.Height < gMapInfo.Height do
7207 begin
7208 if CollideLevel(0, PLAYER_RECT.Height*y) then Exit;
7209 y := y+1;
7210 end;
7212 Result := True;
7213 end;
7215 function OnGround(): Boolean;
7216 begin
7217 Result := StayOnStep(0, 0) or CollideLevel(0, 1);
7218 end;
7220 function OnLadder(): Boolean;
7221 begin
7222 Result := FullInStep(0, 0);
7223 end;
7225 function BelowLadder(): Boolean;
7226 begin
7227 Result := (FullInStep(IfThen(RunDirection() = D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -PLAYER_RECT.Height) and
7228 not CollideLevel(IfThen(RunDirection() = D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -PLAYER_RECT.Height)) or
7229 (FullInStep(IfThen(RunDirection() = D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -BOT_MAXJUMP) and
7230 not CollideLevel(IfThen(RunDirection() = D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -BOT_MAXJUMP));
7231 end;
7233 function BelowLiftUp(): Boolean;
7234 begin
7235 Result := ((FullInLift(IfThen(RunDirection() = D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -PLAYER_RECT.Height) = -1) and
7236 not CollideLevel(IfThen(RunDirection() = D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -PLAYER_RECT.Height)) or
7237 ((FullInLift(IfThen(RunDirection() = D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -BOT_MAXJUMP) = -1) and
7238 not CollideLevel(IfThen(RunDirection() = D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -BOT_MAXJUMP));
7239 end;
7241 function OnTopLift(): Boolean;
7242 begin
7243 Result := (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7244 end;
7246 function CanJumpOver(): Boolean;
7247 var
7248 sx, y: Integer;
7249 begin
7250 sx := IfThen(RunDirection() = D_LEFT, -1, 1);
7252 Result := False;
7254 if not CollideLevel(sx, 0) then Exit;
7256 for y := 1 to BOT_MAXJUMP do
7257 if CollideLevel(0, -y) then Exit else
7258 if not CollideLevel(sx, -y) then
7259 begin
7260 Result := True;
7261 Exit;
7262 end;
7263 end;
7265 function CanJumpUp(Dist: ShortInt): Boolean;
7266 var
7267 y, yy: Integer;
7268 c: Boolean;
7269 begin
7270 Result := False;
7272 if CollideLevel(Dist, 0) then Exit;
7274 c := False;
7275 for y := 0 to BOT_MAXJUMP do
7276 if CollideLevel(Dist, -y) then
7277 begin
7278 c := True;
7279 Break;
7280 end;
7282 if not c then Exit;
7284 c := False;
7285 for yy := y+1 to BOT_MAXJUMP do
7286 if not CollideLevel(Dist, -yy) then
7287 begin
7288 c := True;
7289 Break;
7290 end;
7292 if not c then Exit;
7294 c := False;
7295 for y := 0 to BOT_MAXJUMP do
7296 if CollideLevel(0, -y) then
7297 begin
7298 c := True;
7299 Break;
7300 end;
7302 if c then Exit;
7304 if y < yy then Exit;
7306 Result := True;
7307 end;
7309 function IsSafeTrigger(): Boolean;
7310 var
7311 a: Integer;
7312 begin
7313 Result := True;
7314 if gTriggers = nil then
7315 Exit;
7316 for a := 0 to High(gTriggers) do
7317 if Collide(gTriggers[a].X,
7318 gTriggers[a].Y,
7319 gTriggers[a].Width,
7320 gTriggers[a].Height) and
7321 (gTriggers[a].TriggerType in [TRIGGER_EXIT, TRIGGER_CLOSEDOOR,
7322 TRIGGER_CLOSETRAP, TRIGGER_TRAP,
7323 TRIGGER_PRESS, TRIGGER_ON, TRIGGER_OFF,
7324 TRIGGER_ONOFF, TRIGGER_SPAWNMONSTER,
7325 TRIGGER_DAMAGE, TRIGGER_SHOT]) then
7326 Result := False;
7327 end;
7329 begin
7330 // Âîçìîæíî, íàæèìàåì êíîïêó:
7331 if Rnd(16) and IsSafeTrigger() then
7332 PressKey(KEY_OPEN);
7334 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7335 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7336 begin
7337 ReleaseKey(KEY_LEFT);
7338 ReleaseKey(KEY_RIGHT);
7339 Jump();
7340 end;
7342 // Èäåì âëåâî, åñëè íàäî áûëî:
7343 if GetAIFlag('GOLEFT') <> '' then
7344 begin
7345 RemoveAIFlag('GOLEFT');
7346 if CanRunLeft() then
7347 GoLeft(360);
7348 end;
7350 // Èäåì âïðàâî, åñëè íàäî áûëî:
7351 if GetAIFlag('GORIGHT') <> '' then
7352 begin
7353 RemoveAIFlag('GORIGHT');
7354 if CanRunRight() then
7355 GoRight(360);
7356 end;
7358 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7359 if FObj.X < -32 then
7360 GoRight(360)
7361 else
7362 if FObj.X+32 > gMapInfo.Width then
7363 GoLeft(360);
7365 // Ïðûãàåì, åñëè íàäî áûëî:
7366 if GetAIFlag('NEEDJUMP') <> '' then
7367 begin
7368 Jump(0);
7369 RemoveAIFlag('NEEDJUMP');
7370 end;
7372 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7373 if GetAIFlag('NEEDSEEUP') <> '' then
7374 begin
7375 ReleaseKey(KEY_UP);
7376 ReleaseKey(KEY_DOWN);
7377 PressKey(KEY_UP, 20);
7378 RemoveAIFlag('NEEDSEEUP');
7379 end;
7381 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7382 if GetAIFlag('NEEDSEEDOWN') <> '' then
7383 begin
7384 ReleaseKey(KEY_UP);
7385 ReleaseKey(KEY_DOWN);
7386 PressKey(KEY_DOWN, 20);
7387 RemoveAIFlag('NEEDSEEDOWN');
7388 end;
7390 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7391 if GetAIFlag('GOINHOLE') <> '' then
7392 if not OnGround() then
7393 begin
7394 ReleaseKey(KEY_LEFT);
7395 ReleaseKey(KEY_RIGHT);
7396 RemoveAIFlag('GOINHOLE');
7397 SetAIFlag('FALLINHOLE', '1');
7398 end;
7400 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7401 if GetAIFlag('FALLINHOLE') <> '' then
7402 if OnGround() then
7403 RemoveAIFlag('FALLINHOLE');
7405 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7406 if not (KeyPressed(KEY_LEFT) or KeyPressed(KEY_RIGHT)) then
7407 if GetAIFlag('FALLINHOLE') = '' then
7408 if (not OnLadder()) or (FObj.Vel.Y >= 0) or (OnTopLift()) then
7409 if Rnd(2) then
7410 GoLeft(360)
7411 else
7412 GoRight(360);
7414 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7415 if OnGround() and
7416 CanJumpUp(IfThen(RunDirection() = D_LEFT, -1, 1)*32) and
7417 Rnd(8) then
7418 Jump();
7420 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7421 if OnGround() and NearHole() then
7422 if NearDeepHole() then // Åñëè ýòî áåçäíà
7423 case Random(6) of
7424 0..3: Turn(); // Áåæèì îáðàòíî
7425 4: Jump(); // Ïðûãàåì
7426 5: begin // Ïðûãàåì îáðàòíî
7427 Turn();
7428 Jump();
7429 end;
7430 end
7431 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7432 if GetAIFlag('GOINHOLE') = '' then
7433 case Random(6) of
7434 0: Turn(); // Íå íóæíî òóäà
7435 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7436 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7437 if BorderHole() then
7438 SetAIFlag('GOINHOLE', '1');
7439 end;
7441 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7442 if (not CanRun()) and OnGround() then
7443 begin
7444 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7445 if CanJumpOver() or OnLadder() then
7446 Jump()
7447 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7448 if Random(2) = 0 then
7449 begin
7450 if IsSafeTrigger() then
7451 PressKey(KEY_OPEN);
7452 end else
7453 Turn();
7454 end;
7456 // Îñòàëîñü ìàëî âîçäóõà:
7457 if FAir < 36 * 2 then
7458 Jump(20);
7460 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7461 if (FMegaRulez[MR_SUIT] < gTime) and ((FLastHit = HIT_ACID) or (Healthy() <= 1)) then
7462 if BodyInAcid(0, 0) then
7463 Jump();
7464 end;
7466 function TBot.FullInStep(XInc, YInc: Integer): Boolean;
7467 begin
7468 Result := g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc,
7469 PLAYER_RECT.Width, PLAYER_RECT.Height, PANEL_STEP, False);
7470 end;
7472 {function TBot.NeedItem(Item: Byte): Byte;
7473 begin
7474 Result := 4;
7475 end;}
7477 procedure TBot.SelectWeapon(Dist: Integer);
7478 var
7479 a: Integer;
7481 function HaveAmmo(weapon: Byte): Boolean;
7482 begin
7483 case weapon of
7484 WEAPON_PISTOL: Result := FAmmo[A_BULLETS] >= 1;
7485 WEAPON_SHOTGUN1: Result := FAmmo[A_SHELLS] >= 1;
7486 WEAPON_SHOTGUN2: Result := FAmmo[A_SHELLS] >= 2;
7487 WEAPON_CHAINGUN: Result := FAmmo[A_BULLETS] >= 10;
7488 WEAPON_ROCKETLAUNCHER: Result := FAmmo[A_ROCKETS] >= 1;
7489 WEAPON_PLASMA: Result := FAmmo[A_CELLS] >= 10;
7490 WEAPON_BFG: Result := FAmmo[A_CELLS] >= 40;
7491 WEAPON_SUPERPULEMET: Result := FAmmo[A_SHELLS] >= 1;
7492 WEAPON_FLAMETHROWER: Result := FAmmo[A_FUEL] >= 1;
7493 else Result := True;
7494 end;
7495 end;
7497 begin
7498 if Dist = -1 then Dist := BOT_LONGDIST;
7500 if Dist > BOT_LONGDIST then
7501 begin // Äàëüíèé áîé
7502 for a := 0 to 9 do
7503 if FWeapon[FDifficult.WeaponPrior[a]] and HaveAmmo(FDifficult.WeaponPrior[a]) then
7504 begin
7505 FSelectedWeapon := FDifficult.WeaponPrior[a];
7506 Break;
7507 end;
7508 end
7509 else //if Dist > BOT_UNSAFEDIST then
7510 begin // Áëèæíèé áîé
7511 for a := 0 to 9 do
7512 if FWeapon[FDifficult.CloseWeaponPrior[a]] and HaveAmmo(FDifficult.CloseWeaponPrior[a]) then
7513 begin
7514 FSelectedWeapon := FDifficult.CloseWeaponPrior[a];
7515 Break;
7516 end;
7517 end;
7518 { else
7519 begin
7520 for a := 0 to 9 do
7521 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7522 begin
7523 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7524 Break;
7525 end;
7526 end;}
7527 end;
7529 function TBot.PickItem(ItemType: Byte; force: Boolean; var remove: Boolean): Boolean;
7530 begin
7531 Result := inherited PickItem(ItemType, force, remove);
7533 if Result then SetAIFlag('SELECTWEAPON', '1');
7534 end;
7536 function TBot.Heal(value: Word; Soft: Boolean): Boolean;
7537 begin
7538 Result := inherited Heal(value, Soft);
7539 end;
7541 function TBot.Healthy(): Byte;
7542 begin
7543 if FMegaRulez[MR_INVUL] >= gTime then Result := 3
7544 else if (FHealth > 80) or ((FHealth > 50) and (FArmor > 20)) then Result := 3
7545 else if (FHealth > 50) then Result := 2
7546 else if (FHealth > 20) then Result := 1
7547 else Result := 0;
7548 end;
7550 function TBot.TargetOnScreen(TX, TY: Integer): Boolean;
7551 begin
7552 Result := (Abs(FObj.X-TX) <= Trunc(gPlayerScreenSize.X*0.6)) and
7553 (Abs(FObj.Y-TY) <= Trunc(gPlayerScreenSize.Y*0.6));
7554 end;
7556 procedure TBot.OnDamage(Angle: SmallInt);
7557 var
7558 pla: TPlayer;
7559 mon: TMonster;
7560 ok: Boolean;
7561 begin
7562 inherited;
7564 if (Angle = 0) or (Angle = 180) then
7565 begin
7566 ok := False;
7567 if (g_GetUIDType(FLastSpawnerUID) = UID_PLAYER) and
7568 LongBool(gGameSettings.Options and GAME_OPTION_BOTVSPLAYER) then
7569 begin // Èãðîê
7570 pla := g_Player_Get(FLastSpawnerUID);
7571 ok := not TargetOnScreen(pla.FObj.X + PLAYER_RECT.X,
7572 pla.FObj.Y + PLAYER_RECT.Y);
7573 end
7574 else
7575 if (g_GetUIDType(FLastSpawnerUID) = UID_MONSTER) and
7576 LongBool(gGameSettings.Options and GAME_OPTION_BOTVSMONSTER) then
7577 begin // Ìîíñòð
7578 mon := g_Monsters_ByUID(FLastSpawnerUID);
7579 ok := not TargetOnScreen(mon.Obj.X + mon.Obj.Rect.X,
7580 mon.Obj.Y + mon.Obj.Rect.Y);
7581 end;
7583 if ok then
7584 if Angle = 0 then
7585 SetAIFlag('ATTACKLEFT', '1')
7586 else
7587 SetAIFlag('ATTACKRIGHT', '1');
7588 end;
7589 end;
7591 function TBot.RunDirection(): TDirection;
7592 begin
7593 if Abs(Vel.X) >= 1 then
7594 begin
7595 if Vel.X > 0 then Result := D_RIGHT else Result := D_LEFT;
7596 end else
7597 Result := FDirection;
7598 end;
7600 function TBot.GetRnd(a: Byte): Boolean;
7601 begin
7602 if a = 0 then Result := False
7603 else if a = 255 then Result := True
7604 else Result := Random(256) > 255-a;
7605 end;
7607 function TBot.GetInterval(a: Byte; radius: SmallInt): SmallInt;
7608 begin
7609 Result := Round((255-a)/255*radius*(Random(2)-1));
7610 end;
7612 procedure TBot.SaveState(var Mem: TBinMemoryWriter);
7613 var
7614 i: Integer;
7615 dw: DWORD;
7616 p: Pointer;
7617 begin
7618 inherited SaveState(Mem);
7620 // Âûáðàííîå îðóæèå:
7621 Mem.WriteByte(FSelectedWeapon);
7622 // UID öåëè:
7623 Mem.WriteWord(FTargetUID);
7624 // Âðåìÿ ïîòåðè öåëè:
7625 Mem.WriteDWORD(FLastVisible);
7626 // Êîëè÷åñòâî ôëàãîâ ÈÈ:
7627 dw := Length(FAIFlags);
7628 Mem.WriteDWORD(dw);
7629 // Ôëàãè ÈÈ:
7630 for i := 0 to Integer(dw)-1 do
7631 begin
7632 Mem.WriteString(FAIFlags[i].Name, 20);
7633 Mem.WriteString(FAIFlags[i].Value, 20);
7634 end;
7635 // Íàñòðîéêè ñëîæíîñòè:
7636 p := @FDifficult;
7637 Mem.WriteMemory(p, SizeOf(TDifficult));
7638 end;
7640 procedure TBot.LoadState(var Mem: TBinMemoryReader);
7641 var
7642 i: Integer;
7643 dw: DWORD;
7644 p: Pointer;
7645 begin
7646 inherited LoadState(Mem);
7648 // Âûáðàííîå îðóæèå:
7649 Mem.ReadByte(FSelectedWeapon);
7650 // UID öåëè:
7651 Mem.ReadWord(FTargetUID);
7652 // Âðåìÿ ïîòåðè öåëè:
7653 Mem.ReadDWORD(FLastVisible);
7654 // Êîëè÷åñòâî ôëàãîâ ÈÈ:
7655 Mem.ReadDWORD(dw);
7656 SetLength(FAIFlags, dw);
7657 // Ôëàãè ÈÈ:
7658 for i := 0 to Integer(dw)-1 do
7659 begin
7660 Mem.ReadString(FAIFlags[i].Name);
7661 Mem.ReadString(FAIFlags[i].Value);
7662 end;
7663 // Íàñòðîéêè ñëîæíîñòè:
7664 Mem.ReadMemory(p, dw);
7665 if dw <> SizeOf(TDifficult) then
7666 begin
7667 raise EBinSizeError.Create('TBot.LoadState: Wrong FDifficult Size');
7668 end;
7669 FDifficult := TDifficult(p^);
7670 end;
7672 end.