DEADSOFTWARE

typo in mapcvt: microseconds -> milliseconds
[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, MAPDEF,
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, g_game, g_grid,
528 wadreader, g_main, g_monsters, CONFIG, g_language,
529 g_net, g_netmsg, g_window, GL, g_holmes;
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 TDFPoint = ((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: TDFPoint;
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: TDFPoint;
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+FObj.slopeUpLeft, 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+FObj.slopeUpLeft, 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+FObj.slopeUpLeft, 200)
2291 else
2292 FModel.Draw(FObj.X, FObj.Y+FObj.slopeUpLeft);
2293 end
2294 else
2295 FModel.Draw(FObj.X, FObj.Y+FObj.slopeUpLeft, 254);
2296 end
2297 else
2298 FModel.Draw(FObj.X, FObj.Y+FObj.slopeUpLeft);
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 procedure TPlayer.DrawAim();
2320 procedure drawCast (sz: Integer; ax0, ay0, ax1, ay1: Integer);
2321 var
2322 ex, ey: Integer;
2323 begin
2324 if isValidViewPort and (self = gPlayer1) then
2325 begin
2326 g_Holmes_plrLaser(ax0, ay0, ax1, ay1);
2327 end;
2329 e_DrawLine(sz, ax0, ay0, ax1, ay1, 255, 0, 0, 96);
2330 if (g_Map_traceToNearestWall(ax0, ay0, ax1, ay1, @ex, @ey) <> nil) then
2331 begin
2332 e_DrawLine(sz, ax0, ay0, ex, ey, 0, 255, 0, 96);
2333 end
2334 else
2335 begin
2336 e_DrawLine(sz, ax0, ay0, ex, ey, 0, 0, 255, 96);
2337 end;
2338 end;
2340 var
2341 wx, wy, xx, yy: Integer;
2342 angle: SmallInt;
2343 sz, len: Word;
2344 begin
2345 wx := FObj.X + WEAPONPOINT[FDirection].X + IfThen(FDirection = D_LEFT, 7, -7);
2346 wy := FObj.Y + WEAPONPOINT[FDirection].Y;
2347 angle := FAngle;
2348 len := 1024;
2349 sz := 2;
2350 case FCurrWeap of
2351 0: begin // Punch
2352 len := 12;
2353 sz := 4;
2354 end;
2355 1: begin // Chainsaw
2356 len := 24;
2357 sz := 6;
2358 end;
2359 2: begin // Pistol
2360 len := 1024;
2361 sz := 2;
2362 if angle = ANGLE_RIGHTUP then Dec(angle, 2);
2363 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2364 if angle = ANGLE_LEFTUP then Inc(angle, 2);
2365 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2366 end;
2367 3: begin // Shotgun
2368 len := 1024;
2369 sz := 3;
2370 if angle = ANGLE_RIGHTUP then Dec(angle, 2);
2371 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2372 if angle = ANGLE_LEFTUP then Inc(angle, 2);
2373 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2374 end;
2375 4: begin // Double Shotgun
2376 len := 1024;
2377 sz := 4;
2378 if angle = ANGLE_RIGHTUP then Dec(angle, 2);
2379 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2380 if angle = ANGLE_LEFTUP then Inc(angle, 2);
2381 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2382 end;
2383 5: begin // Chaingun
2384 len := 1024;
2385 sz := 3;
2386 if angle = ANGLE_RIGHTUP then Dec(angle, 2);
2387 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2388 if angle = ANGLE_LEFTUP then Inc(angle, 2);
2389 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2390 end;
2391 6: begin // Rocket Launcher
2392 len := 1024;
2393 sz := 7;
2394 if angle = ANGLE_RIGHTUP then Inc(angle, 2);
2395 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2396 if angle = ANGLE_LEFTUP then Dec(angle, 2);
2397 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2398 end;
2399 7: begin // Plasmagun
2400 len := 1024;
2401 sz := 5;
2402 if angle = ANGLE_RIGHTUP then Inc(angle);
2403 if angle = ANGLE_RIGHTDOWN then Inc(angle, 3);
2404 if angle = ANGLE_LEFTUP then Dec(angle);
2405 if angle = ANGLE_LEFTDOWN then Dec(angle, 3);
2406 end;
2407 8: begin // BFG
2408 len := 1024;
2409 sz := 12;
2410 if angle = ANGLE_RIGHTUP then Inc(angle, 1);
2411 if angle = ANGLE_RIGHTDOWN then Inc(angle, 2);
2412 if angle = ANGLE_LEFTUP then Dec(angle, 1);
2413 if angle = ANGLE_LEFTDOWN then Dec(angle, 2);
2414 end;
2415 9: begin // Super Chaingun
2416 len := 1024;
2417 sz := 4;
2418 if angle = ANGLE_RIGHTUP then Dec(angle, 2);
2419 if angle = ANGLE_RIGHTDOWN then Inc(angle, 4);
2420 if angle = ANGLE_LEFTUP then Inc(angle, 2);
2421 if angle = ANGLE_LEFTDOWN then Dec(angle, 4);
2422 end;
2423 end;
2424 xx := Trunc(Cos(-DegToRad(angle)) * len) + wx;
2425 yy := Trunc(Sin(-DegToRad(angle)) * len) + wy;
2426 {$IF DEFINED(D2F_DEBUG)}
2427 drawCast(sz, wx, wy, xx, yy);
2428 {$ELSE}
2429 e_DrawLine(sz, wx, wy, xx, yy, 255, 0, 0, 96);
2430 {$ENDIF}
2431 end;
2433 procedure TPlayer.DrawGUI();
2434 var
2435 ID: DWORD;
2436 X, Y, SY, a, p, m: Integer;
2437 tw, th: Word;
2438 cw, ch: Byte;
2439 s: string;
2440 stat: TPlayerStatArray;
2441 begin
2442 X := gPlayerScreenSize.X;
2443 SY := gPlayerScreenSize.Y;
2444 Y := 0;
2446 if gShowGoals and (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
2447 begin
2448 if gGameSettings.GameMode = GM_CTF then
2449 a := 32 + 8
2450 else
2451 a := 0;
2452 if gGameSettings.GameMode = GM_CTF then
2453 begin
2454 s := 'TEXTURE_PLAYER_REDFLAG';
2455 if gFlags[FLAG_RED].State = FLAG_STATE_CAPTURED then
2456 s := 'TEXTURE_PLAYER_REDFLAG_S';
2457 if gFlags[FLAG_RED].State = FLAG_STATE_DROPPED then
2458 s := 'TEXTURE_PLAYER_REDFLAG_D';
2459 if g_Texture_Get(s, ID) then
2460 e_Draw(ID, X-16-32, 240-72-4, 0, True, False);
2461 end;
2463 s := IntToStr(gTeamStat[TEAM_RED].Goals);
2464 e_CharFont_GetSize(gMenuFont, s, tw, th);
2465 e_CharFont_PrintEx(gMenuFont, X-16-a-tw, 240-72-4, s, TEAMCOLOR[TEAM_RED]);
2467 if gGameSettings.GameMode = GM_CTF then
2468 begin
2469 s := 'TEXTURE_PLAYER_BLUEFLAG';
2470 if gFlags[FLAG_BLUE].State = FLAG_STATE_CAPTURED then
2471 s := 'TEXTURE_PLAYER_BLUEFLAG_S';
2472 if gFlags[FLAG_BLUE].State = FLAG_STATE_DROPPED then
2473 s := 'TEXTURE_PLAYER_BLUEFLAG_D';
2474 if g_Texture_Get(s, ID) then
2475 e_Draw(ID, X-16-32, 240-32-4, 0, True, False);
2476 end;
2478 s := IntToStr(gTeamStat[TEAM_BLUE].Goals);
2479 e_CharFont_GetSize(gMenuFont, s, tw, th);
2480 e_CharFont_PrintEx(gMenuFont, X-16-a-tw, 240-32-4, s, TEAMCOLOR[TEAM_BLUE]);
2481 end;
2483 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID) then
2484 e_DrawFill(ID, X, 0, 1, (gPlayerScreenSize.Y div 256)+IfThen(gPlayerScreenSize.Y mod 256 > 0, 1, 0),
2485 0, False, False);
2487 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID) then
2488 e_Draw(ID, X+2, Y, 0, True, False);
2490 if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
2491 begin
2492 if gShowStat then
2493 begin
2494 s := IntToStr(Frags);
2495 e_CharFont_GetSize(gMenuFont, s, tw, th);
2496 e_CharFont_PrintEx(gMenuFont, X-16-tw, Y, s, _RGB(255, 0, 0));
2498 s := '';
2499 p := 1;
2500 m := 0;
2501 stat := g_Player_GetStats();
2502 if stat <> nil then
2503 begin
2504 p := 1;
2506 for a := 0 to High(stat) do
2507 if stat[a].Name <> Name then
2508 begin
2509 if stat[a].Frags > m then m := stat[a].Frags;
2510 if stat[a].Frags > Frags then p := p+1;
2511 end;
2512 end;
2514 s := IntToStr(p)+' / '+IntToStr(Length(stat))+' ';
2515 if Frags >= m then s := s+'+' else s := s+'-';
2516 s := s+IntToStr(Abs(Frags-m));
2518 e_CharFont_GetSize(gMenuSmallFont, s, tw, th);
2519 e_CharFont_PrintEx(gMenuSmallFont, X-16-tw, Y+32, s, _RGB(255, 0, 0));
2520 end;
2522 if gShowLives and (gGameSettings.MaxLives > 0) then
2523 begin
2524 s := IntToStr(Lives);
2525 e_CharFont_GetSize(gMenuFont, s, tw, th);
2526 e_CharFont_PrintEx(gMenuFont, X-16-tw, SY-32, s, _RGB(0, 255, 0));
2527 end;
2528 end;
2530 e_CharFont_GetSize(gMenuSmallFont, FName, tw, th);
2531 e_CharFont_PrintEx(gMenuSmallFont, X+98-(tw div 2), Y+8, FName, _RGB(255, 0, 0));
2533 if R_BERSERK in FRulez then
2534 e_Draw(gItemsTexturesID[ITEM_MEDKIT_BLACK], X+37, Y+45, 0, True, False)
2535 else
2536 e_Draw(gItemsTexturesID[ITEM_MEDKIT_LARGE], X+37, Y+45, 0, True, False);
2538 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID) then
2539 e_Draw(ID, X+36, Y+77, 0, True, False);
2541 s := IntToStr(IfThen(FHealth > 0, FHealth, 0));
2542 e_CharFont_GetSize(gMenuFont, s, tw, th);
2543 e_CharFont_PrintEx(gMenuFont, X+178-tw, Y+40, s, _RGB(255, 0, 0));
2545 s := IntToStr(FArmor);
2546 e_CharFont_GetSize(gMenuFont, s, tw, th);
2547 e_CharFont_PrintEx(gMenuFont, X+178-tw, Y+68, s, _RGB(255, 0, 0));
2549 s := IntToStr(GetAmmoByWeapon(FCurrWeap));
2551 case FCurrWeap of
2552 WEAPON_KASTET:
2553 begin
2554 s := '--';
2555 ID := gItemsTexturesID[ITEM_WEAPON_KASTET];
2556 end;
2557 WEAPON_SAW:
2558 begin
2559 s := '--';
2560 ID := gItemsTexturesID[ITEM_WEAPON_SAW];
2561 end;
2562 WEAPON_PISTOL: ID := gItemsTexturesID[ITEM_WEAPON_PISTOL];
2563 WEAPON_CHAINGUN: ID := gItemsTexturesID[ITEM_WEAPON_CHAINGUN];
2564 WEAPON_SHOTGUN1: ID := gItemsTexturesID[ITEM_WEAPON_SHOTGUN1];
2565 WEAPON_SHOTGUN2: ID := gItemsTexturesID[ITEM_WEAPON_SHOTGUN2];
2566 WEAPON_SUPERPULEMET: ID := gItemsTexturesID[ITEM_WEAPON_SUPERPULEMET];
2567 WEAPON_ROCKETLAUNCHER: ID := gItemsTexturesID[ITEM_WEAPON_ROCKETLAUNCHER];
2568 WEAPON_PLASMA: ID := gItemsTexturesID[ITEM_WEAPON_PLASMA];
2569 WEAPON_BFG: ID := gItemsTexturesID[ITEM_WEAPON_BFG];
2570 WEAPON_FLAMETHROWER: ID := gItemsTexturesID[ITEM_WEAPON_FLAMETHROWER];
2571 end;
2573 e_CharFont_GetSize(gMenuFont, s, tw, th);
2574 e_CharFont_PrintEx(gMenuFont, X+178-tw, Y+158, s, _RGB(255, 0, 0));
2575 e_Draw(ID, X+20, Y+160, 0, True, False);
2577 if R_KEY_RED in FRulez then
2578 e_Draw(gItemsTexturesID[ITEM_KEY_RED], X+78, Y+214, 0, True, False);
2580 if R_KEY_GREEN in FRulez then
2581 e_Draw(gItemsTexturesID[ITEM_KEY_GREEN], X+95, Y+214, 0, True, False);
2583 if R_KEY_BLUE in FRulez then
2584 e_Draw(gItemsTexturesID[ITEM_KEY_BLUE], X+112, Y+214, 0, True, False);
2586 if FJetFuel > 0 then
2587 begin
2588 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID) then
2589 e_Draw(ID, X+2, Y+116, 0, True, False);
2590 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID) then
2591 e_Draw(ID, X+2, Y+126, 0, True, False);
2592 e_DrawLine(4, X+16, Y+122, X+16+Trunc(168*IfThen(FAir > 0, FAir, 0)/AIR_MAX), Y+122, 0, 0, 196);
2593 e_DrawLine(4, X+16, Y+132, X+16+Trunc(168*FJetFuel/JET_MAX), Y+132, 208, 0, 0);
2594 end
2595 else
2596 begin
2597 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID) then
2598 e_Draw(ID, X+2, Y+124, 0, True, False);
2599 e_DrawLine(4, X+16, Y+130, X+16+Trunc(168*IfThen(FAir > 0, FAir, 0)/AIR_MAX), Y+130, 0, 0, 196);
2600 end;
2602 if gShowPing and g_Game_IsClient then
2603 begin
2604 s := _lc[I_GAME_PING_HUD] + IntToStr(NetPeer.lastRoundTripTime) + _lc[I_NET_SLIST_PING_MS];
2605 e_TextureFontPrint(X + 4, Y + 242, s, gStdFont);
2606 Y := Y + 16;
2607 end;
2609 if FSpectator then
2610 begin
2611 e_TextureFontPrint(X + 4, Y + 242, _lc[I_PLAYER_SPECT], gStdFont);
2612 e_TextureFontPrint(X + 4, Y + 258, _lc[I_PLAYER_SPECT2], gStdFont);
2613 e_TextureFontPrint(X + 4, Y + 274, _lc[I_PLAYER_SPECT1], gStdFont);
2614 if FNoRespawn then
2615 begin
2616 e_TextureFontGetSize(gStdFont, cw, ch);
2617 s := _lc[I_PLAYER_SPECT4];
2618 e_TextureFontPrintEx(gScreenWidth div 2 - cw*(Length(s) div 2),
2619 gScreenHeight-4-ch, s, gStdFont, 255, 255, 255, 1, True);
2620 e_TextureFontPrint(X + 4, Y + 290, _lc[I_PLAYER_SPECT1S], gStdFont);
2621 end;
2623 end;
2624 end;
2626 procedure TPlayer.DrawRulez();
2627 var
2628 dr: Boolean;
2629 begin
2630 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2631 if FMegaRulez[MR_INVUL] >= gTime then
2632 begin
2633 if (FMegaRulez[MR_INVUL]-gTime) <= 2100 then
2634 dr := not Odd((FMegaRulez[MR_INVUL]-gTime) div 300)
2635 else
2636 dr := True;
2638 if dr then
2639 e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1,
2640 191, 191, 191, 0, B_INVERT);
2641 end;
2643 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2644 if FMegaRulez[MR_SUIT] >= gTime then
2645 begin
2646 if (FMegaRulez[MR_SUIT]-gTime) <= 2100 then
2647 dr := not Odd((FMegaRulez[MR_SUIT]-gTime) div 300)
2648 else
2649 dr := True;
2651 if dr then
2652 e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1,
2653 0, 96, 0, 200, B_NONE);
2654 end;
2656 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2657 if (FBerserk >= 0) and (LongWord(FBerserk) >= gTime) and (gFlash = 2) then
2658 begin
2659 e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1,
2660 255, 0, 0, 200, B_NONE);
2661 end;
2662 end;
2664 procedure TPlayer.DrawPain();
2665 var
2666 a, h: Integer;
2667 begin
2668 if FPain = 0 then Exit;
2670 a := FPain;
2672 if a < 15 then h := 0
2673 else if a < 35 then h := 1
2674 else if a < 55 then h := 2
2675 else if a < 75 then h := 3
2676 else if a < 95 then h := 4
2677 else h := 5;
2679 //if a > 255 then a := 255;
2681 e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255, 0, 0, 255-h*50);
2682 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2683 end;
2685 procedure TPlayer.DrawPickup();
2686 var
2687 a, h: Integer;
2688 begin
2689 if FPickup = 0 then Exit;
2691 a := FPickup;
2693 if a < 15 then h := 1
2694 else if a < 35 then h := 2
2695 else if a < 55 then h := 3
2696 else if a < 75 then h := 4
2697 else h := 5;
2699 e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 150, 200, 150, 255-h*50);
2700 end;
2702 procedure TPlayer.Fire();
2703 var
2704 f, DidFire: Boolean;
2705 wx, wy, xd, yd: Integer;
2706 locobj: TObj;
2707 begin
2708 if g_Game_IsClient then Exit;
2709 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
2710 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
2712 if FSpectator then
2713 begin
2714 Respawn(False);
2715 Exit;
2716 end;
2718 if FReloading[FCurrWeap] <> 0 then Exit;
2720 DidFire := False;
2722 f := False;
2723 wx := FObj.X+WEAPONPOINT[FDirection].X;
2724 wy := FObj.Y+WEAPONPOINT[FDirection].Y;
2725 xd := wx+IfThen(FDirection = D_LEFT, -30, 30);
2726 yd := wy+firediry();
2728 case FCurrWeap of
2729 WEAPON_KASTET:
2730 begin
2731 if R_BERSERK in FRulez then
2732 begin
2733 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2734 locobj.X := FObj.X+FObj.Rect.X;
2735 locobj.Y := FObj.Y+FObj.Rect.Y;
2736 locobj.rect.X := 0;
2737 locobj.rect.Y := 0;
2738 locobj.rect.Width := 39;
2739 locobj.rect.Height := 52;
2740 locobj.Vel.X := (xd-wx) div 2;
2741 locobj.Vel.Y := (yd-wy) div 2;
2742 locobj.Accel.X := xd-wx;
2743 locobj.Accel.y := yd-wy;
2745 if g_Weapon_Hit(@locobj, 50, FUID, HIT_SOME) <> 0 then
2746 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj.X, FObj.Y)
2747 else
2748 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj.X, FObj.Y);
2750 if gFlash = 1 then
2751 if FPain < 50 then
2752 FPain := min(FPain + 25, 50);
2753 end else g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 3, FUID);
2755 DidFire := True;
2756 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
2757 end;
2759 WEAPON_SAW:
2760 begin
2761 if g_Weapon_chainsaw(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y,
2762 IfThen(gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF], 9, 3), FUID) <> 0 then
2763 begin
2764 FSawSoundSelect.Stop();
2765 FSawSound.Stop();
2766 FSawSoundHit.PlayAt(FObj.X, FObj.Y);
2767 end
2768 else if not FSawSoundHit.IsPlaying() then
2769 begin
2770 FSawSoundSelect.Stop();
2771 FSawSound.PlayAt(FObj.X, FObj.Y);
2772 end;
2774 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
2775 DidFire := True;
2776 f := True;
2777 end;
2779 WEAPON_PISTOL:
2780 if FAmmo[A_BULLETS] > 0 then
2781 begin
2782 g_Weapon_pistol(wx, wy, xd, yd, FUID);
2783 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
2784 Dec(FAmmo[A_BULLETS]);
2785 FFireAngle := FAngle;
2786 f := True;
2787 DidFire := True;
2788 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
2789 GameVelX, GameVelY-2, SHELL_BULLET);
2790 end;
2792 WEAPON_SHOTGUN1:
2793 if FAmmo[A_SHELLS] > 0 then
2794 begin
2795 g_Weapon_shotgun(wx, wy, xd, yd, FUID);
2796 if not gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx, wy);
2797 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
2798 Dec(FAmmo[A_SHELLS]);
2799 FFireAngle := FAngle;
2800 f := True;
2801 DidFire := True;
2802 FShellTimer := 10;
2803 FShellType := SHELL_SHELL;
2804 end;
2806 WEAPON_SHOTGUN2:
2807 if FAmmo[A_SHELLS] >= 2 then
2808 begin
2809 g_Weapon_dshotgun(wx, wy, xd, yd, FUID);
2810 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
2811 Dec(FAmmo[A_SHELLS], 2);
2812 FFireAngle := FAngle;
2813 f := True;
2814 DidFire := True;
2815 FShellTimer := 13;
2816 FShellType := SHELL_DBLSHELL;
2817 end;
2819 WEAPON_CHAINGUN:
2820 if FAmmo[A_BULLETS] > 0 then
2821 begin
2822 g_Weapon_mgun(wx, wy, xd, yd, FUID);
2823 if not gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx, wy);
2824 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
2825 Dec(FAmmo[A_BULLETS]);
2826 FFireAngle := FAngle;
2827 f := True;
2828 DidFire := True;
2829 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
2830 GameVelX, GameVelY-2, SHELL_BULLET);
2831 end;
2833 WEAPON_ROCKETLAUNCHER:
2834 if FAmmo[A_ROCKETS] > 0 then
2835 begin
2836 g_Weapon_rocket(wx, wy, xd, yd, FUID);
2837 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
2838 Dec(FAmmo[A_ROCKETS]);
2839 FFireAngle := FAngle;
2840 f := True;
2841 DidFire := True;
2842 end;
2844 WEAPON_PLASMA:
2845 if FAmmo[A_CELLS] > 0 then
2846 begin
2847 g_Weapon_plasma(wx, wy, xd, yd, FUID);
2848 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
2849 Dec(FAmmo[A_CELLS]);
2850 FFireAngle := FAngle;
2851 f := True;
2852 DidFire := True;
2853 end;
2855 WEAPON_BFG:
2856 if (FAmmo[A_CELLS] >= 40) and (FBFGFireCounter = -1) then
2857 begin
2858 FBFGFireCounter := 17;
2859 if not FNoReload then
2860 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj.X, FObj.Y);
2861 Dec(FAmmo[A_CELLS], 40);
2862 DidFire := True;
2863 end;
2865 WEAPON_SUPERPULEMET:
2866 if FAmmo[A_SHELLS] > 0 then
2867 begin
2868 g_Weapon_shotgun(wx, wy, xd, yd, FUID);
2869 if not gSoundEffectsDF then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx, wy);
2870 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
2871 Dec(FAmmo[A_SHELLS]);
2872 FFireAngle := FAngle;
2873 f := True;
2874 DidFire := True;
2875 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
2876 GameVelX, GameVelY-2, SHELL_SHELL);
2877 end;
2879 WEAPON_FLAMETHROWER:
2880 if FAmmo[A_FUEL] > 0 then
2881 begin
2882 g_Weapon_flame(wx, wy, xd, yd, FUID);
2883 FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap];
2884 Dec(FAmmo[A_FUEL]);
2885 FFireAngle := FAngle;
2886 f := True;
2887 DidFire := True;
2888 end;
2889 end;
2891 if g_Game_IsNet then
2892 begin
2893 if DidFire then
2894 begin
2895 if FCurrWeap <> WEAPON_BFG then
2896 MH_SEND_PlayerFire(FUID, FCurrWeap, wx, wy, xd, yd, LastShotID)
2897 else
2898 if not FNoReload then
2899 MH_SEND_Sound(FObj.X, FObj.Y, 'SOUND_WEAPON_STARTFIREBFG');
2900 end;
2902 MH_SEND_PlayerStats(FUID);
2903 end;
2905 if not f then Exit;
2907 if (FAngle = 0) or (FAngle = 180) then SetAction(A_ATTACK)
2908 else if (FAngle = ANGLE_LEFTDOWN) or (FAngle = ANGLE_RIGHTDOWN) then SetAction(A_ATTACKDOWN)
2909 else if (FAngle = ANGLE_LEFTUP) or (FAngle = ANGLE_RIGHTUP) then SetAction(A_ATTACKUP);
2910 end;
2912 function TPlayer.GetAmmoByWeapon(Weapon: Byte): Word;
2913 begin
2914 case Weapon of
2915 WEAPON_PISTOL, WEAPON_CHAINGUN: Result := FAmmo[A_BULLETS];
2916 WEAPON_SHOTGUN1, WEAPON_SHOTGUN2, WEAPON_SUPERPULEMET: Result := FAmmo[A_SHELLS];
2917 WEAPON_ROCKETLAUNCHER: Result := FAmmo[A_ROCKETS];
2918 WEAPON_PLASMA, WEAPON_BFG: Result := FAmmo[A_CELLS];
2919 WEAPON_FLAMETHROWER: Result := FAmmo[A_FUEL];
2920 else Result := 0;
2921 end;
2922 end;
2924 function TPlayer.HeadInLiquid(XInc, YInc: Integer): Boolean;
2925 begin
2926 Result := g_Map_CollidePanel(FObj.X+PLAYER_HEADRECT.X+XInc, FObj.Y+PLAYER_HEADRECT.Y+YInc,
2927 PLAYER_HEADRECT.Width, PLAYER_HEADRECT.Height,
2928 PANEL_WATER or PANEL_ACID1 or PANEL_ACID2, True);
2929 end;
2931 procedure TPlayer.JetpackOn;
2932 begin
2933 FJetSoundFly.Stop;
2934 FJetSoundOff.Stop;
2935 FJetSoundOn.SetPosition(0);
2936 FJetSoundOn.PlayAt(FObj.X, FObj.Y);
2937 FlySmoke(8);
2938 end;
2940 procedure TPlayer.JetpackOff;
2941 begin
2942 FJetSoundFly.Stop;
2943 FJetSoundOn.Stop;
2944 FJetSoundOff.SetPosition(0);
2945 FJetSoundOff.PlayAt(FObj.X, FObj.Y);
2946 end;
2948 procedure TPlayer.CatchFire(Attacker: Word);
2949 begin
2950 FFireTime := 100;
2951 FFireAttacker := Attacker;
2952 if g_Game_IsNet and g_Game_IsServer then
2953 MH_SEND_PlayerStats(FUID);
2954 end;
2956 procedure TPlayer.Jump();
2957 begin
2958 if gFly or FJetpack then
2959 begin
2960 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
2961 if FObj.Vel.Y > -VEL_FLY then
2962 FObj.Vel.Y := FObj.Vel.Y - 3;
2963 if FJetpack then
2964 begin
2965 if FJetFuel > 0 then
2966 Dec(FJetFuel);
2967 if (FJetFuel < 1) and g_Game_IsServer then
2968 begin
2969 FJetpack := False;
2970 JetpackOff;
2971 if g_Game_IsNet then
2972 MH_SEND_PlayerStats(FUID);
2973 end;
2974 end;
2975 Exit;
2976 end;
2978 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
2979 if FGhost then
2980 FCanJetpack := False;
2982 // Ïðûãàåì èëè âñïëûâàåì:
2983 if (CollideLevel(0, 1) or
2984 g_Map_CollidePanel(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y+36, PLAYER_RECT.Width,
2985 PLAYER_RECT.Height-33, PANEL_STEP, False)
2986 ) and (FObj.Accel.Y = 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
2987 begin
2988 FObj.Vel.Y := -VEL_JUMP;
2989 FCanJetpack := False;
2990 end
2991 else
2992 begin
2993 if BodyInLiquid(0, 0) then
2994 FObj.Vel.Y := -VEL_SW
2995 else if (FJetFuel > 0) and FCanJetpack and
2996 g_Game_IsServer and (not g_Obj_CollideLiquid(@FObj, 0, 0)) then
2997 begin
2998 FJetpack := True;
2999 JetpackOn;
3000 if g_Game_IsNet then
3001 MH_SEND_PlayerStats(FUID);
3002 end;
3003 end;
3004 end;
3006 procedure TPlayer.Kill(KillType: Byte; SpawnerUID: Word; t: Byte);
3007 var
3008 a, i, k, ab, ar: Byte;
3009 s: String;
3010 mon: TMonster;
3011 plr: TPlayer;
3012 srv, netsrv: Boolean;
3013 DoFrags: Boolean;
3014 OldLR: Byte;
3015 KP: TPlayer;
3016 it: PItem;
3018 procedure PushItem(t: Byte);
3019 var
3020 id: DWORD;
3021 begin
3022 id := g_Items_Create(FObj.X, FObj.Y, t, True, False);
3023 it := g_Items_ByIdx(id);
3024 if KillType = K_EXTRAHARDKILL then // -7..+7; -8..0
3025 begin
3026 g_Obj_Push(@it.Obj, (FObj.Vel.X div 2)-7+Random(15),
3027 (FObj.Vel.Y div 2)-Random(9));
3028 it.positionChanged(); // this updates spatial accelerators
3029 end
3030 else
3031 begin
3032 if KillType = K_HARDKILL then // -5..+5; -5..0
3033 begin
3034 g_Obj_Push(@it.Obj, (FObj.Vel.X div 2)-5+Random(11),
3035 (FObj.Vel.Y div 2)-Random(6));
3036 end
3037 else // -3..+3; -3..0
3038 begin
3039 g_Obj_Push(@it.Obj, (FObj.Vel.X div 2)-3+Random(7),
3040 (FObj.Vel.Y div 2)-Random(4));
3041 end;
3042 it.positionChanged(); // this updates spatial accelerators
3043 end;
3045 if g_Game_IsNet and g_Game_IsServer then
3046 MH_SEND_ItemSpawn(True, id);
3047 end;
3049 begin
3050 DoFrags := (gGameSettings.MaxLives = 0) or (gGameSettings.GameMode = GM_COOP);
3051 Srv := g_Game_IsServer;
3052 Netsrv := g_Game_IsServer and g_Game_IsNet;
3053 if Srv then FDeath := FDeath + 1;
3054 if FLive then
3055 begin
3056 if FGhost then
3057 FGhost := False;
3058 if not FPhysics then
3059 FPhysics := True;
3060 FLive := False;
3061 end;
3062 FShellTimer := -1;
3064 if (gGameSettings.MaxLives > 0) and Srv and (gLMSRespawn = LMS_RESPAWN_NONE) then
3065 begin
3066 if FLives > 0 then FLives := FLives - 1;
3067 if FLives = 0 then FNoRespawn := True;
3068 end;
3070 // Íîìåð òèïà ñìåðòè:
3071 a := 1;
3072 case KillType of
3073 K_SIMPLEKILL: a := 1;
3074 K_HARDKILL: a := 2;
3075 K_EXTRAHARDKILL: a := 3;
3076 K_FALLKILL: a := 4;
3077 end;
3079 // Çâóê ñìåðòè:
3080 if not FModel.PlaySound(MODELSOUND_DIE, a, FObj.X, FObj.Y) then
3081 for i := 1 to 3 do
3082 if FModel.PlaySound(MODELSOUND_DIE, i, FObj.X, FObj.Y) then
3083 Break;
3085 // Âðåìÿ ðåñïàóíà:
3086 if Srv then
3087 case KillType of
3088 K_SIMPLEKILL:
3089 FTime[T_RESPAWN] := gTime + TIME_RESPAWN1;
3090 K_HARDKILL:
3091 FTime[T_RESPAWN] := gTime + TIME_RESPAWN2;
3092 K_EXTRAHARDKILL, K_FALLKILL:
3093 FTime[T_RESPAWN] := gTime + TIME_RESPAWN3;
3094 end;
3096 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3097 case KillType of
3098 K_SIMPLEKILL:
3099 SetAction(A_DIE1);
3100 K_HARDKILL, K_EXTRAHARDKILL:
3101 SetAction(A_DIE2);
3102 end;
3104 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3105 if (KillType <> K_FALLKILL) and (Srv) then
3106 g_Monsters_killedp();
3108 if SpawnerUID = FUID then
3109 begin // Ñàìîóáèëñÿ
3110 if Srv and (DoFrags or (gGameSettings.GameMode = GM_TDM)) then
3111 begin
3112 Dec(FFrags);
3113 FLastFrag := 0;
3114 end;
3115 g_Console_Add(Format(_lc[I_PLAYER_KILL_SELF], [FName]), True);
3116 end
3117 else
3118 if g_GetUIDType(SpawnerUID) = UID_PLAYER then
3119 begin // Óáèò äðóãèì èãðîêîì
3120 KP := g_Player_Get(SpawnerUID);
3121 if (KP <> nil) and Srv then
3122 begin
3123 if (DoFrags or (gGameSettings.GameMode = GM_TDM)) then
3124 if SameTeam(FUID, SpawnerUID) then
3125 begin
3126 Dec(KP.FFrags);
3127 KP.FLastFrag := 0;
3128 end else
3129 begin
3130 Inc(KP.FFrags);
3131 KP.FragCombo();
3132 end;
3134 if (gGameSettings.GameMode = GM_TDM) and DoFrags then
3135 Inc(gTeamStat[KP.Team].Goals,
3136 IfThen(SameTeam(FUID, SpawnerUID), -1, 1));
3138 if netsrv then MH_SEND_PlayerStats(SpawnerUID);
3139 end;
3141 plr := g_Player_Get(SpawnerUID);
3142 if plr = nil then
3143 s := '?'
3144 else
3145 s := plr.FName;
3147 case KillType of
3148 K_HARDKILL:
3149 g_Console_Add(Format(_lc[I_PLAYER_KILL_EXTRAHARD_2],
3150 [FName, s]),
3151 gShowKillMsg);
3152 K_EXTRAHARDKILL:
3153 g_Console_Add(Format(_lc[I_PLAYER_KILL_EXTRAHARD_1],
3154 [FName, s]),
3155 gShowKillMsg);
3156 else
3157 g_Console_Add(Format(_lc[I_PLAYER_KILL],
3158 [FName, s]),
3159 gShowKillMsg);
3160 end;
3161 end
3162 else if g_GetUIDType(SpawnerUID) = UID_MONSTER then
3163 begin // Óáèò ìîíñòðîì
3164 mon := g_Monsters_ByUID(SpawnerUID);
3165 if mon = nil then
3166 s := '?'
3167 else
3168 s := g_Monsters_GetKilledBy(mon.MonsterType);
3170 case KillType of
3171 K_HARDKILL:
3172 g_Console_Add(Format(_lc[I_PLAYER_KILL_EXTRAHARD_2],
3173 [FName, s]),
3174 gShowKillMsg);
3175 K_EXTRAHARDKILL:
3176 g_Console_Add(Format(_lc[I_PLAYER_KILL_EXTRAHARD_1],
3177 [FName, s]),
3178 gShowKillMsg);
3179 else
3180 g_Console_Add(Format(_lc[I_PLAYER_KILL],
3181 [FName, s]),
3182 gShowKillMsg);
3183 end;
3184 end
3185 else // Îñîáûå òèïû ñìåðòè
3186 case t of
3187 HIT_DISCON: ;
3188 HIT_SELF: g_Console_Add(Format(_lc[I_PLAYER_KILL_SELF], [FName]), True);
3189 HIT_FALL: g_Console_Add(Format(_lc[I_PLAYER_KILL_FALL], [FName]), True);
3190 HIT_WATER: g_Console_Add(Format(_lc[I_PLAYER_KILL_WATER], [FName]), True);
3191 HIT_ACID: g_Console_Add(Format(_lc[I_PLAYER_KILL_ACID], [FName]), True);
3192 HIT_TRAP: g_Console_Add(Format(_lc[I_PLAYER_KILL_TRAP], [FName]), True);
3193 else g_Console_Add(Format(_lc[I_PLAYER_DIED], [FName]), True);
3194 end;
3196 if Srv then
3197 begin
3198 // Âûáðîñ îðóæèÿ:
3199 for a := WP_FIRST to WP_LAST do
3200 if FWeapon[a] then
3201 begin
3202 case a of
3203 WEAPON_SAW: i := ITEM_WEAPON_SAW;
3204 WEAPON_SHOTGUN1: i := ITEM_WEAPON_SHOTGUN1;
3205 WEAPON_SHOTGUN2: i := ITEM_WEAPON_SHOTGUN2;
3206 WEAPON_CHAINGUN: i := ITEM_WEAPON_CHAINGUN;
3207 WEAPON_ROCKETLAUNCHER: i := ITEM_WEAPON_ROCKETLAUNCHER;
3208 WEAPON_PLASMA: i := ITEM_WEAPON_PLASMA;
3209 WEAPON_BFG: i := ITEM_WEAPON_BFG;
3210 WEAPON_SUPERPULEMET: i := ITEM_WEAPON_SUPERPULEMET;
3211 WEAPON_FLAMETHROWER: i := ITEM_WEAPON_FLAMETHROWER;
3212 else i := 0;
3213 end;
3215 if i <> 0 then
3216 PushItem(i);
3217 end;
3219 // Âûáðîñ ðþêçàêà:
3220 if R_ITEM_BACKPACK in FRulez then
3221 PushItem(ITEM_AMMO_BACKPACK);
3223 // Âûáðîñ ðàêåòíîãî ðàíöà:
3224 if FJetFuel > 0 then
3225 PushItem(ITEM_JETPACK);
3227 // Âûáðîñ êëþ÷åé:
3228 if not (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF]) then
3229 begin
3230 if R_KEY_RED in FRulez then
3231 PushItem(ITEM_KEY_RED);
3233 if R_KEY_GREEN in FRulez then
3234 PushItem(ITEM_KEY_GREEN);
3236 if R_KEY_BLUE in FRulez then
3237 PushItem(ITEM_KEY_BLUE);
3238 end;
3240 // Âûáðîñ ôëàãà:
3241 DropFlag();
3242 end;
3244 g_Player_CreateCorpse(Self);
3246 if Srv and (gGameSettings.MaxLives > 0) and FNoRespawn and
3247 (gLMSRespawn = LMS_RESPAWN_NONE) then
3248 begin
3249 a := 0;
3250 k := 0;
3251 ar := 0;
3252 ab := 0;
3253 for i := Low(gPlayers) to High(gPlayers) do
3254 begin
3255 if gPlayers[i] = nil then continue;
3256 if (not gPlayers[i].FNoRespawn) and (not gPlayers[i].FSpectator) then
3257 begin
3258 Inc(a);
3259 if gPlayers[i].FTeam = TEAM_RED then Inc(ar)
3260 else if gPlayers[i].FTeam = TEAM_BLUE then Inc(ab);
3261 k := i;
3262 end;
3263 end;
3265 OldLR := gLMSRespawn;
3266 if (gGameSettings.GameMode = GM_COOP) then
3267 begin
3268 if (a = 0) then
3269 begin
3270 // everyone is dead, restart the map
3271 g_Game_Message(_lc[I_MESSAGE_LMS_LOSE], 144);
3272 if Netsrv then
3273 MH_SEND_GameEvent(NET_EV_LMS_LOSE);
3274 gLMSRespawn := LMS_RESPAWN_FINAL;
3275 gLMSRespawnTime := gTime + 5000;
3276 end
3277 else if (a = 1) then
3278 begin
3279 if (gPlayers[k] <> nil) and not (gPlayers[k] is TBot) then
3280 if (gPlayers[k] = gPlayer1) or
3281 (gPlayers[k] = gPlayer2) then
3282 g_Console_Add('*** ' + _lc[I_MESSAGE_LMS_SURVIVOR] + ' ***', True)
3283 else if Netsrv and (gPlayers[k].FClientID >= 0) then
3284 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR, 0, 'N', gPlayers[k].FClientID);
3285 end;
3286 end
3287 else if (gGameSettings.GameMode = GM_TDM) then
3288 begin
3289 if (ab = 0) and (ar <> 0) then
3290 begin
3291 // blu team ded
3292 g_Game_Message(Format(_lc[I_MESSAGE_TLMS_WIN], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 144);
3293 if Netsrv then
3294 MH_SEND_GameEvent(NET_EV_TLMS_WIN, TEAM_RED);
3295 Inc(gTeamStat[TEAM_RED].Goals);
3296 gLMSRespawn := LMS_RESPAWN_FINAL;
3297 gLMSRespawnTime := gTime + 5000;
3298 end
3299 else if (ar = 0) and (ab <> 0) then
3300 begin
3301 // red team ded
3302 g_Game_Message(Format(_lc[I_MESSAGE_TLMS_WIN], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 144);
3303 if Netsrv then
3304 MH_SEND_GameEvent(NET_EV_TLMS_WIN, TEAM_BLUE);
3305 Inc(gTeamStat[TEAM_BLUE].Goals);
3306 gLMSRespawn := LMS_RESPAWN_FINAL;
3307 gLMSRespawnTime := gTime + 5000;
3308 end
3309 else if (ar = 0) and (ab = 0) then
3310 begin
3311 // everyone ded
3312 g_Game_Message(_lc[I_GAME_WIN_DRAW], 144);
3313 if Netsrv then
3314 MH_SEND_GameEvent(NET_EV_LMS_DRAW, 0, FName);
3315 gLMSRespawn := LMS_RESPAWN_FINAL;
3316 gLMSRespawnTime := gTime + 5000;
3317 end;
3318 end
3319 else if (gGameSettings.GameMode = GM_DM) then
3320 begin
3321 if (a = 1) then
3322 begin
3323 if gPlayers[k] <> nil then
3324 with gPlayers[k] do
3325 begin
3326 // survivor is the winner
3327 g_Game_Message(Format(_lc[I_MESSAGE_LMS_WIN], [AnsiUpperCase(FName)]), 144);
3328 if Netsrv then
3329 MH_SEND_GameEvent(NET_EV_LMS_WIN, 0, FName);
3330 Inc(FFrags);
3331 end;
3332 gLMSRespawn := LMS_RESPAWN_FINAL;
3333 gLMSRespawnTime := gTime + 5000;
3334 end
3335 else if (a = 0) then
3336 begin
3337 // everyone is dead, restart the map
3338 g_Game_Message(_lc[I_GAME_WIN_DRAW], 144);
3339 if Netsrv then
3340 MH_SEND_GameEvent(NET_EV_LMS_DRAW, 0, FName);
3341 gLMSRespawn := LMS_RESPAWN_FINAL;
3342 gLMSRespawnTime := gTime + 5000;
3343 end;
3344 end;
3345 if srv and (OldLR = LMS_RESPAWN_NONE) and (gLMSRespawn > LMS_RESPAWN_NONE) then
3346 begin
3347 if NetMode = NET_SERVER then
3348 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, (gLMSRespawnTime - gTime) div 1000)
3349 else
3350 g_Console_Add(Format(_lc[I_MSG_WARMUP_START], [(gLMSRespawnTime - gTime) div 1000]), True);
3351 end;
3352 end;
3354 if Netsrv then
3355 begin
3356 MH_SEND_PlayerStats(FUID);
3357 MH_SEND_PlayerDeath(FUID, KillType, t, SpawnerUID);
3358 if gGameSettings.GameMode = GM_TDM then MH_SEND_GameStats;
3359 end;
3361 if srv and FNoRespawn then Spectate(True);
3362 FWantsInGame := True;
3363 end;
3365 function TPlayer.BodyInLiquid(XInc, YInc: Integer): Boolean;
3366 begin
3367 Result := g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc, PLAYER_RECT.Width,
3368 PLAYER_RECT.Height-20, PANEL_WATER or PANEL_ACID1 or PANEL_ACID2, False);
3369 end;
3371 function TPlayer.BodyInAcid(XInc, YInc: Integer): Boolean;
3372 begin
3373 Result := g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc, PLAYER_RECT.Width,
3374 PLAYER_RECT.Height-20, PANEL_ACID1 or PANEL_ACID2, False);
3375 end;
3377 procedure TPlayer.MakeBloodSimple(Count: Word);
3378 begin
3379 g_GFX_Blood(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)+8,
3380 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2),
3381 Count div 2, 3, -1, 16, (PLAYER_RECT.Height*2 div 3),
3382 150, 0, 0);
3383 g_GFX_Blood(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-8,
3384 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2),
3385 Count div 2, -3, -1, 16, (PLAYER_RECT.Height*2) div 3,
3386 150, 0, 0);
3387 end;
3389 procedure TPlayer.MakeBloodVector(Count: Word; VelX, VelY: Integer);
3390 begin
3391 g_GFX_Blood(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2),
3392 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2),
3393 Count, VelX, VelY, 16, (PLAYER_RECT.Height*2) div 3,
3394 150, 0, 0);
3395 end;
3397 procedure TPlayer.QueueWeaponSwitch(Weapon: Byte);
3398 begin
3399 if g_Game_IsClient then Exit;
3400 if Weapon > High(FWeapon) then Exit;
3401 FNextWeap := FNextWeap or (1 shl Weapon);
3402 end;
3404 procedure TPlayer.resetWeaponQueue ();
3405 begin
3406 FNextWeap := 0;
3407 FNextWeapDelay := 0;
3408 end;
3410 function TPlayer.hasAmmoForWeapon (weapon: Byte): Boolean;
3411 begin
3412 result := false;
3413 case weapon of
3414 WEAPON_KASTET, WEAPON_SAW: result := true;
3415 WEAPON_SHOTGUN1, WEAPON_SHOTGUN2: result := (FAmmo[A_SHELLS] > 0);
3416 WEAPON_PISTOL, WEAPON_CHAINGUN, WEAPON_SUPERPULEMET: result := (FAmmo[A_BULLETS] > 0);
3417 WEAPON_ROCKETLAUNCHER: result := (FAmmo[A_ROCKETS] > 0);
3418 WEAPON_PLASMA, WEAPON_BFG: result := (FAmmo[A_CELLS] > 0);
3419 WEAPON_FLAMETHROWER: result := (FAmmo[A_FUEL] > 0);
3420 else result := (weapon < length(FWeapon));
3421 end;
3422 end;
3424 // return 255 for "no switch"
3425 function TPlayer.getNextWeaponIndex (): Byte;
3426 var
3427 i: Word;
3428 wantThisWeapon: array[0..64] of Boolean;
3429 wwc: Integer = 0; //HACK!
3430 dir, cwi: Integer;
3431 begin
3432 result := 255; // default result: "no switch"
3433 // had weapon cycling on previous frame? remove that flag
3434 if (FNextWeap and $2000) <> 0 then
3435 begin
3436 FNextWeap := FNextWeap and $1FFF;
3437 FNextWeapDelay := 0;
3438 end;
3439 // cycling has priority
3440 if (FNextWeap and $C000) <> 0 then
3441 begin
3442 if (FNextWeap and $8000) <> 0 then
3443 dir := 1
3444 else
3445 dir := -1;
3446 FNextWeap := FNextWeap or $2000; // we need this
3447 if FNextWeapDelay > 0 then
3448 exit; // cooldown time
3449 cwi := FCurrWeap;
3450 for i := 0 to High(FWeapon) do
3451 begin
3452 cwi := (cwi+length(FWeapon)+dir) mod length(FWeapon);
3453 if FWeapon[cwi] then
3454 begin
3455 //e_WriteLog(Format(' SWITCH: cur=%d; new=%d', [FCurrWeap, cwi]), MSG_WARNING);
3456 result := Byte(cwi);
3457 FNextWeapDelay := 10;
3458 exit;
3459 end;
3460 end;
3461 resetWeaponQueue();
3462 exit;
3463 end;
3464 // no cycling
3465 for i := 0 to High(wantThisWeapon) do
3466 wantThisWeapon[i] := false;
3467 for i := 0 to High(FWeapon) do
3468 if (FNextWeap and (1 shl i)) <> 0 then
3469 begin
3470 wantThisWeapon[i] := true;
3471 Inc(wwc);
3472 end;
3473 // exclude currently selected weapon from the set
3474 wantThisWeapon[FCurrWeap] := false;
3475 // slow down alterations a little
3476 if wwc > 1 then
3477 begin
3478 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3479 // more than one weapon requested, assume "alteration" and check alteration delay
3480 if FNextWeapDelay > 0 then
3481 begin
3482 FNextWeap := 0;
3483 exit;
3484 end; // yeah
3485 end;
3486 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3487 // but clear all counters if no weapon should be switched
3488 if wwc < 1 then
3489 begin
3490 resetWeaponQueue();
3491 exit;
3492 end;
3493 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3494 // try weapons in descending order
3495 for i := High(FWeapon) downto 0 do
3496 begin
3497 if wantThisWeapon[i] and FWeapon[i] and ((wwc = 1) or hasAmmoForWeapon(i)) then
3498 begin
3499 // i found her!
3500 result := Byte(i);
3501 resetWeaponQueue();
3502 FNextWeapDelay := 10; // anyway, 'cause why not
3503 exit;
3504 end;
3505 end;
3506 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3507 resetWeaponQueue();
3508 end;
3510 procedure TPlayer.RealizeCurrentWeapon();
3511 function switchAllowed (): Boolean;
3512 var
3513 i: Byte;
3514 begin
3515 result := false;
3516 if FBFGFireCounter <> -1 then
3517 exit;
3518 if FTime[T_SWITCH] > gTime then
3519 exit;
3520 for i := WP_FIRST to WP_LAST do
3521 if FReloading[i] > 0 then
3522 exit;
3523 result := true;
3524 end;
3526 var
3527 nw: Byte;
3528 begin
3529 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3530 //FNextWeap := FNextWeap and $1FFF;
3531 if FNextWeapDelay > 0 then Dec(FNextWeapDelay); // "alteration delay"
3533 if not switchAllowed then
3534 begin
3535 //HACK for weapon cycling
3536 if (FNextWeap and $7000) <> 0 then FNextWeap := 0;
3537 exit;
3538 end;
3540 nw := getNextWeaponIndex();
3541 if nw = 255 then exit; // don't reset anything here
3542 if nw > High(FWeapon) then
3543 begin
3544 // don't forget to reset queue here!
3545 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
3546 resetWeaponQueue();
3547 exit;
3548 end;
3550 if FWeapon[nw] then
3551 begin
3552 FCurrWeap := nw;
3553 FTime[T_SWITCH] := gTime+156;
3554 if FCurrWeap = WEAPON_SAW then FSawSoundSelect.PlayAt(FObj.X, FObj.Y);
3555 FModel.SetWeapon(FCurrWeap);
3556 if g_Game_IsNet then MH_SEND_PlayerStats(FUID);
3557 end;
3558 end;
3560 procedure TPlayer.NextWeapon();
3561 begin
3562 if g_Game_IsClient then Exit;
3563 FNextWeap := $8000;
3564 end;
3566 procedure TPlayer.PrevWeapon();
3567 begin
3568 if g_Game_IsClient then Exit;
3569 FNextWeap := $4000;
3570 end;
3572 procedure TPlayer.SetWeapon(W: Byte);
3573 begin
3574 if FCurrWeap <> W then
3575 if W = WEAPON_SAW then
3576 FSawSoundSelect.PlayAt(FObj.X, FObj.Y);
3578 FCurrWeap := W;
3579 FModel.SetWeapon(CurrWeap);
3580 resetWeaponQueue();
3581 end;
3583 function TPlayer.PickItem(ItemType: Byte; arespawn: Boolean; var remove: Boolean): Boolean;
3584 var
3585 a: Boolean;
3586 begin
3587 Result := False;
3588 if g_Game_IsClient then Exit;
3590 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3591 a := LongBool(gGameSettings.Options and GAME_OPTION_WEAPONSTAY) and arespawn;
3592 remove := not a;
3594 case ItemType of
3595 ITEM_MEDKIT_SMALL:
3596 if FHealth < PLAYER_HP_SOFT then
3597 begin
3598 IncMax(FHealth, 10, PLAYER_HP_SOFT);
3599 Result := True;
3600 remove := True;
3601 FFireTime := 0;
3602 if gFlash = 2 then Inc(FPickup, 5);
3603 end;
3605 ITEM_MEDKIT_LARGE:
3606 if FHealth < PLAYER_HP_SOFT then
3607 begin
3608 IncMax(FHealth, 25, PLAYER_HP_SOFT);
3609 Result := True;
3610 remove := True;
3611 FFireTime := 0;
3612 if gFlash = 2 then Inc(FPickup, 5);
3613 end;
3615 ITEM_ARMOR_GREEN:
3616 if FArmor < PLAYER_AP_SOFT then
3617 begin
3618 FArmor := PLAYER_AP_SOFT;
3619 Result := True;
3620 remove := True;
3621 if gFlash = 2 then Inc(FPickup, 5);
3622 end;
3624 ITEM_ARMOR_BLUE:
3625 if FArmor < PLAYER_AP_LIMIT then
3626 begin
3627 FArmor := PLAYER_AP_LIMIT;
3628 Result := True;
3629 remove := True;
3630 if gFlash = 2 then Inc(FPickup, 5);
3631 end;
3633 ITEM_SPHERE_BLUE:
3634 if FHealth < PLAYER_HP_LIMIT then
3635 begin
3636 IncMax(FHealth, 100, PLAYER_HP_LIMIT);
3637 Result := True;
3638 remove := True;
3639 FFireTime := 0;
3640 if gFlash = 2 then Inc(FPickup, 5);
3641 end;
3643 ITEM_SPHERE_WHITE:
3644 if (FHealth < PLAYER_HP_LIMIT) or (FArmor < PLAYER_AP_LIMIT) then
3645 begin
3646 if FHealth < PLAYER_HP_LIMIT then
3647 FHealth := PLAYER_HP_LIMIT;
3648 if FArmor < PLAYER_AP_LIMIT then
3649 FArmor := PLAYER_AP_LIMIT;
3650 Result := True;
3651 remove := True;
3652 FFireTime := 0;
3653 if gFlash = 2 then Inc(FPickup, 5);
3654 end;
3656 ITEM_WEAPON_SAW:
3657 if (not FWeapon[WEAPON_SAW]) or ((not arespawn) and (gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF])) then
3658 begin
3659 FWeapon[WEAPON_SAW] := True;
3660 Result := True;
3661 if gFlash = 2 then Inc(FPickup, 5);
3662 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
3663 end;
3665 ITEM_WEAPON_SHOTGUN1:
3666 if (FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS]) or not FWeapon[WEAPON_SHOTGUN1] then
3667 begin
3668 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
3669 if a and FWeapon[WEAPON_SHOTGUN1] then Exit;
3671 IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
3672 FWeapon[WEAPON_SHOTGUN1] := True;
3673 Result := True;
3674 if gFlash = 2 then Inc(FPickup, 5);
3675 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
3676 end;
3678 ITEM_WEAPON_SHOTGUN2:
3679 if (FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS]) or not FWeapon[WEAPON_SHOTGUN2] then
3680 begin
3681 if a and FWeapon[WEAPON_SHOTGUN2] then Exit;
3683 IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
3684 FWeapon[WEAPON_SHOTGUN2] := True;
3685 Result := True;
3686 if gFlash = 2 then Inc(FPickup, 5);
3687 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
3688 end;
3690 ITEM_WEAPON_CHAINGUN:
3691 if (FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS]) or not FWeapon[WEAPON_CHAINGUN] then
3692 begin
3693 if a and FWeapon[WEAPON_CHAINGUN] then Exit;
3695 IncMax(FAmmo[A_BULLETS], 50, FMaxAmmo[A_BULLETS]);
3696 FWeapon[WEAPON_CHAINGUN] := True;
3697 Result := True;
3698 if gFlash = 2 then Inc(FPickup, 5);
3699 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
3700 end;
3702 ITEM_WEAPON_ROCKETLAUNCHER:
3703 if (FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS]) or not FWeapon[WEAPON_ROCKETLAUNCHER] then
3704 begin
3705 if a and FWeapon[WEAPON_ROCKETLAUNCHER] then Exit;
3707 IncMax(FAmmo[A_ROCKETS], 2, FMaxAmmo[A_ROCKETS]);
3708 FWeapon[WEAPON_ROCKETLAUNCHER] := True;
3709 Result := True;
3710 if gFlash = 2 then Inc(FPickup, 5);
3711 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
3712 end;
3714 ITEM_WEAPON_PLASMA:
3715 if (FAmmo[A_CELLS] < FMaxAmmo[A_CELLS]) or not FWeapon[WEAPON_PLASMA] then
3716 begin
3717 if a and FWeapon[WEAPON_PLASMA] then Exit;
3719 IncMax(FAmmo[A_CELLS], 40, FMaxAmmo[A_CELLS]);
3720 FWeapon[WEAPON_PLASMA] := True;
3721 Result := True;
3722 if gFlash = 2 then Inc(FPickup, 5);
3723 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
3724 end;
3726 ITEM_WEAPON_BFG:
3727 if (FAmmo[A_CELLS] < FMaxAmmo[A_CELLS]) or not FWeapon[WEAPON_BFG] then
3728 begin
3729 if a and FWeapon[WEAPON_BFG] then Exit;
3731 IncMax(FAmmo[A_CELLS], 40, FMaxAmmo[A_CELLS]);
3732 FWeapon[WEAPON_BFG] := True;
3733 Result := True;
3734 if gFlash = 2 then Inc(FPickup, 5);
3735 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
3736 end;
3738 ITEM_WEAPON_SUPERPULEMET:
3739 if (FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS]) or not FWeapon[WEAPON_SUPERPULEMET] then
3740 begin
3741 if a and FWeapon[WEAPON_SUPERPULEMET] then Exit;
3743 IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
3744 FWeapon[WEAPON_SUPERPULEMET] := True;
3745 Result := True;
3746 if gFlash = 2 then Inc(FPickup, 5);
3747 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
3748 end;
3750 ITEM_WEAPON_FLAMETHROWER:
3751 if (FAmmo[A_FUEL] < FMaxAmmo[A_FUEL]) or not FWeapon[WEAPON_FLAMETHROWER] then
3752 begin
3753 if a and FWeapon[WEAPON_FLAMETHROWER] then Exit;
3755 IncMax(FAmmo[A_FUEL], 100, FMaxAmmo[A_FUEL]);
3756 FWeapon[WEAPON_FLAMETHROWER] := True;
3757 Result := True;
3758 if gFlash = 2 then Inc(FPickup, 5);
3759 if a and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETWEAPON');
3760 end;
3762 ITEM_AMMO_BULLETS:
3763 if FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS] then
3764 begin
3765 IncMax(FAmmo[A_BULLETS], 10, FMaxAmmo[A_BULLETS]);
3766 Result := True;
3767 remove := True;
3768 if gFlash = 2 then Inc(FPickup, 5);
3769 end;
3771 ITEM_AMMO_BULLETS_BOX:
3772 if FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS] then
3773 begin
3774 IncMax(FAmmo[A_BULLETS], 50, FMaxAmmo[A_BULLETS]);
3775 Result := True;
3776 remove := True;
3777 if gFlash = 2 then Inc(FPickup, 5);
3778 end;
3780 ITEM_AMMO_SHELLS:
3781 if FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS] then
3782 begin
3783 IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
3784 Result := True;
3785 remove := True;
3786 if gFlash = 2 then Inc(FPickup, 5);
3787 end;
3789 ITEM_AMMO_SHELLS_BOX:
3790 if FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS] then
3791 begin
3792 IncMax(FAmmo[A_SHELLS], 25, FMaxAmmo[A_SHELLS]);
3793 Result := True;
3794 remove := True;
3795 if gFlash = 2 then Inc(FPickup, 5);
3796 end;
3798 ITEM_AMMO_ROCKET:
3799 if FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS] then
3800 begin
3801 IncMax(FAmmo[A_ROCKETS], 1, FMaxAmmo[A_ROCKETS]);
3802 Result := True;
3803 remove := True;
3804 if gFlash = 2 then Inc(FPickup, 5);
3805 end;
3807 ITEM_AMMO_ROCKET_BOX:
3808 if FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS] then
3809 begin
3810 IncMax(FAmmo[A_ROCKETS], 5, FMaxAmmo[A_ROCKETS]);
3811 Result := True;
3812 remove := True;
3813 if gFlash = 2 then Inc(FPickup, 5);
3814 end;
3816 ITEM_AMMO_CELL:
3817 if FAmmo[A_CELLS] < FMaxAmmo[A_CELLS] then
3818 begin
3819 IncMax(FAmmo[A_CELLS], 40, FMaxAmmo[A_CELLS]);
3820 Result := True;
3821 remove := True;
3822 if gFlash = 2 then Inc(FPickup, 5);
3823 end;
3825 ITEM_AMMO_CELL_BIG:
3826 if FAmmo[A_CELLS] < FMaxAmmo[A_CELLS] then
3827 begin
3828 IncMax(FAmmo[A_CELLS], 100, FMaxAmmo[A_CELLS]);
3829 Result := True;
3830 remove := True;
3831 if gFlash = 2 then Inc(FPickup, 5);
3832 end;
3834 ITEM_AMMO_FUELCAN:
3835 if FAmmo[A_FUEL] < FMaxAmmo[A_FUEL] then
3836 begin
3837 IncMax(FAmmo[A_FUEL], 100, FMaxAmmo[A_FUEL]);
3838 Result := True;
3839 remove := True;
3840 if gFlash = 2 then Inc(FPickup, 5);
3841 end;
3843 ITEM_AMMO_BACKPACK:
3844 if not(R_ITEM_BACKPACK in FRulez) or
3845 (FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS]) or
3846 (FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS]) or
3847 (FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS]) or
3848 (FAmmo[A_CELLS] < FMaxAmmo[A_CELLS]) or
3849 (FMaxAmmo[A_FUEL] < AmmoLimits[1, A_FUEL]) then
3850 begin
3851 FMaxAmmo[A_BULLETS] := AmmoLimits[1, A_BULLETS];
3852 FMaxAmmo[A_SHELLS] := AmmoLimits[1, A_SHELLS];
3853 FMaxAmmo[A_ROCKETS] := AmmoLimits[1, A_ROCKETS];
3854 FMaxAmmo[A_CELLS] := AmmoLimits[1, A_CELLS];
3855 FMaxAmmo[A_FUEL] := AmmoLimits[1, A_FUEL];
3857 if FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS] then
3858 IncMax(FAmmo[A_BULLETS], 10, FMaxAmmo[A_BULLETS]);
3859 if FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS] then
3860 IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
3861 if FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS] then
3862 IncMax(FAmmo[A_ROCKETS], 1, FMaxAmmo[A_ROCKETS]);
3863 if FAmmo[A_CELLS] < FMaxAmmo[A_CELLS] then
3864 IncMax(FAmmo[A_CELLS], 40, FMaxAmmo[A_CELLS]);
3866 FRulez := FRulez + [R_ITEM_BACKPACK];
3867 Result := True;
3868 remove := True;
3869 if gFlash = 2 then Inc(FPickup, 5);
3870 end;
3872 ITEM_KEY_RED:
3873 if not(R_KEY_RED in FRulez) then
3874 begin
3875 Include(FRulez, R_KEY_RED);
3876 Result := True;
3877 remove := (gGameSettings.GameMode <> GM_COOP) and (g_Player_GetCount() < 2);
3878 if gFlash = 2 then Inc(FPickup, 5);
3879 if (not remove) and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETITEM');
3880 end;
3882 ITEM_KEY_GREEN:
3883 if not(R_KEY_GREEN in FRulez) then
3884 begin
3885 Include(FRulez, R_KEY_GREEN);
3886 Result := True;
3887 remove := (gGameSettings.GameMode <> GM_COOP) and (g_Player_GetCount() < 2);
3888 if gFlash = 2 then Inc(FPickup, 5);
3889 if (not remove) and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETITEM');
3890 end;
3892 ITEM_KEY_BLUE:
3893 if not(R_KEY_BLUE in FRulez) then
3894 begin
3895 Include(FRulez, R_KEY_BLUE);
3896 Result := True;
3897 remove := (gGameSettings.GameMode <> GM_COOP) and (g_Player_GetCount() < 2);
3898 if gFlash = 2 then Inc(FPickup, 5);
3899 if (not remove) and g_Game_IsNet then MH_SEND_Sound(GameX, GameY, 'SOUND_ITEM_GETITEM');
3900 end;
3902 ITEM_SUIT:
3903 if FMegaRulez[MR_SUIT] < gTime+PLAYER_SUIT_TIME then
3904 begin
3905 FMegaRulez[MR_SUIT] := gTime+PLAYER_SUIT_TIME;
3906 Result := True;
3907 remove := True;
3908 FFireTime := 0;
3909 if gFlash = 2 then Inc(FPickup, 5);
3910 end;
3912 ITEM_OXYGEN:
3913 if FAir < AIR_MAX then
3914 begin
3915 FAir := AIR_MAX;
3916 Result := True;
3917 remove := True;
3918 if gFlash = 2 then Inc(FPickup, 5);
3919 end;
3921 ITEM_MEDKIT_BLACK:
3922 begin
3923 if not (R_BERSERK in FRulez) then
3924 begin
3925 Include(FRulez, R_BERSERK);
3926 if FBFGFireCounter = -1 then
3927 begin
3928 FCurrWeap := WEAPON_KASTET;
3929 resetWeaponQueue();
3930 FModel.SetWeapon(WEAPON_KASTET);
3931 end;
3932 if gFlash <> 0 then
3933 Inc(FPain, 100);
3934 if gFlash = 2 then Inc(FPickup, 5);
3935 FBerserk := gTime+30000;
3936 Result := True;
3937 remove := True;
3938 FFireTime := 0;
3939 end;
3940 if FHealth < PLAYER_HP_SOFT then
3941 begin
3942 FHealth := PLAYER_HP_SOFT;
3943 FBerserk := gTime+30000;
3944 Result := True;
3945 remove := True;
3946 FFireTime := 0;
3947 end;
3948 end;
3950 ITEM_INVUL:
3951 if FMegaRulez[MR_INVUL] < gTime+PLAYER_INVUL_TIME then
3952 begin
3953 FMegaRulez[MR_INVUL] := gTime+PLAYER_INVUL_TIME;
3954 Result := True;
3955 remove := True;
3956 if gFlash = 2 then Inc(FPickup, 5);
3957 end;
3959 ITEM_BOTTLE:
3960 if FHealth < PLAYER_HP_LIMIT then
3961 begin
3962 IncMax(FHealth, 4, PLAYER_HP_LIMIT);
3963 Result := True;
3964 remove := True;
3965 FFireTime := 0;
3966 if gFlash = 2 then Inc(FPickup, 5);
3967 end;
3969 ITEM_HELMET:
3970 if FArmor < PLAYER_AP_LIMIT then
3971 begin
3972 IncMax(FArmor, 5, PLAYER_AP_LIMIT);
3973 Result := True;
3974 remove := True;
3975 if gFlash = 2 then Inc(FPickup, 5);
3976 end;
3978 ITEM_JETPACK:
3979 if FJetFuel < JET_MAX then
3980 begin
3981 FJetFuel := JET_MAX;
3982 Result := True;
3983 remove := True;
3984 if gFlash = 2 then Inc(FPickup, 5);
3985 end;
3987 ITEM_INVIS:
3988 if FMegaRulez[MR_INVIS] < gTime+PLAYER_INVIS_TIME then
3989 begin
3990 FMegaRulez[MR_INVIS] := gTime+PLAYER_INVIS_TIME;
3991 Result := True;
3992 remove := True;
3993 if gFlash = 2 then Inc(FPickup, 5);
3994 end;
3995 end;
3996 end;
3998 procedure TPlayer.Touch();
3999 begin
4000 if not FLive then
4001 Exit;
4002 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4003 if FIamBot then
4004 begin
4005 // Áðîñèòü ôëàã òîâàðèùó:
4006 if gGameSettings.GameMode = GM_CTF then
4007 DropFlag();
4008 end;
4009 end;
4011 procedure TPlayer.Push(vx, vy: Integer);
4012 begin
4013 if (not FPhysics) and FGhost then
4014 Exit;
4015 FObj.Accel.X := FObj.Accel.X + vx;
4016 FObj.Accel.Y := FObj.Accel.Y + vy;
4017 if g_Game_IsNet and g_Game_IsServer then
4018 MH_SEND_PlayerPos(True, FUID, NET_EVERYONE);
4019 end;
4021 procedure TPlayer.Reset(Force: Boolean);
4022 begin
4023 if Force then
4024 FLive := False;
4026 FSpawned := False;
4027 FTime[T_RESPAWN] := 0;
4028 FTime[T_FLAGCAP] := 0;
4029 FGodMode := False;
4030 FNoTarget := False;
4031 FNoReload := False;
4032 FFrags := 0;
4033 FLastFrag := 0;
4034 FComboEvnt := -1;
4035 FKills := 0;
4036 FMonsterKills := 0;
4037 FDeath := 0;
4038 FSecrets := 0;
4039 if FNoRespawn then
4040 begin
4041 FSpectator := False;
4042 FGhost := False;
4043 FPhysics := True;
4044 FSpectatePlayer := -1;
4045 FNoRespawn := False;
4046 end;
4047 FLives := gGameSettings.MaxLives;
4049 SetFlag(FLAG_NONE);
4050 end;
4052 procedure TPlayer.SoftReset();
4053 begin
4054 ReleaseKeys();
4056 FDamageBuffer := 0;
4057 FIncCam := 0;
4058 FBFGFireCounter := -1;
4059 FShellTimer := -1;
4060 FPain := 0;
4061 FLastHit := 0;
4062 FLastFrag := 0;
4063 FComboEvnt := -1;
4065 SetFlag(FLAG_NONE);
4066 SetAction(A_STAND, True);
4067 end;
4069 function TPlayer.GetRespawnPoint(): Byte;
4070 var
4071 c: Byte;
4072 begin
4073 Result := 255;
4074 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4076 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4077 if gGameSettings.GameMode in [GM_COOP, GM_SINGLE] then
4078 begin
4079 if (Self = gPlayer1) or (Self = gPlayer2) then
4080 begin
4081 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
4082 if Self = gPlayer1 then
4083 c := RESPAWNPOINT_PLAYER1
4084 else
4085 c := RESPAWNPOINT_PLAYER2;
4086 if g_Map_GetPointCount(c) > 0 then
4087 begin
4088 Result := c;
4089 Exit;
4090 end;
4092 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
4093 if Self = gPlayer1 then
4094 c := RESPAWNPOINT_PLAYER2
4095 else
4096 c := RESPAWNPOINT_PLAYER1;
4097 if g_Map_GetPointCount(c) > 0 then
4098 begin
4099 Result := c;
4100 Exit;
4101 end;
4102 end else
4103 begin
4104 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
4105 if Random(2) = 0 then
4106 c := RESPAWNPOINT_PLAYER1
4107 else
4108 c := RESPAWNPOINT_PLAYER2;
4109 if g_Map_GetPointCount(c) > 0 then
4110 begin
4111 Result := c;
4112 Exit;
4113 end;
4114 end;
4116 // Òî÷êà ëþáîé èç êîìàíä
4117 if Random(2) = 0 then
4118 c := RESPAWNPOINT_RED
4119 else
4120 c := RESPAWNPOINT_BLUE;
4121 if g_Map_GetPointCount(c) > 0 then
4122 begin
4123 Result := c;
4124 Exit;
4125 end;
4127 // Òî÷êà DM
4128 c := RESPAWNPOINT_DM;
4129 if g_Map_GetPointCount(c) > 0 then
4130 begin
4131 Result := c;
4132 Exit;
4133 end;
4134 end;
4136 // Ìÿñîïîâàë
4137 if gGameSettings.GameMode = GM_DM then
4138 begin
4139 // Òî÷êà DM
4140 c := RESPAWNPOINT_DM;
4141 if g_Map_GetPointCount(c) > 0 then
4142 begin
4143 Result := c;
4144 Exit;
4145 end;
4147 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4148 if Random(2) = 0 then
4149 c := RESPAWNPOINT_PLAYER1
4150 else
4151 c := RESPAWNPOINT_PLAYER2;
4152 if g_Map_GetPointCount(c) > 0 then
4153 begin
4154 Result := c;
4155 Exit;
4156 end;
4158 // Òî÷êà ëþáîé èç êîìàíä
4159 if Random(2) = 0 then
4160 c := RESPAWNPOINT_RED
4161 else
4162 c := RESPAWNPOINT_BLUE;
4163 if g_Map_GetPointCount(c) > 0 then
4164 begin
4165 Result := c;
4166 Exit;
4167 end;
4168 end;
4170 // Êîìàíäíûå
4171 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
4172 begin
4173 // Òî÷êà ñâîåé êîìàíäû
4174 c := RESPAWNPOINT_DM;
4175 if FTeam = TEAM_RED then
4176 c := RESPAWNPOINT_RED;
4177 if FTeam = TEAM_BLUE then
4178 c := RESPAWNPOINT_BLUE;
4179 if g_Map_GetPointCount(c) > 0 then
4180 begin
4181 Result := c;
4182 Exit;
4183 end;
4185 // Òî÷êà DM
4186 c := RESPAWNPOINT_DM;
4187 if g_Map_GetPointCount(c) > 0 then
4188 begin
4189 Result := c;
4190 Exit;
4191 end;
4193 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4194 if Random(2) = 0 then
4195 c := RESPAWNPOINT_PLAYER1
4196 else
4197 c := RESPAWNPOINT_PLAYER2;
4198 if g_Map_GetPointCount(c) > 0 then
4199 begin
4200 Result := c;
4201 Exit;
4202 end;
4204 // Òî÷êà äðóãîé êîìàíäû
4205 c := RESPAWNPOINT_DM;
4206 if FTeam = TEAM_RED then
4207 c := RESPAWNPOINT_BLUE;
4208 if FTeam = TEAM_BLUE then
4209 c := RESPAWNPOINT_RED;
4210 if g_Map_GetPointCount(c) > 0 then
4211 begin
4212 Result := c;
4213 Exit;
4214 end;
4215 end;
4216 end;
4218 procedure TPlayer.Respawn(Silent: Boolean; Force: Boolean = False);
4219 var
4220 RespawnPoint: TRespawnPoint;
4221 a, b, c: Byte;
4222 Anim: TAnimation;
4223 ID: DWORD;
4224 begin
4225 if not g_Game_IsServer then
4226 Exit;
4227 if FDummy then
4228 Exit;
4229 FWantsInGame := True;
4230 FJustTeleported := True;
4231 if Force then
4232 begin
4233 FTime[T_RESPAWN] := 0;
4234 FLive := False;
4235 end;
4236 FNetTime := 0;
4237 // if server changes MaxLives we gotta be ready
4238 if gGameSettings.MaxLives = 0 then FNoRespawn := False;
4240 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4241 if FTime[T_RESPAWN] > gTime then
4242 Exit;
4244 // Ïðîñðàë âñå æèçíè:
4245 if FNoRespawn then
4246 begin
4247 if not FSpectator then Spectate(True);
4248 FWantsInGame := True;
4249 Exit;
4250 end;
4252 if (gGameSettings.GameType <> GT_SINGLE) and (gGameSettings.GameMode <> GM_COOP) then
4253 begin // "Ñâîÿ èãðà"
4254 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4255 FRulez := FRulez-[R_BERSERK];
4256 end
4257 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4258 begin
4259 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4260 FRulez := FRulez-[R_KEY_RED, R_KEY_GREEN, R_KEY_BLUE, R_BERSERK];
4261 end;
4263 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4264 c := GetRespawnPoint();
4266 ReleaseKeys();
4267 SetFlag(FLAG_NONE);
4269 // Âîñêðåøåíèå áåç îðóæèÿ:
4270 if not FLive then
4271 begin
4272 FHealth := PLAYER_HP_SOFT;
4273 FArmor := 0;
4274 FLive := True;
4275 FAir := AIR_DEF;
4276 FJetFuel := 0;
4278 for a := WP_FIRST to WP_LAST do
4279 begin
4280 FWeapon[a] := False;
4281 FReloading[a] := 0;
4282 end;
4284 FWeapon[WEAPON_PISTOL] := True;
4285 FWeapon[WEAPON_KASTET] := True;
4286 FCurrWeap := WEAPON_PISTOL;
4287 resetWeaponQueue();
4289 FModel.SetWeapon(FCurrWeap);
4291 for b := A_BULLETS to A_HIGH do
4292 FAmmo[b] := 0;
4294 FAmmo[A_BULLETS] := 50;
4296 FMaxAmmo[A_BULLETS] := AmmoLimits[0, A_BULLETS];
4297 FMaxAmmo[A_SHELLS] := AmmoLimits[0, A_SHELLS];
4298 FMaxAmmo[A_ROCKETS] := AmmoLimits[0, A_SHELLS];
4299 FMaxAmmo[A_CELLS] := AmmoLimits[0, A_CELLS];
4300 FMaxAmmo[A_FUEL] := AmmoLimits[0, A_FUEL];
4302 if gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF] then
4303 FRulez := [R_KEY_RED, R_KEY_GREEN, R_KEY_BLUE]
4304 else
4305 FRulez := [];
4306 end;
4308 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4309 if not g_Map_GetPoint(c, RespawnPoint) then
4310 begin
4311 g_FatalError(_lc[I_GAME_ERROR_GET_SPAWN]);
4312 Exit;
4313 end;
4315 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4316 FObj.X := RespawnPoint.X-PLAYER_RECT.X;
4317 FObj.Y := RespawnPoint.Y-PLAYER_RECT.Y;
4318 FObj.Vel.X := 0;
4319 FObj.Vel.Y := 0;
4320 FObj.Accel.X := 0;
4321 FObj.Accel.Y := 0;
4323 FDirection := RespawnPoint.Direction;
4324 if FDirection = D_LEFT then
4325 FAngle := 180
4326 else
4327 FAngle := 0;
4329 FIncCam := 0;
4330 FBFGFireCounter := -1;
4331 FShellTimer := -1;
4332 FPain := 0;
4333 FLastHit := 0;
4335 SetAction(A_STAND, True);
4336 FModel.Direction := FDirection;
4338 for a := Low(FTime) to High(FTime) do
4339 FTime[a] := 0;
4341 for a := Low(FMegaRulez) to High(FMegaRulez) do
4342 FMegaRulez[a] := 0;
4344 FDamageBuffer := 0;
4345 FJetpack := False;
4346 FCanJetpack := False;
4347 FFireTime := 0;
4348 FFirePainTime := 0;
4349 FFireAttacker := 0;
4351 // Àíèìàöèÿ âîçðîæäåíèÿ:
4352 if (not gLoadGameMode) and (not Silent) then
4353 if g_Frames_Get(ID, 'FRAMES_TELEPORT') then
4354 begin
4355 Anim := TAnimation.Create(ID, False, 3);
4356 g_GFX_OnceAnim(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
4357 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32, Anim);
4358 Anim.Free();
4359 end;
4361 FSpectator := False;
4362 FGhost := False;
4363 FPhysics := True;
4364 FSpectatePlayer := -1;
4365 FSpawned := True;
4367 if g_Game_IsNet then
4368 begin
4369 MH_SEND_PlayerPos(True, FUID, NET_EVERYONE);
4370 MH_SEND_PlayerStats(FUID, NET_EVERYONE);
4371 if not Silent then
4372 MH_SEND_Effect(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
4373 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32,
4374 0, NET_GFX_TELE);
4375 end;
4376 end;
4378 procedure TPlayer.Spectate(NoMove: Boolean = False);
4379 begin
4380 if FLive then
4381 Kill(K_EXTRAHARDKILL, FUID, HIT_SOME)
4382 else if (not NoMove) then
4383 begin
4384 GameX := gMapInfo.Width div 2;
4385 GameY := gMapInfo.Height div 2;
4386 end;
4387 FXTo := GameX;
4388 FYTo := GameY;
4390 FLive := False;
4391 FSpectator := True;
4392 FGhost := True;
4393 FPhysics := False;
4394 FWantsInGame := False;
4395 FSpawned := False;
4397 if FNoRespawn then
4398 begin
4399 if Self = gPlayer1 then
4400 begin
4401 gLMSPID1 := FUID;
4402 gPlayer1 := nil;
4403 end;
4404 if Self = gPlayer2 then
4405 begin
4406 gLMSPID2 := FUID;
4407 gPlayer2 := nil;
4408 end;
4409 end;
4411 if g_Game_IsNet then
4412 MH_SEND_PlayerStats(FUID);
4413 end;
4415 procedure TPlayer.SwitchNoClip;
4416 begin
4417 if not FLive then
4418 Exit;
4419 FGhost := not FGhost;
4420 FPhysics := not FGhost;
4421 if FGhost then
4422 begin
4423 FXTo := FObj.X;
4424 FYTo := FObj.Y;
4425 end else
4426 begin
4427 FObj.Accel.X := 0;
4428 FObj.Accel.Y := 0;
4429 end;
4430 end;
4432 procedure TPlayer.Run(Direction: TDirection);
4433 var
4434 a, b: Integer;
4435 begin
4436 if MAX_RUNVEL > 8 then
4437 FlySmoke();
4439 // Áåæèì:
4440 if Direction = D_LEFT then
4441 begin
4442 if FObj.Vel.X > -MAX_RUNVEL then
4443 FObj.Vel.X := FObj.Vel.X - (MAX_RUNVEL shr 3);
4444 end
4445 else
4446 if FObj.Vel.X < MAX_RUNVEL then
4447 FObj.Vel.X := FObj.Vel.X + (MAX_RUNVEL shr 3);
4449 // Âîçìîæíî, ïèíàåì êóñêè:
4450 if (FObj.Vel.X <> 0) and (gGibs <> nil) then
4451 begin
4452 b := Abs(FObj.Vel.X);
4453 if b > 1 then b := b * (Random(8 div b) + 1);
4454 for a := 0 to High(gGibs) do
4455 begin
4456 if gGibs[a].Live and
4457 g_Obj_Collide(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y+FObj.Rect.Height-4,
4458 FObj.Rect.Width, 8, @gGibs[a].Obj) and (Random(3) = 0) then
4459 begin
4460 // Ïèíàåì êóñêè
4461 if FObj.Vel.X < 0 then
4462 begin
4463 g_Obj_PushA(@gGibs[a].Obj, b, Random(61)+120) // íàëåâî
4464 end
4465 else
4466 begin
4467 g_Obj_PushA(@gGibs[a].Obj, b, Random(61)); // íàïðàâî
4468 end;
4469 gGibs[a].positionChanged(); // this updates spatial accelerators
4470 end;
4471 end;
4472 end;
4474 SetAction(A_WALK);
4475 end;
4477 procedure TPlayer.SeeDown();
4478 begin
4479 SetAction(A_SEEDOWN);
4481 if FDirection = D_LEFT then FAngle := ANGLE_LEFTDOWN else FAngle := ANGLE_RIGHTDOWN;
4483 if FIncCam > -120 then DecMin(FIncCam, 5, -120);
4484 end;
4486 procedure TPlayer.SeeUp();
4487 begin
4488 SetAction(A_SEEUP);
4490 if FDirection = D_LEFT then FAngle := ANGLE_LEFTUP else FAngle := ANGLE_RIGHTUP;
4492 if FIncCam < 120 then IncMax(FIncCam, 5, 120);
4493 end;
4495 procedure TPlayer.SetAction(Action: Byte; Force: Boolean = False);
4496 var
4497 Prior: Byte;
4498 begin
4499 case Action of
4500 A_WALK: Prior := 3;
4501 A_DIE1: Prior := 5;
4502 A_DIE2: Prior := 5;
4503 A_ATTACK: Prior := 2;
4504 A_SEEUP: Prior := 1;
4505 A_SEEDOWN: Prior := 1;
4506 A_ATTACKUP: Prior := 2;
4507 A_ATTACKDOWN: Prior := 2;
4508 A_PAIN: Prior := 4;
4509 else Prior := 0;
4510 end;
4512 if (Prior > FActionPrior) or Force then
4513 if not ((Prior = 2) and (FCurrWeap = WEAPON_SAW)) then
4514 begin
4515 FActionPrior := Prior;
4516 FActionAnim := Action;
4517 FActionForce := Force;
4518 FActionChanged := True;
4519 end;
4521 if Action in [A_ATTACK, A_ATTACKUP, A_ATTACKDOWN] then FModel.SetFire(True);
4522 end;
4524 function TPlayer.StayOnStep(XInc, YInc: Integer): Boolean;
4525 begin
4526 Result := not g_Map_CollidePanel(FObj.X+PLAYER_RECT.X, FObj.Y+YInc+PLAYER_RECT.Y+PLAYER_RECT.Height-1,
4527 PLAYER_RECT.Width, 1, PANEL_STEP, False)
4528 and g_Map_CollidePanel(FObj.X+PLAYER_RECT.X, FObj.Y+YInc+PLAYER_RECT.Y+PLAYER_RECT.Height,
4529 PLAYER_RECT.Width, 1, PANEL_STEP, False);
4530 end;
4532 function TPlayer.TeleportTo(X, Y: Integer; silent: Boolean; dir: Byte): Boolean;
4533 var
4534 Anim: TAnimation;
4535 ID: DWORD;
4536 begin
4537 Result := False;
4539 if g_CollideLevel(X, Y, PLAYER_RECT.Width, PLAYER_RECT.Height) then
4540 begin
4541 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj.X, FObj.Y);
4542 if g_Game_IsServer and g_Game_IsNet then
4543 MH_SEND_Sound(FObj.X, FObj.Y, 'SOUND_GAME_NOTELEPORT');
4544 Exit;
4545 end;
4547 FJustTeleported := True;
4549 Anim := nil;
4550 if not silent then
4551 begin
4552 if g_Frames_Get(ID, 'FRAMES_TELEPORT') then
4553 begin
4554 Anim := TAnimation.Create(ID, False, 3);
4555 end;
4557 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj.X, FObj.Y);
4558 g_GFX_OnceAnim(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
4559 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32, Anim);
4560 if g_Game_IsServer and g_Game_IsNet then
4561 MH_SEND_Effect(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
4562 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32, 1,
4563 NET_GFX_TELE);
4564 end;
4566 FObj.X := X-PLAYER_RECT.X;
4567 FObj.Y := Y-PLAYER_RECT.Y;
4568 if FLive and FGhost then
4569 begin
4570 FXTo := FObj.X;
4571 FYTo := FObj.Y;
4572 end;
4574 if not g_Game_IsNet then
4575 begin
4576 if dir = 1 then
4577 begin
4578 SetDirection(D_LEFT);
4579 FAngle := 180;
4580 end
4581 else
4582 if dir = 2 then
4583 begin
4584 SetDirection(D_RIGHT);
4585 FAngle := 0;
4586 end
4587 else
4588 if dir = 3 then
4589 begin // îáðàòíîå
4590 if FDirection = D_RIGHT then
4591 begin
4592 SetDirection(D_LEFT);
4593 FAngle := 180;
4594 end
4595 else
4596 begin
4597 SetDirection(D_RIGHT);
4598 FAngle := 0;
4599 end;
4600 end;
4601 end;
4603 if not silent and (Anim <> nil) then
4604 begin
4605 g_GFX_OnceAnim(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
4606 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32, Anim);
4607 Anim.Free();
4609 if g_Game_IsServer and g_Game_IsNet then
4610 MH_SEND_Effect(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2)-32,
4611 FObj.Y+PLAYER_RECT.Y+(PLAYER_RECT.Height div 2)-32, 0,
4612 NET_GFX_TELE);
4613 end;
4615 Result := True;
4616 end;
4618 function nonz(a: Single): Single;
4619 begin
4620 if a <> 0 then
4621 Result := a
4622 else
4623 Result := 1;
4624 end;
4626 procedure TPlayer.Update();
4627 var
4628 b: Byte;
4629 i, ii, wx, wy, xd, yd, k: Integer;
4630 blockmon, headwater, dospawn: Boolean;
4631 NetServer: Boolean;
4632 AnyServer: Boolean;
4633 SetSpect: Boolean;
4634 begin
4635 NetServer := g_Game_IsNet and g_Game_IsServer;
4636 AnyServer := g_Game_IsServer;
4638 if g_Game_IsClient and (NetInterpLevel > 0) then
4639 DoLerp(NetInterpLevel + 1)
4640 else
4641 if FGhost then
4642 DoLerp(4);
4644 if NetServer then
4645 if FClientID >= 0 then
4646 begin
4647 FPing := NetClients[FClientID].Peer^.lastRoundTripTime;
4648 if NetClients[FClientID].Peer^.packetsSent > 0 then
4649 FLoss := Round(100*NetClients[FClientID].Peer^.packetsLost/NetClients[FClientID].Peer^.packetsSent)
4650 else
4651 FLoss := 0;
4652 end else
4653 begin
4654 FPing := 0;
4655 FLoss := 0;
4656 end;
4658 if FLive and (gFly or FJetpack) then
4659 FlySmoke();
4661 if FDirection = D_LEFT then
4662 FAngle := 180
4663 else
4664 FAngle := 0;
4666 if FLive and (not FGhost) then
4667 begin
4668 if FKeys[KEY_UP].Pressed then
4669 SeeUp();
4670 if FKeys[KEY_DOWN].Pressed then
4671 SeeDown();
4672 end;
4674 if (not (FKeys[KEY_UP].Pressed or FKeys[KEY_DOWN].Pressed)) and
4675 (FIncCam <> 0) then
4676 begin
4677 i := g_basic.Sign(FIncCam);
4678 FIncCam := Abs(FIncCam);
4679 DecMin(FIncCam, 5, 0);
4680 FIncCam := FIncCam*i;
4681 end;
4683 // no need to do that each second frame, weapon queue will take care of it
4684 if FLive and FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
4685 if FLive and FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
4687 if gTime mod (GAME_TICK*2) <> 0 then
4688 begin
4689 if (FObj.Vel.X = 0) and FLive then
4690 begin
4691 if FKeys[KEY_LEFT].Pressed then
4692 Run(D_LEFT);
4693 if FKeys[KEY_RIGHT].Pressed then
4694 Run(D_RIGHT);
4695 end;
4697 if FPhysics then
4698 begin
4699 g_Obj_Move(@FObj, True, True, True);
4700 positionChanged(); // this updates spatial accelerators
4701 end;
4703 Exit;
4704 end;
4706 FActionChanged := False;
4708 if FLive then
4709 begin
4710 // Let alive player do some actions
4711 if FKeys[KEY_LEFT].Pressed then Run(D_LEFT);
4712 if FKeys[KEY_RIGHT].Pressed then Run(D_RIGHT);
4713 //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
4714 //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
4715 if FKeys[KEY_FIRE].Pressed and AnyServer then Fire();
4716 if FKeys[KEY_OPEN].Pressed and AnyServer then Use();
4717 if FKeys[KEY_JUMP].Pressed then Jump()
4718 else
4719 begin
4720 if AnyServer and FJetpack then
4721 begin
4722 FJetpack := False;
4723 JetpackOff;
4724 if NetServer then MH_SEND_PlayerStats(FUID);
4725 end;
4726 FCanJetpack := True;
4727 end;
4728 end
4729 else // Dead
4730 begin
4731 dospawn := False;
4732 if not FGhost then
4733 for k := Low(FKeys) to KEY_CHAT-1 do
4734 begin
4735 if FKeys[k].Pressed then
4736 begin
4737 dospawn := True;
4738 break;
4739 end;
4740 end;
4741 if dospawn then
4742 begin
4743 if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
4744 Respawn(False)
4745 else // Single
4746 if (FTime[T_RESPAWN] <= gTime) and
4747 gGameOn and (not FLive) then
4748 begin
4749 if (g_Player_GetCount() > 1) then
4750 Respawn(False)
4751 else
4752 begin
4753 gExit := EXIT_RESTART;
4754 Exit;
4755 end;
4756 end;
4757 end;
4758 // Dead spectator actions
4759 if FGhost then
4760 begin
4761 if FKeys[KEY_OPEN].Pressed and AnyServer then Fire();
4762 if FKeys[KEY_FIRE].Pressed and AnyServer then
4763 begin
4764 if FSpectator then
4765 begin
4766 if (FSpectatePlayer >= High(gPlayers)) then
4767 FSpectatePlayer := -1
4768 else
4769 begin
4770 SetSpect := False;
4771 for I := FSpectatePlayer + 1 to High(gPlayers) do
4772 if gPlayers[I] <> nil then
4773 if gPlayers[I].Live then
4774 if gPlayers[I].UID <> FUID then
4775 begin
4776 FSpectatePlayer := I;
4777 SetSpect := True;
4778 break;
4779 end;
4781 if not SetSpect then FSpectatePlayer := -1;
4782 end;
4784 ReleaseKeys;
4785 end;
4786 end;
4787 end;
4788 end;
4789 // No clipping
4790 if FGhost then
4791 begin
4792 if FKeys[KEY_UP].Pressed or FKeys[KEY_JUMP].Pressed then
4793 begin
4794 FYTo := FObj.Y - 32;
4795 FSpectatePlayer := -1;
4796 end;
4797 if FKeys[KEY_DOWN].Pressed then
4798 begin
4799 FYTo := FObj.Y + 32;
4800 FSpectatePlayer := -1;
4801 end;
4802 if FKeys[KEY_LEFT].Pressed then
4803 begin
4804 FXTo := FObj.X - 32;
4805 FSpectatePlayer := -1;
4806 end;
4807 if FKeys[KEY_RIGHT].Pressed then
4808 begin
4809 FXTo := FObj.X + 32;
4810 FSpectatePlayer := -1;
4811 end;
4813 if (FXTo < -64) then
4814 FXTo := -64
4815 else if (FXTo > gMapInfo.Width + 32) then
4816 FXTo := gMapInfo.Width + 32;
4817 if (FYTo < -72) then
4818 FYTo := -72
4819 else if (FYTo > gMapInfo.Height + 32) then
4820 FYTo := gMapInfo.Height + 32;
4821 end;
4823 if FPhysics then
4824 begin
4825 g_Obj_Move(@FObj, True, True, True);
4826 positionChanged(); // this updates spatial accelerators
4827 end
4828 else
4829 begin
4830 FObj.Vel.X := 0;
4831 FObj.Vel.Y := 0;
4832 if FSpectator then
4833 if (FSpectatePlayer <= High(gPlayers)) and (FSpectatePlayer >= 0) then
4834 if gPlayers[FSpectatePlayer] <> nil then
4835 if gPlayers[FSpectatePlayer].Live then
4836 begin
4837 FXTo := gPlayers[FSpectatePlayer].GameX;
4838 FYTo := gPlayers[FSpectatePlayer].GameY;
4839 end;
4840 end;
4842 blockmon := g_Map_CollidePanel(FObj.X+PLAYER_HEADRECT.X, FObj.Y+PLAYER_HEADRECT.Y,
4843 PLAYER_HEADRECT.Width, PLAYER_HEADRECT.Height,
4844 PANEL_BLOCKMON, True);
4845 headwater := HeadInLiquid(0, 0);
4847 // Ñîïðîòèâëåíèå âîçäóõà:
4848 if (not FLive) or not (FKeys[KEY_LEFT].Pressed or FKeys[KEY_RIGHT].Pressed) then
4849 if FObj.Vel.X <> 0 then
4850 FObj.Vel.X := z_dec(FObj.Vel.X, 1);
4852 if (FLastHit = HIT_TRAP) and (FPain > 90) then FPain := 90;
4853 DecMin(FPain, 5, 0);
4854 DecMin(FPickup, 1, 0);
4856 if FLive and (FObj.Y > Integer(gMapInfo.Height)+128) and AnyServer then
4857 begin
4858 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
4859 FMegaRulez[MR_SUIT] := 0;
4860 FMegaRulez[MR_INVUL] := 0;
4861 FMegaRulez[MR_INVIS] := 0;
4862 Kill(K_FALLKILL, 0, HIT_FALL);
4863 end;
4865 i := 9;
4867 if FLive then
4868 begin
4869 if FCurrWeap = WEAPON_SAW then
4870 if not (FSawSound.IsPlaying() or FSawSoundHit.IsPlaying() or
4871 FSawSoundSelect.IsPlaying()) then
4872 FSawSoundIdle.PlayAt(FObj.X, FObj.Y);
4874 if FJetpack then
4875 if (not FJetSoundFly.IsPlaying()) and (not FJetSoundOn.IsPlaying()) and
4876 (not FJetSoundOff.IsPlaying()) then
4877 begin
4878 FJetSoundFly.SetPosition(0);
4879 FJetSoundFly.PlayAt(FObj.X, FObj.Y);
4880 end;
4882 for b := WP_FIRST to WP_LAST do
4883 if FReloading[b] > 0 then
4884 if FNoReload then
4885 FReloading[b] := 0
4886 else
4887 Dec(FReloading[b]);
4889 if FShellTimer > -1 then
4890 if FShellTimer = 0 then
4891 begin
4892 if FShellType = SHELL_SHELL then
4893 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
4894 GameVelX, GameVelY-2, SHELL_SHELL)
4895 else if FShellType = SHELL_DBLSHELL then
4896 begin
4897 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
4898 GameVelX+1, GameVelY-2, SHELL_SHELL);
4899 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
4900 GameVelX-1, GameVelY-2, SHELL_SHELL);
4901 end;
4902 FShellTimer := -1;
4903 end else Dec(FShellTimer);
4905 if (FBFGFireCounter > -1) then
4906 if FBFGFireCounter = 0 then
4907 begin
4908 if AnyServer then
4909 begin
4910 wx := FObj.X+WEAPONPOINT[FDirection].X;
4911 wy := FObj.Y+WEAPONPOINT[FDirection].Y;
4912 xd := wx+IfThen(FDirection = D_LEFT, -30, 30);
4913 yd := wy+firediry();
4914 g_Weapon_bfgshot(wx, wy, xd, yd, FUID);
4915 if NetServer then MH_SEND_PlayerFire(FUID, WEAPON_BFG, wx, wy, xd, yd);
4916 if (FAngle = 0) or (FAngle = 180) then SetAction(A_ATTACK)
4917 else if (FAngle = ANGLE_LEFTDOWN) or (FAngle = ANGLE_RIGHTDOWN) then SetAction(A_ATTACKDOWN)
4918 else if (FAngle = ANGLE_LEFTUP) or (FAngle = ANGLE_RIGHTUP) then SetAction(A_ATTACKUP);
4919 end;
4921 FReloading[WEAPON_BFG] := WEAPON_RELOAD[WEAPON_BFG];
4922 FBFGFireCounter := -1;
4923 end else
4924 if FNoReload then
4925 FBFGFireCounter := 0
4926 else
4927 Dec(FBFGFireCounter);
4929 if (FMegaRulez[MR_SUIT] < gTime) and AnyServer then
4930 begin
4931 b := g_GetAcidHit(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width, PLAYER_RECT.Height);
4933 if (b > 0) and (gTime mod (15*GAME_TICK) = 0) then Damage(b, 0, 0, 0, HIT_ACID);
4934 end;
4936 if (headwater or blockmon) then
4937 begin
4938 Dec(FAir);
4940 if FAir < -9 then
4941 begin
4942 if AnyServer then Damage(10, 0, 0, 0, HIT_WATER);
4943 FAir := 0;
4944 end
4945 else if (FAir mod 31 = 0) and not blockmon then
4946 begin
4947 g_GFX_Bubbles(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2), FObj.Y+PLAYER_RECT.Y-4, 5+Random(6), 8, 4);
4948 if Random(2) = 0 then
4949 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj.X, FObj.Y)
4950 else
4951 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj.X, FObj.Y);
4952 end;
4953 end else if FAir < AIR_DEF then
4954 FAir := AIR_DEF;
4956 if FFireTime > 0 then
4957 begin
4958 if BodyInLiquid(0, 0) then
4959 begin
4960 FFireTime := 0;
4961 FFirePainTime := 0;
4962 end
4963 else if FMegaRulez[MR_SUIT] >= gTime then
4964 begin
4965 if FMegaRulez[MR_SUIT] = gTime then
4966 FFireTime := 1;
4967 FFirePainTime := 0;
4968 end
4969 else
4970 begin
4971 OnFireFlame(1);
4972 if FFirePainTime <= 0 then
4973 begin
4974 if g_Game_IsServer then
4975 Damage(5, FFireAttacker, 0, 0, HIT_FLAME);
4976 FFirePainTime := 18;
4977 end;
4978 FFirePainTime := FFirePainTime - 1;
4979 FFireTime := FFireTime - 1;
4980 if (FFireTime = 0) and g_Game_IsNet and g_Game_IsServer then
4981 MH_SEND_PlayerStats(FUID);
4982 end;
4983 end;
4985 if FDamageBuffer > 0 then
4986 begin
4987 if FDamageBuffer >= 9 then
4988 begin
4989 SetAction(A_PAIN);
4991 if FDamageBuffer < 30 then i := 9
4992 else if FDamageBuffer < 100 then i := 18
4993 else i := 27;
4994 end;
4996 ii := Round(FDamageBuffer*FHealth / nonz(FArmor*(3/4)+FHealth));
4997 FArmor := FArmor-(FDamageBuffer-ii);
4998 FHealth := FHealth-ii;
4999 if FArmor < 0 then
5000 begin
5001 FHealth := FHealth+FArmor;
5002 FArmor := 0;
5003 end;
5005 if AnyServer then
5006 if FHealth <= 0 then
5007 if FHealth > -30 then Kill(K_SIMPLEKILL, FLastSpawnerUID, FLastHit)
5008 else if FHealth > -50 then Kill(K_HARDKILL, FLastSpawnerUID, FLastHit)
5009 else Kill(K_EXTRAHARDKILL, FLastSpawnerUID, FLastHit);
5011 if FLive then
5012 begin
5013 if FDamageBuffer <= 20 then FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y)
5014 else if FDamageBuffer <= 55 then FModel.PlaySound(MODELSOUND_PAIN, 2, FObj.X, FObj.Y)
5015 else if FDamageBuffer <= 120 then FModel.PlaySound(MODELSOUND_PAIN, 3, FObj.X, FObj.Y)
5016 else FModel.PlaySound(MODELSOUND_PAIN, 4, FObj.X, FObj.Y);
5017 end;
5019 FDamageBuffer := 0;
5020 end;
5022 {CollideItem();}
5023 end; // if FLive then ...
5025 if (FActionAnim = A_PAIN) and (FModel.Animation <> A_PAIN) then
5026 begin
5027 FModel.ChangeAnimation(FActionAnim, FActionForce);
5028 FModel.GetCurrentAnimation.MinLength := i;
5029 FModel.GetCurrentAnimationMask.MinLength := i;
5030 end else FModel.ChangeAnimation(FActionAnim, FActionForce and (FModel.Animation <> A_STAND));
5032 if (FModel.GetCurrentAnimation.Played or ((not FActionChanged) and (FModel.Animation = A_WALK)))
5033 then SetAction(A_STAND, True);
5035 if not ((FModel.Animation = A_WALK) and (Abs(FObj.Vel.X) < 4) and not FModel.Fire) then FModel.Update;
5037 for b := Low(FKeys) to High(FKeys) do
5038 if FKeys[b].Time = 0 then FKeys[b].Pressed := False else Dec(FKeys[b].Time);
5039 end;
5041 procedure TPlayer.getMapBox (out x, y, w, h: Integer); inline;
5042 begin
5043 x := FObj.X+PLAYER_RECT.X;
5044 y := FObj.Y+PLAYER_RECT.Y;
5045 w := PLAYER_RECT.Width;
5046 h := PLAYER_RECT.Height;
5047 end;
5049 function TPlayer.Collide(X, Y: Integer; Width, Height: Word): Boolean;
5050 begin
5051 Result := g_Collide(FObj.X+PLAYER_RECT.X,
5052 FObj.Y+PLAYER_RECT.Y,
5053 PLAYER_RECT.Width,
5054 PLAYER_RECT.Height,
5055 X, Y,
5056 Width, Height);
5057 end;
5059 function TPlayer.Collide(Panel: TPanel): Boolean;
5060 begin
5061 Result := g_Collide(FObj.X+PLAYER_RECT.X,
5062 FObj.Y+PLAYER_RECT.Y,
5063 PLAYER_RECT.Width,
5064 PLAYER_RECT.Height,
5065 Panel.X, Panel.Y,
5066 Panel.Width, Panel.Height);
5067 end;
5069 function TPlayer.Collide(X, Y: Integer): Boolean;
5070 begin
5071 X := X-FObj.X-PLAYER_RECT.X;
5072 Y := Y-FObj.Y-PLAYER_RECT.Y;
5073 Result := (x >= 0) and (x <= PLAYER_RECT.Width) and
5074 (y >= 0) and (y <= PLAYER_RECT.Height);
5075 end;
5077 function g_Player_ValidName(Name: string): Boolean;
5078 var
5079 a: Integer;
5080 begin
5081 Result := True;
5083 if gPlayers = nil then Exit;
5085 for a := 0 to High(gPlayers) do
5086 if gPlayers[a] <> nil then
5087 if LowerCase(Name) = LowerCase(gPlayers[a].FName) then
5088 begin
5089 Result := False;
5090 Exit;
5091 end;
5092 end;
5094 procedure TPlayer.SetDirection(Direction: TDirection);
5095 var
5096 d: TDirection;
5097 begin
5098 d := FModel.Direction;
5100 FModel.Direction := Direction;
5101 if d <> Direction then FModel.ChangeAnimation(FModel.Animation, True);
5103 FDirection := Direction;
5104 end;
5106 function TPlayer.GetKeys(): Byte;
5107 begin
5108 Result := 0;
5110 if R_KEY_RED in FRulez then Result := KEY_RED;
5111 if R_KEY_GREEN in FRulez then Result := Result or KEY_GREEN;
5112 if R_KEY_BLUE in FRulez then Result := Result or KEY_BLUE;
5114 if FTeam = TEAM_RED then Result := Result or KEY_REDTEAM;
5115 if FTeam = TEAM_BLUE then Result := Result or KEY_BLUETEAM;
5116 end;
5118 procedure TPlayer.Use();
5119 var
5120 a: Integer;
5121 begin
5122 if FTime[T_USE] > gTime then Exit;
5124 g_Triggers_PressR(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
5125 PLAYER_RECT.Height, FUID, ACTIVATE_PLAYERPRESS);
5127 for a := 0 to High(gPlayers) do
5128 if (gPlayers[a] <> nil) and (gPlayers[a] <> Self) and
5129 gPlayers[a].Live and SameTeam(FUID, gPlayers[a].FUID) and
5130 g_Obj_Collide(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y,
5131 FObj.Rect.Width, FObj.Rect.Height, @gPlayers[a].FObj) then
5132 begin
5133 gPlayers[a].Touch();
5134 if g_Game_IsNet and g_Game_IsServer then
5135 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH, gPlayers[a].FUID);
5136 end;
5138 FTime[T_USE] := gTime+120;
5139 end;
5141 procedure TPlayer.NetFire(Wpn: Byte; X, Y, AX, AY: Integer; WID: Integer = -1);
5142 var
5143 locObj: TObj;
5144 F: Boolean;
5145 WX, WY, XD, YD: Integer;
5146 begin
5147 F := False;
5148 WX := X;
5149 WY := Y;
5150 XD := AX;
5151 YD := AY;
5153 case FCurrWeap of
5154 WEAPON_KASTET:
5155 begin
5156 if R_BERSERK in FRulez then
5157 begin
5158 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5159 locobj.X := FObj.X+FObj.Rect.X;
5160 locobj.Y := FObj.Y+FObj.Rect.Y;
5161 locobj.rect.X := 0;
5162 locobj.rect.Y := 0;
5163 locobj.rect.Width := 39;
5164 locobj.rect.Height := 52;
5165 locobj.Vel.X := (xd-wx) div 2;
5166 locobj.Vel.Y := (yd-wy) div 2;
5167 locobj.Accel.X := xd-wx;
5168 locobj.Accel.y := yd-wy;
5170 if g_Weapon_Hit(@locobj, 50, FUID, HIT_SOME) <> 0 then
5171 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj.X, FObj.Y)
5172 else
5173 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj.X, FObj.Y);
5175 if gFlash = 1 then
5176 if FPain < 50 then
5177 FPain := min(FPain + 25, 50);
5178 end else
5179 g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 3, FUID);
5180 end;
5182 WEAPON_SAW:
5183 begin
5184 if g_Weapon_chainsaw(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y,
5185 IfThen(gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF], 9, 3), FUID) <> 0 then
5186 begin
5187 FSawSoundSelect.Stop();
5188 FSawSound.Stop();
5189 FSawSoundHit.PlayAt(FObj.X, FObj.Y);
5190 end
5191 else if not FSawSoundHit.IsPlaying() then
5192 begin
5193 FSawSoundSelect.Stop();
5194 FSawSound.PlayAt(FObj.X, FObj.Y);
5195 end;
5196 f := True;
5197 end;
5199 WEAPON_PISTOL:
5200 begin
5201 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX, Gamey);
5202 FFireAngle := FAngle;
5203 f := True;
5204 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
5205 GameVelX, GameVelY-2, SHELL_BULLET);
5206 end;
5208 WEAPON_SHOTGUN1:
5209 begin
5210 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex, Gamey);
5211 FFireAngle := FAngle;
5212 f := True;
5213 FShellTimer := 10;
5214 FShellType := SHELL_SHELL;
5215 end;
5217 WEAPON_SHOTGUN2:
5218 begin
5219 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex, Gamey);
5220 FFireAngle := FAngle;
5221 f := True;
5222 FShellTimer := 13;
5223 FShellType := SHELL_DBLSHELL;
5224 end;
5226 WEAPON_CHAINGUN:
5227 begin
5228 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex, Gamey);
5229 FFireAngle := FAngle;
5230 f := True;
5231 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
5232 GameVelX, GameVelY-2, SHELL_BULLET);
5233 end;
5235 WEAPON_ROCKETLAUNCHER:
5236 begin
5237 g_Weapon_Rocket(wx, wy, xd, yd, FUID, WID);
5238 FFireAngle := FAngle;
5239 f := True;
5240 end;
5242 WEAPON_PLASMA:
5243 begin
5244 g_Weapon_Plasma(wx, wy, xd, yd, FUID, WID);
5245 FFireAngle := FAngle;
5246 f := True;
5247 end;
5249 WEAPON_BFG:
5250 begin
5251 g_Weapon_BFGShot(wx, wy, xd, yd, FUID, WID);
5252 FFireAngle := FAngle;
5253 f := True;
5254 end;
5256 WEAPON_SUPERPULEMET:
5257 begin
5258 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex, Gamey);
5259 FFireAngle := FAngle;
5260 f := True;
5261 g_Player_CreateShell(GameX+PLAYER_RECT_CX, GameY+PLAYER_RECT_CX,
5262 GameVelX, GameVelY-2, SHELL_SHELL);
5263 end;
5265 WEAPON_FLAMETHROWER:
5266 begin
5267 g_Weapon_flame(wx, wy, xd, yd, FUID, WID);
5268 FFireAngle := FAngle;
5269 f := True;
5270 end;
5271 end;
5273 if not f then Exit;
5275 if (FAngle = 0) or (FAngle = 180) then SetAction(A_ATTACK)
5276 else if (FAngle = ANGLE_LEFTDOWN) or (FAngle = ANGLE_RIGHTDOWN) then SetAction(A_ATTACKDOWN)
5277 else if (FAngle = ANGLE_LEFTUP) or (FAngle = ANGLE_RIGHTUP) then SetAction(A_ATTACKUP);
5278 end;
5280 procedure TPlayer.DoLerp(Level: Integer = 2);
5281 begin
5282 if FObj.X <> FXTo then FObj.X := Lerp(FObj.X, FXTo, Level);
5283 if FObj.Y <> FYTo then FObj.Y := Lerp(FObj.Y, FYTo, Level);
5284 end;
5286 procedure TPlayer.SetLerp(XTo, YTo: Integer);
5287 var
5288 AX, AY: Integer;
5289 begin
5290 if NetInterpLevel < 1 then
5291 begin
5292 FObj.X := XTo;
5293 FObj.Y := YTo;
5294 end
5295 else
5296 begin
5297 FXTo := XTo;
5298 FYTo := YTo;
5300 AX := Abs(FXTo - FObj.X);
5301 AY := Abs(FYTo - FObj.Y);
5302 if (AX > 32) or (AX <= NetInterpLevel) then
5303 FObj.X := FXTo;
5304 if (AY > 32) or (AY <= NetInterpLevel) then
5305 FObj.Y := FYTo;
5306 end;
5307 end;
5309 function TPlayer.FullInLift(XInc, YInc: Integer): Integer;
5310 begin
5311 if g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc,
5312 PLAYER_RECT.Width, PLAYER_RECT.Height-8,
5313 PANEL_LIFTUP, False) then Result := -1
5314 else
5315 if g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc,
5316 PLAYER_RECT.Width, PLAYER_RECT.Height-8,
5317 PANEL_LIFTDOWN, False) then Result := 1
5318 else Result := 0;
5319 end;
5321 function TPlayer.GetFlag(Flag: Byte): Boolean;
5322 var
5323 s, ts: String;
5324 evtype: Byte;
5325 begin
5326 Result := False;
5328 if Flag = FLAG_NONE then
5329 Exit;
5331 if not g_Game_IsServer then Exit;
5333 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5334 if (Flag = FTeam) and
5335 (gFlags[Flag].State = FLAG_STATE_NORMAL) and
5336 (FFlag <> FLAG_NONE) then
5337 begin
5338 if FFlag = FLAG_RED then
5339 s := _lc[I_PLAYER_FLAG_RED]
5340 else
5341 s := _lc[I_PLAYER_FLAG_BLUE];
5343 evtype := FLAG_STATE_SCORED;
5345 ts := Format('%.4d', [gFlags[FFlag].CaptureTime]);
5346 Insert('.', ts, Length(ts) + 1 - 3);
5347 g_Console_Add(Format(_lc[I_PLAYER_FLAG_CAPTURE], [FName, s, ts]), True);
5349 g_Map_ResetFlag(FFlag);
5350 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_CAPTURE], [AnsiUpperCase(s)]), 144);
5352 gTeamStat[FTeam].Goals := gTeamStat[FTeam].Goals + 1;
5354 Result := True;
5355 if g_Game_IsNet then
5356 begin
5357 MH_SEND_FlagEvent(evtype, FFlag, FUID, False);
5358 MH_SEND_GameStats;
5359 end;
5361 gFlags[FFlag].CaptureTime := 0;
5362 SetFlag(FLAG_NONE);
5363 Exit;
5364 end;
5366 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5367 if (Flag = FTeam) and
5368 (gFlags[Flag].State = FLAG_STATE_DROPPED) then
5369 begin
5370 if Flag = FLAG_RED then
5371 s := _lc[I_PLAYER_FLAG_RED]
5372 else
5373 s := _lc[I_PLAYER_FLAG_BLUE];
5375 evtype := FLAG_STATE_RETURNED;
5376 gFlags[Flag].CaptureTime := 0;
5378 g_Console_Add(Format(_lc[I_PLAYER_FLAG_RETURN], [FName, s]), True);
5380 g_Map_ResetFlag(Flag);
5381 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_RETURN], [AnsiUpperCase(s)]), 144);
5383 Result := True;
5384 if g_Game_IsNet then
5385 begin
5386 MH_SEND_FlagEvent(evtype, Flag, FUID, False);
5387 MH_SEND_GameStats;
5388 end;
5389 Exit;
5390 end;
5392 // Ïîäîáðàë ÷óæîé ôëàã:
5393 if (Flag <> FTeam) and (FTime[T_FLAGCAP] <= gTime) then
5394 begin
5395 SetFlag(Flag);
5397 if Flag = FLAG_RED then
5398 s := _lc[I_PLAYER_FLAG_RED]
5399 else
5400 s := _lc[I_PLAYER_FLAG_BLUE];
5402 evtype := FLAG_STATE_CAPTURED;
5404 g_Console_Add(Format(_lc[I_PLAYER_FLAG_GET], [FName, s]), True);
5406 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_GET], [AnsiUpperCase(s)]), 144);
5408 gFlags[Flag].State := FLAG_STATE_CAPTURED;
5410 Result := True;
5411 if g_Game_IsNet then
5412 begin
5413 MH_SEND_FlagEvent(evtype, Flag, FUID, False);
5414 MH_SEND_GameStats;
5415 end;
5416 end;
5417 end;
5419 procedure TPlayer.SetFlag(Flag: Byte);
5420 begin
5421 FFlag := Flag;
5422 if FModel <> nil then
5423 FModel.SetFlag(FFlag);
5424 end;
5426 function TPlayer.DropFlag(): Boolean;
5427 var
5428 s: String;
5429 begin
5430 Result := False;
5431 if (not g_Game_IsServer) or (FFlag = FLAG_NONE) then
5432 Exit;
5433 FTime[T_FLAGCAP] := gTime + 2000;
5434 with gFlags[FFlag] do
5435 begin
5436 Obj.X := FObj.X;
5437 Obj.Y := FObj.Y;
5438 Direction := FDirection;
5439 State := FLAG_STATE_DROPPED;
5440 Count := FLAG_TIME;
5441 g_Obj_Push(@Obj, (FObj.Vel.X div 2)-2+Random(5),
5442 (FObj.Vel.Y div 2)-2+Random(5));
5443 positionChanged(); // this updates spatial accelerators
5445 if FFlag = FLAG_RED then
5446 s := _lc[I_PLAYER_FLAG_RED]
5447 else
5448 s := _lc[I_PLAYER_FLAG_BLUE];
5450 g_Console_Add(Format(_lc[I_PLAYER_FLAG_DROP], [FName, s]), True);
5451 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_DROP], [AnsiUpperCase(s)]), 144);
5453 if g_Game_IsNet then
5454 MH_SEND_FlagEvent(FLAG_STATE_DROPPED, Flag, FUID, False);
5455 end;
5456 SetFlag(FLAG_NONE);
5457 Result := True;
5458 end;
5460 procedure TPlayer.GetSecret();
5461 begin
5462 Inc(FSecrets);
5463 end;
5465 procedure TPlayer.PressKey(Key: Byte; Time: Word = 1);
5466 begin
5467 Assert(Key <= High(FKeys));
5469 FKeys[Key].Pressed := True;
5470 FKeys[Key].Time := Time;
5471 end;
5473 function TPlayer.IsKeyPressed(K: Byte): Boolean;
5474 begin
5475 Result := FKeys[K].Pressed;
5476 end;
5478 procedure TPlayer.ReleaseKeys();
5479 var
5480 a: Integer;
5481 begin
5482 for a := Low(FKeys) to High(FKeys) do
5483 begin
5484 FKeys[a].Pressed := False;
5485 FKeys[a].Time := 0;
5486 end;
5487 end;
5489 procedure TPlayer.OnDamage(Angle: SmallInt);
5490 begin
5491 end;
5493 function TPlayer.firediry(): Integer;
5494 begin
5495 if FKeys[KEY_UP].Pressed then Result := -42
5496 else if FKeys[KEY_DOWN].Pressed then Result := 19
5497 else Result := 0;
5498 end;
5500 procedure TPlayer.RememberState();
5501 var
5502 i: Integer;
5503 begin
5504 FSavedState.Health := FHealth;
5505 FSavedState.Armor := FArmor;
5506 FSavedState.Air := FAir;
5507 FSavedState.JetFuel := FJetFuel;
5508 FSavedState.CurrWeap := FCurrWeap;
5509 FSavedState.NextWeap := FNextWeap;
5510 FSavedState.NextWeapDelay := FNextWeapDelay;
5512 for i := 0 to 3 do
5513 FSavedState.Ammo[i] := FAmmo[i];
5514 for i := 0 to 3 do
5515 FSavedState.MaxAmmo[i] := FMaxAmmo[i];
5517 FSavedState.Rulez := FRulez;
5518 FSavedState.WaitRecall := True;
5519 end;
5521 procedure TPlayer.RecallState();
5522 var
5523 i: Integer;
5524 begin
5525 if not FSavedState.WaitRecall then Exit;
5527 FHealth := FSavedState.Health;
5528 FArmor := FSavedState.Armor;
5529 FAir := FSavedState.Air;
5530 FJetFuel := FSavedState.JetFuel;
5531 FCurrWeap := FSavedState.CurrWeap;
5532 FNextWeap := FSavedState.NextWeap;
5533 FNextWeapDelay := FSavedState.NextWeapDelay;
5535 for i := 0 to 3 do
5536 FAmmo[i] := FSavedState.Ammo[i];
5537 for i := 0 to 3 do
5538 FMaxAmmo[i] := FSavedState.MaxAmmo[i];
5540 FRulez := FSavedState.Rulez;
5541 FSavedState.WaitRecall := False;
5543 if gGameSettings.GameType = GT_SERVER then
5544 MH_SEND_PlayerStats(FUID);
5545 end;
5547 procedure TPlayer.SaveState(var Mem: TBinMemoryWriter);
5548 var
5549 i: Integer;
5550 sig: DWORD;
5551 str: String;
5552 b: Byte;
5553 begin
5554 if FIamBot then
5555 i := 512
5556 else
5557 i := 256;
5559 Mem := TBinMemoryWriter.Create(i);
5561 // Ñèãíàòóðà èãðîêà:
5562 sig := PLAYER_SIGNATURE; // 'PLYR'
5563 Mem.WriteDWORD(sig);
5564 // Áîò èëè ÷åëîâåê:
5565 Mem.WriteBoolean(FIamBot);
5566 // UID èãðîêà:
5567 Mem.WriteWord(FUID);
5568 // Èìÿ èãðîêà:
5569 Mem.WriteString(FName, 32);
5570 // Êîìàíäà:
5571 Mem.WriteByte(FTeam);
5572 // Æèâ ëè:
5573 Mem.WriteBoolean(FLive);
5574 // Èçðàñõîäîâàë ëè âñå æèçíè:
5575 Mem.WriteBoolean(FNoRespawn);
5576 // Íàïðàâëåíèå:
5577 if FDirection = D_LEFT then
5578 b := 1
5579 else // D_RIGHT
5580 b := 2;
5581 Mem.WriteByte(b);
5582 // Çäîðîâüå:
5583 Mem.WriteInt(FHealth);
5584 // Æèçíè:
5585 Mem.WriteByte(FLives);
5586 // Áðîíÿ:
5587 Mem.WriteInt(FArmor);
5588 // Çàïàñ âîçäóõà:
5589 Mem.WriteInt(FAir);
5590 // Çàïàñ ãîðþ÷åãî:
5591 Mem.WriteInt(FJetFuel);
5592 // Áîëü:
5593 Mem.WriteInt(FPain);
5594 // Óáèë:
5595 Mem.WriteInt(FKills);
5596 // Óáèë ìîíñòðîâ:
5597 Mem.WriteInt(FMonsterKills);
5598 // Ôðàãîâ:
5599 Mem.WriteInt(FFrags);
5600 // Ôðàãîâ ïîäðÿä:
5601 Mem.WriteByte(FFragCombo);
5602 // Âðåìÿ ïîñëåäíåãî ôðàãà:
5603 Mem.WriteDWORD(FLastFrag);
5604 // Ñìåðòåé:
5605 Mem.WriteInt(FDeath);
5606 // Êàêîé ôëàã íåñåò:
5607 Mem.WriteByte(FFlag);
5608 // Íàøåë ñåêðåòîâ:
5609 Mem.WriteInt(FSecrets);
5610 // Òåêóùåå îðóæèå:
5611 Mem.WriteByte(FCurrWeap);
5612 // Æåëàåìîå îðóæèå:
5613 Mem.WriteWord(FNextWeap);
5614 // ...è ïàóçà
5615 Mem.WriteByte(FNextWeapDelay);
5616 // Âðåìÿ çàðÿäêè BFG:
5617 Mem.WriteSmallInt(FBFGFireCounter);
5618 // Áóôåð óðîíà:
5619 Mem.WriteInt(FDamageBuffer);
5620 // Ïîñëåäíèé óäàðèâøèé:
5621 Mem.WriteWord(FLastSpawnerUID);
5622 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
5623 Mem.WriteByte(FLastHit);
5624 // Îáúåêò èãðîêà:
5625 Obj_SaveState(@FObj, Mem);
5626 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
5627 for i := A_BULLETS to A_HIGH do
5628 Mem.WriteWord(FAmmo[i]);
5629 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
5630 for i := A_BULLETS to A_HIGH do
5631 Mem.WriteWord(FMaxAmmo[i]);
5632 // Íàëè÷èå îðóæèÿ:
5633 for i := WP_FIRST to WP_LAST do
5634 Mem.WriteBoolean(FWeapon[i]);
5635 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
5636 for i := WP_FIRST to WP_LAST do
5637 Mem.WriteWord(FReloading[i]);
5638 // Íàëè÷èå ðþêçàêà:
5639 if R_ITEM_BACKPACK in FRulez then
5640 b := 1
5641 else
5642 b := 0;
5643 Mem.WriteByte(b);
5644 // Íàëè÷èå êðàñíîãî êëþ÷à:
5645 if R_KEY_RED in FRulez then
5646 b := 1
5647 else
5648 b := 0;
5649 Mem.WriteByte(b);
5650 // Íàëè÷èå çåëåíîãî êëþ÷à:
5651 if R_KEY_GREEN in FRulez then
5652 b := 1
5653 else
5654 b := 0;
5655 Mem.WriteByte(b);
5656 // Íàëè÷èå ñèíåãî êëþ÷à:
5657 if R_KEY_BLUE in FRulez then
5658 b := 1
5659 else
5660 b := 0;
5661 Mem.WriteByte(b);
5662 // Íàëè÷èå áåðñåðêà:
5663 if R_BERSERK in FRulez then
5664 b := 1
5665 else
5666 b := 0;
5667 Mem.WriteByte(b);
5668 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
5669 for i := MR_SUIT to MR_MAX do
5670 Mem.WriteDWORD(FMegaRulez[i]);
5671 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
5672 for i := T_RESPAWN to T_FLAGCAP do
5673 Mem.WriteDWORD(FTime[i]);
5674 // Íàçâàíèå ìîäåëè:
5675 str := FModel.Name;
5676 Mem.WriteString(str);
5677 // Öâåò ìîäåëè:
5678 b := FColor.R;
5679 Mem.WriteByte(b);
5680 b := FColor.G;
5681 Mem.WriteByte(b);
5682 b := FColor.B;
5683 Mem.WriteByte(b);
5684 end;
5686 procedure TPlayer.LoadState(var Mem: TBinMemoryReader);
5687 var
5688 i: Integer;
5689 sig: DWORD;
5690 str: String;
5691 b: Byte;
5692 begin
5693 if Mem = nil then
5694 Exit;
5696 // Ñèãíàòóðà èãðîêà:
5697 Mem.ReadDWORD(sig);
5698 if sig <> PLAYER_SIGNATURE then // 'PLYR'
5699 begin
5700 raise EBinSizeError.Create('TPlayer.LoadState: Wrong Player Signature');
5701 end;
5702 // Áîò èëè ÷åëîâåê:
5703 Mem.ReadBoolean(FIamBot);
5704 // UID èãðîêà:
5705 Mem.ReadWord(FUID);
5706 // Èìÿ èãðîêà:
5707 Mem.ReadString(str);
5708 if (Self <> gPlayer1) and (Self <> gPlayer2) then
5709 FName := str;
5710 // Êîìàíäà:
5711 Mem.ReadByte(FTeam);
5712 // Æèâ ëè:
5713 Mem.ReadBoolean(FLive);
5714 // Èçðàñõîäîâàë ëè âñå æèçíè:
5715 Mem.ReadBoolean(FNoRespawn);
5716 // Íàïðàâëåíèå:
5717 Mem.ReadByte(b);
5718 if b = 1 then
5719 FDirection := D_LEFT
5720 else // b = 2
5721 FDirection := D_RIGHT;
5722 // Çäîðîâüå:
5723 Mem.ReadInt(FHealth);
5724 // Æèçíè:
5725 Mem.ReadByte(FLives);
5726 // Áðîíÿ:
5727 Mem.ReadInt(FArmor);
5728 // Çàïàñ âîçäóõà:
5729 Mem.ReadInt(FAir);
5730 // Çàïàñ ãîðþ÷åãî:
5731 Mem.ReadInt(FJetFuel);
5732 // Áîëü:
5733 Mem.ReadInt(FPain);
5734 // Óáèë:
5735 Mem.ReadInt(FKills);
5736 // Óáèë ìîíñòðîâ:
5737 Mem.ReadInt(FMonsterKills);
5738 // Ôðàãîâ:
5739 Mem.ReadInt(FFrags);
5740 // Ôðàãîâ ïîäðÿä:
5741 Mem.ReadByte(FFragCombo);
5742 // Âðåìÿ ïîñëåäíåãî ôðàãà:
5743 Mem.ReadDWORD(FLastFrag);
5744 // Ñìåðòåé:
5745 Mem.ReadInt(FDeath);
5746 // Êàêîé ôëàã íåñåò:
5747 Mem.ReadByte(FFlag);
5748 // Íàøåë ñåêðåòîâ:
5749 Mem.ReadInt(FSecrets);
5750 // Òåêóùåå îðóæèå:
5751 Mem.ReadByte(FCurrWeap);
5752 // Æåëàåìîå îðóæèå:
5753 Mem.ReadWord(FNextWeap);
5754 // ...è ïàóçà
5755 Mem.ReadByte(FNextWeapDelay);
5756 // Âðåìÿ çàðÿäêè BFG:
5757 Mem.ReadSmallInt(FBFGFireCounter);
5758 // Áóôåð óðîíà:
5759 Mem.ReadInt(FDamageBuffer);
5760 // Ïîñëåäíèé óäàðèâøèé:
5761 Mem.ReadWord(FLastSpawnerUID);
5762 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
5763 Mem.ReadByte(FLastHit);
5764 // Îáúåêò èãðîêà:
5765 Obj_LoadState(@FObj, Mem);
5766 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
5767 for i := A_BULLETS to A_HIGH do
5768 Mem.ReadWord(FAmmo[i]);
5769 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
5770 for i := A_BULLETS to A_HIGH do
5771 Mem.ReadWord(FMaxAmmo[i]);
5772 // Íàëè÷èå îðóæèÿ:
5773 for i := WP_FIRST to WP_LAST do
5774 Mem.ReadBoolean(FWeapon[i]);
5775 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
5776 for i := WP_FIRST to WP_LAST do
5777 Mem.ReadWord(FReloading[i]);
5778 // Íàëè÷èå ðþêçàêà:
5779 Mem.ReadByte(b);
5780 if b = 1 then
5781 Include(FRulez, R_ITEM_BACKPACK);
5782 // Íàëè÷èå êðàñíîãî êëþ÷à:
5783 Mem.ReadByte(b);
5784 if b = 1 then
5785 Include(FRulez, R_KEY_RED);
5786 // Íàëè÷èå çåëåíîãî êëþ÷à:
5787 Mem.ReadByte(b);
5788 if b = 1 then
5789 Include(FRulez, R_KEY_GREEN);
5790 // Íàëè÷èå ñèíåãî êëþ÷à:
5791 Mem.ReadByte(b);
5792 if b = 1 then
5793 Include(FRulez, R_KEY_BLUE);
5794 // Íàëè÷èå áåðñåðêà:
5795 Mem.ReadByte(b);
5796 if b = 1 then
5797 Include(FRulez, R_BERSERK);
5798 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
5799 for i := MR_SUIT to MR_MAX do
5800 Mem.ReadDWORD(FMegaRulez[i]);
5801 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
5802 for i := T_RESPAWN to T_FLAGCAP do
5803 Mem.ReadDWORD(FTime[i]);
5804 // Íàçâàíèå ìîäåëè:
5805 Mem.ReadString(str);
5806 // Öâåò ìîäåëè:
5807 Mem.ReadByte(FColor.R);
5808 Mem.ReadByte(FColor.G);
5809 Mem.ReadByte(FColor.B);
5810 if Self = gPlayer1 then
5811 begin
5812 str := gPlayer1Settings.Model;
5813 FColor := gPlayer1Settings.Color;
5814 end;
5815 if Self = gPlayer2 then
5816 begin
5817 str := gPlayer2Settings.Model;
5818 FColor := gPlayer2Settings.Color;
5819 end;
5820 // Îáíîâëÿåì ìîäåëü èãðîêà:
5821 SetModel(str);
5822 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
5823 FModel.Color := TEAMCOLOR[FTeam]
5824 else
5825 FModel.Color := FColor;
5826 end;
5828 procedure TPlayer.AllRulez(Health: Boolean);
5829 var
5830 a: Integer;
5831 begin
5832 if Health then
5833 begin
5834 FHealth := PLAYER_HP_LIMIT;
5835 FArmor := PLAYER_AP_LIMIT;
5836 Exit;
5837 end;
5839 for a := WP_FIRST to WP_LAST do FWeapon[a] := True;
5840 for a := A_BULLETS to A_HIGH do FAmmo[a] := 30000;
5841 FRulez := FRulez+[R_KEY_RED, R_KEY_GREEN, R_KEY_BLUE];
5842 end;
5844 procedure TPlayer.RestoreHealthArmor();
5845 begin
5846 FHealth := PLAYER_HP_LIMIT;
5847 FArmor := PLAYER_AP_LIMIT;
5848 end;
5850 procedure TPlayer.FragCombo();
5851 var
5852 Param: Integer;
5853 begin
5854 if (gGameSettings.GameMode in [GM_COOP, GM_SINGLE]) or g_Game_IsClient then
5855 Exit;
5856 if gTime - FLastFrag < FRAG_COMBO_TIME then
5857 begin
5858 if FFragCombo < 5 then
5859 Inc(FFragCombo);
5860 Param := FUID or (FFragCombo shl 16);
5861 if (FComboEvnt >= Low(gDelayedEvents)) and
5862 (FComboEvnt <= High(gDelayedEvents)) and
5863 gDelayedEvents[FComboEvnt].Pending and
5864 (gDelayedEvents[FComboEvnt].DEType = DE_KILLCOMBO) and
5865 (gDelayedEvents[FComboEvnt].DENum and $FFFF = FUID) then
5866 begin
5867 gDelayedEvents[FComboEvnt].Time := gTime + 500;
5868 gDelayedEvents[FComboEvnt].DENum := Param;
5869 end
5870 else
5871 FComboEvnt := g_Game_DelayEvent(DE_KILLCOMBO, 500, Param);
5872 end
5873 else
5874 FFragCombo := 1;
5876 FLastFrag := gTime;
5877 end;
5879 procedure TPlayer.GiveItem(ItemType: Byte);
5880 begin
5881 case ItemType of
5882 ITEM_SUIT:
5883 if FMegaRulez[MR_SUIT] < gTime+PLAYER_SUIT_TIME then
5884 begin
5885 FMegaRulez[MR_SUIT] := gTime+PLAYER_SUIT_TIME;
5886 end;
5888 ITEM_OXYGEN:
5889 if FAir < AIR_MAX then
5890 begin
5891 FAir := AIR_MAX;
5892 end;
5894 ITEM_MEDKIT_BLACK:
5895 begin
5896 if not (R_BERSERK in FRulez) then
5897 begin
5898 Include(FRulez, R_BERSERK);
5899 if FBFGFireCounter < 1 then
5900 begin
5901 FCurrWeap := WEAPON_KASTET;
5902 resetWeaponQueue();
5903 FModel.SetWeapon(WEAPON_KASTET);
5904 end;
5905 if gFlash <> 0 then
5906 Inc(FPain, 100);
5907 FBerserk := gTime+30000;
5908 end;
5909 if FHealth < PLAYER_HP_SOFT then
5910 begin
5911 FHealth := PLAYER_HP_SOFT;
5912 FBerserk := gTime+30000;
5913 end;
5914 end;
5916 ITEM_INVUL:
5917 if FMegaRulez[MR_INVUL] < gTime+PLAYER_INVUL_TIME then
5918 begin
5919 FMegaRulez[MR_INVUL] := gTime+PLAYER_INVUL_TIME;
5920 end;
5922 ITEM_INVIS:
5923 if FMegaRulez[MR_INVIS] < gTime+PLAYER_INVIS_TIME then
5924 begin
5925 FMegaRulez[MR_INVIS] := gTime+PLAYER_INVIS_TIME;
5926 end;
5928 ITEM_JETPACK:
5929 if FJetFuel < JET_MAX then
5930 begin
5931 FJetFuel := JET_MAX;
5932 end;
5934 ITEM_MEDKIT_SMALL: if FHealth < PLAYER_HP_SOFT then IncMax(FHealth, 10, PLAYER_HP_SOFT);
5935 ITEM_MEDKIT_LARGE: if FHealth < PLAYER_HP_SOFT then IncMax(FHealth, 25, PLAYER_HP_SOFT);
5937 ITEM_ARMOR_GREEN: if FArmor < PLAYER_AP_SOFT then FArmor := PLAYER_AP_SOFT;
5938 ITEM_ARMOR_BLUE: if FArmor < PLAYER_AP_LIMIT then FArmor := PLAYER_AP_LIMIT;
5940 ITEM_SPHERE_BLUE: if FHealth < PLAYER_HP_LIMIT then IncMax(FHealth, 100, PLAYER_HP_LIMIT);
5941 ITEM_SPHERE_WHITE:
5942 if (FHealth < PLAYER_HP_LIMIT) or (FArmor < PLAYER_AP_LIMIT) then
5943 begin
5944 if FHealth < PLAYER_HP_LIMIT then FHealth := PLAYER_HP_LIMIT;
5945 if FArmor < PLAYER_AP_LIMIT then FArmor := PLAYER_AP_LIMIT;
5946 end;
5948 ITEM_WEAPON_SAW: FWeapon[WEAPON_SAW] := True;
5949 ITEM_WEAPON_SHOTGUN1: FWeapon[WEAPON_SHOTGUN1] := True;
5950 ITEM_WEAPON_SHOTGUN2: FWeapon[WEAPON_SHOTGUN2] := True;
5951 ITEM_WEAPON_CHAINGUN: FWeapon[WEAPON_CHAINGUN] := True;
5952 ITEM_WEAPON_ROCKETLAUNCHER: FWeapon[WEAPON_ROCKETLAUNCHER] := True;
5953 ITEM_WEAPON_PLASMA: FWeapon[WEAPON_PLASMA] := True;
5954 ITEM_WEAPON_BFG: FWeapon[WEAPON_BFG] := True;
5955 ITEM_WEAPON_SUPERPULEMET: FWeapon[WEAPON_SUPERPULEMET] := True;
5956 ITEM_WEAPON_FLAMETHROWER: FWeapon[WEAPON_FLAMETHROWER] := True;
5958 ITEM_AMMO_BULLETS: if FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS] then IncMax(FAmmo[A_BULLETS], 10, FMaxAmmo[A_BULLETS]);
5959 ITEM_AMMO_BULLETS_BOX: if FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS] then IncMax(FAmmo[A_BULLETS], 50, FMaxAmmo[A_BULLETS]);
5960 ITEM_AMMO_SHELLS: if FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS] then IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
5961 ITEM_AMMO_SHELLS_BOX: if FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS] then IncMax(FAmmo[A_SHELLS], 25, FMaxAmmo[A_SHELLS]);
5962 ITEM_AMMO_ROCKET: if FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS] then IncMax(FAmmo[A_ROCKETS], 1, FMaxAmmo[A_ROCKETS]);
5963 ITEM_AMMO_ROCKET_BOX: if FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS] then IncMax(FAmmo[A_ROCKETS], 5, FMaxAmmo[A_ROCKETS]);
5964 ITEM_AMMO_CELL: if FAmmo[A_CELLS] < FMaxAmmo[A_CELLS] then IncMax(FAmmo[A_CELLS], 40, FMaxAmmo[A_CELLS]);
5965 ITEM_AMMO_CELL_BIG: if FAmmo[A_CELLS] < FMaxAmmo[A_CELLS] then IncMax(FAmmo[A_CELLS], 100, FMaxAmmo[A_CELLS]);
5966 ITEM_AMMO_FUELCAN: if FAmmo[A_FUEL] < FMaxAmmo[A_FUEL] then IncMax(FAmmo[A_FUEL], 100, FMaxAmmo[A_FUEL]);
5968 ITEM_AMMO_BACKPACK:
5969 if (FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS]) or
5970 (FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS]) or
5971 (FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS]) or
5972 (FAmmo[A_CELLS] < FMaxAmmo[A_CELLS]) or
5973 (FMaxAmmo[A_FUEL] < AmmoLimits[1, A_FUEL]) then
5974 begin
5975 FMaxAmmo[A_BULLETS] := AmmoLimits[1, A_BULLETS];
5976 FMaxAmmo[A_SHELLS] := AmmoLimits[1, A_SHELLS];
5977 FMaxAmmo[A_ROCKETS] := AmmoLimits[1, A_ROCKETS];
5978 FMaxAmmo[A_CELLS] := AmmoLimits[1, A_CELLS];
5979 FMaxAmmo[A_FUEL] := AmmoLimits[1, A_FUEL];
5981 if FAmmo[A_BULLETS] < FMaxAmmo[A_BULLETS] then IncMax(FAmmo[A_BULLETS], 10, FMaxAmmo[A_BULLETS]);
5982 if FAmmo[A_SHELLS] < FMaxAmmo[A_SHELLS] then IncMax(FAmmo[A_SHELLS], 4, FMaxAmmo[A_SHELLS]);
5983 if FAmmo[A_ROCKETS] < FMaxAmmo[A_ROCKETS] then IncMax(FAmmo[A_ROCKETS], 1, FMaxAmmo[A_ROCKETS]);
5984 if FAmmo[A_CELLS] < FMaxAmmo[A_CELLS] then IncMax(FAmmo[A_CELLS], 40, FMaxAmmo[A_CELLS]);
5986 FRulez := FRulez + [R_ITEM_BACKPACK];
5987 end;
5989 ITEM_KEY_RED: if not (R_KEY_RED in FRulez) then Include(FRulez, R_KEY_RED);
5990 ITEM_KEY_GREEN: if not (R_KEY_GREEN in FRulez) then Include(FRulez, R_KEY_GREEN);
5991 ITEM_KEY_BLUE: if not (R_KEY_BLUE in FRulez) then Include(FRulez, R_KEY_BLUE);
5993 ITEM_BOTTLE: if FHealth < PLAYER_HP_LIMIT then IncMax(FHealth, 4, PLAYER_HP_LIMIT);
5994 ITEM_HELMET: if FArmor < PLAYER_AP_LIMIT then IncMax(FArmor, 5, PLAYER_AP_LIMIT);
5996 else
5997 Exit;
5998 end;
5999 if g_Game_IsNet and g_Game_IsServer then
6000 MH_SEND_PlayerStats(FUID);
6001 end;
6003 procedure TPlayer.FlySmoke(Times: DWORD = 1);
6004 var
6005 id, i: DWORD;
6006 Anim: TAnimation;
6007 begin
6008 if (Random(5) = 1) and (Times = 1) then
6009 Exit;
6011 if BodyInLiquid(0, 0) then
6012 begin
6013 g_GFX_Bubbles(Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2)+Random(3)-1,
6014 Obj.Y+Obj.Rect.Height+8, 1, 8, 4);
6015 if Random(2) = 0 then
6016 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj.X, FObj.Y)
6017 else
6018 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj.X, FObj.Y);
6019 Exit;
6020 end;
6022 if g_Frames_Get(id, 'FRAMES_SMOKE') then
6023 begin
6024 for i := 1 to Times do
6025 begin
6026 Anim := TAnimation.Create(id, False, 3);
6027 Anim.Alpha := 150;
6028 g_GFX_OnceAnim(Obj.X+Obj.Rect.X+Random(Obj.Rect.Width+Times*2)-(Anim.Width div 2),
6029 Obj.Y+Obj.Rect.Height-4+Random(8+Times*2), Anim, ONCEANIM_SMOKE);
6030 Anim.Free();
6031 end;
6032 end;
6033 end;
6035 procedure TPlayer.OnFireFlame(Times: DWORD = 1);
6036 var
6037 id, i: DWORD;
6038 Anim: TAnimation;
6039 begin
6040 if (Random(10) = 1) and (Times = 1) then
6041 Exit;
6043 if g_Frames_Get(id, 'FRAMES_FLAME') then
6044 begin
6045 for i := 1 to Times do
6046 begin
6047 Anim := TAnimation.Create(id, False, 3);
6048 Anim.Alpha := 0;
6049 g_GFX_OnceAnim(Obj.X+Obj.Rect.X+Random(Obj.Rect.Width+Times*2)-(Anim.Width div 2),
6050 Obj.Y+8+Random(8+Times*2), Anim, ONCEANIM_SMOKE);
6051 Anim.Free();
6052 end;
6053 end;
6054 end;
6056 procedure TPlayer.PauseSounds(Enable: Boolean);
6057 begin
6058 FSawSound.Pause(Enable);
6059 FSawSoundIdle.Pause(Enable);
6060 FSawSoundHit.Pause(Enable);
6061 FSawSoundSelect.Pause(Enable);
6062 end;
6064 { T C o r p s e : }
6066 constructor TCorpse.Create(X, Y: Integer; ModelName: String; aMess: Boolean);
6067 begin
6068 g_Obj_Init(@FObj);
6069 FObj.X := X;
6070 FObj.Y := Y;
6071 FObj.Rect := PLAYER_CORPSERECT;
6072 FModelName := ModelName;
6073 FMess := aMess;
6075 if FMess then
6076 begin
6077 FState := CORPSE_STATE_MESS;
6078 g_PlayerModel_GetAnim(ModelName, A_DIE2, FAnimation, FAnimationMask);
6079 end
6080 else
6081 begin
6082 FState := CORPSE_STATE_NORMAL;
6083 g_PlayerModel_GetAnim(ModelName, A_DIE1, FAnimation, FAnimationMask);
6084 end;
6085 end;
6087 destructor TCorpse.Destroy();
6088 begin
6089 FAnimation.Free();
6091 inherited;
6092 end;
6094 procedure TCorpse.positionChanged (); begin end;
6096 procedure TCorpse.Damage(Value: Word; vx, vy: Integer);
6097 var
6098 pm: TPlayerModel;
6099 begin
6100 if FState = CORPSE_STATE_REMOVEME then
6101 Exit;
6103 FDamage := FDamage + Value;
6105 if FDamage > 150 then
6106 begin
6107 if FAnimation <> nil then
6108 begin
6109 FAnimation.Free();
6110 FAnimation := nil;
6112 FState := CORPSE_STATE_REMOVEME;
6114 g_Player_CreateGibs(FObj.X+FObj.Rect.X+(FObj.Rect.Width div 2),
6115 FObj.Y+FObj.Rect.Y+(FObj.Rect.Height div 2),
6116 FModelName, FColor);
6117 // Çâóê ìÿñà îò òðóïà:
6118 pm := g_PlayerModel_Get(FModelName);
6119 pm.PlaySound(MODELSOUND_DIE, 5, FObj.X, FObj.Y);
6120 pm.Free;
6121 end;
6122 end
6123 else
6124 begin
6125 FObj.Vel.X := FObj.Vel.X + vx;
6126 FObj.Vel.Y := FObj.Vel.Y + vy;
6127 g_GFX_Blood(FObj.X+PLAYER_CORPSERECT.X+(PLAYER_CORPSERECT.Width div 2),
6128 FObj.Y+PLAYER_CORPSERECT.Y+(PLAYER_CORPSERECT.Height div 2),
6129 Value, vx, vy, 16, (PLAYER_CORPSERECT.Height*2) div 3,
6130 150, 0, 0);
6131 end;
6132 end;
6134 procedure TCorpse.Draw();
6135 begin
6136 if FState = CORPSE_STATE_REMOVEME then
6137 Exit;
6139 if FAnimation <> nil then
6140 FAnimation.Draw(FObj.X, FObj.Y, M_NONE);
6142 if FAnimationMask <> nil then
6143 begin
6144 e_Colors := FColor;
6145 FAnimationMask.Draw(FObj.X, FObj.Y, M_NONE);
6146 e_Colors.R := 255;
6147 e_Colors.G := 255;
6148 e_Colors.B := 255;
6149 end;
6150 end;
6152 procedure TCorpse.Update();
6153 var
6154 st: Word;
6155 begin
6156 if FState = CORPSE_STATE_REMOVEME then
6157 Exit;
6159 if gTime mod (GAME_TICK*2) <> 0 then
6160 begin
6161 g_Obj_Move(@FObj, True, True, True);
6162 positionChanged(); // this updates spatial accelerators
6163 Exit;
6164 end;
6166 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6167 FObj.Vel.X := z_dec(FObj.Vel.X, 1);
6169 st := g_Obj_Move(@FObj, True, True, True);
6170 positionChanged(); // this updates spatial accelerators
6172 if WordBool(st and MOVE_FALLOUT) then
6173 begin
6174 FState := CORPSE_STATE_REMOVEME;
6175 Exit;
6176 end;
6178 if FAnimation <> nil then
6179 FAnimation.Update();
6180 if FAnimationMask <> nil then
6181 FAnimationMask.Update();
6182 end;
6184 procedure TCorpse.SaveState(var Mem: TBinMemoryWriter);
6185 var
6186 sig: DWORD;
6187 anim: Boolean;
6188 begin
6189 if Mem = nil then
6190 Exit;
6192 // Ñèãíàòóðà òðóïà:
6193 sig := CORPSE_SIGNATURE; // 'CORP'
6194 Mem.WriteDWORD(sig);
6195 // Ñîñòîÿíèå:
6196 Mem.WriteByte(FState);
6197 // Íàêîïëåííûé óðîí:
6198 Mem.WriteByte(FDamage);
6199 // Öâåò:
6200 Mem.WriteByte(FColor.R);
6201 Mem.WriteByte(FColor.G);
6202 Mem.WriteByte(FColor.B);
6203 // Îáúåêò òðóïà:
6204 Obj_SaveState(@FObj, Mem);
6205 // Åñòü ëè àíèìàöèÿ:
6206 anim := FAnimation <> nil;
6207 Mem.WriteBoolean(anim);
6208 // Åñëè åñòü - ñîõðàíÿåì:
6209 if anim then
6210 FAnimation.SaveState(Mem);
6211 // Åñòü ëè ìàñêà àíèìàöèè:
6212 anim := FAnimationMask <> nil;
6213 Mem.WriteBoolean(anim);
6214 // Åñëè åñòü - ñîõðàíÿåì:
6215 if anim then
6216 FAnimationMask.SaveState(Mem);
6217 end;
6219 procedure TCorpse.LoadState(var Mem: TBinMemoryReader);
6220 var
6221 sig: DWORD;
6222 anim: Boolean;
6223 begin
6224 if Mem = nil then
6225 Exit;
6227 // Ñèãíàòóðà òðóïà:
6228 Mem.ReadDWORD(sig);
6229 if sig <> CORPSE_SIGNATURE then // 'CORP'
6230 begin
6231 raise EBinSizeError.Create('TCorpse.LoadState: Wrong Corpse Signature');
6232 end;
6233 // Ñîñòîÿíèå:
6234 Mem.ReadByte(FState);
6235 // Íàêîïëåííûé óðîí:
6236 Mem.ReadByte(FDamage);
6237 // Öâåò:
6238 Mem.ReadByte(FColor.R);
6239 Mem.ReadByte(FColor.G);
6240 Mem.ReadByte(FColor.B);
6241 // Îáúåêò òðóïà:
6242 Obj_LoadState(@FObj, Mem);
6243 // Åñòü ëè àíèìàöèÿ:
6244 Mem.ReadBoolean(anim);
6245 // Åñëè åñòü - çàãðóæàåì:
6246 if anim then
6247 begin
6248 Assert(FAnimation <> nil, 'TCorpse.LoadState: no FAnimation');
6249 FAnimation.LoadState(Mem);
6250 end;
6251 // Åñòü ëè ìàñêà àíèìàöèè:
6252 Mem.ReadBoolean(anim);
6253 // Åñëè åñòü - çàãðóæàåì:
6254 if anim then
6255 begin
6256 Assert(FAnimationMask <> nil, 'TCorpse.LoadState: no FAnimationMask');
6257 FAnimationMask.LoadState(Mem);
6258 end;
6259 end;
6261 { T B o t : }
6263 constructor TBot.Create();
6264 var
6265 a: Integer;
6266 begin
6267 inherited Create();
6269 FPhysics := True;
6270 FSpectator := False;
6271 FGhost := False;
6273 FIamBot := True;
6275 Inc(gNumBots);
6277 for a := WP_FIRST to WP_LAST do
6278 begin
6279 FDifficult.WeaponPrior[a] := WEAPON_PRIOR1[a];
6280 FDifficult.CloseWeaponPrior[a] := WEAPON_PRIOR2[a];
6281 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6282 end;
6283 end;
6285 destructor TBot.Destroy();
6286 begin
6287 Dec(gNumBots);
6288 inherited Destroy();
6289 end;
6291 procedure TBot.Draw();
6292 begin
6293 inherited Draw();
6295 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6296 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6297 end;
6299 procedure TBot.Respawn(Silent: Boolean; Force: Boolean = False);
6300 begin
6301 inherited Respawn(Silent, Force);
6303 FAIFlags := nil;
6304 FSelectedWeapon := FCurrWeap;
6305 resetWeaponQueue();
6306 FTargetUID := 0;
6307 end;
6309 procedure TBot.UpdateCombat();
6310 type
6311 TTarget = record
6312 UID: Word;
6313 X, Y: Integer;
6314 Rect: TRectWH;
6315 cX, cY: Integer;
6316 Dist: Word;
6317 Line: Boolean;
6318 Visible: Boolean;
6319 IsPlayer: Boolean;
6320 end;
6322 TTargetRecord = array of TTarget;
6324 function Compare(a, b: TTarget): Integer;
6325 begin
6326 if a.Line and not b.Line then // A íà ëèíèè îãíÿ
6327 Result := -1
6328 else
6329 if not a.Line and b.Line then // B íà ëèíèè îãíÿ
6330 Result := 1
6331 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6332 if (a.Line and b.Line) or ((not a.Line) and (not b.Line)) then
6333 begin
6334 if a.Dist > b.Dist then // B áëèæå
6335 Result := 1
6336 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6337 Result := -1;
6338 end
6339 else // Ñòðàííî -> A
6340 Result := -1;
6341 end;
6343 var
6344 a, x1, y1, x2, y2: Integer;
6345 targets: TTargetRecord;
6346 ammo: Word;
6347 Target, BestTarget: TTarget;
6348 firew, fireh: Integer;
6349 angle: SmallInt;
6350 mon: TMonster;
6351 pla, tpla: TPlayer;
6352 vsPlayer, vsMonster, ok: Boolean;
6355 function monsUpdate (mon: TMonster): Boolean;
6356 begin
6357 result := false; // don't stop
6358 if mon.Live and (mon.MonsterType <> MONSTER_BARREL) then
6359 begin
6360 if not TargetOnScreen(mon.Obj.X+mon.Obj.Rect.X, mon.Obj.Y+mon.Obj.Rect.Y) then exit;
6362 x2 := mon.Obj.X+mon.Obj.Rect.X+(mon.Obj.Rect.Width div 2);
6363 y2 := mon.Obj.Y+mon.Obj.Rect.Y+(mon.Obj.Rect.Height div 2);
6365 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6366 if g_TraceVector(x1, y1, x2, y2) then
6367 begin
6368 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6369 SetLength(targets, Length(targets)+1);
6370 with targets[High(targets)] do
6371 begin
6372 UID := mon.UID;
6373 X := mon.Obj.X;
6374 Y := mon.Obj.Y;
6375 cX := x2;
6376 cY := y2;
6377 Rect := mon.Obj.Rect;
6378 Dist := g_PatchLength(x1, y1, x2, y2);
6379 Line := (y1+4 < Target.Y + mon.Obj.Rect.Y + mon.Obj.Rect.Height) and
6380 (y1-4 > Target.Y + mon.Obj.Rect.Y);
6381 Visible := True;
6382 IsPlayer := False;
6383 end;
6384 end;
6385 end;
6386 end;
6388 begin
6389 vsPlayer := LongBool(gGameSettings.Options and GAME_OPTION_BOTVSPLAYER);
6390 vsMonster := LongBool(gGameSettings.Options and GAME_OPTION_BOTVSMONSTER);
6392 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6393 if FCurrWeap <> FSelectedWeapon then
6394 NextWeapon();
6396 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6397 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap = FSelectedWeapon) then
6398 begin
6399 RemoveAIFlag('NEEDFIRE');
6401 case FCurrWeap of
6402 WEAPON_PLASMA, WEAPON_SUPERPULEMET, WEAPON_CHAINGUN: PressKey(KEY_FIRE, 20);
6403 WEAPON_SAW, WEAPON_KASTET, WEAPON_FLAMETHROWER: PressKey(KEY_FIRE, 40);
6404 else PressKey(KEY_FIRE);
6405 end;
6406 end;
6408 // Êîîðäèíàòû ñòâîëà:
6409 x1 := FObj.X + WEAPONPOINT[FDirection].X;
6410 y1 := FObj.Y + WEAPONPOINT[FDirection].Y;
6412 Target.UID := FTargetUID;
6414 ok := False;
6415 if Target.UID <> 0 then
6416 begin // Öåëü åñòü - íàñòðàèâàåì
6417 if (g_GetUIDType(Target.UID) = UID_PLAYER) and
6418 vsPlayer then
6419 begin // Èãðîê
6420 tpla := g_Player_Get(Target.UID);
6421 if tpla <> nil then
6422 with tpla do
6423 begin
6424 if (@FObj) <> nil then
6425 begin
6426 Target.X := FObj.X;
6427 Target.Y := FObj.Y;
6428 end;
6429 end;
6431 Target.cX := Target.X + PLAYER_RECT_CX;
6432 Target.cY := Target.Y + PLAYER_RECT_CY;
6433 Target.Rect := PLAYER_RECT;
6434 Target.Visible := g_TraceVector(x1, y1, Target.cX, Target.cY);
6435 Target.Line := (y1+4 < Target.Y+PLAYER_RECT.Y+PLAYER_RECT.Height) and
6436 (y1-4 > Target.Y+PLAYER_RECT.Y);
6437 Target.IsPlayer := True;
6438 ok := True;
6439 end
6440 else
6441 if (g_GetUIDType(Target.UID) = UID_MONSTER) and
6442 vsMonster then
6443 begin // Ìîíñòð
6444 mon := g_Monsters_ByUID(Target.UID);
6445 if mon <> nil then
6446 begin
6447 Target.X := mon.Obj.X;
6448 Target.Y := mon.Obj.Y;
6450 Target.cX := Target.X + mon.Obj.Rect.X + (mon.Obj.Rect.Width div 2);
6451 Target.cY := Target.Y + mon.Obj.Rect.Y + (mon.Obj.Rect.Height div 2);
6452 Target.Rect := mon.Obj.Rect;
6453 Target.Visible := g_TraceVector(x1, y1, Target.cX, Target.cY);
6454 Target.Line := (y1+4 < Target.Y + mon.Obj.Rect.Y + mon.Obj.Rect.Height) and
6455 (y1-4 > Target.Y + mon.Obj.Rect.Y);
6456 Target.IsPlayer := False;
6457 ok := True;
6458 end;
6459 end;
6460 end;
6462 if not ok then
6463 begin // Öåëè íåò - îáíóëÿåì
6464 Target.X := 0;
6465 Target.Y := 0;
6466 Target.cX := 0;
6467 Target.cY := 0;
6468 Target.Visible := False;
6469 Target.Line := False;
6470 Target.IsPlayer := False;
6471 end;
6473 targets := nil;
6475 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6476 if (not Target.Line) or (not Target.Visible) then
6477 begin
6478 // Èãðîêè:
6479 if vsPlayer then
6480 for a := 0 to High(gPlayers) do
6481 if (gPlayers[a] <> nil) and (gPlayers[a].Live) and
6482 (gPlayers[a].FUID <> FUID) and
6483 (not SameTeam(FUID, gPlayers[a].FUID)) and
6484 (not gPlayers[a].NoTarget) and
6485 (gPlayers[a].FMegaRulez[MR_INVIS] < gTime) then
6486 begin
6487 if not TargetOnScreen(gPlayers[a].FObj.X + PLAYER_RECT.X,
6488 gPlayers[a].FObj.Y + PLAYER_RECT.Y) then
6489 Continue;
6491 x2 := gPlayers[a].FObj.X + PLAYER_RECT_CX;
6492 y2 := gPlayers[a].FObj.Y + PLAYER_RECT_CY;
6494 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6495 if g_TraceVector(x1, y1, x2, y2) then
6496 begin
6497 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6498 SetLength(targets, Length(targets)+1);
6499 with targets[High(targets)] do
6500 begin
6501 UID := gPlayers[a].FUID;
6502 X := gPlayers[a].FObj.X;
6503 Y := gPlayers[a].FObj.Y;
6504 cX := x2;
6505 cY := y2;
6506 Rect := PLAYER_RECT;
6507 Dist := g_PatchLength(x1, y1, x2, y2);
6508 Line := (y1+4 < Target.Y+PLAYER_RECT.Y+PLAYER_RECT.Height) and
6509 (y1-4 > Target.Y+PLAYER_RECT.Y);
6510 Visible := True;
6511 IsPlayer := True;
6512 end;
6513 end;
6514 end;
6516 // Ìîíñòðû:
6517 if vsMonster then g_Mons_ForEach(monsUpdate);
6518 end;
6520 // Åñëè åñòü âîçìîæíûå öåëè:
6521 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6522 if targets <> nil then
6523 begin
6524 // Âûáèðàåì íàèëó÷øóþ öåëü:
6525 BestTarget := targets[0];
6526 if Length(targets) > 1 then
6527 for a := 1 to High(targets) do
6528 if Compare(BestTarget, targets[a]) = 1 then
6529 BestTarget := targets[a];
6531 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6532 if ((not Target.Visible) and BestTarget.Visible and (Target.UID <> BestTarget.UID)) or
6533 ((not Target.Line) and BestTarget.Line and BestTarget.Visible) then
6534 begin
6535 Target := BestTarget;
6537 if (Healthy() = 3) or ((Healthy() = 2)) then
6538 begin // Åñëè çäîðîâû - äîãîíÿåì
6539 if ((RunDirection() = D_LEFT) and (Target.X > FObj.X)) then
6540 SetAIFlag('GORIGHT', '1');
6541 if ((RunDirection() = D_RIGHT) and (Target.X < FObj.X)) then
6542 SetAIFlag('GOLEFT', '1');
6543 end
6544 else
6545 begin // Åñëè ïîáèòû - óáåãàåì
6546 if ((RunDirection() = D_LEFT) and (Target.X < FObj.X)) then
6547 SetAIFlag('GORIGHT', '1');
6548 if ((RunDirection() = D_RIGHT) and (Target.X > FObj.X)) then
6549 SetAIFlag('GOLEFT', '1');
6550 end;
6552 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6553 SelectWeapon(Abs(x1-Target.cX));
6554 end;
6555 end;
6557 // Åñëè åñòü öåëü:
6558 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6559 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6560 if Target.UID <> 0 then
6561 begin
6562 if not TargetOnScreen(Target.X + Target.Rect.X,
6563 Target.Y + Target.Rect.Y) then
6564 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6565 if (Healthy() = 3) or ((Healthy() = 2)) then
6566 begin // Åñëè çäîðîâû - äîãîíÿåì
6567 if ((RunDirection() = D_LEFT) and (Target.X > FObj.X)) then
6568 SetAIFlag('GORIGHT', '1');
6569 if ((RunDirection() = D_RIGHT) and (Target.X < FObj.X)) then
6570 SetAIFlag('GOLEFT', '1');
6571 end
6572 else
6573 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6574 Target.UID := 0;
6575 if ((RunDirection() = D_LEFT) and (Target.X < FObj.X)) then
6576 SetAIFlag('GORIGHT', '1');
6577 if ((RunDirection() = D_RIGHT) and (Target.X > FObj.X)) then
6578 SetAIFlag('GOLEFT', '1');
6579 end;
6580 end
6581 else
6582 begin // Öåëü ïîêà íà "ýêðàíå"
6583 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
6584 if g_TraceVector(x1, y1, Target.cX, Target.cY) then
6585 FLastVisible := gTime;
6586 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
6587 if (Abs(FObj.Y-Target.Y) <= 128) then
6588 begin
6589 if ((RunDirection() = D_LEFT) and (Target.X > FObj.X)) then
6590 SetAIFlag('GORIGHT', '1');
6591 if ((RunDirection() = D_RIGHT) and (Target.X < FObj.X)) then
6592 SetAIFlag('GOLEFT', '1');
6593 end;
6594 end;
6596 // Âûáèðàåì óãîë ââåðõ:
6597 if FDirection = D_LEFT then
6598 angle := ANGLE_LEFTUP
6599 else
6600 angle := ANGLE_RIGHTUP;
6602 firew := Trunc(Cos(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
6603 fireh := Trunc(Sin(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
6605 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6606 if g_CollideLine(x1, y1, x1+firew, y1+fireh,
6607 Target.X+Target.Rect.X+GetInterval(FDifficult.DiagPrecision, 128), //96
6608 Target.Y+Target.Rect.Y+GetInterval(FDifficult.DiagPrecision, 128),
6609 Target.Rect.Width, Target.Rect.Height) and
6610 g_TraceVector(x1, y1, Target.cX, Target.cY) then
6611 begin // òî íóæíî ñòðåëÿòü ââåðõ
6612 SetAIFlag('NEEDFIRE', '1');
6613 SetAIFlag('NEEDSEEUP', '1');
6614 end;
6616 // Âûáèðàåì óãîë âíèç:
6617 if FDirection = D_LEFT then
6618 angle := ANGLE_LEFTDOWN
6619 else
6620 angle := ANGLE_RIGHTDOWN;
6622 firew := Trunc(Cos(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
6623 fireh := Trunc(Sin(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
6625 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6626 if g_CollideLine(x1, y1, x1+firew, y1+fireh,
6627 Target.X+Target.Rect.X+GetInterval(FDifficult.DiagPrecision, 128),
6628 Target.Y+Target.Rect.Y+GetInterval(FDifficult.DiagPrecision, 128),
6629 Target.Rect.Width, Target.Rect.Height) and
6630 g_TraceVector(x1, y1, Target.cX, Target.cY) then
6631 begin // òî íóæíî ñòðåëÿòü âíèç
6632 SetAIFlag('NEEDFIRE', '1');
6633 SetAIFlag('NEEDSEEDOWN', '1');
6634 end;
6636 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
6637 if Target.Visible and
6638 (y1+4 < Target.Y+Target.Rect.Y+Target.Rect.Height) and
6639 (y1-4 > Target.Y+Target.Rect.Y) then
6640 begin
6641 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
6642 if ((FDirection = D_LEFT) and (Target.X < FObj.X)) or
6643 ((FDirection = D_RIGHT) and (Target.X > FObj.X)) then
6644 begin // òî íóæíî ñòðåëÿòü âïåðåä
6645 SetAIFlag('NEEDFIRE', '1');
6646 SetAIFlag('NEEDSEEDOWN', '');
6647 SetAIFlag('NEEDSEEUP', '');
6648 end;
6649 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
6650 if Abs(FObj.X-Target.X) < Trunc(gPlayerScreenSize.X*0.75) then
6651 if GetRnd(FDifficult.CloseJump) then
6652 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
6653 if Abs(FObj.X-Target.X) < 128 then
6654 a := 4
6655 else
6656 a := 30;
6657 if Random(a) = 0 then
6658 SetAIFlag('NEEDJUMP', '1');
6659 end;
6660 end;
6662 // Åñëè öåëü âñå åùå åñòü:
6663 if Target.UID <> 0 then
6664 if gTime-FLastVisible > 2000 then // Åñëè âèäåëè äàâíî
6665 Target.UID := 0 // òî çàáûòü öåëü
6666 else // Åñëè âèäåëè íåäàâíî
6667 begin // íî öåëü óáèëè
6668 if Target.IsPlayer then
6669 begin // Öåëü - èãðîê
6670 pla := g_Player_Get(Target.UID);
6671 if (pla = nil) or (not pla.Live) or pla.NoTarget or
6672 (pla.FMegaRulez[MR_INVIS] >= gTime) then
6673 Target.UID := 0; // òî çàáûòü öåëü
6674 end
6675 else
6676 begin // Öåëü - ìîíñòð
6677 mon := g_Monsters_ByUID(Target.UID);
6678 if (mon = nil) or (not mon.Live) then
6679 Target.UID := 0; // òî çàáûòü öåëü
6680 end;
6681 end;
6682 end; // if Target.UID <> 0
6684 FTargetUID := Target.UID;
6686 // Åñëè âîçìîæíûõ öåëåé íåò:
6687 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
6688 if targets = nil then
6689 if GetAIFlag('ATTACKLEFT') <> '' then
6690 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
6691 RemoveAIFlag('ATTACKLEFT');
6693 SetAIFlag('NEEDJUMP', '1');
6695 if RunDirection() = D_RIGHT then
6696 begin // Èäåì íå â òó ñòîðîíó
6697 if (Healthy() > 1) and GetRnd(FDifficult.InvisFire) then
6698 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
6699 SetAIFlag('NEEDFIRE', '1');
6700 SetAIFlag('GOLEFT', '1');
6701 end;
6702 end
6703 else
6704 begin // Èäåì â íóæíóþ ñòîðîíó
6705 if GetRnd(FDifficult.InvisFire) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6706 SetAIFlag('NEEDFIRE', '1');
6707 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6708 SetAIFlag('GORIGHT', '1');
6709 end;
6710 end
6711 else
6712 if GetAIFlag('ATTACKRIGHT') <> '' then
6713 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
6714 RemoveAIFlag('ATTACKRIGHT');
6716 SetAIFlag('NEEDJUMP', '1');
6718 if RunDirection() = D_LEFT then
6719 begin // Èäåì íå â òó ñòîðîíó
6720 if (Healthy() > 1) and GetRnd(FDifficult.InvisFire) then
6721 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
6722 SetAIFlag('NEEDFIRE', '1');
6723 SetAIFlag('GORIGHT', '1');
6724 end;
6725 end
6726 else
6727 begin
6728 if GetRnd(FDifficult.InvisFire) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6729 SetAIFlag('NEEDFIRE', '1');
6730 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6731 SetAIFlag('GOLEFT', '1');
6732 end;
6733 end;
6735 //HACK! (does it belongs there?)
6736 RealizeCurrentWeapon();
6738 // Åñëè åñòü âîçìîæíûå öåëè:
6739 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
6740 if (targets <> nil) and (GetAIFlag('NEEDFIRE') <> '') then
6741 for a := 0 to High(targets) do
6742 begin
6743 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
6744 if GetRnd(FDifficult.DiagFire) then
6745 begin
6746 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
6747 if FDirection = D_LEFT then
6748 angle := ANGLE_LEFTUP
6749 else
6750 angle := ANGLE_RIGHTUP;
6752 firew := Trunc(Cos(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
6753 fireh := Trunc(Sin(DegToRad(-angle))*gPlayerScreenSize.X*0.6);
6755 if g_CollideLine(x1, y1, x1+firew, y1+fireh,
6756 targets[a].X+targets[a].Rect.X+GetInterval(FDifficult.DiagPrecision, 128),
6757 targets[a].Y+targets[a].Rect.Y+GetInterval(FDifficult.DiagPrecision, 128),
6758 targets[a].Rect.Width, targets[a].Rect.Height) and
6759 g_TraceVector(x1, y1, targets[a].cX, targets[a].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 if g_CollideLine(x1, y1, x1+firew, y1+fireh,
6775 targets[a].X+targets[a].Rect.X+GetInterval(FDifficult.DiagPrecision, 128),
6776 targets[a].Y+targets[a].Rect.Y+GetInterval(FDifficult.DiagPrecision, 128),
6777 targets[a].Rect.Width, targets[a].Rect.Height) and
6778 g_TraceVector(x1, y1, targets[a].cX, targets[a].cY) then
6779 begin
6780 SetAIFlag('NEEDFIRE', '1');
6781 SetAIFlag('NEEDSEEDOWN', '1');
6782 end;
6783 end;
6785 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
6786 if targets[a].Line and targets[a].Visible and
6787 (((FDirection = D_LEFT) and (targets[a].X < FObj.X)) or
6788 ((FDirection = D_RIGHT) and (targets[a].X > FObj.X))) then
6789 begin
6790 SetAIFlag('NEEDFIRE', '1');
6791 Break;
6792 end;
6793 end;
6795 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
6796 if g_Weapon_Danger(FUID, FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y,
6797 PLAYER_RECT.Width, PLAYER_RECT.Height,
6798 40+GetInterval(FDifficult.Cover, 40)) then
6799 SetAIFlag('NEEDJUMP', '1');
6801 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
6802 ammo := GetAmmoByWeapon(FCurrWeap);
6803 if ((FCurrWeap = WEAPON_SHOTGUN2) and (ammo < 2)) or
6804 ((FCurrWeap = WEAPON_BFG) and (ammo < 40)) or
6805 (ammo = 0) then
6806 SetAIFlag('SELECTWEAPON', '1');
6808 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
6809 if GetAIFlag('SELECTWEAPON') = '1' then
6810 begin
6811 SelectWeapon(-1);
6812 RemoveAIFlag('SELECTWEAPON');
6813 end;
6814 end;
6816 procedure TBot.Update();
6817 var
6818 EnableAI: Boolean;
6819 begin
6820 if not FLive then
6821 begin // Respawn
6822 ReleaseKeys();
6823 PressKey(KEY_UP);
6824 end
6825 else
6826 begin
6827 EnableAI := True;
6829 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
6830 if (g_debug_BotAIOff = 1) and (Team = TEAM_RED) then
6831 EnableAI := False;
6832 if (g_debug_BotAIOff = 2) and (Team = TEAM_BLUE) then
6833 EnableAI := False;
6834 if g_debug_BotAIOff = 3 then
6835 EnableAI := False;
6837 if EnableAI then
6838 begin
6839 UpdateMove();
6840 UpdateCombat();
6841 end
6842 else
6843 begin
6844 RealizeCurrentWeapon();
6845 end;
6846 end;
6848 inherited Update();
6849 end;
6851 procedure TBot.ReleaseKey(Key: Byte);
6852 begin
6853 with FKeys[Key] do
6854 begin
6855 Pressed := False;
6856 Time := 0;
6857 end;
6858 end;
6860 function TBot.KeyPressed(Key: Word): Boolean;
6861 begin
6862 Result := FKeys[Key].Pressed;
6863 end;
6865 function TBot.GetAIFlag(aName: String20): String20;
6866 var
6867 a: Integer;
6868 begin
6869 Result := '';
6871 aName := LowerCase(aName);
6873 if FAIFlags <> nil then
6874 for a := 0 to High(FAIFlags) do
6875 if LowerCase(FAIFlags[a].Name) = aName then
6876 begin
6877 Result := FAIFlags[a].Value;
6878 Break;
6879 end;
6880 end;
6882 procedure TBot.RemoveAIFlag(aName: String20);
6883 var
6884 a, b: Integer;
6885 begin
6886 if FAIFlags = nil then Exit;
6888 aName := LowerCase(aName);
6890 for a := 0 to High(FAIFlags) do
6891 if LowerCase(FAIFlags[a].Name) = aName then
6892 begin
6893 if a <> High(FAIFlags) then
6894 for b := a to High(FAIFlags)-1 do
6895 FAIFlags[b] := FAIFlags[b+1];
6897 SetLength(FAIFlags, Length(FAIFlags)-1);
6898 Break;
6899 end;
6900 end;
6902 procedure TBot.SetAIFlag(aName, fValue: String20);
6903 var
6904 a: Integer;
6905 ok: Boolean;
6906 begin
6907 a := 0;
6908 ok := False;
6910 aName := LowerCase(aName);
6912 if FAIFlags <> nil then
6913 for a := 0 to High(FAIFlags) do
6914 if LowerCase(FAIFlags[a].Name) = aName then
6915 begin
6916 ok := True;
6917 Break;
6918 end;
6920 if ok then FAIFlags[a].Value := fValue
6921 else
6922 begin
6923 SetLength(FAIFlags, Length(FAIFlags)+1);
6924 with FAIFlags[High(FAIFlags)] do
6925 begin
6926 Name := aName;
6927 Value := fValue;
6928 end;
6929 end;
6930 end;
6932 procedure TBot.UpdateMove;
6934 procedure GoLeft(Time: Word = 1);
6935 begin
6936 ReleaseKey(KEY_LEFT);
6937 ReleaseKey(KEY_RIGHT);
6938 PressKey(KEY_LEFT, Time);
6939 SetDirection(D_LEFT);
6940 end;
6942 procedure GoRight(Time: Word = 1);
6943 begin
6944 ReleaseKey(KEY_LEFT);
6945 ReleaseKey(KEY_RIGHT);
6946 PressKey(KEY_RIGHT, Time);
6947 SetDirection(D_RIGHT);
6948 end;
6950 function Rnd(a: Word): Boolean;
6951 begin
6952 Result := Random(a) = 0;
6953 end;
6955 procedure Turn(Time: Word = 1200);
6956 begin
6957 if RunDirection() = D_LEFT then GoRight(Time) else GoLeft(Time);
6958 end;
6960 procedure Stop();
6961 begin
6962 ReleaseKey(KEY_LEFT);
6963 ReleaseKey(KEY_RIGHT);
6964 end;
6966 function CanRunLeft(): Boolean;
6967 begin
6968 Result := not CollideLevel(-1, 0);
6969 end;
6971 function CanRunRight(): Boolean;
6972 begin
6973 Result := not CollideLevel(1, 0);
6974 end;
6976 function CanRun(): Boolean;
6977 begin
6978 if RunDirection() = D_LEFT then Result := CanRunLeft() else Result := CanRunRight();
6979 end;
6981 procedure Jump(Time: Word = 30);
6982 begin
6983 PressKey(KEY_JUMP, Time);
6984 end;
6986 function NearHole(): Boolean;
6987 var
6988 x, sx: Integer;
6989 begin
6990 { TODO 5 : Ëåñòíèöû }
6991 sx := IfThen(RunDirection() = D_LEFT, -1, 1);
6992 for x := 1 to PLAYER_RECT.Width do
6993 if (not StayOnStep(x*sx, 0)) and
6994 (not CollideLevel(x*sx, PLAYER_RECT.Height)) and
6995 (not CollideLevel(x*sx, PLAYER_RECT.Height*2)) then
6996 begin
6997 Result := True;
6998 Exit;
6999 end;
7001 Result := False;
7002 end;
7004 function BorderHole(): Boolean;
7005 var
7006 x, sx, xx: Integer;
7007 begin
7008 { TODO 5 : Ëåñòíèöû }
7009 sx := IfThen(RunDirection() = D_LEFT, -1, 1);
7010 for x := 1 to PLAYER_RECT.Width do
7011 if (not StayOnStep(x*sx, 0)) and
7012 (not CollideLevel(x*sx, PLAYER_RECT.Height)) and
7013 (not CollideLevel(x*sx, PLAYER_RECT.Height*2)) then
7014 begin
7015 for xx := x to x+32 do
7016 if CollideLevel(xx*sx, PLAYER_RECT.Height) then
7017 begin
7018 Result := True;
7019 Exit;
7020 end;
7021 end;
7023 Result := False;
7024 end;
7026 function NearDeepHole(): Boolean;
7027 var
7028 x, sx, y: Integer;
7029 begin
7030 Result := False;
7032 sx := IfThen(RunDirection() = D_LEFT, -1, 1);
7033 y := 3;
7035 for x := 1 to PLAYER_RECT.Width do
7036 if (not StayOnStep(x*sx, 0)) and
7037 (not CollideLevel(x*sx, PLAYER_RECT.Height)) and
7038 (not CollideLevel(x*sx, PLAYER_RECT.Height*2)) then
7039 begin
7040 while FObj.Y+y*PLAYER_RECT.Height < gMapInfo.Height do
7041 begin
7042 if CollideLevel(x*sx, PLAYER_RECT.Height*y) then Exit;
7043 y := y+1;
7044 end;
7046 Result := True;
7047 end else Result := False;
7048 end;
7050 function OverDeepHole(): Boolean;
7051 var
7052 y: Integer;
7053 begin
7054 Result := False;
7056 y := 1;
7057 while FObj.Y+y*PLAYER_RECT.Height < gMapInfo.Height do
7058 begin
7059 if CollideLevel(0, PLAYER_RECT.Height*y) then Exit;
7060 y := y+1;
7061 end;
7063 Result := True;
7064 end;
7066 function OnGround(): Boolean;
7067 begin
7068 Result := StayOnStep(0, 0) or CollideLevel(0, 1);
7069 end;
7071 function OnLadder(): Boolean;
7072 begin
7073 Result := FullInStep(0, 0);
7074 end;
7076 function BelowLadder(): Boolean;
7077 begin
7078 Result := (FullInStep(IfThen(RunDirection() = D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -PLAYER_RECT.Height) and
7079 not CollideLevel(IfThen(RunDirection() = D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -PLAYER_RECT.Height)) or
7080 (FullInStep(IfThen(RunDirection() = D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -BOT_MAXJUMP) and
7081 not CollideLevel(IfThen(RunDirection() = D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -BOT_MAXJUMP));
7082 end;
7084 function BelowLiftUp(): Boolean;
7085 begin
7086 Result := ((FullInLift(IfThen(RunDirection() = D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -PLAYER_RECT.Height) = -1) and
7087 not CollideLevel(IfThen(RunDirection() = D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -PLAYER_RECT.Height)) or
7088 ((FullInLift(IfThen(RunDirection() = D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -BOT_MAXJUMP) = -1) and
7089 not CollideLevel(IfThen(RunDirection() = D_LEFT, -1, 1)*(PLAYER_RECT.Width div 2), -BOT_MAXJUMP));
7090 end;
7092 function OnTopLift(): Boolean;
7093 begin
7094 Result := (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7095 end;
7097 function CanJumpOver(): Boolean;
7098 var
7099 sx, y: Integer;
7100 begin
7101 sx := IfThen(RunDirection() = D_LEFT, -1, 1);
7103 Result := False;
7105 if not CollideLevel(sx, 0) then Exit;
7107 for y := 1 to BOT_MAXJUMP do
7108 if CollideLevel(0, -y) then Exit else
7109 if not CollideLevel(sx, -y) then
7110 begin
7111 Result := True;
7112 Exit;
7113 end;
7114 end;
7116 function CanJumpUp(Dist: ShortInt): Boolean;
7117 var
7118 y, yy: Integer;
7119 c: Boolean;
7120 begin
7121 Result := False;
7123 if CollideLevel(Dist, 0) then Exit;
7125 c := False;
7126 for y := 0 to BOT_MAXJUMP do
7127 if CollideLevel(Dist, -y) then
7128 begin
7129 c := True;
7130 Break;
7131 end;
7133 if not c then Exit;
7135 c := False;
7136 for yy := y+1 to BOT_MAXJUMP do
7137 if not CollideLevel(Dist, -yy) then
7138 begin
7139 c := True;
7140 Break;
7141 end;
7143 if not c then Exit;
7145 c := False;
7146 for y := 0 to BOT_MAXJUMP do
7147 if CollideLevel(0, -y) then
7148 begin
7149 c := True;
7150 Break;
7151 end;
7153 if c then Exit;
7155 if y < yy then Exit;
7157 Result := True;
7158 end;
7160 function IsSafeTrigger(): Boolean;
7161 var
7162 a: Integer;
7163 begin
7164 Result := True;
7165 if gTriggers = nil then
7166 Exit;
7167 for a := 0 to High(gTriggers) do
7168 if Collide(gTriggers[a].X,
7169 gTriggers[a].Y,
7170 gTriggers[a].Width,
7171 gTriggers[a].Height) and
7172 (gTriggers[a].TriggerType in [TRIGGER_EXIT, TRIGGER_CLOSEDOOR,
7173 TRIGGER_CLOSETRAP, TRIGGER_TRAP,
7174 TRIGGER_PRESS, TRIGGER_ON, TRIGGER_OFF,
7175 TRIGGER_ONOFF, TRIGGER_SPAWNMONSTER,
7176 TRIGGER_DAMAGE, TRIGGER_SHOT]) then
7177 Result := False;
7178 end;
7180 begin
7181 // Âîçìîæíî, íàæèìàåì êíîïêó:
7182 if Rnd(16) and IsSafeTrigger() then
7183 PressKey(KEY_OPEN);
7185 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7186 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7187 begin
7188 ReleaseKey(KEY_LEFT);
7189 ReleaseKey(KEY_RIGHT);
7190 Jump();
7191 end;
7193 // Èäåì âëåâî, åñëè íàäî áûëî:
7194 if GetAIFlag('GOLEFT') <> '' then
7195 begin
7196 RemoveAIFlag('GOLEFT');
7197 if CanRunLeft() then
7198 GoLeft(360);
7199 end;
7201 // Èäåì âïðàâî, åñëè íàäî áûëî:
7202 if GetAIFlag('GORIGHT') <> '' then
7203 begin
7204 RemoveAIFlag('GORIGHT');
7205 if CanRunRight() then
7206 GoRight(360);
7207 end;
7209 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7210 if FObj.X < -32 then
7211 GoRight(360)
7212 else
7213 if FObj.X+32 > gMapInfo.Width then
7214 GoLeft(360);
7216 // Ïðûãàåì, åñëè íàäî áûëî:
7217 if GetAIFlag('NEEDJUMP') <> '' then
7218 begin
7219 Jump(0);
7220 RemoveAIFlag('NEEDJUMP');
7221 end;
7223 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7224 if GetAIFlag('NEEDSEEUP') <> '' then
7225 begin
7226 ReleaseKey(KEY_UP);
7227 ReleaseKey(KEY_DOWN);
7228 PressKey(KEY_UP, 20);
7229 RemoveAIFlag('NEEDSEEUP');
7230 end;
7232 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7233 if GetAIFlag('NEEDSEEDOWN') <> '' then
7234 begin
7235 ReleaseKey(KEY_UP);
7236 ReleaseKey(KEY_DOWN);
7237 PressKey(KEY_DOWN, 20);
7238 RemoveAIFlag('NEEDSEEDOWN');
7239 end;
7241 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7242 if GetAIFlag('GOINHOLE') <> '' then
7243 if not OnGround() then
7244 begin
7245 ReleaseKey(KEY_LEFT);
7246 ReleaseKey(KEY_RIGHT);
7247 RemoveAIFlag('GOINHOLE');
7248 SetAIFlag('FALLINHOLE', '1');
7249 end;
7251 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7252 if GetAIFlag('FALLINHOLE') <> '' then
7253 if OnGround() then
7254 RemoveAIFlag('FALLINHOLE');
7256 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7257 if not (KeyPressed(KEY_LEFT) or KeyPressed(KEY_RIGHT)) then
7258 if GetAIFlag('FALLINHOLE') = '' then
7259 if (not OnLadder()) or (FObj.Vel.Y >= 0) or (OnTopLift()) then
7260 if Rnd(2) then
7261 GoLeft(360)
7262 else
7263 GoRight(360);
7265 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7266 if OnGround() and
7267 CanJumpUp(IfThen(RunDirection() = D_LEFT, -1, 1)*32) and
7268 Rnd(8) then
7269 Jump();
7271 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7272 if OnGround() and NearHole() then
7273 if NearDeepHole() then // Åñëè ýòî áåçäíà
7274 case Random(6) of
7275 0..3: Turn(); // Áåæèì îáðàòíî
7276 4: Jump(); // Ïðûãàåì
7277 5: begin // Ïðûãàåì îáðàòíî
7278 Turn();
7279 Jump();
7280 end;
7281 end
7282 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7283 if GetAIFlag('GOINHOLE') = '' then
7284 case Random(6) of
7285 0: Turn(); // Íå íóæíî òóäà
7286 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7287 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7288 if BorderHole() then
7289 SetAIFlag('GOINHOLE', '1');
7290 end;
7292 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7293 if (not CanRun()) and OnGround() then
7294 begin
7295 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7296 if CanJumpOver() or OnLadder() then
7297 Jump()
7298 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7299 if Random(2) = 0 then
7300 begin
7301 if IsSafeTrigger() then
7302 PressKey(KEY_OPEN);
7303 end else
7304 Turn();
7305 end;
7307 // Îñòàëîñü ìàëî âîçäóõà:
7308 if FAir < 36 * 2 then
7309 Jump(20);
7311 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7312 if (FMegaRulez[MR_SUIT] < gTime) and ((FLastHit = HIT_ACID) or (Healthy() <= 1)) then
7313 if BodyInAcid(0, 0) then
7314 Jump();
7315 end;
7317 function TBot.FullInStep(XInc, YInc: Integer): Boolean;
7318 begin
7319 Result := g_Map_CollidePanel(FObj.X+PLAYER_RECT.X+XInc, FObj.Y+PLAYER_RECT.Y+YInc,
7320 PLAYER_RECT.Width, PLAYER_RECT.Height, PANEL_STEP, False);
7321 end;
7323 {function TBot.NeedItem(Item: Byte): Byte;
7324 begin
7325 Result := 4;
7326 end;}
7328 procedure TBot.SelectWeapon(Dist: Integer);
7329 var
7330 a: Integer;
7332 function HaveAmmo(weapon: Byte): Boolean;
7333 begin
7334 case weapon of
7335 WEAPON_PISTOL: Result := FAmmo[A_BULLETS] >= 1;
7336 WEAPON_SHOTGUN1: Result := FAmmo[A_SHELLS] >= 1;
7337 WEAPON_SHOTGUN2: Result := FAmmo[A_SHELLS] >= 2;
7338 WEAPON_CHAINGUN: Result := FAmmo[A_BULLETS] >= 10;
7339 WEAPON_ROCKETLAUNCHER: Result := FAmmo[A_ROCKETS] >= 1;
7340 WEAPON_PLASMA: Result := FAmmo[A_CELLS] >= 10;
7341 WEAPON_BFG: Result := FAmmo[A_CELLS] >= 40;
7342 WEAPON_SUPERPULEMET: Result := FAmmo[A_SHELLS] >= 1;
7343 WEAPON_FLAMETHROWER: Result := FAmmo[A_FUEL] >= 1;
7344 else Result := True;
7345 end;
7346 end;
7348 begin
7349 if Dist = -1 then Dist := BOT_LONGDIST;
7351 if Dist > BOT_LONGDIST then
7352 begin // Äàëüíèé áîé
7353 for a := 0 to 9 do
7354 if FWeapon[FDifficult.WeaponPrior[a]] and HaveAmmo(FDifficult.WeaponPrior[a]) then
7355 begin
7356 FSelectedWeapon := FDifficult.WeaponPrior[a];
7357 Break;
7358 end;
7359 end
7360 else //if Dist > BOT_UNSAFEDIST then
7361 begin // Áëèæíèé áîé
7362 for a := 0 to 9 do
7363 if FWeapon[FDifficult.CloseWeaponPrior[a]] and HaveAmmo(FDifficult.CloseWeaponPrior[a]) then
7364 begin
7365 FSelectedWeapon := FDifficult.CloseWeaponPrior[a];
7366 Break;
7367 end;
7368 end;
7369 { else
7370 begin
7371 for a := 0 to 9 do
7372 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7373 begin
7374 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7375 Break;
7376 end;
7377 end;}
7378 end;
7380 function TBot.PickItem(ItemType: Byte; force: Boolean; var remove: Boolean): Boolean;
7381 begin
7382 Result := inherited PickItem(ItemType, force, remove);
7384 if Result then SetAIFlag('SELECTWEAPON', '1');
7385 end;
7387 function TBot.Heal(value: Word; Soft: Boolean): Boolean;
7388 begin
7389 Result := inherited Heal(value, Soft);
7390 end;
7392 function TBot.Healthy(): Byte;
7393 begin
7394 if FMegaRulez[MR_INVUL] >= gTime then Result := 3
7395 else if (FHealth > 80) or ((FHealth > 50) and (FArmor > 20)) then Result := 3
7396 else if (FHealth > 50) then Result := 2
7397 else if (FHealth > 20) then Result := 1
7398 else Result := 0;
7399 end;
7401 function TBot.TargetOnScreen(TX, TY: Integer): Boolean;
7402 begin
7403 Result := (Abs(FObj.X-TX) <= Trunc(gPlayerScreenSize.X*0.6)) and
7404 (Abs(FObj.Y-TY) <= Trunc(gPlayerScreenSize.Y*0.6));
7405 end;
7407 procedure TBot.OnDamage(Angle: SmallInt);
7408 var
7409 pla: TPlayer;
7410 mon: TMonster;
7411 ok: Boolean;
7412 begin
7413 inherited;
7415 if (Angle = 0) or (Angle = 180) then
7416 begin
7417 ok := False;
7418 if (g_GetUIDType(FLastSpawnerUID) = UID_PLAYER) and
7419 LongBool(gGameSettings.Options and GAME_OPTION_BOTVSPLAYER) then
7420 begin // Èãðîê
7421 pla := g_Player_Get(FLastSpawnerUID);
7422 ok := not TargetOnScreen(pla.FObj.X + PLAYER_RECT.X,
7423 pla.FObj.Y + PLAYER_RECT.Y);
7424 end
7425 else
7426 if (g_GetUIDType(FLastSpawnerUID) = UID_MONSTER) and
7427 LongBool(gGameSettings.Options and GAME_OPTION_BOTVSMONSTER) then
7428 begin // Ìîíñòð
7429 mon := g_Monsters_ByUID(FLastSpawnerUID);
7430 ok := not TargetOnScreen(mon.Obj.X + mon.Obj.Rect.X,
7431 mon.Obj.Y + mon.Obj.Rect.Y);
7432 end;
7434 if ok then
7435 if Angle = 0 then
7436 SetAIFlag('ATTACKLEFT', '1')
7437 else
7438 SetAIFlag('ATTACKRIGHT', '1');
7439 end;
7440 end;
7442 function TBot.RunDirection(): TDirection;
7443 begin
7444 if Abs(Vel.X) >= 1 then
7445 begin
7446 if Vel.X > 0 then Result := D_RIGHT else Result := D_LEFT;
7447 end else
7448 Result := FDirection;
7449 end;
7451 function TBot.GetRnd(a: Byte): Boolean;
7452 begin
7453 if a = 0 then Result := False
7454 else if a = 255 then Result := True
7455 else Result := Random(256) > 255-a;
7456 end;
7458 function TBot.GetInterval(a: Byte; radius: SmallInt): SmallInt;
7459 begin
7460 Result := Round((255-a)/255*radius*(Random(2)-1));
7461 end;
7463 procedure TBot.SaveState(var Mem: TBinMemoryWriter);
7464 var
7465 i: Integer;
7466 dw: DWORD;
7467 p: Pointer;
7468 begin
7469 inherited SaveState(Mem);
7471 // Âûáðàííîå îðóæèå:
7472 Mem.WriteByte(FSelectedWeapon);
7473 // UID öåëè:
7474 Mem.WriteWord(FTargetUID);
7475 // Âðåìÿ ïîòåðè öåëè:
7476 Mem.WriteDWORD(FLastVisible);
7477 // Êîëè÷åñòâî ôëàãîâ ÈÈ:
7478 dw := Length(FAIFlags);
7479 Mem.WriteDWORD(dw);
7480 // Ôëàãè ÈÈ:
7481 for i := 0 to Integer(dw)-1 do
7482 begin
7483 Mem.WriteString(FAIFlags[i].Name, 20);
7484 Mem.WriteString(FAIFlags[i].Value, 20);
7485 end;
7486 // Íàñòðîéêè ñëîæíîñòè:
7487 p := @FDifficult;
7488 Mem.WriteMemory(p, SizeOf(TDifficult));
7489 end;
7491 procedure TBot.LoadState(var Mem: TBinMemoryReader);
7492 var
7493 i: Integer;
7494 dw: DWORD;
7495 p: Pointer;
7496 begin
7497 inherited LoadState(Mem);
7499 // Âûáðàííîå îðóæèå:
7500 Mem.ReadByte(FSelectedWeapon);
7501 // UID öåëè:
7502 Mem.ReadWord(FTargetUID);
7503 // Âðåìÿ ïîòåðè öåëè:
7504 Mem.ReadDWORD(FLastVisible);
7505 // Êîëè÷åñòâî ôëàãîâ ÈÈ:
7506 Mem.ReadDWORD(dw);
7507 SetLength(FAIFlags, dw);
7508 // Ôëàãè ÈÈ:
7509 for i := 0 to Integer(dw)-1 do
7510 begin
7511 Mem.ReadString(FAIFlags[i].Name);
7512 Mem.ReadString(FAIFlags[i].Value);
7513 end;
7514 // Íàñòðîéêè ñëîæíîñòè:
7515 Mem.ReadMemory(p, dw);
7516 if dw <> SizeOf(TDifficult) then
7517 begin
7518 raise EBinSizeError.Create('TBot.LoadState: Wrong FDifficult Size');
7519 end;
7520 FDifficult := TDifficult(p^);
7521 end;
7523 end.