World of Might and Magic  0.2.0
Open reimplementation of Might and Magic 6 7 8 game engine
DecorationList.cpp
См. документацию.
2 
3 #include <cstdlib>
4 
6 #include "Engine/stru123.h"
7 #include "Engine/Engine.h"
8 #include "Level/Decoration.h"
9 #include "Sprites.h"
10 
12 
13 //----- (0045864C) --------------------------------------------------------
14 void DecorationList::FromFile(void *data_mm6, void *data_mm7, void *data_mm8) {
15  size_t num_mm6_decs = data_mm6 ? *(uint32_t*)data_mm6 : 0;
16  size_t num_mm7_decs = data_mm7 ? *(uint32_t*)data_mm7 : 0;
17  size_t num_mm8_decs = data_mm8 ? *(uint32_t*)data_mm8 : 0;
18 
19  size_t uNumDecorations = num_mm6_decs + num_mm7_decs + num_mm8_decs;
20  Assert(uNumDecorations);
21  Assert(!num_mm8_decs);
22 
23  DecorationDesc *decors = (DecorationDesc*)((char*)data_mm7 + 4);
24  for (size_t i = 0; i < num_mm7_decs; i++) {
25  pDecorations.push_back(decors[i]);
26  }
27 
28  DecorationDesc_mm6 *decors_mm6 = (DecorationDesc_mm6*)((char*)data_mm6 + 4);
29  for (size_t i = 0; i < num_mm6_decs; ++i) {
30  DecorationDesc decor;
31  memcpy(&decor, &decors_mm6[i], sizeof(DecorationDesc_mm6));
32  decor.uColoredLightRed = 255;
33  decor.uColoredLightGreen = 255;
34  decor.uColoredLightBlue = 255;
35  decor.__padding = 255;
36  pDecorations.push_back(decor);
37  }
38 
39  DecorationDesc *decors_mm8 = (DecorationDesc*)((char*)data_mm8 + 4);
40  for (size_t i = 0; i < num_mm8_decs; i++) {
41  pDecorations.push_back(decors_mm8[i]);
42  }
43 }
44 
45 void DecorationList::InitializeDecorationSprite(unsigned int uDecID) {
46  pSpriteFrameTable->InitializeSprite(this->pDecorations[uDecID].uSpriteID);
47 }
48 
50  FILE *file = fopen("data\\ddeclist.bin", "wb");
51  if (file == nullptr) {
52  Error("Unable to save ddeclist.bin!", 0);
53  }
54 
55  fwrite(this, 4, 1, file);
56  fwrite(&pDecorations[0], sizeof(DecorationDesc), pDecorations.size(), file);
57  fclose(file);
58 }
59 
61  if (pName && pDecorations.size() > 1) {
62  for (uint uID = 1; uID < pDecorations.size(); ++uID) {
63  if (!_stricmp(pName, pDecorations[uID].pName)) return uID;
64  }
65  }
66 
67  return 0;
68 }
69 
71  memset(stru_5E4C90_MapPersistVars._decor_events.data(), 0, 125);
72 
73  uint decorEventIdx = 0;
74  for (uint i = 0; i < uNumLevelDecorations; ++i) {
76 
77  if (!decor->uEventID) {
78  if (decor->IsInteractive()) {
79  if (decorEventIdx < 124) {
80  decor->_idx_in_stru123 = decorEventIdx + 75;
81  stru_5E4C90_MapPersistVars._decor_events[decorEventIdx++] =
82  decor->GetGlobalEvent();
83  }
84  }
85  }
86  }
87 }
uint16_t
unsigned __int16 uint16_t
Definition: SDL_config.h:37
pLevelDecorations
std::array< LevelDecoration, 3000 > pLevelDecorations
Definition: Decoration.cpp:8
DecorationList.h
pSpriteFrameTable
struct SpriteFrameTable * pSpriteFrameTable
Definition: Sprites.cpp:22
DecorationList::FromFile
void FromFile(void *data_mm6, void *data_mm7, void *data_mm8)
Definition: DecorationList.cpp:14
DecorationDesc::uColoredLightRed
uint8_t uColoredLightRed
Definition: DecorationList.h:50
LevelDecoration::IsInteractive
bool IsInteractive()
Definition: Decoration.cpp:345
DecorationList::pDecorations
std::vector< DecorationDesc > pDecorations
Definition: DecorationList.h:70
LevelDecoration::uEventID
uint16_t uEventID
Definition: Decoration.h:31
DecorationList::GetDecorIdByName
uint16_t GetDecorIdByName(const char *pName)
Definition: DecorationList.cpp:60
Engine.h
stru123.h
stru123::_decor_events
std::array< unsigned char, 125 > _decor_events
Definition: stru123.h:8
uNumLevelDecorations
size_t uNumLevelDecorations
Definition: Decoration.cpp:9
DecorationList::ToFile
void ToFile()
Definition: DecorationList.cpp:49
LevelDecoration
Definition: Decoration.h:20
SpriteFrameTable::InitializeSprite
void InitializeSprite(signed int uSpriteID)
Definition: Sprites.cpp:46
DecorationList
Definition: DecorationList.h:57
FrameTableInc.h
LevelDecoration::_idx_in_stru123
int16_t _idx_in_stru123
Definition: Decoration.h:34
uint
unsigned int uint
Definition: MM7.h:4
DecorationDesc_mm6
Definition: DecorationList.h:25
DecorationList::InitializeDecorationSprite
void InitializeDecorationSprite(unsigned int uDecID)
Definition: DecorationList.cpp:45
Decoration.h
DecorationDesc
Definition: DecorationList.h:49
DecorationDesc::__padding
char __padding
Definition: DecorationList.h:53
stru_5E4C90_MapPersistVars
stru123 stru_5E4C90_MapPersistVars
Definition: mm7_data.cpp:23
RespawnGlobalDecorations
void RespawnGlobalDecorations()
Definition: DecorationList.cpp:70
DecorationDesc::uColoredLightBlue
uint8_t uColoredLightBlue
Definition: DecorationList.h:52
uint32_t
unsigned __int32 uint32_t
Definition: SDL_config.h:39
Sprites.h
LevelDecoration::GetGlobalEvent
int GetGlobalEvent()
Definition: Decoration.cpp:16
DecorationDesc::uColoredLightGreen
uint8_t uColoredLightGreen
Definition: DecorationList.h:51
pDecorationList
struct DecorationList * pDecorationList
Definition: DecorationList.cpp:11