Rainbow search modernized.
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
#include "libs/mathlib.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
|
||||
namespace
|
||||
{
|
||||
@@ -37,6 +38,8 @@ namespace
|
||||
bool generatePlanets( SolarSystem *solarSys ) override;
|
||||
bool generateOrbital( SolarSystem *solarSys,
|
||||
PLANET_DESC *world ) override;
|
||||
|
||||
static int getRainbowIndex();
|
||||
};
|
||||
|
||||
auto init= []
|
||||
@@ -77,22 +80,11 @@ GenerateRainbowWorld::generateOrbital( SolarSystem *const solarSys, PLANET_DESC
|
||||
{
|
||||
if (matchWorld (solarSys, world, 0, MATCH_PLANET))
|
||||
{
|
||||
BYTE which_rainbow;
|
||||
UWORD rainbow_mask;
|
||||
STAR_DESC *SDPtr;
|
||||
|
||||
rainbow_mask = MAKE_WORD (
|
||||
const int which_rainbow= getRainbowIndex();
|
||||
UWORD rainbow_mask = MAKE_WORD (
|
||||
GET_GAME_STATE (RAINBOW_WORLD0),
|
||||
GET_GAME_STATE (RAINBOW_WORLD1));
|
||||
|
||||
which_rainbow = 0;
|
||||
SDPtr = &star_array[0];
|
||||
while (SDPtr != CurStarDescPtr)
|
||||
{
|
||||
if (SDPtr->supplement and SDPtr->supplement == "Rainbow"s)
|
||||
++which_rainbow;
|
||||
++SDPtr;
|
||||
}
|
||||
std::cerr << "I think I'm at Rainbow world #" << (int) which_rainbow << std::endl;
|
||||
rainbow_mask |= 1 << which_rainbow;
|
||||
SET_GAME_STATE (RAINBOW_WORLD0, LOBYTE (rainbow_mask));
|
||||
@@ -103,3 +95,14 @@ GenerateRainbowWorld::generateOrbital( SolarSystem *const solarSys, PLANET_DESC
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
GenerateRainbowWorld::getRainbowIndex()
|
||||
{
|
||||
return std::count_if( star_array, CurStarDescPtr,
|
||||
[]( const auto &star )
|
||||
{
|
||||
return star.supplement and star.supplement == "Rainbow"s;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user