Skip to content

Commit

Permalink
feat(mechanics): Events can now be made to apply instantly with a del…
Browse files Browse the repository at this point in the history
…ay of 0 days (endless-sky#10054)

Not defining a delay is now the same as defining a delay of 1 day.
  • Loading branch information
RisingLeaf authored May 18, 2024
1 parent 6ebacb8 commit e96054d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion source/GameAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ void GameAction::LoadSingle(const DataNode &child)
}
else if(key == "event" && hasValue)
{
int minDays = (child.Size() >= 3 ? child.Value(2) : 0);
int minDays = (child.Size() >= 3 ? child.Value(2) : 1);
int maxDays = (child.Size() >= 4 ? child.Value(3) : minDays);
if(maxDays < minDays)
swap(minDays, maxDays);
Expand Down
5 changes: 1 addition & 4 deletions source/PlanetPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ PlanetPanel::PlanetPanel(PlayerInfo &player, function<void()> callback)
text.SetFont(FontSet::Get(14));
text.SetAlignment(Alignment::JUSTIFIED);
text.SetWrapWidth(480);
text.Wrap(planet.Description());

// Since the loading of landscape images is deferred, make sure that the
// landscapes for this system are loaded before showing the planet panel.
Expand Down Expand Up @@ -144,10 +143,8 @@ void PlanetPanel::Draw()
{
Rectangle box = ui.GetBox("content");
if(box.Width() != text.WrapWidth())
{
text.SetWrapWidth(box.Width());
text.Wrap(planet.Description());
}
text.Wrap(planet.Description());
text.Draw(box.TopLeft(), *GameData::Colors().Get("bright"));
}
}
Expand Down
15 changes: 13 additions & 2 deletions source/PlayerInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,8 +586,19 @@ void PlayerInfo::AddChanges(list<DataNode> &changes)
// Add an event that will happen at the given date.
void PlayerInfo::AddEvent(const GameEvent &event, const Date &date)
{
gameEvents.push_back(event);
gameEvents.back().SetDate(date);
// Check if the event should be applied directly.
if(date <= this->date)
{
GameEvent eventCopy = event;
list<DataNode> eventChanges = {eventCopy.Apply(*this)};
if(!eventChanges.empty())
AddChanges(eventChanges);
}
else
{
gameEvents.push_back(event);
gameEvents.back().SetDate(date);
}
}


Expand Down
2 changes: 1 addition & 1 deletion source/SpaceportPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ SpaceportPanel::SpaceportPanel(PlayerInfo &player)
text.SetFont(FontSet::Get(14));
text.SetAlignment(Alignment::JUSTIFIED);
text.SetWrapWidth(ui.GetBox("content").Width());
text.Wrap(port.Description());

// Query the news interface to find out the wrap width.
// TODO: Allow Interface to handle wrapped text directly.
Expand Down Expand Up @@ -93,6 +92,7 @@ void SpaceportPanel::Draw()
return;

Rectangle box = ui.GetBox("content");
text.Wrap(port.Description());
text.Draw(box.TopLeft(), *GameData::Colors().Get("bright"));

if(hasNews)
Expand Down

0 comments on commit e96054d

Please sign in to comment.