diff options
author | Aki <please@ignore.pl> | 2024-04-01 05:16:14 +0200 |
---|---|---|
committer | Aki <please@ignore.pl> | 2024-04-01 05:21:16 +0200 |
commit | 3be3bfaa17773550a696ed2b756136debfe79ae2 (patch) | |
tree | db55a420e43ddaa4a72140d2795892757c1672d3 /StarsEx/Campaign.cpp | |
parent | 0a3451f251f360267e2927d8320787d59148eadd (diff) | |
download | starshatter-3be3bfaa17773550a696ed2b756136debfe79ae2.zip starshatter-3be3bfaa17773550a696ed2b756136debfe79ae2.tar.gz starshatter-3be3bfaa17773550a696ed2b756136debfe79ae2.tar.bz2 |
Fixed date and time consistency across Campaigns and Missions
This fixes campaign mission generation mostly, but a full playthrough
will be needed. Missions now serialize and accept stardate setting a
bit better. Thanks to this, date is propagated over multiplayer, too.
This seems to break points system?
Code-wise, this does not workaround the problems from before namely
over-reliance on side-effects. Stardate class is at least one small
step into good direction. Now, it'd be nice to attach clocks to
simulation and campaign and whatever else that needs them.
Diffstat (limited to 'StarsEx/Campaign.cpp')
-rw-r--r-- | StarsEx/Campaign.cpp | 114 |
1 files changed, 48 insertions, 66 deletions
diff --git a/StarsEx/Campaign.cpp b/StarsEx/Campaign.cpp index 70846f0..b139787 100644 --- a/StarsEx/Campaign.cpp +++ b/StarsEx/Campaign.cpp @@ -12,33 +12,34 @@ */ #include "Campaign.h" -#include "CampaignPlanStrategic.h" + +#include "Bitmap.h" #include "CampaignPlanAssignment.h" #include "CampaignPlanEvent.h" #include "CampaignPlanMission.h" #include "CampaignPlanMovement.h" -#include "CampaignSituationReport.h" +#include "CampaignPlanStrategic.h" #include "CampaignSaveGame.h" -#include "Combatant.h" +#include "CampaignSituationReport.h" +#include "Clock.h" #include "CombatAction.h" +#include "Combatant.h" #include "CombatEvent.h" #include "CombatGroup.h" #include "CombatRoster.h" #include "CombatUnit.h" #include "CombatZone.h" -#include "Galaxy.h" -#include "Mission.h" -#include "StarSystem.h" -#include "Starshatter.h" -#include "Player.h" - #include "ContentBundle.h" -#include "Bitmap.h" -#include "Clock.h" #include "DataLoader.h" +#include "FormatUtil.h" +#include "Galaxy.h" +#include "Mission.h" #include "ParseUtil.h" +#include "Player.h" #include "Random.h" -#include "FormatUtil.h" +#include "Stardate.h" +#include "Starshatter.h" +#include "StarSystem.h" const int TIME_NEVER = (int) 1e9; @@ -108,7 +109,7 @@ static Campaign* current_campaign = 0; Campaign::Campaign(int id, const char* n) : campaign_id(id), name(n), mission_id(-1), mission(0), net_mission(0), - scripted(false), sequential(false), time(0), startTime(0), loadTime(0), + scripted(false), sequential(false), time(0), load_time(0), player_group(0), player_unit(0), status(CAMPAIGN_INIT), lockout(0), loaded_from_savegame(false) { @@ -118,7 +119,7 @@ Campaign::Campaign(int id, const char* n) Campaign::Campaign(int id, const char* n, const char* p) : campaign_id(id), name(n), mission_id(-1), mission(0), net_mission(0), - scripted(false), sequential(false), time(0), startTime(0), loadTime(0), + scripted(false), sequential(false), time(0), load_time(0), player_group(0), player_unit(0), status(CAMPAIGN_INIT), lockout(0), loaded_from_savegame(false) { @@ -316,8 +317,6 @@ Campaign::Clear() player_group = 0; player_unit = 0; - - updateTime = time; } // +--------------------------------------------------------------------+ @@ -408,11 +407,10 @@ Campaign::Unload() { SetStatus(CAMPAIGN_INIT); + starshatter::engine::SetOperationStart(); + starshatter::engine::SetMissionStart(); Clock::GetInstance()->ResetGameTime(); - StarSystem::SetBaseTime(0); - startTime = Stardate(); - loadTime = startTime; lockout = 0; for (int i = 0; i < NUM_IMAGES; i++) @@ -1849,7 +1847,7 @@ Campaign::SetMissionId(int id) long double Campaign::Stardate() { - return StarSystem::Stardate(); + return starshatter::engine::OperationTime(); } // +--------------------------------------------------------------------+ @@ -1882,7 +1880,9 @@ Campaign::Prep() LoadCampaign(loader, true); } - StarSystem::SetBaseTime(loadTime); + starshatter::engine::SetOperationStart(); + starshatter::engine::SetMissionStart(); + Clock::GetInstance()->ResetGameTime(load_time); // load scripted missions: if (IsScripted() && actions.isEmpty()) { @@ -1917,7 +1917,7 @@ Campaign::ExecFrame() if (InCutscene()) return; - time = Stardate() - startTime; + time = Stardate(); if (status < CAMPAIGN_ACTIVE) return; @@ -1936,12 +1936,10 @@ Campaign::ExecFrame() ::Print("Campaign::ExecFrame() destroying mission list after completion...\n"); missions.destroy(); - if (!player_group || player_group->IsFighterGroup()) - time += 10 * 3600; - else - time += 20 * 3600; - - StarSystem::SetBaseTime(startTime + time - Clock::GetInstance()->GameTime()/1000.0); + const auto factor = (!player_group || player_group->IsFighterGroup()) ? 10.0 : 20.0; + Clock::GetInstance()->ResetGameTime(starshatter::engine::OperationTime() + 3600.0 * factor); + starshatter::engine::SetMissionStart(); + time = Stardate(); } else { m.reset(); @@ -2043,20 +2041,10 @@ Campaign::StartMission() ::Print("\n\nCampaign Start Mission - %d. '%s'\n", m->Identity(), m->Name()); if (!scripted) { - long double gtime = (long double) Clock::GetInstance()->GameTime() / 1000.0; - long double base = startTime + m->Start() - 15 - gtime; - - StarSystem::SetBaseTime(base); - - long double current_time = Stardate() - startTime; - - char buffer[32]; - FormatDayTime(buffer, current_time); - ::Print(" current time: %s\n", buffer); - - FormatDayTime(buffer, m->Start()); - ::Print(" mission start: %s\n", buffer); - ::Print("\n"); + const auto now = starshatter::engine::OperationTime().Format(); + const auto mission_start = starshatter::engine::Stardate{m->Start()}.Format(); + ::Print(" current time: %s\n", now.data()); + ::Print(" mission start: %s\n", mission_start.data()); } } } @@ -2070,14 +2058,10 @@ Campaign::RollbackMission() if (m) { if (!scripted) { - long double gtime = (long double) Clock::GetInstance()->GameTime() / 1000.0; - long double base = startTime + m->Start() - 60 - gtime; - - StarSystem::SetBaseTime(base); - - long double current_time = Stardate() - startTime; - ::Print(" mission start: %d\n", m->Start()); - ::Print(" current time: %d\n", (int) current_time); + const auto now = starshatter::engine::OperationTime().Format(); + const auto mission_start = starshatter::engine::Stardate{m->Start()}.Format(); + ::Print(" current time: %s\n", now.data()); + ::Print(" mission start: %s\n", mission_start.data()); } m->SetActive(false); @@ -2085,6 +2069,20 @@ Campaign::RollbackMission() } } + +long double +Campaign::LoadTime() const +{ + return load_time; +} + + +void +Campaign::SetLoadTime(long double value) +{ + load_time = value; +} + // +--------------------------------------------------------------------+ bool @@ -2229,22 +2227,6 @@ Campaign::FindStrikeTarget(int iff, CombatGroup* strike_group) // +--------------------------------------------------------------------+ -void -Campaign::CommitExpiredActions() -{ - ListIter<CombatAction> iter = actions; - while (++iter) { - CombatAction* a = iter.value(); - - if (a->IsAvailable()) - a->SetStatus(CombatAction::COMPLETE); - } - - updateTime = time; -} - -// +--------------------------------------------------------------------+ - int Campaign::GetPlayerTeamScore() { |