From 064d717e2789a03484d6abb8dcd8bb93da32b192 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Tue, 19 Sep 2023 04:24:07 -0500 Subject: [PATCH] HasProperty config parameter recursion is now a thing, allowing for subproperties to be checked via the . syntax. --- Crawler/SlimeKing.cpp | 43 +++++++++++++++++++------------------- Crawler/Version.h | 2 +- Crawler/olcUTIL_DataFile.h | 15 +++++++++++-- 3 files changed, 36 insertions(+), 24 deletions(-) diff --git a/Crawler/SlimeKing.cpp b/Crawler/SlimeKing.cpp index d890d6d2..8c2fa56d 100644 --- a/Crawler/SlimeKing.cpp +++ b/Crawler/SlimeKing.cpp @@ -38,33 +38,34 @@ void Monster::STRATEGY::SLIMEKING(Monster&m,float fElapsedTime,int strategyNumbe }; const auto TransitionPhase=[&](int newPhase){ + const int MAX_ATTEMPTS=100; //Maximum number of tries to find a valid location. + Player*player=game->GetPlayer(); + const auto PositionInRangeOfPlayer=[&player](vf2d&pos,float radius){ + return geom2d::line(player->GetPos(),pos).length()<=player->GetSizeMult()*12*2+radius; + }; + const auto SpawnMonsterFromConfig=[&](int phase){ + std::string spawnMonster=ConfigStringArr("Phase"+std::to_string(phase)+".MonsterSpawnOnChange",0); + int spawnCount=ConfigIntArr("Phase"+std::to_string(phase)+".MonsterSpawnOnChange",1); + + for(int i=0;iGetSizeMult()*12);attempts++){ + randomAngle=util::random(2*PI); + spawnPos=m.pos+vf2d{cos(randomAngle),sin(randomAngle)}*m.GetSizeMult()*12; + } + game->SpawnMonster(spawnPos,MONSTER_NAME_DATA[spawnMonster]); + } + }; switch(newPhase){ case 2:{ - std::string spawnMonster=ConfigStringArr("Phase2.MonsterSpawnOnChange",0); - int spawnCount=ConfigIntArr("Phase2.MonsterSpawnOnChange",1); - - for(int i=0;iSpawnMonster(m.pos+vf2d{cos(randomAngle),sin(randomAngle)}*m.GetSizeMult()*12,MONSTER_NAME_DATA[spawnMonster]); - } + SpawnMonsterFromConfig(2); }break; case 3:{ - std::string spawnMonster=ConfigStringArr("Phase3.MonsterSpawnOnChange",0); - int spawnCount=ConfigIntArr("Phase3.MonsterSpawnOnChange",1); - - for(int i=0;iSpawnMonster(m.pos+vf2d{cos(randomAngle),sin(randomAngle)}*m.GetSizeMult()*12,MONSTER_NAME_DATA[spawnMonster]); - } + SpawnMonsterFromConfig(3); }break; case 4:{ - std::string spawnMonster=ConfigStringArr("Phase4.MonsterSpawnOnChange",0); - int spawnCount=ConfigIntArr("Phase4.MonsterSpawnOnChange",1); - - for(int i=0;iSpawnMonster(m.pos+vf2d{cos(randomAngle),sin(randomAngle)}*m.GetSizeMult()*12,MONSTER_NAME_DATA[spawnMonster]); - } + SpawnMonsterFromConfig(4); }break; case 5:{ diff --git a/Crawler/Version.h b/Crawler/Version.h index 3f553d61..246f9b9e 100644 --- a/Crawler/Version.h +++ b/Crawler/Version.h @@ -2,7 +2,7 @@ #define VERSION_MAJOR 0 #define VERSION_MINOR 2 #define VERSION_PATCH 0 -#define VERSION_BUILD 1344 +#define VERSION_BUILD 1349 #define stringify(a) stringify_(a) #define stringify_(a) #a diff --git a/Crawler/olcUTIL_DataFile.h b/Crawler/olcUTIL_DataFile.h index c0cad777..219ad087 100644 --- a/Crawler/olcUTIL_DataFile.h +++ b/Crawler/olcUTIL_DataFile.h @@ -136,9 +136,20 @@ namespace olc::utils // Checks if a property exists - useful to avoid creating properties // via reading them, though non-essential - inline bool HasProperty(const std::string& sName) const + inline bool HasProperty(const std::string& sName) { - return m_mapObjects.count(sName) > 0; + size_t x = sName.find_first_of('.'); + if (x != std::string::npos) + { + std::string sProperty = sName.substr(0, x); + if(HasProperty(sProperty)){ + return GetProperty(sName.substr(0, x)).HasProperty(sName.substr(x + 1, sName.size())); + }else{ + return false; + } + }else{ + return m_mapObjects.count(sName) > 0; + } } // Access a datafile via a convenient name - "root.node.something.property"