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

summaryrefslogtreecommitdiff
path: root/source/game/StarWarping.hpp
blob: f5e6c0473b74c26b5c69facdee526179f021e84e (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#pragma once

#include "StarStrongTypedef.hpp"
#include "StarUuid.hpp"
#include "StarCelestialCoordinate.hpp"
#include "StarGameTypes.hpp"

namespace Star {

enum class WarpMode : uint8_t {
  None,
  BeamOnly,
  DeployOnly,
  BeamOrDeploy
};
extern EnumMap<WarpMode> WarpModeNames;

struct InstanceWorldId {
  String instance;
  Maybe<Uuid> uuid;
  Maybe<float> level;

  InstanceWorldId();
  InstanceWorldId(String instance, Maybe<Uuid> uuid = {}, Maybe<float> level = {});

  bool operator==(InstanceWorldId const& rhs) const;
  bool operator<(InstanceWorldId const& rhs) const;
};

template <>
struct hash<InstanceWorldId> {
  size_t operator()(InstanceWorldId const& id) const;
};

DataStream& operator>>(DataStream& ds, InstanceWorldId& missionWorldId);
DataStream& operator<<(DataStream& ds, InstanceWorldId const& missionWorldId);

strong_typedef(CelestialCoordinate, CelestialWorldId);
strong_typedef(Uuid, ClientShipWorldId);
typedef MVariant<CelestialWorldId, ClientShipWorldId, InstanceWorldId> WorldId;

String printWorldId(WorldId const& worldId);
WorldId parseWorldId(String const& printedId);

// Same as outputting printWorldId
std::ostream& operator<<(std::ostream& os, CelestialWorldId const& worldId);
std::ostream& operator<<(std::ostream& os, ClientShipWorldId const& worldId);
std::ostream& operator<<(std::ostream& os, InstanceWorldId const& worldId);
std::ostream& operator<<(std::ostream& os, WorldId const& worldId);

strong_typedef(String, SpawnTargetUniqueEntity);
strong_typedef(Vec2F, SpawnTargetPosition);
strong_typedef_builtin(float, SpawnTargetX);
typedef MVariant<SpawnTargetUniqueEntity, SpawnTargetPosition, SpawnTargetX> SpawnTarget;

Json spawnTargetToJson(SpawnTarget spawnTarget);
SpawnTarget spawnTargetFromJson(Json v);

String printSpawnTarget(SpawnTarget spawnTarget);

struct WarpToWorld {
  WarpToWorld();
  explicit WarpToWorld(WorldId world, SpawnTarget spawn = {});
  explicit WarpToWorld(Json v);

  WorldId world;
  SpawnTarget target;

  bool operator==(WarpToWorld const& rhs) const;
  explicit operator bool() const;

  Json toJson() const;
};

strong_typedef(Uuid, WarpToPlayer);

enum class WarpAlias {
  Return,
  OrbitedWorld,
  OwnShip
};

typedef MVariant<WarpToWorld, WarpToPlayer, WarpAlias> WarpAction;

WarpAction parseWarpAction(String const& warpString);
String printWarpAction(WarpAction const& warpAction);

DataStream& operator>>(DataStream& ds, WarpToWorld& warpToWorld);
DataStream& operator<<(DataStream& ds, WarpToWorld const& warpToWorld);

}

template <> struct fmt::formatter<Star::CelestialWorldId> : ostream_formatter {};
template <> struct fmt::formatter<Star::ClientShipWorldId> : ostream_formatter {};
template <> struct fmt::formatter<Star::InstanceWorldId> : ostream_formatter {};
template <> struct fmt::formatter<Star::WorldId> : ostream_formatter {};
template <> struct fmt::formatter<Star::WarpToWorld> : ostream_formatter {};