HasProperty config parameter recursion is now a thing, allowing for subproperties to be checked via the . syntax.
This commit is contained in:
parent
7745010099
commit
064d717e27
@ -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<float>(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;i<spawnCount;i++){
|
||||
float randomAngle=util::random(2*PI);
|
||||
vf2d spawnPos=m.pos+vf2d{cos(randomAngle),sin(randomAngle)}*m.GetSizeMult()*12;
|
||||
for(int attempts=0;attempts<MAX_ATTEMPTS&&PositionInRangeOfPlayer(spawnPos,MONSTER_NAME_DATA[spawnMonster]->GetSizeMult()*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;i<spawnCount;i++){
|
||||
float randomAngle=util::random(2*PI);
|
||||
game->SpawnMonster(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;i<spawnCount;i++){
|
||||
float randomAngle=util::random(2*PI);
|
||||
game->SpawnMonster(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;i<spawnCount;i++){
|
||||
float randomAngle=util::random(2*PI);
|
||||
game->SpawnMonster(m.pos+vf2d{cos(randomAngle),sin(randomAngle)}*m.GetSizeMult()*12,MONSTER_NAME_DATA[spawnMonster]);
|
||||
}
|
||||
SpawnMonsterFromConfig(4);
|
||||
}break;
|
||||
case 5:{
|
||||
|
||||
|
@ -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
|
||||
|
@ -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"
|
||||
|
Loading…
x
Reference in New Issue
Block a user