86 lines
1.8 KiB
C++
86 lines
1.8 KiB
C++
#ifndef GENERATOR_H
|
|
#define GENERATOR_H
|
|
|
|
#include <num/num.h>
|
|
#include "settings.h"
|
|
using namespace libnum;
|
|
|
|
//======= Generation utilities =======//
|
|
|
|
/* A utility structure holding data for path carver - a generator tool that
|
|
produces a random traversable path. */
|
|
struct path_carver
|
|
{
|
|
/* Start a path on the provided face. */
|
|
path_carver(int initial_face);
|
|
/* Advance by one platform of the specified length and generate the
|
|
associated platform data. A platform might not be generated if the path
|
|
decides to skip for a jump! Returns true if a platform was generated in
|
|
*p, false otherwise (in that case don't use *p). If force is set, always
|
|
generates a platform. */
|
|
bool next(num length, struct platform *p, bool force=false);
|
|
|
|
private:
|
|
/* Face where the next platform will be generated */
|
|
int m_face;
|
|
/* Current z position */
|
|
num m_z;
|
|
/* Whether last face was skipped */
|
|
bool m_last_skipped;
|
|
};
|
|
|
|
static inline int add_to_face(int face, int how_much)
|
|
{
|
|
int f = (face + how_much) % PLATFORM_COUNT;
|
|
return (f < 0) ? f + PLATFORM_COUNT : f;
|
|
}
|
|
|
|
static inline int next_face(int face)
|
|
{
|
|
return add_to_face(face, 1);
|
|
}
|
|
|
|
static inline int prev_face(int face)
|
|
{
|
|
return add_to_face(face, -1);
|
|
}
|
|
|
|
//======= Level generator API =======//
|
|
|
|
struct generator
|
|
{
|
|
/* Generate more stuff. */
|
|
virtual void generate(struct level *) = 0;
|
|
virtual ~generator() = default;
|
|
};
|
|
|
|
struct gen1 : public generator
|
|
{
|
|
gen1();
|
|
void generate(struct level *) override;
|
|
~gen1() override = default;
|
|
|
|
num m_last_z;
|
|
path_carver m_path_carvers[3];
|
|
};
|
|
|
|
struct gen2 : public generator
|
|
{
|
|
gen2();
|
|
void generate(struct level *) override;
|
|
~gen2() override = default;
|
|
|
|
path_carver m_path_carver;
|
|
};
|
|
|
|
struct gen3 : public generator
|
|
{
|
|
gen3();
|
|
void generate(struct level *) override;
|
|
~gen3() override = default;
|
|
|
|
path_carver m_path_carvers[3];
|
|
};
|
|
|
|
#endif /* GENERATOR_H */
|