summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: fb8592a)
raw | patch | inline | side by side (parent: fb8592a)
author | Stas'M <x86corez@gmail.com> | |
Fri, 12 Jan 2018 21:31:09 +0000 (00:31 +0300) | ||
committer | Stas'M <x86corez@gmail.com> | |
Fri, 12 Jan 2018 21:31:09 +0000 (00:31 +0300) |
src/game/g_game.pas | patch | blob | history | |
src/game/g_netmsg.pas | patch | blob | history |
diff --git a/src/game/g_game.pas b/src/game/g_game.pas
index 8444232487b70404ff6b6575e96c4778e65fa51e..ebb1387e79153cebaeeb33d2382545a2d2c44ebe 100644 (file)
--- a/src/game/g_game.pas
+++ b/src/game/g_game.pas
DEStr: String;
end;
+ TChatSound = record
+ Sound: TPlayableSound;
+ Tags: Array of String;
+ FullWord: Boolean;
+ end;
+
TPlayerSettings = record
Name: String;
Model: String;
procedure g_Game_StopAllSounds(all: Boolean);
procedure g_Game_UpdateTriggerSounds();
function g_Game_GetMegaWADInfo(WAD: String): TMegaWADInfo;
+procedure g_Game_ChatSound(Text: String; Taunt: Boolean = True);
procedure g_Game_Announce_GoodShot(SpawnerUID: Word);
procedure g_Game_Announce_KillCombo(Param: Integer);
procedure g_Game_StartVote(Command, Initiator: string);
gVotesEnabled: Boolean = True;
gEvents: Array of TGameEvent;
gDelayedEvents: Array of TDelayedEvent;
+ gChatSounds: Array of TChatSound;
// move button values:
// bits 0-1: l/r state:
end;
end;
+procedure g_Game_LoadChatSounds(Resource: string);
+var
+ WAD: TWADFile;
+ FileName, Snd: string;
+ p: Pointer;
+ len, cnt, tags, i, j: Integer;
+ cfg: TConfig;
+begin
+ FileName := g_ExtractWadName(Resource);
+
+ WAD := TWADFile.Create();
+ WAD.ReadFile(FileName);
+
+ if not WAD.GetResource(g_ExtractFilePathName(Resource), p, len) then
+ begin
+ gChatSounds := nil;
+ WAD.Free();
+ Exit;
+ end;
+
+ cfg := TConfig.CreateMem(p, len);
+ cnt := cfg.ReadInt('ChatSounds', 'Count', 0);
+
+ SetLength(gChatSounds, cnt);
+ for i := 0 to Length(gChatSounds) - 1 do
+ begin
+ gChatSounds[i].Sound := nil;
+ Snd := Trim(cfg.ReadStr(IntToStr(i), 'Sound', ''));
+ tags := cfg.ReadInt(IntToStr(i), 'Tags', 0);
+ if (Snd = '') or (Tags <= 0) then
+ continue;
+ g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i), GameWAD+':'+Snd);
+ gChatSounds[i].Sound := TPlayableSound.Create();
+ gChatSounds[i].Sound.SetByName('SOUND_CHAT_MACRO' + IntToStr(i));
+ SetLength(gChatSounds[i].Tags, tags);
+ for j := 0 to tags - 1 do
+ gChatSounds[i].Tags[j] := LowerCase(cfg.ReadStr(IntToStr(i), 'Tag' + IntToStr(j), ''));
+ gChatSounds[i].FullWord := cfg.ReadBool(IntToStr(i), 'FullWord', False);
+ end;
+
+ cfg.Free();
+ WAD.Free();
+end;
+
+procedure g_Game_FreeChatSounds();
+var
+ i: Integer;
+begin
+ for i := 0 to Length(gChatSounds) - 1 do
+ begin
+ gChatSounds[i].Sound.Free();
+ g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i));
+ end;
+ SetLength(gChatSounds, 0);
+ gChatSounds := nil;
+end;
+
procedure g_Game_LoadData();
var
wl, hl: Integer;
killsnd[2].SetByName('SOUND_ANNOUNCER_KILL4X');
killsnd[3].SetByName('SOUND_ANNOUNCER_KILLMX');
+ g_Game_LoadChatSounds(GameWAD+':CHATSND\SNDCFG');
+
g_Game_SetLoadingText(_lc[I_LOAD_ITEMS_DATA], 0, False);
g_Items_LoadData();
g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
+ g_Game_FreeChatSounds();
+
DataLoaded := False;
end;
MessageTime := Time;
end;
+procedure g_Game_ChatSound(Text: String; Taunt: Boolean = True);
+var
+ i, j: Integer;
+ ok: Boolean;
+ fpText: String;
+
+ function FilterPunctuation(S: String): String;
+ begin
+ S := StringReplace(S, '.', ' ', [rfReplaceAll]);
+ S := StringReplace(S, ',', ' ', [rfReplaceAll]);
+ S := StringReplace(S, ':', ' ', [rfReplaceAll]);
+ S := StringReplace(S, ';', ' ', [rfReplaceAll]);
+ S := StringReplace(S, '!', ' ', [rfReplaceAll]);
+ S := StringReplace(S, '?', ' ', [rfReplaceAll]);
+ Result := S;
+ end;
+begin
+ g_Sound_PlayEx('SOUND_GAME_RADIO');
+
+ if Taunt and (gChatSounds <> nil) and (Pos(': ', Text) > 0) then
+ begin
+ // remove player name
+ Delete(Text, 1, Pos(': ', Text) + 2 - 1);
+ // for FullWord check
+ Text := LowerCase(' ' + Text + ' ');
+ fpText := FilterPunctuation(Text);
+
+ for i := 0 to Length(gChatSounds) - 1 do
+ begin
+ ok := True;
+ for j := 0 to Length(gChatSounds[i].Tags) - 1 do
+ begin
+ if gChatSounds[i].FullWord and
+ (gChatSounds[i].Tags[j] <> '.') and (gChatSounds[i].Tags[j] <> ',') and
+ (gChatSounds[i].Tags[j] <> ':') and (gChatSounds[i].Tags[j] <> ';') and
+ (gChatSounds[i].Tags[j] <> '!') and (gChatSounds[i].Tags[j] <> '?') then
+ ok := Pos(' ' + gChatSounds[i].Tags[j] + ' ', fpText) > 0
+ else
+ ok := Pos(gChatSounds[i].Tags[j], Text) > 0;
+ if not ok then
+ break;
+ end;
+ if ok then
+ begin
+ gChatSounds[i].Sound.Play();
+ break;
+ end;
+ end;
+ end;
+end;
+
procedure g_Game_Announce_GoodShot(SpawnerUID: Word);
var
a: Integer;
diff --git a/src/game/g_netmsg.pas b/src/game/g_netmsg.pas
index abe7278a5a42267f06c0df26db3658604193af66..29e9223af93c0994aa62eab83b0b70c4a03893a7 100644 (file)
--- a/src/game/g_netmsg.pas
+++ b/src/game/g_netmsg.pas
begin
g_Console_Add(Txt, True);
e_WriteLog('[Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
- g_Sound_PlayEx('SOUND_GAME_RADIO');
+ g_Game_ChatSound(b_Text_Unformat(Txt));
end
else
if Mode = NET_CHAT_TEAM then
begin
g_Console_Add(#18'[Team] '#2 + Txt, True);
e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
- g_Sound_PlayEx('SOUND_GAME_RADIO');
+ g_Game_ChatSound(b_Text_Unformat(Txt));
end
else if (gPlayer1.Team = TEAM_BLUE) and (Team = TEAM_BLUE) then
begin
g_Console_Add(#20'[Team] '#2 + Txt, True);
e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
- g_Sound_PlayEx('SOUND_GAME_RADIO');
+ g_Game_ChatSound(b_Text_Unformat(Txt));
end;
end;
end
Name := g_Net_ClientName_ByID(ID);
g_Console_Add('-> ' + Name + ': ' + Txt, True);
e_WriteLog('[Tell ' + Name + '] ' + b_Text_Unformat(Txt), TMsgType.Notify);
- g_Sound_PlayEx('SOUND_GAME_RADIO');
+ g_Game_ChatSound(b_Text_Unformat(Txt), False);
end;
end;
begin
g_Console_Add(Txt, True);
e_WriteLog('[Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
- g_Sound_PlayEx('SOUND_GAME_RADIO');
+ g_Game_ChatSound(b_Text_Unformat(Txt));
end else
if (Mode = NET_CHAT_TEAM) and (gPlayer1 <> nil) then
begin
if gPlayer1.Team = TEAM_BLUE then
g_Console_Add(b_Text_Format('\b[Team] ') + Txt, True);
e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
- g_Sound_PlayEx('SOUND_GAME_RADIO');
+ g_Game_ChatSound(b_Text_Unformat(Txt));
end;
end else
g_Console_Add(Txt, True);