Rainbow search modernized.

This commit is contained in:
2024-04-27 20:06:04 -04:00
parent cc2d7db63b
commit db25fb4537
+18 -15
View File
@@ -24,6 +24,7 @@
#include "libs/mathlib.h" #include "libs/mathlib.h"
#include <iostream> #include <iostream>
#include <algorithm>
namespace namespace
{ {
@@ -37,6 +38,8 @@ namespace
bool generatePlanets( SolarSystem *solarSys ) override; bool generatePlanets( SolarSystem *solarSys ) override;
bool generateOrbital( SolarSystem *solarSys, bool generateOrbital( SolarSystem *solarSys,
PLANET_DESC *world ) override; PLANET_DESC *world ) override;
static int getRainbowIndex();
}; };
auto init= [] auto init= []
@@ -77,22 +80,11 @@ GenerateRainbowWorld::generateOrbital( SolarSystem *const solarSys, PLANET_DESC
{ {
if (matchWorld (solarSys, world, 0, MATCH_PLANET)) if (matchWorld (solarSys, world, 0, MATCH_PLANET))
{ {
BYTE which_rainbow; const int which_rainbow= getRainbowIndex();
UWORD rainbow_mask; UWORD rainbow_mask = MAKE_WORD (
STAR_DESC *SDPtr; GET_GAME_STATE (RAINBOW_WORLD0),
GET_GAME_STATE (RAINBOW_WORLD1));
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; std::cerr << "I think I'm at Rainbow world #" << (int) which_rainbow << std::endl;
rainbow_mask |= 1 << which_rainbow; rainbow_mask |= 1 << which_rainbow;
SET_GAME_STATE (RAINBOW_WORLD0, LOBYTE (rainbow_mask)); SET_GAME_STATE (RAINBOW_WORLD0, LOBYTE (rainbow_mask));
@@ -103,3 +95,14 @@ GenerateRainbowWorld::generateOrbital( SolarSystem *const solarSys, PLANET_DESC
return true; return true;
} }
int
GenerateRainbowWorld::getRainbowIndex()
{
return std::count_if( star_array, CurStarDescPtr,
[]( const auto &star )
{
return star.supplement and star.supplement == "Rainbow"s;
}
);
}