From 3704c1e18ca0890649078b372a8d750c61dffaef Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Sun, 3 Sep 2023 22:25:07 -0500 Subject: [PATCH] Final changes. Show timer as hh:mm:ss, fix tutorial bug using AI routine, fix bug enemy units attacking themselves. --- olcCodeJam2023Entry/Scenario.cpp | 2 ++ olcCodeJam2023Entry/Unit.cpp | 3 +++ olcCodeJam2023Entry/VirusAttack.cpp | 14 +++++++++++++- olcCodeJam2023Entry/VirusAttack.h | 1 + 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/olcCodeJam2023Entry/Scenario.cpp b/olcCodeJam2023Entry/Scenario.cpp index af3ef61..7c9bf7c 100644 --- a/olcCodeJam2023Entry/Scenario.cpp +++ b/olcCodeJam2023Entry/Scenario.cpp @@ -41,6 +41,8 @@ void Scenario::_Update(Resources&enemy_resources,std::vector>&collectionPoints,int availableMemory,std::vector>&queuedUnits,std::vector>&SOUNDS){ + if(!flags.guideEnabled||flags.limitedBuildOptions||flags.unitMetersGreyedOut)return; //We don't enable advanced AI during tutorials. + if(!setupEasyMode&&flags.difficulty==0){ enemy_resources={100,100,100,100,100}; } diff --git a/olcCodeJam2023Entry/Unit.cpp b/olcCodeJam2023Entry/Unit.cpp index ca2d6b9..44718f2 100644 --- a/olcCodeJam2023Entry/Unit.cpp +++ b/olcCodeJam2023Entry/Unit.cpp @@ -945,6 +945,9 @@ void Unit::_Attacked(std::weak_ptrattacker,std::vectorIsFriendly()!=IsFriendly()&&CanInteractWithEnemies()){ SetTargetUnit(attacker); } + if(!IsFriendly()&&!attacker.lock()->IsFriendly()&&!attacker.lock()->CanInteractWithAllies()){ + attacker.lock()->SetTargetLocation(attacker.lock()->GetPos()); //This effectively negates enemies targeting each other for attacking if they're not supposed to. Somehow this occurs sometimes. + } if(attacker.lock()->IsFriendly()!=IsFriendly()){ for(auto&u:otherUnits){ if(this!=u.get()&&!u->IsFriendly()&&u->GetCurrentTarget().expired()&&u->CanMove()&&!u->IsAllocator()){ diff --git a/olcCodeJam2023Entry/VirusAttack.cpp b/olcCodeJam2023Entry/VirusAttack.cpp index 16bcd13..be41ff5 100644 --- a/olcCodeJam2023Entry/VirusAttack.cpp +++ b/olcCodeJam2023Entry/VirusAttack.cpp @@ -1393,7 +1393,8 @@ bool VirusAttack::OnUserUpdate(float fElapsedTime){ #pragma region COMPLETED case GameState::COMPLETED:{ DrawPartialDecal({0,0},GetScreenSize(),IMAGES[MATRIX]->Decal(),randomBackgroundOffset+gametv.GetWorldOffset()*(vf2d{32,32}/vf2d(GetScreenSize()))*gametv.GetWorldScale(),{32,32},Pixel{currentLevel->levelColor.r,currentLevel->levelColor.g,currentLevel->levelColor.b,164}/2); - completedBox.Initialize("Thank you for playing Virus Attack!\n\nCompletion Time:"+std::to_string(gameSeconds)+" seconds\n\nHuge shoutout to the OLC community, javidx9 for the PGE, and all supporters!\n\n\nPress [Escape] to return to the main menu.",{0,0},"Congratulations!",nullptr,{float(ScreenWidth()-2),1.f}); + + completedBox.Initialize("Thank you for playing Virus Attack!\n\nCompletion Time:"+DisplayTime(gameSeconds)+" seconds\nDifficulty Completed:\n+"+(flags.difficulty==0?"Easy":flags.difficulty==1?"Normal":"Hard")+"+\n\nHuge shoutout to the OLC community, javidx9 for the PGE existing, and all supporters!\n\n\nPress [Escape] to return to the main menu.",{0,0},"Congratulations!",nullptr,{float(ScreenWidth()-2),1.f}); completedBox.UpdateAndDraw({0,0},this,player_resources,IMAGES,GetTotalUsedMemory(),currentLevel->availableMemory); if(GetKey(ESCAPE).bPressed){ state=GameState::MAIN_MENU; @@ -1408,6 +1409,17 @@ bool VirusAttack::OnUserUpdate(float fElapsedTime){ return true; } +std::string VirusAttack::DisplayTime(int gameSeconds){ + int totalMinutes=gameSeconds/60; + int totalHours=totalMinutes/60; + + std::string secondsDisplay=std::to_string(gameSeconds%60); + std::string minutesDisplay=std::to_string(totalMinutes%60); + std::string hoursDisplay=std::to_string(totalHours); + + return hoursDisplay+":"+((minutesDisplay.length()==1)?"0":"")+minutesDisplay+":"+((secondsDisplay.length()==1)?"0":"")+secondsDisplay; +} + void VirusAttack::DrawSystemMemoryBar(float fElapsedTime){ memoryChangeTimer=std::max(0.f,memoryChangeTimer-fElapsedTime); memoryDisplayDelay-=fElapsedTime; diff --git a/olcCodeJam2023Entry/VirusAttack.h b/olcCodeJam2023Entry/VirusAttack.h index 9fac479..e553639 100644 --- a/olcCodeJam2023Entry/VirusAttack.h +++ b/olcCodeJam2023Entry/VirusAttack.h @@ -155,6 +155,7 @@ public: void RestartLevel(); void HandleRestartButton(float fElapsedTime); void DrawCurvedTexture(vf2d offset,vf2d size,Decal*decal,vf2d texOffset,Pixel col=WHITE,float curveThickness=0.8); + std::string DisplayTime(int gameSeconds); public: VirusAttack();