World of Might and Magic  0.2.0
Open reimplementation of Might and Magic 6 7 8 game engine
Указатель Классы Пространства имен Файлы Функции Переменные Определения типов Перечисления Элементы перечислений Друзья Группы Страницы
Файл Chest.h

См. исходные тексты.

Классы

struct  ChestDesc
 
class  ChestList
 
struct  Chest
 

Перечисления

enum  CHEST_FLAGS { CHEST_TRAPPED = 0x1, CHEST_ITEMS_PLACED = 0x2, CHEST_OPENED = 0x4 }
 

Функции

void RemoveItemAtChestIndex (int index)
 
void GenerateItemsInChest ()
 
char * ChestsSerialize (char *pData)
 
char * ChestsDeserialize (char *pData)
 

Переменные

ChestListpChestList
 
std::vector< ChestvChests
 

Перечисления

◆ CHEST_FLAGS

Элементы перечислений
CHEST_TRAPPED 
CHEST_ITEMS_PLACED 
CHEST_OPENED 

См. определение в файле Chest.h строка 8

8  {
9  CHEST_TRAPPED = 0x1,
10  CHEST_ITEMS_PLACED = 0x2,
11  CHEST_OPENED = 0x4,
12 };

Функции

◆ RemoveItemAtChestIndex()

void RemoveItemAtChestIndex ( int  index)

См. определение в файле Chest.cpp строка 513

513  {
515 
516  int chestindex = chest->pInventoryIndices[index];
517  ItemGen *item_in_slot = &chest->igChestItems[chestindex - 1];
518 
519  auto img = assets->GetImage_ColorKey(item_in_slot->GetIconName(), 0x7FF);
520  unsigned int slot_width = GetSizeInInventorySlots(img->GetWidth());
521  unsigned int slot_height = GetSizeInInventorySlots(img->GetHeight());
522 
523  int chestwidth = pChestWidthsByType[chest->uChestBitmapID];
524 
525  item_in_slot->Reset();
526 
527  if (slot_width > 0) {
528  // blank inventory indices - memset was eratic??
529  for (unsigned int x = 0; x < slot_width; x++) {
530  for (unsigned int y = 0; y < slot_height; y++) {
531  chest->pInventoryIndices[y * chestwidth + x + index] = 0;
532  }
533  }
534  }
535 }

Перекрестные ссылки assets, ItemGen::GetIconName(), AssetsManager::GetImage_ColorKey(), GetSizeInInventorySlots(), Chest::igChestItems, GUIWindow::par1C, pChestWidthsByType, pGUIWindow_CurrentMenu, Chest::pInventoryIndices, ItemGen::Reset(), Chest::uChestBitmapID и vChests.

Используется в Chest::GrabItem() и Chest::OnChestLeftClick().

+ Граф вызовов:
+ Граф вызова функции:

◆ GenerateItemsInChest()

void GenerateItemsInChest ( )

См. определение в файле Chest.cpp строка 631

631  {
632  unsigned int mapType = pMapStats->GetMapInfo(pCurrentMapName);
633  MapInfo *currMapInfo = &pMapStats->pInfos[mapType];
634  for (int i = 1; i < 20; ++i) {
635  for (int j = 0; j < 140; ++j) {
636  ItemGen *currItem = &vChests[i].igChestItems[j];
637  if (currItem->uItemID < 0) {
638  int additionaItemCount = rand() % 5; // additional items in chect
639  additionaItemCount++; // + 1 because it's the item at pChests[i].igChestItems[j] and the additional ones
640  int treasureLevelBot = byte_4E8168[abs(currItem->uItemID) - 1][2 * currMapInfo->Treasure_prob];
641  int treasureLevelTop = byte_4E8168[abs(currItem->uItemID) - 1][2 * currMapInfo->Treasure_prob + 1];
642  int treasureLevelRange = treasureLevelTop - treasureLevelBot + 1;
643  int resultTreasureLevel = treasureLevelBot + rand() % treasureLevelRange; // treasure level
644  if (resultTreasureLevel < 7) {
645  for (int k = 0; k < additionaItemCount; k++) {
646  int whatToGenerateProb = rand() % 100;
647  if (whatToGenerateProb < 20) {
648  currItem->Reset();
649  } else if (whatToGenerateProb < 60) { // generate gold
650  int goldAmount = 0;
651  currItem->Reset();
652  switch (resultTreasureLevel) {
653  case 1:
654  goldAmount = rand() % 51 + 50;
655  currItem->uItemID = ITEM_GOLD_SMALL;
656  break;
657  case 2:
658  goldAmount = rand() % 101 + 100;
659  currItem->uItemID = ITEM_GOLD_SMALL;
660  break;
661  case 3:
662  goldAmount = rand() % 301 + 200;
663  currItem->uItemID = ITEM_GOLD_MEDIUM;
664  break;
665  case 4:
666  goldAmount = rand() % 501 + 500;
667  currItem->uItemID = ITEM_GOLD_MEDIUM;
668  break;
669  case 5:
670  goldAmount = rand() % 1001 + 1000;
671  currItem->uItemID = ITEM_GOLD_LARGE;
672  break;
673  case 6:
674  goldAmount = rand() % 3001 + 2000;
675  currItem->uItemID = ITEM_GOLD_LARGE;
676  break;
677  }
678  currItem->SetIdentified();
679  currItem->special_enchantment = (ITEM_ENCHANTMENT)goldAmount;
680  } else {
681  pItemsTable->GenerateItem(resultTreasureLevel, 0, currItem);
682  }
683 
684  for (int m = 0; m < 140; m++) {
685  if (vChests[i].igChestItems[m].uItemID == ITEM_NULL) {
686  currItem = &vChests[i].igChestItems[m];
687  break;
688  }
689  }
690  }
691  } else {
692  currItem->GenerateArtifact();
693  }
694  }
695  }
696  }
697 }

Перекрестные ссылки byte_4E8168, ItemGen::GenerateArtifact(), ItemsTable::GenerateItem(), MapStats::GetMapInfo(), ITEM_GOLD_LARGE, ITEM_GOLD_MEDIUM, ITEM_GOLD_SMALL, ITEM_NULL, pCurrentMapName, MapStats::pInfos, pItemsTable, pMapStats, ItemGen::Reset(), ItemGen::SetIdentified(), ItemGen::special_enchantment, MapInfo::Treasure_prob, ItemGen::uItemID и vChests.

Используется в Engine::_461103_load_level_sub().

+ Граф вызовов:
+ Граф вызова функции:

◆ ChestsSerialize()

char* ChestsSerialize ( char *  pData)

См. определение в файле Chest.cpp строка 486

486  {
487  static_assert(sizeof(Chest) == 5324, "Wrong type size");
488 
489  uint32_t uNumChests = vChests.size();
490  memcpy(pData, &uNumChests, 4);
491  pData += 4;
492  Chest *pChests = (Chest*)pData;
493  for (int i = 0; i < uNumChests; i++) {
494  memcpy(pChests + i, &vChests[i], sizeof(Chest));
495  }
496  pData += sizeof(Chest) * uNumChests;
497  return pData;
498 }

Перекрестные ссылки vChests.

Используется в SaveGame().

+ Граф вызова функции:

◆ ChestsDeserialize()

char* ChestsDeserialize ( char *  pData)

См. определение в файле Chest.cpp строка 500

500  {
501  vChests.clear();
502  uint32_t uNumChests = 0;
503  memcpy(&uNumChests, pData, 4);
504  pData += 4;
505  Chest *pChests = (Chest*)pData;
506  for (int i = 0; i < uNumChests; i++) {
507  vChests.push_back(pChests[i]);
508  }
509  pData += uNumChests * sizeof(Chest);
510  return pData;
511 }

Перекрестные ссылки vChests.

Используется в OutdoorLocation::Load() и IndoorLocation::Load().

+ Граф вызова функции:

Переменные

◆ pChestList

ChestList* pChestList

См. определение в файле Chest.cpp строка 38

Используется в Engine::MM7_Initialize() и GUIWindow_Chest::Update().

◆ vChests

MapStats::pInfos
MapInfo pInfos[77]
Definition: MapInfo.h:79
Chest::igChestItems
struct ItemGen igChestItems[140]
Definition: Chest.h:60
ItemGen::SetIdentified
void SetIdentified()
Definition: Items.h:307
pGUIWindow_CurrentMenu
GUIWindow * pGUIWindow_CurrentMenu
Definition: GUIWindow.cpp:54
MapStats::GetMapInfo
MAP_TYPE GetMapInfo(const String &Str2)
Definition: MapInfo.cpp:225
GetSizeInInventorySlots
unsigned int GetSizeInInventorySlots(unsigned int uNumPixels)
Definition: UICharacter.cpp:919
ItemGen::Reset
void Reset()
Definition: Items.cpp:133
index
GLuint index
Definition: SDL_opengl_glext.h:663
pChestWidthsByType
int pChestWidthsByType[8]
Definition: UIChest.cpp:17
pMapStats
struct MapStats * pMapStats
Definition: mm7_data.cpp:20
pItemsTable
struct ItemsTable * pItemsTable
Definition: Items.cpp:37
y
EGLSurface EGLint EGLint y
Definition: SDL_egl.h:1596
ItemGen::special_enchantment
ITEM_ENCHANTMENT special_enchantment
Definition: Items.h:330
x
EGLSurface EGLint x
Definition: SDL_egl.h:1596
ItemsTable::GenerateItem
void GenerateItem(int treasure_level, unsigned int uTreasureType, ItemGen *pItem)
Definition: Items.cpp:680
ITEM_GOLD_LARGE
@ ITEM_GOLD_LARGE
Definition: Items.h:99
ItemGen::GetIconName
char * GetIconName()
Definition: Items.cpp:1521
ItemGen::uItemID
int uItemID
Definition: Items.h:326
AssetsManager::GetImage_ColorKey
Texture * GetImage_ColorKey(const String &name, uint16_t colorkey)
Definition: AssetsManager.cpp:34
ITEM_GOLD_SMALL
@ ITEM_GOLD_SMALL
Definition: Items.h:97
Chest::uChestBitmapID
uint16_t uChestBitmapID
Definition: Chest.h:58
MapInfo
Definition: MapInfo.h:35
ITEM_ENCHANTMENT
ITEM_ENCHANTMENT
Definition: Items.h:38
pCurrentMapName
String pCurrentMapName
Definition: mm7_data.cpp:712
byte_4E8168
std::array< std::array< char, 14 >, 7 > byte_4E8168
Definition: Items.cpp:25
vChests
std::vector< Chest > vChests
Definition: Chest.cpp:39
CHEST_ITEMS_PLACED
@ CHEST_ITEMS_PLACED
Definition: Chest.h:10
ITEM_NULL
@ ITEM_NULL
Definition: Items.h:74
assets
AssetsManager * assets
Definition: AssetsManager.cpp:12
GUIWindow::par1C
unsigned int par1C
Definition: GUIWindow.h:477
ItemGen::GenerateArtifact
bool GenerateArtifact()
Definition: Items.cpp:978
m
const GLfloat * m
Definition: SDL_opengl_glext.h:6095
CHEST_TRAPPED
@ CHEST_TRAPPED
Definition: Chest.h:9
Chest
Definition: Chest.h:35
Chest::pInventoryIndices
int16_t pInventoryIndices[140]
Definition: Chest.h:61
ItemGen
Definition: Items.h:263
CHEST_OPENED
@ CHEST_OPENED
Definition: Chest.h:11
MapInfo::Treasure_prob
char Treasure_prob
Definition: MapInfo.h:52
uint32_t
unsigned __int32 uint32_t
Definition: SDL_config.h:39
ITEM_GOLD_MEDIUM
@ ITEM_GOLD_MEDIUM
Definition: Items.h:98
img
GLint GLvoid * img
Definition: SDL_opengl.h:1980