-Subproject commit b63c91ead8b510b614efccc97b4000fc3aca9c87
+Subproject commit 46d3c2d2fb145405994b69291037a3c9e66ab3d1
in.Skip(io::Token::EQUALS);
if (name == "label") {
in.ReadString(data.resources[id].label);
+ } else if (name == "state") {
+ in.ReadIdentifier(name);
+ if (name == "solid") {
+ data.resources[id].state = world::Resource::SOLID;
+ } else if (name == "liquid") {
+ data.resources[id].state = world::Resource::LIQUID;
+ } else if (name == "gas") {
+ data.resources[id].state = world::Resource::GAS;
+ } else if (name == "plasma") {
+ data.resources[id].state = world::Resource::PLASMA;
+ } else {
+ throw std::runtime_error("unknown resource state '" + name + "'");
+ }
} else {
throw std::runtime_error("unknown resource property '" + name + "'");
}
sim.AddPlanet(moon);
world::GenerateEarthlike(assets.data.tiles, planet);
+ planet.Atmosphere(assets.data.resources["air"].id);
world::GenerateTest(assets.data.tiles, moon);
world::GenerateTest(assets.data.tiles, second_planet);
auto blob = new world::Creature;
blob->BuildVAO();
- planet.AddCreature(blob);
- blob->Surface(0);
- blob->Position(glm::dvec3(0.0, 0.0, 0.0));
+ Spawn(*blob, planet, assets);
app::MasterState state(assets, sim);
state.GetCamera()
namespace world {
class Body;
+class Planet;
class Creature {
void Surface(int s) noexcept { surface = s; }
void Position(const glm::dvec3 &p) noexcept { position = p; }
+ void RequireBreathing(int r) noexcept { breathes = r; }
+ int Breathes() const noexcept { return breathes; }
+ bool MustBreathe() const noexcept { return breathes > -1; }
+
+ void RequireDrinking(int r) noexcept { drinks = r; }
+ int Drinks() const noexcept { return drinks; }
+ bool MustDrink() const noexcept { return drinks > -1; }
+
+ void RequireEating(int r) noexcept { eats = r; }
+ int Eats() const noexcept { return eats; }
+ bool MustEat() const noexcept { return eats > -1; }
+
glm::dmat4 LocalTransform() noexcept;
void BuildVAO();
int surface;
glm::dvec3 position;
+ int breathes;
+ int drinks;
+ int eats;
+
struct Attributes {
glm::vec3 position;
glm::vec3 normal;
};
+/// put creature on planet and configure it to (hopefully) survive
+void Spawn(Creature &, Planet &, app::Assets &);
+
}
}
glm::dvec3 TileCenter(int surface, int x, int y) const noexcept;
+ void Atmosphere(int a) noexcept { atmosphere = a; }
+ int Atmosphere() const noexcept { return atmosphere; }
+ bool HasAtmosphere() const noexcept { return atmosphere >= 0; }
+
void BuildVAO(const Set<TileType> &);
void Draw(app::Assets &, graphics::Viewport &) override;
int sidelength;
std::vector<Tile> tiles;
+ int atmosphere;
+
struct Attributes {
glm::vec3 position;
glm::vec3 tex_coord;
int id;
+ enum State {
+ SOLID = 0,
+ LIQUID = 1,
+ GAS = 2,
+ PLASMA = 3,
+ };
+ // the resource's natural state
+ // TODO: something about temperature and pressure and stuff
+ int state;
+
};
}
#include "Creature.hpp"
#include "Body.hpp"
+#include "Planet.hpp"
+#include "TileType.hpp"
+#include "../app/Assets.hpp"
#include <glm/gtx/transform.hpp>
+#include <iostream>
+
namespace blobs {
namespace world {
Creature::Creature()
-: vao() {
+: body(nullptr)
+, surface(0)
+, position()
+, breathes(-1)
+, drinks(-1)
+, eats(-1)
+, vao() {
}
Creature::~Creature() {
vao.DrawTriangles(6 * 6);
}
+
+void Spawn(Creature &c, Planet &p, app::Assets &assets) {
+ p.AddCreature(&c);
+ c.Surface(0);
+ c.Position(glm::dvec3(0.0, 0.0, 0.0));
+
+ // probe surrounding area for common resources
+ int start = p.SideLength() / 2 - 2;
+ int end = start + 5;
+ std::map<int, double> yields;
+ for (int y = start; y < end; ++y) {
+ for (int x = start; x < end; ++x) {
+ const TileType &t = assets.data.tiles[p.TileAt(0, x, y).type];
+ for (auto yield : t.resources) {
+ yields[yield.resource] += yield.ubiquity;
+ }
+ }
+ }
+ int liquid = -1;
+ int solid = -1;
+ for (auto e : yields) {
+ if (assets.data.resources[e.first].state == Resource::LIQUID) {
+ if (liquid < 0 || e.second > yields[liquid]) {
+ liquid = e.first;
+ }
+ } else if (assets.data.resources[e.first].state == Resource::SOLID) {
+ if (solid < 0 || e.second > yields[solid]) {
+ solid = e.first;
+ }
+ }
+ }
+
+ if (p.HasAtmosphere()) {
+ std::cout << "require breathing " << assets.data.resources[p.Atmosphere()].label << std::endl;
+ c.RequireBreathing(p.Atmosphere());
+ }
+ if (liquid > -1) {
+ std::cout << "require drinking " << assets.data.resources[liquid].label << std::endl;
+ c.RequireDrinking(liquid);
+ }
+ if (solid > -1) {
+ std::cout << "require eating " << assets.data.resources[solid].label << std::endl;
+ c.RequireEating(solid);
+ }
+}
+
}
}
: Body()
, sidelength(sidelength)
, tiles(TilesTotal())
+, atmosphere(-1)
, vao() {
Radius(double(sidelength) / 2.0);
}