generator: generation utilities
This commit is contained in:
parent
68eecf7d26
commit
8182afc61c
|
@ -5,6 +5,8 @@
|
|||
#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
|
||||
|
@ -14,8 +16,9 @@ struct path_carver
|
|||
/* 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). */
|
||||
bool next(num length, struct platform *p);
|
||||
*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 */
|
||||
|
@ -26,8 +29,27 @@ private:
|
|||
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;
|
||||
};
|
||||
|
|
|
@ -8,9 +8,9 @@ path_carver::path_carver(int initial_face)
|
|||
m_z = num(0);
|
||||
}
|
||||
|
||||
bool path_carver::next(num length, struct platform *p)
|
||||
bool path_carver::next(num length, struct platform *p, bool force)
|
||||
{
|
||||
int skip = !m_last_skipped && (rand() % 4 == 0);
|
||||
int skip = !force && !m_last_skipped && (rand() % 4 == 0);
|
||||
|
||||
if(skip) {
|
||||
m_last_skipped = true;
|
||||
|
|
Loading…
Reference in New Issue