HasProperty config parameter recursion is now a thing, allowing for subproperties to be checked via the . syntax.
This commit is contained in:
+22
-21
@@ -38,33 +38,34 @@ void Monster::STRATEGY::SLIMEKING(Monster&m,float fElapsedTime,int strategyNumbe
|
|||||||
};
|
};
|
||||||
|
|
||||||
const auto TransitionPhase=[&](int newPhase){
|
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){
|
switch(newPhase){
|
||||||
case 2:{
|
case 2:{
|
||||||
std::string spawnMonster=ConfigStringArr("Phase2.MonsterSpawnOnChange",0);
|
SpawnMonsterFromConfig(2);
|
||||||
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]);
|
|
||||||
}
|
|
||||||
}break;
|
}break;
|
||||||
case 3:{
|
case 3:{
|
||||||
std::string spawnMonster=ConfigStringArr("Phase3.MonsterSpawnOnChange",0);
|
SpawnMonsterFromConfig(3);
|
||||||
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]);
|
|
||||||
}
|
|
||||||
}break;
|
}break;
|
||||||
case 4:{
|
case 4:{
|
||||||
std::string spawnMonster=ConfigStringArr("Phase4.MonsterSpawnOnChange",0);
|
SpawnMonsterFromConfig(4);
|
||||||
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]);
|
|
||||||
}
|
|
||||||
}break;
|
}break;
|
||||||
case 5:{
|
case 5:{
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,7 @@
|
|||||||
#define VERSION_MAJOR 0
|
#define VERSION_MAJOR 0
|
||||||
#define VERSION_MINOR 2
|
#define VERSION_MINOR 2
|
||||||
#define VERSION_PATCH 0
|
#define VERSION_PATCH 0
|
||||||
#define VERSION_BUILD 1344
|
#define VERSION_BUILD 1349
|
||||||
|
|
||||||
#define stringify(a) stringify_(a)
|
#define stringify(a) stringify_(a)
|
||||||
#define stringify_(a) #a
|
#define stringify_(a) #a
|
||||||
|
|||||||
@@ -136,9 +136,20 @@ namespace olc::utils
|
|||||||
|
|
||||||
// Checks if a property exists - useful to avoid creating properties
|
// Checks if a property exists - useful to avoid creating properties
|
||||||
// via reading them, though non-essential
|
// 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"
|
// Access a datafile via a convenient name - "root.node.something.property"
|
||||||
|
|||||||
Reference in New Issue
Block a user