From a9e0874abcfd9f070c6f1288eff0c031d7a31010 Mon Sep 17 00:00:00 2001 From: melex750 Date: Tue, 24 Oct 2017 04:46:07 -0400 Subject: [PATCH 1/3] Fix 'this' for object:: functions Fixes #672 Fixes #1026 --- src/CBot/CBotInstr/CBotExprVar.cpp | 4 ++++ src/CBot/CBotInstr/CBotFunction.cpp | 10 ++++++---- src/CBot/CBotInstr/CBotLeftExpr.cpp | 2 ++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/CBot/CBotInstr/CBotExprVar.cpp b/src/CBot/CBotInstr/CBotExprVar.cpp index ed77d8ac..ed20c6fd 100644 --- a/src/CBot/CBotInstr/CBotExprVar.cpp +++ b/src/CBot/CBotInstr/CBotExprVar.cpp @@ -76,6 +76,8 @@ CBotInstr* CBotExprVar::Compile(CBotToken*& p, CBotCStack* pStack, bool bCheckRe // This is an element of the current class // ads the equivalent of this. before CBotToken token("this"); + // invisible 'this.' highlights member token on error + token.SetPos(p->GetStart(), p->GetEnd()); inst->SetToken(&token); (static_cast(inst))->m_nIdent = -2; // identificator for this @@ -196,6 +198,8 @@ CBotInstr* CBotExprVar::CompileMethode(CBotToken* &p, CBotCStack* pStack) // this is an element of the current class // adds the equivalent of this. before + // invisible 'this.' highlights member token on error + pthis.SetPos(pp->GetStart(), pp->GetEnd()); inst->SetToken(&pthis); (static_cast(inst))->m_nIdent = -2; // ident for this diff --git a/src/CBot/CBotInstr/CBotFunction.cpp b/src/CBot/CBotInstr/CBotFunction.cpp index c24f9861..13b9005b 100644 --- a/src/CBot/CBotInstr/CBotFunction.cpp +++ b/src/CBot/CBotInstr/CBotFunction.cpp @@ -464,6 +464,7 @@ void CBotFunction::RestoreState(CBotVar** ppVars, CBotStack* &pj, CBotVar* pInst { CBotVar* pThis = pile->FindVar("this"); pThis->SetInit(CBotVar::InitType::IS_POINTER); + pThis->SetPointer(pInstance); pThis->SetUniqNum(-2); } @@ -672,6 +673,7 @@ int CBotFunction::DoCall(CBotProgram* program, const std::list& l { CBotTypResult type; CBotFunction* pt = nullptr; + CBotProgram* baseProg = pStack->GetProgram(true); pt = FindLocalOrPublic(localFunctionList, nIdent, name, ppVars, type); @@ -695,7 +697,7 @@ int CBotFunction::DoCall(CBotProgram* program, const std::list& l if (pStk3b->GetState() == 0 && !pt->m_MasterClass.empty()) { - CBotVar* pInstance = program->m_thisVar; + CBotVar* pInstance = (baseProg != nullptr) ? baseProg->m_thisVar : nullptr; // make "this" known CBotVar* pThis ; if ( pInstance == nullptr ) @@ -762,8 +764,7 @@ void CBotFunction::RestoreCall(const std::list& localFunctionList CBotFunction* pt = nullptr; CBotStack* pStk1; CBotStack* pStk3; - - // search function to return the ok identifier + CBotProgram* baseProg = pStack->GetProgram(true); pt = FindLocalOrPublic(localFunctionList, nIdent, name, ppVars, type); @@ -792,10 +793,11 @@ void CBotFunction::RestoreCall(const std::list& localFunctionList { if ( !pt->m_MasterClass.empty() ) { -// CBotVar* pInstance = m_pProg->m_thisVar; + CBotVar* pInstance = (baseProg != nullptr) ? baseProg->m_thisVar : nullptr; // make "this" known CBotVar* pThis = pStk1->FindVar("this"); pThis->SetInit(CBotVar::InitType::IS_POINTER); + pThis->SetPointer(pInstance); pThis->SetUniqNum(-2); } } diff --git a/src/CBot/CBotInstr/CBotLeftExpr.cpp b/src/CBot/CBotInstr/CBotLeftExpr.cpp index 4c4400a9..3c701eb8 100644 --- a/src/CBot/CBotInstr/CBotLeftExpr.cpp +++ b/src/CBot/CBotInstr/CBotLeftExpr.cpp @@ -72,6 +72,8 @@ CBotLeftExpr* CBotLeftExpr::Compile(CBotToken* &p, CBotCStack* pStack) // this is an element of the current class // adds the equivalent of this. before CBotToken pthis("this"); + // invisible 'this.' highlights member token on error + pthis.SetPos(p->GetStart(), p->GetEnd()); inst->SetToken(&pthis); inst->m_nIdent = -2; // indent for this From 1eee06d9f952ad679931e616332bfd35a837fa4a Mon Sep 17 00:00:00 2001 From: melex750 Date: Tue, 24 Oct 2017 04:55:22 -0400 Subject: [PATCH 2/3] Keep mission history after loading a crashsave Fixes #812 --- src/level/player_profile.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/level/player_profile.cpp b/src/level/player_profile.cpp index bedd76cd..21bb3b25 100644 --- a/src/level/player_profile.cpp +++ b/src/level/player_profile.cpp @@ -518,6 +518,8 @@ void CPlayerProfile::LoadScene(std::string dir) CLevelParserLine* line = levelParser.Get("Mission"); cat = GetLevelCategoryFromDir(line->GetParam("base")->AsString()); + if (dir == "../../crashsave") LoadFinishedLevels(cat); + rank = line->GetParam("rank")->AsInt(); if (cat == LevelCategory::CustomLevels) { From d357de14385fdf249e9c358fba35c2efaa9ff77e Mon Sep 17 00:00:00 2001 From: melex750 Date: Tue, 24 Oct 2017 05:12:19 -0400 Subject: [PATCH 3/3] Save object lifetime and abstime Fixes #1006 --- src/level/robotmain.cpp | 6 +++++- src/object/old_object.cpp | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/level/robotmain.cpp b/src/level/robotmain.cpp index a92b10b2..d55cd174 100644 --- a/src/level/robotmain.cpp +++ b/src/level/robotmain.cpp @@ -3689,7 +3689,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) // TODO: m_engine->TimeInit(); ?? m_input->ResetKeyStates(); m_time = 0.0f; - m_gameTime = 0.0f; + if (m_sceneReadPath.empty()) m_gameTime = 0.0f; m_gameTimeAbsolute = 0.0f; m_autosaveLast = 0.0f; m_infoUsed = 0; @@ -4542,6 +4542,7 @@ bool CRobotMain::IOWriteScene(std::string filename, std::string filecbot, std::s else line->AddParam("chap", MakeUnique(m_levelChap)); line->AddParam("rank", MakeUnique(m_levelRank)); + line->AddParam("gametime", MakeUnique(GetGameTime())); levelParser.AddLine(std::move(line)); line = MakeUnique("Map"); @@ -4722,6 +4723,9 @@ CObject* CRobotMain::IOReadScene(std::string filename, std::string filecbot) int objCounter = 0; for (auto& line : levelParser.GetLines()) { + if (line->GetCommand() == "Mission") + m_gameTime = line->GetParam("gametime")->AsFloat(0.0f); + if (line->GetCommand() == "Map") m_map->ZoomMap(line->GetParam("zoom")->AsFloat()); diff --git a/src/object/old_object.cpp b/src/object/old_object.cpp index dbe92b32..247b5a17 100644 --- a/src/object/old_object.cpp +++ b/src/object/old_object.cpp @@ -1010,6 +1010,8 @@ void COldObject::Write(CLevelParserLine* line) if ( m_virusTime != 0.0f ) line->AddParam("virusTime", MakeUnique(m_virusTime)); + line->AddParam("lifetime", MakeUnique(m_aTime)); + // Sets the parameters of the command line. CLevelParserParamVec cmdline; for(float value : GetCmdLine()) @@ -1144,6 +1146,8 @@ void COldObject::Read(CLevelParserLine* line) m_bVirusMode = line->GetParam("virusMode")->AsBool(false); m_virusTime = line->GetParam("virusTime")->AsFloat(0.0f); + m_aTime = line->GetParam("lifetime")->AsFloat(0.0f); + if ( m_motion != nullptr ) { m_motion->Read(line);