Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/game/StarTenantDatabase.hpp
blob: fdcc4db37840aa2a8579359e95e97576c49cc08e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#pragma once

#include "StarRoot.hpp"
#include "StarAssets.hpp"
#include "StarTtlCache.hpp"

namespace Star {

STAR_STRUCT(Tenant);
STAR_CLASS(TenantDatabase);

STAR_EXCEPTION(TenantException, StarException);

struct TenantNpcSpawnable {
  List<String> species;
  String type;
  Maybe<float> level;
  Maybe<Json> overrides;
};

struct TenantMonsterSpawnable {
  String type;
  Maybe<float> level;
  Maybe<Json> overrides;
};

typedef MVariant<TenantNpcSpawnable, TenantMonsterSpawnable> TenantSpawnable;

struct TenantRent {
  Vec2F periodRange;
  String pool;
};

struct Tenant {
  bool criteriaSatisfied(StringMap<unsigned> const& colonyTags) const;

  String name;
  float priority;

  // The colonyTag multiset the house must contain in order to satisfy this
  // tenant.
  StringMap<unsigned> colonyTagCriteria;

  List<TenantSpawnable> tenants;

  Maybe<TenantRent> rent;

  // The Json this tenant was parsed from
  Json config;
};

class TenantDatabase {
public:
  TenantDatabase();

  void cleanup();

  TenantPtr getTenant(String const& name) const;

  // Return the list of all tenants for which colonyTags is a superset of
  // colonyTagCriteria
  List<TenantPtr> getMatchingTenants(StringMap<unsigned> const& colonyTags) const;

private:
  static TenantPtr readTenant(String const& path);

  Map<String, String> m_paths;
  mutable Mutex m_cacheMutex;
  mutable HashTtlCache<String, TenantPtr> m_tenantCache;
};

}