Worldstone
 All Classes Files Functions Variables Enumerations Enumerator Macros Pages
cof.h
1 #pragma once
2 
3 #include <stdint.h>
4 #include <Stream.h>
5 #include <Vector.h>
6 #include <memory>
7 #include <type_traits>
8 
9 namespace WorldStone
10 {
24 class COF
25 {
26 public:
27  struct Header
28  {
29  uint8_t layers;
30  uint8_t frames;
31  uint8_t directions;
32  uint8_t version;
33  uint32_t unknown1;
34  int32_t xMin;
37  int32_t xMax;
38  int32_t yMin;
39  int32_t yMax;
41  int16_t animRate;
42  int16_t zeros;
43  };
44 
45  struct Layer
46  {
47  uint8_t component;
48  uint8_t castsShadow;
49  uint8_t isSelectable;
50  uint8_t overrideTranslvl;
51  uint8_t newTranslvl;
52  char weaponClass[4];
53  };
54 
56  enum Keyframe : uint8_t
57  {
58  COFKEY_NONE,
59  COFKEY_ATTACK,
60  COFKEY_MISSILE,
61  COFKEY_SOUND,
62  COFKEY_SKILL,
63  COFKEY_MAX,
64  };
65 
66  bool read(const StreamPtr& streamPtr);
67 
68  const Header& getHeader() const { return header; }
69  const Vector<Layer>& getLayers() const { return layers; }
70  const Vector<Keyframe>& getKeyframes() const { return keyframes; }
71  const Vector<uint8_t>& getAllLayersOrders() const { return layersOrder; }
72 
74  const uint8_t* getFrameLayerOrder(size_t direction, size_t frame) const
75  {
76 
77  const size_t frameIdx = (direction * header.frames + frame) * header.layers;
78  return &layersOrder[frameIdx];
79  }
81  static constexpr uint8_t componentsNumber = 16;
82  static constexpr const char* componentsNames[componentsNumber] = {
83  "HD", "TR", "LG", "RA", "LA", "RH", "LH", "SH",
84  "S1", "S2", "S3", "S4", "S5", "S6", "S7", "S8"};
85 
86 private:
87  Header header;
88  Vector<Layer> layers;
89  Vector<Keyframe> keyframes;
95  Vector<uint8_t> layersOrder;
96 };
97 } // namespace WorldStone
uint8_t component
See componentsNames.
Definition: cof.h:47
uint8_t directions
Number of directions in the animation.
Definition: cof.h:31
int16_t zeros
Always zero.
Definition: cof.h:42
uint8_t frames
Number of frames in the animation.
Definition: cof.h:30
Keyframe
Frame trigger type.
Definition: cof.h:56
uint8_t isSelectable
Can the layer be selected and used for the "hit" underlay.
Definition: cof.h:49
Just a placeholder to use if we ever want to implement our own vector type.
const uint8_t * getFrameLayerOrder(size_t direction, size_t frame) const
Definition: cof.h:74
int16_t animRate
Default animation rate(speed) in 8-bit fixed-point: 256 == 1.f.
Definition: cof.h:41
uint8_t layers
Number of components layers.
Definition: cof.h:29
uint8_t castsShadow
Does this layer cast a shadow.
Definition: cof.h:48
uint32_t unknown1
Possible bitfield values : loopAnim / underlay color when hit.
Definition: cof.h:33
uint8_t version
The version of the COF, always 20 in the game files.
Definition: cof.h:32
static constexpr uint8_t componentsNumber
Definition: cof.h:81
Decoder for the COF (Components Object File) file format.
Definition: cof.h:24