Proper town logic; needs lots of fixing
This commit is contained in:
@@ -352,7 +352,7 @@ void Characters_::character_physics(Object *obj)
|
||||
} else if (obj->has_meta("cmdqueue") && obj->has_meta("climb")) {
|
||||
go = true;
|
||||
}
|
||||
if (!kb->is_on_floor() && !obj->has_meta("climb"))
|
||||
if (!kb->is_on_floor() && !obj->has_meta("climb") && !obj->has_meta("vehicle"))
|
||||
velocity += Vector3(0.0f, -9.8f, 0.0f);
|
||||
if (go)
|
||||
velocity = kb->move_and_slide(velocity, Vector3(0.0f, 1.0f, 0.0f), true, 4, 0.785f, false);
|
||||
@@ -605,7 +605,6 @@ void Characters_::_notification(int p_what)
|
||||
continue;
|
||||
if (!ch->has_meta("orientation"))
|
||||
continue;
|
||||
printf("running physics for %p\n", ch);
|
||||
character_physics(ch);
|
||||
Spatial *sp = Object::cast_to<Spatial>(ch);
|
||||
Vector3 direction = sp->get_global_transform().xform(Vector3(0, 0, -1));
|
||||
|
||||
@@ -285,8 +285,8 @@ void RoadDiagram::process_diagram(const Dictionary &diagram)
|
||||
RoadDiagram::RoadDiagram()
|
||||
{
|
||||
class_sizes[map_site::SITE_EMPTY] = 10000;
|
||||
class_sizes[map_site::SITE_TOWN] = 100000;
|
||||
class_sizes[map_site::SITE_FARM] = 500000;
|
||||
class_sizes[map_site::SITE_FARM] = 100000;
|
||||
class_sizes[map_site::SITE_TOWN] = 240000;
|
||||
class_sizes[map_site::SITE_FOREST] = 1000000;
|
||||
class_sizes[map_site::SITE_UNASSIGNED] = 2000000;
|
||||
}
|
||||
@@ -680,4 +680,40 @@ void RoadGrid::save_json(const String &path)
|
||||
f->close();
|
||||
}
|
||||
}
|
||||
PoolVector<Vector3> RoadGrid::get_site_border(int site)
|
||||
{
|
||||
const struct map_site &msite = map_sites[site];
|
||||
List<struct vshape *> site_vshapes;
|
||||
List<struct vshape *>::Element *e;
|
||||
PoolVector<Vector3> ret;
|
||||
int i, j;
|
||||
for (i = 0; i < msite.polygon_ind.size(); i++) {
|
||||
int p1 = i;
|
||||
int p2 = (i + 1) % msite.polygon_ind.size();
|
||||
int p3 = (i + 2) % msite.polygon_ind.size();
|
||||
for (j = 0; j < vshapes.size(); j++) {
|
||||
struct vshape &v = vshapes.write()[j];
|
||||
if (v.site != site)
|
||||
continue;
|
||||
struct half_edge *hedge1 = map_hedges[v.e1];
|
||||
struct half_edge *hedge2 = map_hedges[v.e2];
|
||||
if (hedge1->a != p1 ||
|
||||
hedge1->b != p2 || hedge2->b != p3)
|
||||
continue;
|
||||
site_vshapes.push_back(&v);
|
||||
}
|
||||
}
|
||||
ret.resize(site_vshapes.size());
|
||||
int count = 0;
|
||||
for (e = site_vshapes.front(); e; e = e->next()) {
|
||||
struct vshape *pv = e->get();
|
||||
float l = pv->curve3->get_baked_length();
|
||||
Vector3 bp = pv->curve3->interpolate_baked(l * 0.5f) + pv->p2;
|
||||
ret.write()[count++] = bp;
|
||||
}
|
||||
printf("polygon count %d border count %d\n",
|
||||
msite.polygon_ind.size(), ret.size());
|
||||
assert(msite.polygon_ind.size() == ret.size());
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#ifndef ROAD_GRID_H
|
||||
#define ROAD_GRID_H
|
||||
#include <cassert>
|
||||
#include <unordered_map>
|
||||
#include <core/object.h>
|
||||
#include <core/reference.h>
|
||||
@@ -44,8 +45,8 @@ struct map_site {
|
||||
enum {
|
||||
SITE_UNASSIGNED = 0,
|
||||
SITE_FOREST,
|
||||
SITE_FARM,
|
||||
SITE_TOWN,
|
||||
SITE_FARM,
|
||||
SITE_EMPTY,
|
||||
SITE_MAX
|
||||
};
|
||||
@@ -107,11 +108,12 @@ protected:
|
||||
}
|
||||
int cl_area = (int)(r.get_area() + 1.0f);
|
||||
for (i = 0; i < map_site::SITE_MAX; i++) {
|
||||
if (class_sizes.has(i))
|
||||
if (cl_area <= class_sizes[i]) {
|
||||
if (class_sizes.has(i)) {
|
||||
if (cl_area >= class_sizes[i]) {
|
||||
map_sites.write[j].site_type = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* for now the starting town is at 0 */
|
||||
printf("area: %d class: %d\n", cl_area, map_sites[j].site_type);
|
||||
@@ -280,19 +282,19 @@ public:
|
||||
void generate_building_positions();
|
||||
void generate_site_building_positions(const struct map_site *site);
|
||||
int get_site_from_point(int x, int z);
|
||||
inline bool site_is_town(int site)
|
||||
inline bool site_is_town(int site) const
|
||||
{
|
||||
return map_sites[site].site_type == map_site::SITE_TOWN;
|
||||
}
|
||||
inline bool site_is_farm(int site)
|
||||
inline bool site_is_farm(int site) const
|
||||
{
|
||||
return map_sites[site].site_type == map_site::SITE_FARM;
|
||||
}
|
||||
inline float get_site_avg_height(int site)
|
||||
inline float get_site_avg_height(int site) const
|
||||
{
|
||||
return map_sites[site].avg_height;
|
||||
}
|
||||
inline Vector2 get_site_pos(int site)
|
||||
inline Vector2 get_site_pos(int site) const
|
||||
{
|
||||
return map_sites[site].pos;
|
||||
}
|
||||
@@ -358,5 +360,14 @@ public:
|
||||
return ret;
|
||||
}
|
||||
void save_json(const String &path);
|
||||
PoolVector<Vector3> get_site_border(int site);
|
||||
inline int get_site_count() const
|
||||
{
|
||||
return map_sites.size();
|
||||
}
|
||||
inline int get_site_type(int site) const
|
||||
{
|
||||
return map_sites[site].site_type;
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -395,17 +395,6 @@ void Roads::add_scene_element(Node *root, Node *xnode, const Vector3 &p2, Ref<Co
|
||||
Transform xform(Basis(), p2);
|
||||
assert(xmi->get_mesh().is_valid() && xmi->get_mesh()->get_surface_count() > 0);
|
||||
xmi->set_global_transform(xform);
|
||||
printf("trimesh collision\n");
|
||||
#if 0
|
||||
Node *c = xmi->create_trimesh_collision();
|
||||
assert(c);
|
||||
add_child(c);
|
||||
#if 0
|
||||
CollisionShape *cs = memnew(CollisionShape);
|
||||
cs->set_shape(shape);
|
||||
body->add_child(cs);
|
||||
#endif
|
||||
#endif
|
||||
StaticBody *sb = memnew(StaticBody);
|
||||
CollisionShape *cs = memnew(CollisionShape);
|
||||
assert(sb);
|
||||
@@ -573,9 +562,14 @@ void RoadsData::_bind_methods()
|
||||
ClassDB::bind_method(D_METHOD("get_site_pos", "site"), &RoadsData::get_site_pos);
|
||||
ClassDB::bind_method(D_METHOD("get_site_polygon_2d", "site"), &RoadsData::get_site_polygon_2d);
|
||||
ClassDB::bind_method(D_METHOD("get_site_polygon_3d", "site"), &RoadsData::get_site_polygon_3d);
|
||||
ClassDB::bind_method(D_METHOD("get_here_sites", "site"), &RoadsData::get_here_sites);
|
||||
ClassDB::bind_method(D_METHOD("get_here_sites", "position"), &RoadsData::get_here_sites);
|
||||
ClassDB::bind_method(D_METHOD("get_site_avg_height", "site"), &RoadsData::get_site_avg_height);
|
||||
ClassDB::bind_method(D_METHOD("get_site_border", "site"), &RoadsData::get_site_border);
|
||||
ClassDB::bind_method(D_METHOD("site_is_town", "site"), &RoadsData::site_is_town);
|
||||
ClassDB::bind_method(D_METHOD("site_is_farm", "site"), &RoadsData::site_is_farm);
|
||||
ClassDB::bind_method(D_METHOD("get_site_count"), &RoadsData::get_site_count);
|
||||
ClassDB::bind_method(D_METHOD("save_json", "path"), &RoadsData::save_json);
|
||||
ClassDB::bind_method(D_METHOD("get_site_type", "site"), &RoadsData::get_site_type);
|
||||
}
|
||||
void RoadsData::set_noise(Ref<FastNoiseLite> noise)
|
||||
{
|
||||
@@ -599,12 +593,12 @@ float RoadsData::get_sdf(int x, int y, int z)
|
||||
Vector2 ifl = rg->get_influence(x, z, 32.0f);
|
||||
if (ifl.x > 0.0f) {
|
||||
sdf_mutex.lock();
|
||||
if (n <= ifl.y - 0.5f) {
|
||||
ret = (float)y - ifl.y - 0.6f;
|
||||
sdf_data[x * 50000 + z] = ifl.y + 0.6f;
|
||||
if (n <= ifl.y) {
|
||||
ret = (float)y - ifl.y - 2.1f;
|
||||
sdf_data[x * 50000 + z] = ifl.y + 2.1f;
|
||||
} else {
|
||||
ret = (float)y - ifl.y;
|
||||
sdf_data[x * 50000 + z] = ifl.y;
|
||||
ret = (float)y - ifl.y - 2.1f;
|
||||
sdf_data[x * 50000 + z] = ifl.y + 2.1f;
|
||||
}
|
||||
sdf_mutex.unlock();
|
||||
goto out;
|
||||
@@ -640,3 +634,13 @@ PoolVector<int> RoadsData::get_here_sites(const Vector3 &position)
|
||||
{
|
||||
return rg->get_here_sites(position);
|
||||
}
|
||||
bool RoadsData::site_is_town(int site) const
|
||||
{
|
||||
return rg->site_is_town(site);
|
||||
}
|
||||
bool RoadsData::site_is_farm(int site) const
|
||||
{
|
||||
return rg->site_is_farm(site);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -118,6 +118,8 @@ public:
|
||||
PoolVector<Vector2> get_site_polygon_2d(int site);
|
||||
PoolVector<Vector3> get_site_polygon_3d(int site);
|
||||
PoolVector<int> get_here_sites(const Vector3 &pos);
|
||||
bool site_is_town(int site) const;
|
||||
bool site_is_farm(int site) const;
|
||||
inline float get_site_avg_height(int site)
|
||||
{
|
||||
return rg->get_site_avg_height(site);
|
||||
@@ -126,5 +128,17 @@ public:
|
||||
{
|
||||
rg->save_json(path);
|
||||
}
|
||||
inline PoolVector<Vector3> get_site_border(int site)
|
||||
{
|
||||
return rg->get_site_border(site);
|
||||
}
|
||||
inline int get_site_count() const
|
||||
{
|
||||
return rg->get_site_count();
|
||||
}
|
||||
inline int get_site_type(int site) const
|
||||
{
|
||||
return rg->get_site_type(site);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user