Proper town logic; needs lots of fixing

This commit is contained in:
Segey Lapin
2021-10-25 13:36:58 +03:00
parent aef8a11cc4
commit 6442245253
5 changed files with 92 additions and 28 deletions

View File

@@ -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