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

summaryrefslogtreecommitdiff
path: root/source/game/StarGameTypes.cpp
blob: d3171f03393b835529d4c1a9471170eb6dc2de9e (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
98
99
100
101
#include "StarGameTypes.hpp"

namespace Star {

float GlobalTimescale = 1.0f;
float GlobalTimestep = 1.0f / 60.0f;
float ServerGlobalTimestep = 1.0f / 60.0f;

EnumMap<Direction> const DirectionNames{
  {Direction::Left, "left"},
  {Direction::Right, "right"},
};

EnumMap<Gender> const GenderNames{
  {Gender::Male, "male"},
  {Gender::Female, "female"},
};

EnumMap<FireMode> const FireModeNames{
  {FireMode::None, "none"},
  {FireMode::Primary, "primary"},
  {FireMode::Alt, "alt"}
};

EnumMap<ToolHand> const ToolHandNames{
  {ToolHand::Primary, "primary"},
  {ToolHand::Alt, "alt"}
};

EnumMap<TileLayer> const TileLayerNames{
  {TileLayer::Foreground, "foreground"},
  {TileLayer::Background, "background"}
};

EnumMap<MoveControlType> const MoveControlTypeNames{
  {MoveControlType::Left, "left"},
  {MoveControlType::Right, "right"},
  {MoveControlType::Down, "down"},
  {MoveControlType::Up, "up"},
  {MoveControlType::Jump, "jump"}
};

EnumMap<PortraitMode> const PortraitModeNames{
  {PortraitMode::Head, "head"},
  {PortraitMode::Bust, "bust"},
  {PortraitMode::Full, "full"},
  {PortraitMode::FullNeutral, "fullneutral"},
  {PortraitMode::FullNude, "fullnude"},
  {PortraitMode::FullNeutralNude, "fullneutralnude"}
};

EnumMap<Rarity> const RarityNames{
  {Rarity::Common, "common"},
  {Rarity::Uncommon, "uncommon"},
  {Rarity::Rare, "rare"},
  {Rarity::Legendary, "legendary"},
  {Rarity::Essential, "essential"}
};

std::pair<EntityId, EntityId> connectionEntitySpace(ConnectionId connectionId) {
  if (connectionId == ServerConnectionId) {
    return {MinServerEntityId, MaxServerEntityId};
  } else if (connectionId >= MinClientConnectionId && connectionId <= MaxClientConnectionId) {
    EntityId beginIdSpace = (EntityId)connectionId * -65536;
    EntityId endIdSpace = beginIdSpace + 65535;
    return {beginIdSpace, endIdSpace};
  } else {
    throw StarException::format("Invalid connection id in clientEntitySpace({})", connectionId);
  }
}

bool entityIdInSpace(EntityId entityId, ConnectionId connectionId) {
  auto pair = connectionEntitySpace(connectionId);
  return entityId >= pair.first && entityId <= pair.second;
}

ConnectionId connectionForEntity(EntityId entityId) {
  if (entityId > 0)
    return ServerConnectionId;
  else
    return (-entityId - 1) / 65536 + 1;
}

pair<float, Direction> getAngleSide(float angle, bool ccRotation) {
  angle = constrainAngle(angle);
  Direction direction = Direction::Right;
  if (angle > Constants::pi / 2) {
    direction = Direction::Left;
    angle = Constants::pi - angle;
  } else if (angle < -Constants::pi / 2) {
    direction = Direction::Left;
    angle = -Constants::pi - angle;
  }

  if (direction == Direction::Left && ccRotation)
    angle *= -1;

  return make_pair(angle, direction);
}

}