summaryrefslogtreecommitdiff
path: root/src/game
diff options
context:
space:
mode:
authorPaweł Redman <pawel.redman@gmail.com>2018-04-26 16:41:02 +0200
committerPaweł Redman <pawel.redman@gmail.com>2018-04-26 16:41:02 +0200
commitfe96448665543ba762f237328570ff55cd89a24f (patch)
tree308a355113b503fa1cae82394afaecd366ca665e /src/game
parentd5d545887569f9b11fa6aa16eee524afec3da19e (diff)
Random worlds.
Diffstat (limited to 'src/game')
-rw-r--r--src/game/game.cpp44
-rw-r--r--src/game/game.hpp9
2 files changed, 43 insertions, 10 deletions
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 {