2020-09-14 00:00:00 +00:00
|
|
|
#include "./template.h"
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include "util/chaos/xorshift.h"
|
|
|
|
#include "util/math/algorithm.h"
|
|
|
|
#include "util/math/vector.h"
|
|
|
|
|
2020-10-09 00:00:00 +00:00
|
|
|
#include "core/lochara/base.h"
|
|
|
|
#include "core/lochara/big_warder.h"
|
|
|
|
#include "core/lochara/cavia.h"
|
|
|
|
#include "core/lochara/encephalon.h"
|
|
|
|
#include "core/lochara/theists_child.h"
|
|
|
|
#include "core/lochara/warder.h"
|
2020-09-14 00:00:00 +00:00
|
|
|
#include "core/locommon/position.h"
|
|
|
|
#include "core/loentity/entity.h"
|
2020-10-09 00:00:00 +00:00
|
|
|
#include "core/loentity/ground.h"
|
2020-09-14 00:00:00 +00:00
|
|
|
#include "core/loground/base.h"
|
|
|
|
#include "core/loground/island.h"
|
|
|
|
|
|
|
|
#include "./chunk.h"
|
|
|
|
#include "./poolset.h"
|
|
|
|
|
2020-10-09 00:00:00 +00:00
|
|
|
static loentity_ground_t* loworld_template_add_ground_island_(
|
2020-09-14 00:00:00 +00:00
|
|
|
const loworld_template_building_param_t* param,
|
|
|
|
const vec2_t* pos,
|
|
|
|
const vec2_t* sz) {
|
|
|
|
assert(loworld_template_building_param_valid(param));
|
|
|
|
assert(vec2_valid(pos));
|
|
|
|
assert(vec2_valid(sz));
|
|
|
|
assert(sz->x >= 0 && sz->y >= 0);
|
|
|
|
|
|
|
|
const locommon_position_t p = locommon_position(
|
|
|
|
param->target->pos.x, param->target->pos.y, *pos);
|
|
|
|
|
|
|
|
loground_base_t* island = loground_pool_create(param->pools->ground);
|
|
|
|
loground_island_build(island, &p, sz);
|
|
|
|
loworld_chunk_add_entity(param->target, &island->super.super);
|
2020-10-09 00:00:00 +00:00
|
|
|
return &island->super;
|
2020-09-14 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2020-10-09 00:00:00 +00:00
|
|
|
static void loworld_template_add_random_enemy_(
|
2020-09-14 00:00:00 +00:00
|
|
|
const loworld_template_building_param_t* param,
|
|
|
|
uint64_t seed,
|
2020-10-09 00:00:00 +00:00
|
|
|
const loentity_ground_t* gnd,
|
2020-09-14 00:00:00 +00:00
|
|
|
float pos) {
|
2020-10-09 00:00:00 +00:00
|
|
|
assert(loworld_template_building_param_valid(param));
|
|
|
|
assert(gnd != NULL);
|
|
|
|
assert(MATH_FLOAT_VALID(pos));
|
|
|
|
|
|
|
|
static void (*const builders[])(
|
|
|
|
lochara_base_t*, const loentity_ground_t*, float) = {
|
|
|
|
lochara_cavia_build,
|
|
|
|
lochara_warder_build,
|
|
|
|
};
|
|
|
|
|
|
|
|
lochara_base_t* base = lochara_pool_create(param->pools->chara);
|
|
|
|
|
|
|
|
const size_t i = chaos_xorshift(seed)%(sizeof(builders)/sizeof(builders[0]));
|
|
|
|
builders[i](base, gnd, pos);
|
|
|
|
|
2020-09-14 00:00:00 +00:00
|
|
|
loworld_chunk_add_entity(param->target, &base->super.super);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool loworld_template_building_param_valid(
|
|
|
|
const loworld_template_building_param_t* param) {
|
|
|
|
return
|
|
|
|
param != NULL &&
|
|
|
|
param->target != NULL &&
|
|
|
|
param->pools != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void loworld_template_metaphysical_gate_build_chunk(
|
|
|
|
const loworld_template_building_param_t* param) {
|
|
|
|
assert(loworld_template_building_param_valid(param));
|
|
|
|
|
2020-10-09 00:00:00 +00:00
|
|
|
loworld_template_add_ground_island_(param, &vec2(.5f, .2f), &vec2(.5f, .1f));
|
2020-09-14 00:00:00 +00:00
|
|
|
|
2020-10-09 00:00:00 +00:00
|
|
|
const loentity_ground_t* platform = loworld_template_add_ground_island_(
|
2020-09-14 00:00:00 +00:00
|
|
|
param, &vec2(.5f, .45f), &vec2(.2f, .02f));
|
|
|
|
|
2020-10-09 00:00:00 +00:00
|
|
|
lochara_base_t* encephalon = lochara_pool_create(param->pools->chara);
|
|
|
|
lochara_encephalon_build(encephalon, platform);
|
2020-09-14 00:00:00 +00:00
|
|
|
loworld_chunk_add_entity(param->target, &encephalon->super.super);
|
|
|
|
}
|
|
|
|
|
|
|
|
void loworld_template_open_space_build_chunk(
|
|
|
|
const loworld_template_building_param_t* param) {
|
|
|
|
assert(loworld_template_building_param_valid(param));
|
|
|
|
|
|
|
|
uint64_t s = param->seed;
|
|
|
|
|
|
|
|
const size_t enemy_count = (s = chaos_xorshift(s))%3+1;
|
|
|
|
|
2020-10-09 00:00:00 +00:00
|
|
|
const loentity_ground_t* gnd = loworld_template_add_ground_island_(
|
2020-09-14 00:00:00 +00:00
|
|
|
param, &vec2(.5f, .2f), &vec2(.47f, .01f));
|
|
|
|
|
|
|
|
for (size_t i = 0; i < enemy_count; ++i) {
|
2020-10-09 00:00:00 +00:00
|
|
|
loworld_template_add_random_enemy_(
|
|
|
|
param, s = chaos_xorshift(s), gnd, .1f+.8f/enemy_count*i);
|
2020-09-14 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void loworld_template_broken_open_space_build_chunk(
|
|
|
|
const loworld_template_building_param_t* param) {
|
|
|
|
assert(loworld_template_building_param_valid(param));
|
|
|
|
|
|
|
|
uint64_t s = param->seed;
|
|
|
|
|
2020-10-09 00:00:00 +00:00
|
|
|
const loentity_ground_t* floor1 = loworld_template_add_ground_island_(
|
2020-09-14 00:00:00 +00:00
|
|
|
param, &vec2(.2f, .2f), &vec2(.18f, .01f));
|
|
|
|
if ((s = chaos_xorshift(s))%2) {
|
2020-10-09 00:00:00 +00:00
|
|
|
loworld_template_add_random_enemy_(
|
|
|
|
param, s = chaos_xorshift(s), floor1, .5f);
|
2020-09-14 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2020-10-09 00:00:00 +00:00
|
|
|
const loentity_ground_t* floor2 = loworld_template_add_ground_island_(
|
2020-09-14 00:00:00 +00:00
|
|
|
param, &vec2(.8f, .2f), &vec2(.18f, .01f));
|
|
|
|
if ((s = chaos_xorshift(s))%2) {
|
2020-10-09 00:00:00 +00:00
|
|
|
loworld_template_add_random_enemy_(
|
|
|
|
param, s = chaos_xorshift(s), floor2, .5f);
|
2020-09-14 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
loworld_template_add_ground_island_(
|
|
|
|
param, &vec2(.5f, .05f), &vec2(.15f, .01f));
|
|
|
|
}
|
|
|
|
|
|
|
|
void loworld_template_passage_build_chunk(
|
|
|
|
const loworld_template_building_param_t* param) {
|
|
|
|
assert(loworld_template_building_param_valid(param));
|
|
|
|
|
|
|
|
uint64_t s = param->seed;
|
|
|
|
|
2020-10-09 00:00:00 +00:00
|
|
|
const loentity_ground_t* floor = loworld_template_add_ground_island_(
|
2020-09-14 00:00:00 +00:00
|
|
|
param, &vec2(.5f, .25f), &vec2(.5f, .01f));
|
|
|
|
if ((s = chaos_xorshift(s))%2) {
|
2020-10-09 00:00:00 +00:00
|
|
|
loworld_template_add_random_enemy_(
|
|
|
|
param, s = chaos_xorshift(s), floor, .5f);
|
2020-09-14 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2020-10-09 00:00:00 +00:00
|
|
|
const loentity_ground_t* ceiling = loworld_template_add_ground_island_(
|
2020-09-14 00:00:00 +00:00
|
|
|
param, &vec2(.55f, .4f), &vec2(.3f, .007f));
|
|
|
|
if ((s = chaos_xorshift(s))%2) {
|
2020-10-09 00:00:00 +00:00
|
|
|
loworld_template_add_random_enemy_(
|
|
|
|
param, s = chaos_xorshift(s), ceiling, .5f);
|
2020-09-14 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void loworld_template_broken_passage_build_chunk(
|
|
|
|
const loworld_template_building_param_t* param) {
|
|
|
|
assert(loworld_template_building_param_valid(param));
|
|
|
|
|
|
|
|
uint64_t s = param->seed;
|
|
|
|
|
2020-10-09 00:00:00 +00:00
|
|
|
const loentity_ground_t* floor1 = loworld_template_add_ground_island_(
|
2020-09-14 00:00:00 +00:00
|
|
|
param, &vec2(.15f, .25f), &vec2(.15f, .01f));
|
|
|
|
if ((s = chaos_xorshift(s))%2) {
|
2020-10-09 00:00:00 +00:00
|
|
|
loworld_template_add_random_enemy_(
|
|
|
|
param, s = chaos_xorshift(s), floor1, .5f);
|
2020-09-14 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2020-10-09 00:00:00 +00:00
|
|
|
const loentity_ground_t* floor2 = loworld_template_add_ground_island_(
|
2020-09-14 00:00:00 +00:00
|
|
|
param, &vec2(.45f, .25f), &vec2(.1f, .01f));
|
|
|
|
if ((s = chaos_xorshift(s))%2) {
|
2020-10-09 00:00:00 +00:00
|
|
|
loworld_template_add_random_enemy_(
|
|
|
|
param, s = chaos_xorshift(s), floor2, .5f);
|
2020-09-14 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2020-10-09 00:00:00 +00:00
|
|
|
const loentity_ground_t* floor3 = loworld_template_add_ground_island_(
|
2020-09-14 00:00:00 +00:00
|
|
|
param, &vec2(.85f, .25f), &vec2(.15f, .01f));
|
|
|
|
if ((s = chaos_xorshift(s))%2) {
|
2020-10-09 00:00:00 +00:00
|
|
|
loworld_template_add_random_enemy_(
|
|
|
|
param, s = chaos_xorshift(s), floor3, .5f);
|
2020-09-14 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const uint64_t layout = (s = chaos_xorshift(s))%3;
|
|
|
|
if (layout == 0 || layout == 1) {
|
2020-10-09 00:00:00 +00:00
|
|
|
const loentity_ground_t* ceiling = loworld_template_add_ground_island_(
|
2020-09-14 00:00:00 +00:00
|
|
|
param, &vec2(.2f, .4f), &vec2(.15f, .007f));
|
|
|
|
if ((s = chaos_xorshift(s))%2) {
|
2020-10-09 00:00:00 +00:00
|
|
|
loworld_template_add_random_enemy_(
|
|
|
|
param, s = chaos_xorshift(s), ceiling, .5f);
|
2020-09-14 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (layout == 0 || layout == 2) {
|
2020-10-09 00:00:00 +00:00
|
|
|
const loentity_ground_t* ceiling = loworld_template_add_ground_island_(
|
2020-09-14 00:00:00 +00:00
|
|
|
param, &vec2(.7f, .38f), &vec2(.12f, .007f));
|
|
|
|
if ((s = chaos_xorshift(s))%2) {
|
2020-10-09 00:00:00 +00:00
|
|
|
loworld_template_add_random_enemy_(
|
|
|
|
param, s = chaos_xorshift(s), ceiling, .5f);
|
2020-09-14 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void loworld_template_stairs_build_chunk(
|
|
|
|
const loworld_template_building_param_t* param) {
|
|
|
|
assert(loworld_template_building_param_valid(param));
|
|
|
|
|
|
|
|
uint64_t s = param->seed;
|
|
|
|
|
2020-10-09 00:00:00 +00:00
|
|
|
const loentity_ground_t* floor1 = loworld_template_add_ground_island_(
|
2020-09-14 00:00:00 +00:00
|
|
|
param, &vec2(.5f, .3f), &vec2(.5f, .015f));
|
|
|
|
if ((s = chaos_xorshift(s))%2) {
|
2020-10-09 00:00:00 +00:00
|
|
|
loworld_template_add_random_enemy_(
|
|
|
|
param, s = chaos_xorshift(s), floor1, .5f);
|
2020-09-14 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool layout = (s = chaos_xorshift(s))%2;
|
2020-10-09 00:00:00 +00:00
|
|
|
const loentity_ground_t* floor2 = loworld_template_add_ground_island_(
|
2020-09-14 00:00:00 +00:00
|
|
|
param, &vec2(layout? .3f: .6f, .5f), &vec2(.2f, .015f));
|
|
|
|
if ((s = chaos_xorshift(s))%2) {
|
2020-10-09 00:00:00 +00:00
|
|
|
loworld_template_add_random_enemy_(
|
|
|
|
param, s = chaos_xorshift(s), floor2, .5f);
|
2020-09-14 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
layout = !layout;
|
2020-10-09 00:00:00 +00:00
|
|
|
const loentity_ground_t* floor3 = loworld_template_add_ground_island_(
|
2020-09-14 00:00:00 +00:00
|
|
|
param, &vec2(layout? .2f: .8f, .7f), &vec2(.18f, .007f));
|
|
|
|
if ((s = chaos_xorshift(s))%2) {
|
2020-10-09 00:00:00 +00:00
|
|
|
loworld_template_add_random_enemy_(
|
|
|
|
param, s = chaos_xorshift(s), floor3, .5f);
|
2020-09-14 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2020-10-09 00:00:00 +00:00
|
|
|
const loentity_ground_t* floor4 = loworld_template_add_ground_island_(
|
2020-09-14 00:00:00 +00:00
|
|
|
param, &vec2(.5f, .9f), &vec2(.32f, .007f));
|
|
|
|
if ((s = chaos_xorshift(s))%2) {
|
2020-10-09 00:00:00 +00:00
|
|
|
loworld_template_add_random_enemy_(
|
|
|
|
param, s = chaos_xorshift(s), floor4, .5f);
|
2020-09-14 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void loworld_template_boss_theists_child_build_chunk(
|
|
|
|
const loworld_template_building_param_t* param) {
|
|
|
|
assert(loworld_template_building_param_valid(param));
|
|
|
|
|
2020-10-09 00:00:00 +00:00
|
|
|
loentity_ground_t* gnd = loworld_template_add_ground_island_(
|
2020-09-14 00:00:00 +00:00
|
|
|
param, &vec2(.5f, .1f), &vec2(.5f, .05f));
|
|
|
|
|
2020-10-09 00:00:00 +00:00
|
|
|
lochara_base_t* boss = lochara_pool_create(param->pools->chara);
|
|
|
|
lochara_theists_child_build(boss, gnd);
|
2020-09-14 00:00:00 +00:00
|
|
|
loworld_chunk_add_entity(param->target, &boss->super.super);
|
|
|
|
}
|
|
|
|
|
|
|
|
void loworld_template_boss_big_warder_build_chunk(
|
|
|
|
const loworld_template_building_param_t* param) {
|
|
|
|
assert(loworld_template_building_param_valid(param));
|
|
|
|
|
2020-10-09 00:00:00 +00:00
|
|
|
loentity_ground_t* gnd = loworld_template_add_ground_island_(
|
2020-09-14 00:00:00 +00:00
|
|
|
param, &vec2(.5f, .1f), &vec2(.5f, .05f));
|
|
|
|
|
2020-10-09 00:00:00 +00:00
|
|
|
lochara_base_t* boss = lochara_pool_create(param->pools->chara);
|
|
|
|
lochara_big_warder_build(boss, gnd);
|
2020-09-14 00:00:00 +00:00
|
|
|
loworld_chunk_add_entity(param->target, &boss->super.super);
|
|
|
|
}
|
|
|
|
|
|
|
|
void loworld_template_boss_greedy_scientist_build_chunk(
|
|
|
|
const loworld_template_building_param_t* param) {
|
|
|
|
assert(loworld_template_building_param_valid(param));
|
|
|
|
|
2020-10-09 00:00:00 +00:00
|
|
|
const loentity_ground_t* ground = loworld_template_add_ground_island_(
|
2020-09-14 00:00:00 +00:00
|
|
|
param, &vec2(.5f, .1f), &vec2(.5f, .05f));
|
2020-10-09 00:00:00 +00:00
|
|
|
(void) ground;
|
2020-09-14 00:00:00 +00:00
|
|
|
}
|