Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow triggers to play a sound #10008

Merged
merged 25 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion source/GameAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ this program. If not, see <https://www.gnu.org/licenses/>.

#include "GameAction.h"

#include "Audio.h"
#include "DataNode.h"
#include "DataWriter.h"
#include "Dialog.h"
Expand All @@ -23,9 +24,11 @@ this program. If not, see <https://www.gnu.org/licenses/>.
#include "GameEvent.h"
#include "Messages.h"
#include "Outfit.h"
#include "Planet.h"
#include "PlayerInfo.h"
#include "Random.h"
#include "Ship.h"
#include "System.h"
#include "UI.h"

#include <cstdlib>
Expand Down Expand Up @@ -190,7 +193,11 @@ void GameAction::LoadSingle(const DataNode &child)
swap(minDays, maxDays);
events[GameData::Events().Get(child.Token(1))] = make_pair(minDays, maxDays);
}
else if(key == "fail" && child.Size() >= 2)
else if(key == "music" && hasValue)
music = child.Token(1);
else if(key == "mute")
music = "";
else if(key == "fail" && hasValue)
fail.insert(child.Token(1));
else if(key == "fail")
failCaller = true;
Expand Down Expand Up @@ -239,6 +246,13 @@ void GameAction::Save(DataWriter &out) const
out.Write("fail", name);
if(failCaller)
out.Write("fail");
if(music.has_value())
{
if(music->empty())
out.Write("mute");
else
out.Write("music", music.value());
}

conditions.Save(out);
}
Expand Down Expand Up @@ -364,6 +378,18 @@ void GameAction::Do(PlayerInfo &player, UI *ui, const Mission *caller) const
}
if(failCaller && caller)
player.FailMission(*caller);
if(music.has_value())
{
if(*music == "<ambient>")
{
if(player.GetPlanet())
Audio::PlayMusic(player.GetPlanet()->MusicName());
else
Audio::PlayMusic(player.GetSystem()->MusicName());
}
else
Audio::PlayMusic(music.value());
}

// Check if applying the conditions changes the player's reputations.
conditions.Apply(player.Conditions());
Expand All @@ -388,6 +414,8 @@ GameAction GameAction::Instantiate(map<string, string> &subs, int jumps, int pay
result.giftShips = giftShips;
result.giftOutfits = giftOutfits;

result.music = music;

result.payment = payment + (jumps + 1) * payload * paymentMultiplier;
if(result.payment)
subs["<payment>"] = Format::CreditString(abs(result.payment));
Expand Down
3 changes: 3 additions & 0 deletions source/GameAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ this program. If not, see <https://www.gnu.org/licenses/>.
#include <map>
#include <set>
#include <string>
#include <optional>
Amazinite marked this conversation as resolved.
Show resolved Hide resolved
#include <utility>
#include <vector>

Expand Down Expand Up @@ -87,6 +88,8 @@ class GameAction {
int64_t paymentMultiplier = 0;
int64_t fine = 0;

std::optional<std::string> music;

// When this action is performed, the missions with these names fail.
std::set<std::string> fail;
// When this action is performed, the mission that called this action is failed.
Expand Down
Loading