summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/common.hpp3
-rw-r--r--src/game/game.cpp44
-rw-r--r--src/game/game.hpp9
-rw-r--r--src/world.cpp4
4 files changed, 46 insertions, 14 deletions
diff --git a/src/common.hpp b/src/common.hpp
index 7e449a2..6aa88d7 100644
--- a/src/common.hpp
+++ b/src/common.hpp
@@ -184,12 +184,11 @@ namespace world {
public:
procgen::perlin_noise_t perlin;
+ void seed_procgen(uint32_t seed);
void (*generator)(world_t *world, sector_index_t index, sector_t *sector,
bool gen_tiles, bool gen_decos, void *data) = 0;
void *generator_data = 0;
- world_t(void);
-
sector_t *get_sector(sector_index_t index, sector_level_t level);
tile_t *get_tile(tile_index_t index, sector_level_t level);
diff --git a/src/game/game.cpp b/src/game/game.cpp
index 3adfd85..ae2cb0f 100644
--- a/src/game/game.cpp
+++ b/src/game/game.cpp
@@ -16,6 +16,7 @@ along with Minitrem. If not, see <http://www.gnu.org/licenses/>.
*/
#include "game.hpp"
+#include <random>
namespace game {
@@ -80,17 +81,13 @@ void entity_t::sleep(void)
void state_t::start(void)
{
- unit_teleporter_t *teleporter;
+ std::random_device rd;
+ std::uniform_int_distribution<uint32_t> dist(0, (uint32_t)1 << 31);
+ world.seed_procgen(dist(rd));
world.generator = worldgen;
world.generator_data = (void*)this;
- teleporter = new unit_teleporter_t(this);
- teleporter->place(&world, v2f_t(5.3, 4.2));
- teleporter->constructed = true;
- teleporter->health = teleporter->max_health;
- select_unit(teleporter, SELECT_NEW);
-
resume();
}
@@ -178,6 +175,8 @@ void state_t::select(rectf_t rect, int type)
}
enum {
+ COMMAND_FIRST_TELEPORTER,
+
COMMAND_MOVE,
COMMAND_FIRE,
COMMAND_THROW_GRENADE,
@@ -207,6 +206,11 @@ bool state_t::populate_pie_menu(std::vector<interface::pie_item_t> &items)
items.clear();
+ if (!first_teleporter_placed) {
+ items.push_back((interface::pie_item_t){"Place the teleporter", COMMAND_FIRST_TELEPORTER});
+ return true;
+ }
+
if (selected_units.size() == 0)
return false;
@@ -283,6 +287,27 @@ bool state_t::populate_pie_menu(std::vector<interface::pie_item_t> &items)
return true;
}
+void state_t::command_first_teleporter(v2f_t where)
+{
+ unit_teleporter_t *teleporter;
+ world::cmodel_t test;
+
+ teleporter = new unit_teleporter_t(this);
+ teleporter->place(&world, where);
+
+ test = teleporter->cmodel;
+ test.cflags = CF_SOLID|CF_BODY|CF_BODY_SMALL|CF_DECOS|CF_WATER|CF_SURFACE2;
+ if (world.test_rect(&test, teleporter)) {
+ interface.print("There is no room for a teleporter here.");
+ delete teleporter;
+ return;
+ }
+
+ teleporter->constructed = true;
+ teleporter->health = teleporter->max_health;
+ first_teleporter_placed = true;
+}
+
static void command_soldier(unit_soldier_t *soldier, v2f_t x, int number)
{
switch (number) {
@@ -413,6 +438,11 @@ void state_t::command(v2f_t x, int number)
{
bool unlink;
+ if (!first_teleporter_placed || number == COMMAND_FIRST_TELEPORTER) {
+ command_first_teleporter(x);
+ return;
+ }
+
if (!selected_units.size())
return;
diff --git a/src/game/game.hpp b/src/game/game.hpp
index c378524..3e5042c 100644
--- a/src/game/game.hpp
+++ b/src/game/game.hpp
@@ -66,7 +66,7 @@ namespace interface {
v2f_t zero_point_s = v2f_t(0, 0);
v2f_t center = v2f_t(0, 0);
- int zoom = 3;
+ int zoom = 17;
float zoom_s = 3.0f;
bool panning = false;
@@ -139,6 +139,11 @@ namespace game {
void pause(void);
void resume(void);
+ bool first_teleporter_placed = false;
+ size_t crystals = 150;
+
+ void command_first_teleporter(v2f_t where);
+
void wake_area(v2f_t x);
void explosion(v2f_t x);
void hivemind_alert(v2f_t x, float r, bool do_move, v2f_t move_to);
@@ -147,8 +152,6 @@ namespace game {
void select(rectf_t rect, int type);
bool populate_pie_menu(std::vector<interface::pie_item_t> &items);
void command(v2f_t x, int number);
-
- size_t crystals = 150;
};
enum {
diff --git a/src/world.cpp b/src/world.cpp
index cdb36a4..f7ab3d9 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -30,9 +30,9 @@ tile_index_t tile_index_at(v2f_t x)
return sector_index_t(x.floor());
}
-world_t::world_t(void)
+void world_t::seed_procgen(uint32_t seed)
{
- prng.seed(125);
+ prng.seed(seed);
perlin.generate(&prng, 32);
}