Implemented mission timer
parent
61e06149c6
commit
6d2fd18b41
|
@ -26,6 +26,8 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <sstream>
|
||||||
|
#include <iomanip>
|
||||||
|
|
||||||
|
|
||||||
// Returns a non-accented letter.
|
// Returns a non-accented letter.
|
||||||
|
@ -232,6 +234,17 @@ void TimeToAsciiClean(time_t time, char *buffer)
|
||||||
when.tm_hour, when.tm_min);
|
when.tm_hour, when.tm_min);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string TimeFormat(float time)
|
||||||
|
{
|
||||||
|
int minutes = floor(time/60);
|
||||||
|
double time2 = fmod(time, 60);
|
||||||
|
double seconds;
|
||||||
|
double fraction = modf(time2, &seconds)*100;
|
||||||
|
std::ostringstream sstream;
|
||||||
|
sstream << std::setfill('0') << std::setw(2) << minutes << ":" << std::setfill('0') << std::setw(2) << floor(seconds) << "." << std::setfill('0') << std::setw(2) << floor(fraction);
|
||||||
|
return sstream.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Adds an extension to file, if doesn't already one.
|
// Adds an extension to file, if doesn't already one.
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
|
|
||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
|
||||||
// TODO: rewrite/refactor or remove
|
// TODO: rewrite/refactor or remove
|
||||||
|
@ -32,6 +33,7 @@ extern char GetToLower(char letter);
|
||||||
|
|
||||||
extern void TimeToAscii(time_t time, char *buffer);
|
extern void TimeToAscii(time_t time, char *buffer);
|
||||||
extern void TimeToAsciiClean(time_t time, char *buffer);
|
extern void TimeToAsciiClean(time_t time, char *buffer);
|
||||||
|
extern std::string TimeFormat(float time);
|
||||||
|
|
||||||
extern void AddExt(char* filename, const char* ext);
|
extern void AddExt(char* filename, const char* ext);
|
||||||
|
|
||||||
|
|
|
@ -520,6 +520,11 @@ void CEngine::SetStatisticPos(Math::Vector pos)
|
||||||
m_statisticPos = pos;
|
m_statisticPos = pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CEngine::SetTimerDisplay(const std::string& text)
|
||||||
|
{
|
||||||
|
m_timerText = text;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************
|
/*******************************************************
|
||||||
|
@ -3510,6 +3515,7 @@ void CEngine::DrawInterface()
|
||||||
DrawMouse();
|
DrawMouse();
|
||||||
DrawHighlight();
|
DrawHighlight();
|
||||||
DrawStats();
|
DrawStats();
|
||||||
|
DrawTimer();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CEngine::UpdateGroundSpotTextures()
|
void CEngine::UpdateGroundSpotTextures()
|
||||||
|
@ -4479,6 +4485,14 @@ void CEngine::DrawStats()
|
||||||
m_text->DrawText(str.str(), FONT_COLOBOT, 12.0f, pos, 1.0f, TEXT_ALIGN_LEFT, 0, Color(1.0f, 1.0f, 1.0f, 1.0f));
|
m_text->DrawText(str.str(), FONT_COLOBOT, 12.0f, pos, 1.0f, TEXT_ALIGN_LEFT, 0, Color(1.0f, 1.0f, 1.0f, 1.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CEngine::DrawTimer()
|
||||||
|
{
|
||||||
|
SetState(ENG_RSTATE_TEXT);
|
||||||
|
|
||||||
|
Math::Point pos(0.98f, 0.98f-m_text->GetAscent(FONT_COLOBOT, 15.0f));
|
||||||
|
m_text->DrawText(m_timerText, FONT_COLOBOT, 15.0f, pos, 1.0f, TEXT_ALIGN_RIGHT, 0, Color(1.0f, 1.0f, 1.0f, 1.0f));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace Gfx
|
} // namespace Gfx
|
||||||
|
|
||||||
|
|
|
@ -780,6 +780,9 @@ public:
|
||||||
|
|
||||||
//! Sets the coordinates to display in stats window
|
//! Sets the coordinates to display in stats window
|
||||||
void SetStatisticPos(Math::Vector pos);
|
void SetStatisticPos(Math::Vector pos);
|
||||||
|
|
||||||
|
//! Sets text to display as mission timer
|
||||||
|
void SetTimerDisplay(const std::string& text);
|
||||||
|
|
||||||
|
|
||||||
/* *************** Object management *************** */
|
/* *************** Object management *************** */
|
||||||
|
@ -1236,6 +1239,8 @@ protected:
|
||||||
void DrawMouseSprite(Math::Point pos, Math::Point dim, int icon);
|
void DrawMouseSprite(Math::Point pos, Math::Point dim, int icon);
|
||||||
//! Draw statistic texts
|
//! Draw statistic texts
|
||||||
void DrawStats();
|
void DrawStats();
|
||||||
|
//! Draw mission timer
|
||||||
|
void DrawTimer();
|
||||||
|
|
||||||
//! Creates a new tier 2 object (texture)
|
//! Creates a new tier 2 object (texture)
|
||||||
EngineBaseObjTexTier& AddLevel2(EngineBaseObject& p1, const std::string& tex1Name, const std::string& tex2Name);
|
EngineBaseObjTexTier& AddLevel2(EngineBaseObject& p1, const std::string& tex1Name, const std::string& tex2Name);
|
||||||
|
@ -1442,6 +1447,8 @@ protected:
|
||||||
|
|
||||||
bool m_debugLights;
|
bool m_debugLights;
|
||||||
bool m_debugDumpLights;
|
bool m_debugDumpLights;
|
||||||
|
|
||||||
|
std::string m_timerText;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2546,6 +2546,8 @@ void CBrain::RunProgram(int rank)
|
||||||
BlinkScript(true); // blink
|
BlinkScript(true); // blink
|
||||||
m_object->CreateSelectParticle();
|
m_object->CreateSelectParticle();
|
||||||
m_main->UpdateShortcuts();
|
m_main->UpdateShortcuts();
|
||||||
|
if(m_object->GetTrainer())
|
||||||
|
m_main->StartMissionTimer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -645,6 +645,10 @@ CRobotMain::CRobotMain(CApplication* app, bool loadProfile)
|
||||||
m_time = 0.0f;
|
m_time = 0.0f;
|
||||||
m_gameTime = 0.0f;
|
m_gameTime = 0.0f;
|
||||||
m_checkEndTime = 0.0f;
|
m_checkEndTime = 0.0f;
|
||||||
|
|
||||||
|
m_missionTimerEnabled = false;
|
||||||
|
m_missionTimerStarted = false;
|
||||||
|
m_missionTimer = 0.0f;
|
||||||
|
|
||||||
m_phase = PHASE_NAME;
|
m_phase = PHASE_NAME;
|
||||||
m_cameraRank = -1;
|
m_cameraRank = -1;
|
||||||
|
@ -1087,6 +1091,9 @@ void CRobotMain::ResetKeyStates()
|
||||||
//! Changes phase
|
//! Changes phase
|
||||||
void CRobotMain::ChangePhase(Phase phase)
|
void CRobotMain::ChangePhase(Phase phase)
|
||||||
{
|
{
|
||||||
|
m_missionTimerEnabled = m_missionTimerStarted = false;
|
||||||
|
m_missionTimer = 0.0f;
|
||||||
|
|
||||||
if (m_phase == PHASE_SIMUL) // ends a simulation?
|
if (m_phase == PHASE_SIMUL) // ends a simulation?
|
||||||
{
|
{
|
||||||
SaveAllScript();
|
SaveAllScript();
|
||||||
|
@ -1417,10 +1424,7 @@ bool CRobotMain::ProcessEvent(Event &event)
|
||||||
if (m_displayInfo != nullptr) // current edition?
|
if (m_displayInfo != nullptr) // current edition?
|
||||||
m_displayInfo->EventProcess(event);
|
m_displayInfo->EventProcess(event);
|
||||||
|
|
||||||
if (m_phase == PHASE_SIMUL)
|
UpdateInfoText();
|
||||||
{
|
|
||||||
UpdateInfoText();
|
|
||||||
}
|
|
||||||
|
|
||||||
return EventFrame(event);
|
return EventFrame(event);
|
||||||
}
|
}
|
||||||
|
@ -1754,12 +1758,14 @@ bool CRobotMain::ProcessEvent(Event &event)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case EVENT_WIN:
|
case EVENT_WIN:
|
||||||
|
m_missionTimerEnabled = m_missionTimerStarted = false;
|
||||||
ChangePhase(PHASE_WIN);
|
ChangePhase(PHASE_WIN);
|
||||||
if(m_exitAfterMission)
|
if(m_exitAfterMission)
|
||||||
m_eventQueue->AddEvent(Event(EVENT_QUIT));
|
m_eventQueue->AddEvent(Event(EVENT_QUIT));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case EVENT_LOST:
|
case EVENT_LOST:
|
||||||
|
m_missionTimerEnabled = m_missionTimerStarted = false;
|
||||||
ChangePhase(PHASE_LOST);
|
ChangePhase(PHASE_LOST);
|
||||||
if(m_exitAfterMission)
|
if(m_exitAfterMission)
|
||||||
m_eventQueue->AddEvent(Event(EVENT_QUIT));
|
m_eventQueue->AddEvent(Event(EVENT_QUIT));
|
||||||
|
@ -3365,12 +3371,16 @@ void CRobotMain::AbortMovie()
|
||||||
//! Updates the text information
|
//! Updates the text information
|
||||||
void CRobotMain::UpdateInfoText()
|
void CRobotMain::UpdateInfoText()
|
||||||
{
|
{
|
||||||
CObject* obj = GetSelect();
|
if (m_phase == PHASE_SIMUL)
|
||||||
if (obj != nullptr)
|
|
||||||
{
|
{
|
||||||
Math::Vector pos = obj->GetPosition(0);
|
CObject* obj = GetSelect();
|
||||||
m_engine->SetStatisticPos(pos);
|
if (obj != nullptr)
|
||||||
|
{
|
||||||
|
Math::Vector pos = obj->GetPosition(0);
|
||||||
|
m_engine->SetStatisticPos(pos);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
m_engine->SetTimerDisplay(m_missionTimerEnabled && m_missionTimerStarted ? TimeFormat(m_missionTimer) : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -3394,6 +3404,9 @@ bool CRobotMain::EventFrame(const Event &event)
|
||||||
m_displayText->DisplayError(INFO_BEGINSATCOM, Math::Vector(0.0f,0.0f,0.0f));
|
m_displayText->DisplayError(INFO_BEGINSATCOM, Math::Vector(0.0f,0.0f,0.0f));
|
||||||
m_beginSatCom = true; // message appears
|
m_beginSatCom = true; // message appears
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!m_movieLock && m_pause->GetPause() == PAUSE_NONE && m_missionTimerStarted)
|
||||||
|
m_missionTimer += event.rTime;
|
||||||
|
|
||||||
m_water->EventProcess(event);
|
m_water->EventProcess(event);
|
||||||
m_cloud->EventProcess(event);
|
m_cloud->EventProcess(event);
|
||||||
|
@ -3760,6 +3773,11 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
|
||||||
m_missionResult = ERR_MISSION_NOTERM;
|
m_missionResult = ERR_MISSION_NOTERM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//NOTE: Reset timer always, even when only resetting object positions
|
||||||
|
m_missionTimerEnabled = false;
|
||||||
|
m_missionTimerStarted = false;
|
||||||
|
m_missionTimer = 0.0f;
|
||||||
|
|
||||||
CLevelParser* level = new CLevelParser(base, rank/100, rank%100);
|
CLevelParser* level = new CLevelParser(base, rank/100, rank%100);
|
||||||
level->Load();
|
level->Load();
|
||||||
|
|
||||||
|
@ -3853,6 +3871,15 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (line->GetCommand() == "MissionTimer")
|
||||||
|
{
|
||||||
|
m_missionTimerEnabled = line->GetParam("enabled")->AsBool();
|
||||||
|
if(!line->GetParam("program")->AsBool(false)) {
|
||||||
|
m_missionTimerStarted = true;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (line->GetCommand() == "CacheAudio" && !resetObject && m_version >= 2)
|
if (line->GetCommand() == "CacheAudio" && !resetObject && m_version >= 2)
|
||||||
{
|
{
|
||||||
m_sound->CacheMusic(std::string("../")+line->GetParam("filename")->AsPath("music"));
|
m_sound->CacheMusic(std::string("../")+line->GetParam("filename")->AsPath("music"));
|
||||||
|
@ -6342,12 +6369,14 @@ Error CRobotMain::CheckEndMission(bool frame)
|
||||||
if (m_missionResult == INFO_LOST) //mission lost?
|
if (m_missionResult == INFO_LOST) //mission lost?
|
||||||
{
|
{
|
||||||
m_displayText->DisplayError(INFO_LOST, Math::Vector(0.0f,0.0f,0.0f));
|
m_displayText->DisplayError(INFO_LOST, Math::Vector(0.0f,0.0f,0.0f));
|
||||||
|
m_missionTimerEnabled = m_missionTimerStarted = false;
|
||||||
m_winDelay = 0.0f;
|
m_winDelay = 0.0f;
|
||||||
if (m_lostDelay == 0) m_lostDelay = m_endTakeLostDelay;
|
if (m_lostDelay == 0) m_lostDelay = m_endTakeLostDelay;
|
||||||
m_displayText->SetEnable(false);
|
m_displayText->SetEnable(false);
|
||||||
}
|
}
|
||||||
if (m_missionResult == INFO_LOSTq) //mission lost?
|
if (m_missionResult == INFO_LOSTq) //mission lost?
|
||||||
{
|
{
|
||||||
|
m_missionTimerEnabled = m_missionTimerStarted = false;
|
||||||
m_winDelay = 0.0f;
|
m_winDelay = 0.0f;
|
||||||
if (m_lostDelay == 0) m_lostDelay = 0.1f;
|
if (m_lostDelay == 0) m_lostDelay = 0.1f;
|
||||||
m_displayText->SetEnable(false);
|
m_displayText->SetEnable(false);
|
||||||
|
@ -6355,6 +6384,11 @@ Error CRobotMain::CheckEndMission(bool frame)
|
||||||
if (frame && m_base) return ERR_MISSION_NOTERM;
|
if (frame && m_base) return ERR_MISSION_NOTERM;
|
||||||
if (m_missionResult == ERR_OK) { //mission win?
|
if (m_missionResult == ERR_OK) { //mission win?
|
||||||
m_displayText->DisplayError(INFO_WIN, Math::Vector(0.0f,0.0f,0.0f));
|
m_displayText->DisplayError(INFO_WIN, Math::Vector(0.0f,0.0f,0.0f));
|
||||||
|
if(m_missionTimerEnabled && m_missionTimerStarted) {
|
||||||
|
CLogger::GetInstancePointer()->Info("Mission time: %s\n", TimeFormat(m_missionTimer).c_str());
|
||||||
|
m_displayText->DisplayText(("Time: "+TimeFormat(m_missionTimer)).c_str(), Math::Vector(0.0f,0.0f,0.0f));
|
||||||
|
}
|
||||||
|
m_missionTimerEnabled = m_missionTimerStarted = false;
|
||||||
if (m_winDelay == 0) m_winDelay = m_endTakeWinDelay;
|
if (m_winDelay == 0) m_winDelay = m_endTakeWinDelay;
|
||||||
m_lostDelay = 0.0f;
|
m_lostDelay = 0.0f;
|
||||||
m_displayText->SetEnable(false);
|
m_displayText->SetEnable(false);
|
||||||
|
@ -6431,6 +6465,7 @@ Error CRobotMain::CheckEndMission(bool frame)
|
||||||
m_lostDelay = 0.1f; // lost immediately
|
m_lostDelay = 0.1f; // lost immediately
|
||||||
m_winDelay = 0.0f;
|
m_winDelay = 0.0f;
|
||||||
}
|
}
|
||||||
|
m_missionTimerEnabled = m_missionTimerStarted = false;
|
||||||
m_displayText->SetEnable(false);
|
m_displayText->SetEnable(false);
|
||||||
return INFO_LOSTq;
|
return INFO_LOSTq;
|
||||||
}
|
}
|
||||||
|
@ -6442,6 +6477,7 @@ Error CRobotMain::CheckEndMission(bool frame)
|
||||||
m_lostDelay = m_endTakeLostDelay; // lost in 6 seconds
|
m_lostDelay = m_endTakeLostDelay; // lost in 6 seconds
|
||||||
m_winDelay = 0.0f;
|
m_winDelay = 0.0f;
|
||||||
}
|
}
|
||||||
|
m_missionTimerEnabled = m_missionTimerStarted = false;
|
||||||
m_displayText->SetEnable(false);
|
m_displayText->SetEnable(false);
|
||||||
return INFO_LOST;
|
return INFO_LOST;
|
||||||
}
|
}
|
||||||
|
@ -6460,6 +6496,7 @@ Error CRobotMain::CheckEndMission(bool frame)
|
||||||
m_winDelay = m_endTakeWinDelay; // wins in x seconds
|
m_winDelay = m_endTakeWinDelay; // wins in x seconds
|
||||||
m_lostDelay = 0.0f;
|
m_lostDelay = 0.0f;
|
||||||
}
|
}
|
||||||
|
m_missionTimerEnabled = m_missionTimerStarted = false;
|
||||||
m_displayText->SetEnable(false);
|
m_displayText->SetEnable(false);
|
||||||
return ERR_OK; // mission ended
|
return ERR_OK; // mission ended
|
||||||
}
|
}
|
||||||
|
@ -6478,6 +6515,7 @@ Error CRobotMain::CheckEndMission(bool frame)
|
||||||
{
|
{
|
||||||
m_winDelay = 1.0f; // wins in one second
|
m_winDelay = 1.0f; // wins in one second
|
||||||
m_lostDelay = 0.0f;
|
m_lostDelay = 0.0f;
|
||||||
|
m_missionTimerEnabled = m_missionTimerStarted = false;
|
||||||
m_displayText->SetEnable(false);
|
m_displayText->SetEnable(false);
|
||||||
return ERR_OK; // mission ended
|
return ERR_OK; // mission ended
|
||||||
}
|
}
|
||||||
|
@ -6487,6 +6525,11 @@ Error CRobotMain::CheckEndMission(bool frame)
|
||||||
if (m_winDelay == 0.0f)
|
if (m_winDelay == 0.0f)
|
||||||
{
|
{
|
||||||
m_displayText->DisplayError(INFO_WIN, Math::Vector(0.0f,0.0f,0.0f));
|
m_displayText->DisplayError(INFO_WIN, Math::Vector(0.0f,0.0f,0.0f));
|
||||||
|
if(m_missionTimerEnabled && m_missionTimerStarted) {
|
||||||
|
CLogger::GetInstancePointer()->Info("Mission time: %s\n", TimeFormat(m_missionTimer).c_str());
|
||||||
|
m_displayText->DisplayText(("Time: "+TimeFormat(m_missionTimer)).c_str(), Math::Vector(0.0f,0.0f,0.0f));
|
||||||
|
}
|
||||||
|
m_missionTimerEnabled = m_missionTimerStarted = false;
|
||||||
m_winDelay = m_endTakeWinDelay; // wins in two seconds
|
m_winDelay = m_endTakeWinDelay; // wins in two seconds
|
||||||
m_lostDelay = 0.0f;
|
m_lostDelay = 0.0f;
|
||||||
}
|
}
|
||||||
|
@ -6960,3 +7003,11 @@ std::string& CRobotMain::GetUserLevelName(int id)
|
||||||
{
|
{
|
||||||
return m_dialog->GetUserLevelName(id);
|
return m_dialog->GetUserLevelName(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CRobotMain::StartMissionTimer()
|
||||||
|
{
|
||||||
|
if(m_missionTimerEnabled && !m_missionTimerStarted) {
|
||||||
|
CLogger::GetInstancePointer()->Info("Starting mission timer...\n");
|
||||||
|
m_missionTimerStarted = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -397,6 +397,8 @@ public:
|
||||||
void DisplayError(Error err, Math::Vector goal, float height=15.0f, float dist=60.0f, float time=10.0f);
|
void DisplayError(Error err, Math::Vector goal, float height=15.0f, float dist=60.0f, float time=10.0f);
|
||||||
|
|
||||||
std::string& GetUserLevelName(int id);
|
std::string& GetUserLevelName(int id);
|
||||||
|
|
||||||
|
void StartMissionTimer();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool EventFrame(const Event &event);
|
bool EventFrame(const Event &event);
|
||||||
|
@ -589,5 +591,9 @@ protected:
|
||||||
float m_colorShiftWater;
|
float m_colorShiftWater;
|
||||||
|
|
||||||
std::string m_oldLocale;
|
std::string m_oldLocale;
|
||||||
|
|
||||||
|
bool m_missionTimerEnabled;
|
||||||
|
bool m_missionTimerStarted;
|
||||||
|
float m_missionTimer;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue