X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fgame%2Fg_player.pas;h=5d1f863faa686c667ec21470ffed524e700c4778;hb=281969a1bea9afbf36babebcf9208549929a96f4;hp=da7e6d2eea8f7a52fac7bb5dcdc366e3e20e50d9;hpb=d001446ed83b8c55697892867289381d495bc2e5;p=d2df-sdl.git diff --git a/src/game/g_player.pas b/src/game/g_player.pas index da7e6d2..5d1f863 100644 --- a/src/game/g_player.pas +++ b/src/game/g_player.pas @@ -95,6 +95,7 @@ const PLAYER_AP_SOFT = 100; PLAYER_AP_LIMIT = 200; SUICIDE_DAMAGE = 112; + WEAPON_DELAY = 5; PLAYER1_DEF_COLOR: TRGB = (R:64; G:175; B:48); PLAYER2_DEF_COLOR: TRGB = (R:96; G:96; B:96); @@ -190,6 +191,9 @@ type FSawSoundIdle: TPlayableSound; FSawSoundHit: TPlayableSound; FSawSoundSelect: TPlayableSound; + FFlameSoundOn: TPlayableSound; + FFlameSoundOff: TPlayableSound; + FFlameSoundWork: TPlayableSound; FJetSoundOn: TPlayableSound; FJetSoundOff: TPlayableSound; FJetSoundFly: TPlayableSound; @@ -252,6 +256,7 @@ type FWantsInGame: Boolean; FGhost: Boolean; FPhysics: Boolean; + FFlaming: Boolean; FJetpack: Boolean; FActualModelName: string; FClientID: SmallInt; @@ -291,7 +296,7 @@ type procedure BFGHit(); function GetFlag(Flag: Byte): Boolean; procedure SetFlag(Flag: Byte); - function DropFlag(): Boolean; + function DropFlag(Silent: Boolean = True): Boolean; procedure AllRulez(Health: Boolean); procedure RestoreHealthArmor(); procedure FragCombo(); @@ -310,6 +315,7 @@ type procedure DrawPickup(); procedure DrawRulez(); procedure DrawAim(); + procedure DrawIndicator(); procedure DrawBubble(); procedure DrawGUI(); procedure Update(); virtual; @@ -323,6 +329,8 @@ type procedure SetLerp(XTo, YTo: Integer); procedure QueueWeaponSwitch(Weapon: Byte); procedure RealizeCurrentWeapon(); + procedure FlamerOn; + procedure FlamerOff; procedure JetpackOn; procedure JetpackOff; procedure CatchFire(Attacker: Word); @@ -542,6 +550,7 @@ var gFly: Boolean = False; gAimLine: Boolean = False; gChatBubble: Byte = 0; + gPlayerIndicator: Boolean = True; gNumBots: Word = 0; gLMSPID1: Word = 0; gLMSPID2: Word = 0; @@ -2096,6 +2105,9 @@ begin FSawSoundIdle := TPlayableSound.Create(); FSawSoundHit := TPlayableSound.Create(); FSawSoundSelect := TPlayableSound.Create(); + FFlameSoundOn := TPlayableSound.Create(); + FFlameSoundOff := TPlayableSound.Create(); + FFlameSoundWork := TPlayableSound.Create(); FJetSoundFly := TPlayableSound.Create(); FJetSoundOn := TPlayableSound.Create(); FJetSoundOff := TPlayableSound.Create(); @@ -2104,6 +2116,9 @@ begin FSawSoundIdle.SetByName('SOUND_WEAPON_IDLESAW'); FSawSoundHit.SetByName('SOUND_WEAPON_HITSAW'); FSawSoundSelect.SetByName('SOUND_WEAPON_SELECTSAW'); + FFlameSoundOn.SetByName('SOUND_WEAPON_FLAMEON'); + FFlameSoundOff.SetByName('SOUND_WEAPON_FLAMEOFF'); + FFlameSoundWork.SetByName('SOUND_WEAPON_FLAMEWORK'); FJetSoundFly.SetByName('SOUND_PLAYER_JETFLY'); FJetSoundOn.SetByName('SOUND_PLAYER_JETON'); FJetSoundOff.SetByName('SOUND_PLAYER_JETOFF'); @@ -2263,6 +2278,10 @@ begin FSawSound.Free(); FSawSoundIdle.Free(); FSawSoundHit.Free(); + FSawSoundSelect.Free(); + FFlameSoundOn.Free(); + FFlameSoundOff.Free(); + FFlameSoundWork.Free(); FJetSoundFly.Free(); FJetSoundOn.Free(); FJetSoundOff.Free(); @@ -2273,6 +2292,25 @@ begin inherited; end; +procedure TPlayer.DrawIndicator(); +var + indX, indY: Integer; + indW, indH: Word; + ID: DWORD; +begin + if FAlive then + begin + indX := FObj.X+FObj.Rect.X; + indY := FObj.Y; + if g_Texture_Get('TEXTURE_PLAYER_INDICATOR', ID) then + begin + e_GetTextureSize(ID, @indW, @indH); + e_Draw(ID, indX + indW div 2, indY - indH, 0, True, False); + end; + end; + //e_TextureFontPrint(indX, indY, FName, gStdFont); // Shows player name overhead +end; + procedure TPlayer.DrawBubble(); var bubX, bubY: Integer; @@ -2422,7 +2460,9 @@ begin end; if (gChatBubble > 0) and (FKeys[KEY_CHAT].Pressed) and not FGhost then - DrawBubble(); + if (FMegaRulez[MR_INVIS] <= gTime) or ((gPlayerDrawn <> nil) and ((Self = gPlayerDrawn) or + ((FTeam = gPlayerDrawn.Team) and (gGameSettings.GameMode <> GM_DM)))) then + DrawBubble(); // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR if gAimLine and alive and ((Self = gPlayer1) or (Self = gPlayer2)) then @@ -3021,11 +3061,17 @@ begin if FAmmo[A_FUEL] > 0 then begin g_Weapon_flame(wx, wy, xd, yd, FUID); + FlamerOn; FReloading[FCurrWeap] := WEAPON_RELOAD[FCurrWeap]; Dec(FAmmo[A_FUEL]); FFireAngle := FAngle; f := True; DidFire := True; + end + else + begin + FlamerOff; + if g_Game_IsNet and g_Game_IsServer then MH_SEND_PlayerStats(FUID); end; end; @@ -3069,6 +3115,35 @@ begin PANEL_WATER or PANEL_ACID1 or PANEL_ACID2, True); end; +procedure TPlayer.FlamerOn; +begin + FFlameSoundOff.Stop(); + FFlameSoundOff.SetPosition(0); + if FFlaming then + begin + if (not FFlameSoundOn.IsPlaying()) and (not FFlameSoundWork.IsPlaying()) then + FFlameSoundWork.PlayAt(FObj.X, FObj.Y); + end + else + begin + FFlameSoundOn.PlayAt(FObj.X, FObj.Y); + FFlaming := True; + end; +end; + +procedure TPlayer.FlamerOff; +begin + if FFlaming then + begin + FFlameSoundOn.Stop(); + FFlameSoundOn.SetPosition(0); + FFlameSoundWork.Stop(); + FFlameSoundWork.SetPosition(0); + FFlameSoundOff.PlayAt(FObj.X, FObj.Y); + FFlaming := False; + end; +end; + procedure TPlayer.JetpackOn; begin FJetSoundFly.Stop; @@ -3379,7 +3454,7 @@ begin end; // Âûáðîñ ôëàãà: - DropFlag(); + DropFlag(KillType = K_FALLKILL); end; g_Player_CreateCorpse(Self); @@ -3567,167 +3642,83 @@ function TPlayer.getNextWeaponIndex (): Byte; var i: Word; wantThisWeapon: array[0..64] of Boolean; - weaponOrder: array[0..16] of Integer; // value: index in `FWeapon` - wwc: Integer; - f, dir, cwi, rwidx, curlidx: Integer; - - function real2log (ridx: Integer): Integer; - var - f: Integer; - begin - if (ridx >= 0) then - begin - for f := 0 to High(weaponOrder) do if (weaponOrder[f] = ridx) then begin result := f; exit; end; - end; - result := -1; - end; - + wwc: Integer = 0; //HACK! + dir, cwi: Integer; begin result := 255; // default result: "no switch" - // had weapon cycling on previous frame? remove that flag if (FNextWeap and $2000) <> 0 then begin FNextWeap := FNextWeap and $1FFF; FNextWeapDelay := 0; end; - - for f := 0 to High(weaponOrder) do weaponOrder[f] := -1; - - // build weapon order (k8: i know, i know, learn how to do constants and such... gtfo, please!) - // two knuckles are for "normal" and "berserk" (see `if` below -- it removes the one that is not needed) - // priorities: - // bfg, launcher, plasma, flamethrower, ssg, minigun, sg, pistol, berserk, chainsaw, fist - weaponOrder[0] := WEAPON_SUPERPULEMET; - weaponOrder[1] := WEAPON_BFG; - weaponOrder[2] := WEAPON_ROCKETLAUNCHER; - weaponOrder[3] := WEAPON_PLASMA; - weaponOrder[4] := WEAPON_FLAMETHROWER; - weaponOrder[5] := WEAPON_SHOTGUN2; - weaponOrder[6] := WEAPON_CHAINGUN; - weaponOrder[7] := WEAPON_SHOTGUN1; - weaponOrder[8] := WEAPON_PISTOL; - weaponOrder[9] := WEAPON_KASTET+666; // berserk fist - weaponOrder[10] := WEAPON_SAW; - weaponOrder[11] := WEAPON_KASTET; // normal fist - - for f := 0 to High(weaponOrder) do - begin - if (weaponOrder[f] = WEAPON_KASTET) then - begin - // normal fist: remove if we have a berserk pack - if (R_BERSERK in FRulez) then weaponOrder[f] := -1; - end - else - if (weaponOrder[f] = WEAPON_KASTET+666) then - begin - // berserk fist: remove if we don't have a berserk pack - if (R_BERSERK in FRulez) then weaponOrder[f] := WEAPON_KASTET else weaponOrder[f] := -1; - end; - end; - - (* - WEAPON_KASTET = 0; - WEAPON_SAW = 1; - WEAPON_PISTOL = 2; - WEAPON_SHOTGUN1 = 3; - WEAPON_SHOTGUN2 = 4; - WEAPON_CHAINGUN = 5; - WEAPON_ROCKETLAUNCHER = 6; - WEAPON_PLASMA = 7; - WEAPON_BFG = 8; - WEAPON_SUPERPULEMET = 9; - WEAPON_FLAMETHROWER = 10; - *) - // cycling has priority if (FNextWeap and $C000) <> 0 then begin - if (FNextWeap and $8000) <> 0 then dir := 1 else dir := -1; // should be reversed if we want "priority-driven cycling" + if (FNextWeap and $8000) <> 0 then + dir := 1 + else + dir := -1; FNextWeap := FNextWeap or $2000; // we need this - if FNextWeapDelay > 0 then exit; // cooldown time - //cwi := real2log(FCurrWeap); - //if (cwi < 0) then cwi := 0; + if FNextWeapDelay > 0 then + exit; // cooldown time cwi := FCurrWeap; for i := 0 to High(FWeapon) do begin cwi := (cwi+length(FWeapon)+dir) mod length(FWeapon); - //rwidx := weaponOrder[cwi]; - rwidx := cwi; // sorry - if (rwidx < 0) then continue; - if FWeapon[rwidx] then - begin - //e_WriteLog(Format(' SWITCH: cur=%d; new=%d (dir=%d; log=%d)', [FCurrWeap, rwidx, dir, cwi]), TMsgType.Warning); - result := Byte(rwidx); - FNextWeapDelay := 10; + if FWeapon[cwi] then + begin + //e_WriteLog(Format(' SWITCH: cur=%d; new=%d', [FCurrWeap, cwi]), MSG_WARNING); + result := Byte(cwi); + FNextWeapDelay := WEAPON_DELAY; exit; end; end; resetWeaponQueue(); exit; end; - // no cycling - for i := 0 to High(wantThisWeapon) do wantThisWeapon[i] := false; - wwc := 0; + for i := 0 to High(wantThisWeapon) do + wantThisWeapon[i] := false; for i := 0 to High(FWeapon) do - begin if (FNextWeap and (1 shl i)) <> 0 then begin - cwi := real2log(i); - if (cwi >= 0) then wantThisWeapon[cwi] := true; + wantThisWeapon[i] := true; Inc(wwc); end; - end; - + // exclude currently selected weapon from the set + wantThisWeapon[FCurrWeap] := false; // slow down alterations a little - if (wwc > 1) then + if wwc > 1 then begin - // more than one weapon requested, assume "alteration", and check alteration delay + //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING); + // more than one weapon requested, assume "alteration" and check alteration delay if FNextWeapDelay > 0 then begin - //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), TMsgType.Warning); FNextWeap := 0; exit; end; // yeah end; - // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()` // but clear all counters if no weapon should be switched - if (wwc < 1) then + if wwc < 1 then begin resetWeaponQueue(); exit; end; - - // exclude currently selected weapon from the set - curlidx := real2log(FCurrWeap); - //e_WriteLog(Format('*** wwc=%d; currweap=%d; logweap=%d', [wwc, FCurrWeap, curlidx]), TMsgType.Warning); - //e_WriteLog(Format('FCurrWeap=%d; curlidx=%d', [FCurrWeap, curlidx]), TMsgType.Warning); - //if (curlidx >= 0) then wantThisWeapon[curlidx] := false; - //if (wwc = 2) then begin Dec(wwc); end; // easy case: switch between two weapons - - // find next weapon to switch onto - cwi := curlidx; - for i := 0 to High(FWeapon) do + //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING); + // try weapons in descending order + for i := High(FWeapon) downto 0 do begin - cwi := (cwi+length(FWeapon)+1) mod length(FWeapon); - if (cwi = curlidx) then continue; // skip current weapon - if not wantThisWeapon[cwi] then continue; - rwidx := weaponOrder[cwi]; - if (rwidx < 0) then continue; - //e_WriteLog(Format(' trying logical %d (real %d)', [cwi, rwidx]), TMsgType.Warning); - if FWeapon[rwidx] and ((wwc = 1) or hasAmmoForWeapon(rwidx)) then + if wantThisWeapon[i] and FWeapon[i] and ((wwc = 1) or hasAmmoForWeapon(i)) then begin - //e_WriteLog(' I FOUND HER!', TMsgType.Warning); // i found her! - result := Byte(rwidx); + result := Byte(i); resetWeaponQueue(); - FNextWeapDelay := 10; // anyway, 'cause why not + FNextWeapDelay := WEAPON_DELAY; // anyway, 'cause why not exit; end; end; - // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo resetWeaponQueue(); end; @@ -3767,7 +3758,7 @@ begin if nw > High(FWeapon) then begin // don't forget to reset queue here! - //e_WriteLog(Format(' RealizeCurrentWeapon: WUTAFUUUU?! (%d)', [nw]), TMsgType.Warning); + //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING); resetWeaponQueue(); exit; end; @@ -4581,6 +4572,7 @@ begin FDamageBuffer := 0; FJetpack := False; FCanJetpack := False; + FFlaming := False; FFireTime := 0; FFirePainTime := 0; FFireAttacker := 0; @@ -4982,7 +4974,15 @@ begin if FKeys[KEY_RIGHT].Pressed then Run(TDirection.D_RIGHT); //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon(); //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon(); - if FKeys[KEY_FIRE].Pressed and AnyServer then Fire(); + if FKeys[KEY_FIRE].Pressed and AnyServer then Fire() + else + begin + if AnyServer then + begin + FlamerOff; + if NetServer then MH_SEND_PlayerStats(FUID); + end; + end; if FKeys[KEY_OPEN].Pressed and AnyServer then Use(); if FKeys[KEY_JUMP].Pressed then Jump() else @@ -5550,6 +5550,7 @@ begin WEAPON_FLAMETHROWER: begin g_Weapon_flame(wx, wy, xd, yd, FUID, WID); + FlamerOn; FFireAngle := FAngle; f := True; end; @@ -5606,7 +5607,7 @@ end; function TPlayer.GetFlag(Flag: Byte): Boolean; var s, ts: String; - evtype: Byte; + evtype, a: Byte; begin Result := False; @@ -5634,6 +5635,16 @@ begin g_Map_ResetFlag(FFlag); g_Game_Message(Format(_lc[I_MESSAGE_FLAG_CAPTURE], [AnsiUpperCase(s)]), 144); + if ((Self = gPlayer1) or (Self = gPlayer2) + or ((gPlayer1 <> nil) and (gPlayer1.Team = FTeam)) + or ((gPlayer2 <> nil) and (gPlayer2.Team = FTeam))) then + a := 0 + else + a := 1; + + if not sound_cap_flag[a].IsPlaying() then + sound_cap_flag[a].Play(); + gTeamStat[FTeam].Goals := gTeamStat[FTeam].Goals + 1; Result := True; @@ -5665,6 +5676,16 @@ begin g_Map_ResetFlag(Flag); g_Game_Message(Format(_lc[I_MESSAGE_FLAG_RETURN], [AnsiUpperCase(s)]), 144); + if ((Self = gPlayer1) or (Self = gPlayer2) + or ((gPlayer1 <> nil) and (gPlayer1.Team = FTeam)) + or ((gPlayer2 <> nil) and (gPlayer2.Team = FTeam))) then + a := 0 + else + a := 1; + + if not sound_ret_flag[a].IsPlaying() then + sound_ret_flag[a].Play(); + Result := True; if g_Game_IsNet then begin @@ -5692,6 +5713,16 @@ begin gFlags[Flag].State := FLAG_STATE_CAPTURED; + if ((Self = gPlayer1) or (Self = gPlayer2) + or ((gPlayer1 <> nil) and (gPlayer1.Team = FTeam)) + or ((gPlayer2 <> nil) and (gPlayer2.Team = FTeam))) then + a := 0 + else + a := 1; + + if not sound_get_flag[a].IsPlaying() then + sound_get_flag[a].Play(); + Result := True; if g_Game_IsNet then begin @@ -5708,9 +5739,10 @@ begin FModel.SetFlag(FFlag); end; -function TPlayer.DropFlag(): Boolean; +function TPlayer.DropFlag(Silent: Boolean = True): Boolean; var s: String; + a: Byte; begin Result := False; if (not g_Game_IsServer) or (FFlag = FLAG_NONE) then @@ -5735,6 +5767,16 @@ begin g_Console_Add(Format(_lc[I_PLAYER_FLAG_DROP], [FName, s]), True); g_Game_Message(Format(_lc[I_MESSAGE_FLAG_DROP], [AnsiUpperCase(s)]), 144); + if ((Self = gPlayer1) or (Self = gPlayer2) + or ((gPlayer1 <> nil) and (gPlayer1.Team = FTeam)) + or ((gPlayer2 <> nil) and (gPlayer2.Team = FTeam))) then + a := 0 + else + a := 1; + + if (not Silent) and (not sound_lost_flag[a].IsPlaying()) then + sound_lost_flag[a].Play(); + if g_Game_IsNet then MH_SEND_FlagEvent(FLAG_STATE_DROPPED, Flag, FUID, False); end; @@ -6279,6 +6321,12 @@ begin FSawSoundIdle.Pause(Enable); FSawSoundHit.Pause(Enable); FSawSoundSelect.Pause(Enable); + FFlameSoundOn.Pause(Enable); + FFlameSoundOff.Pause(Enable); + FFlameSoundWork.Pause(Enable); + FJetSoundFly.Pause(Enable); + FJetSoundOn.Pause(Enable); + FJetSoundOff.Pause(Enable); end; { T C o r p s e : }