summaryrefslogtreecommitdiff
path: root/src/game/game.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/game/game.cpp')
-rw-r--r--src/game/game.cpp44
1 files changed, 37 insertions, 7 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;