60 assert(uChestID < 20);
61 if ((uChestID < 0) && (uChestID >= 20))
return false;
69 if (chest->
Trapped() && pMapID) {
76 int pRandom = rand() % 4;
110 length_vector = sqrt((dir_x * dir_x) + (dir_y * dir_y) + (dir_z * dir_z));
111 if (length_vector <= 1.0) {
112 *(
float*)&sRotX = 0.0;
113 *(
float*)&sRotY = 0.0;
115 sRotY = (
int64_t)sqrt(dir_x * dir_x + dir_y * dir_y);
121 if (length_vector < 256.0)
122 pDepth = (
int64_t)length_vector / 4;
126 Vec3_int_::Rotate(pDepth, sRotX, sRotY,
v, &pOut.x, &pOut.z,
129 pOut.z, pOut.y, 0, 1, 0, 48, 0);
136 pSpellObject.
uType = pSpriteID[pRandom];
148 pSpellObject.
Create(0, 0, 0, 0);
166 if (flag_shout ==
true) {
177 unsigned int pX = pt.
x;
178 unsigned int pY = pt.
y;
187 int invMatrixIndex = inventoryXCoord + (chestheight * inventoryYCoord);
189 if (inventoryYCoord >= 0 && inventoryYCoord < chestheight &&
190 inventoryXCoord >= 0 && inventoryXCoord < chestwidth) {
192 if (chestindex < 0) {
193 invMatrixIndex = (-(chestindex + 1));
198 int itemindex = chestindex - 1;
274 Assert(slot_height > 0 && slot_width > 0,
"Items should have nonzero dimensions");
275 if ((slot_width + test_cell_position % chest_cell_width <= chest_cell_width) &&
276 (slot_height + test_cell_position / chest_cell_width <= chest_cell_heght)) {
277 for (
unsigned int x = 0;
x < slot_width;
x++) {
278 for (
unsigned int y = 0;
y < slot_height;
y++) {
295 if (max_items <= 0) {
300 if (item_count >= max_items) {
317 if (item_in_chest_count == -1)
return 0;
319 if (position != -1) {
327 if (position == -1) {
328 for (
int _i = 0; _i < max_size; _i++) {
335 if (test_pos == max_size) {
347 Assert(slot_height > 0 && slot_width > 0,
"Items should have nonzero dimensions");
350 for (
unsigned int x = 0;
x < slot_width;
x++) {
351 for (
unsigned int y = 0;
y < slot_height;
y++) {
352 vChests[uChestID].pInventoryIndices[
y * chest_width +
x + test_pos] = (-1 - test_pos);
356 vChests[uChestID].pInventoryIndices[test_pos] = item_in_chest_count + 1;
359 return (test_pos + 1);
363 int uItemID =
vChests[uChestID].igChestItems[item_at_cell].uItemID;
365 if (uItemID >= 135 && uItemID <= 159 &&
367 int v6 = rand() % 21 + 10;
368 vChests[uChestID].igChestItems[item_at_cell].uNumCharges = v6;
369 vChests[uChestID].igChestItems[item_at_cell].uMaxCharges = v6;
375 if (v9 < 14) v9 = 14;
376 unsigned int texture_cell_width = ((v9 - 14) >> 5) + 1;
377 int v10 =
img->GetHeight();
378 if (v10 < 14) v10 = 14;
379 int textute_cell_height = ((v10 - 14) >> 5) + 1;
382 int chest_cell_row_pos = 0;
383 for (
int i = 0; i < textute_cell_height; ++i) {
384 for (
int j = 0; j < texture_cell_width; ++j)
386 chest_cell_row_pos += chest_cell_width;
388 vChests[uChestID].pInventoryIndices[put_cell_pos] = item_at_cell + 1;
392 char chest_cells_map[144];
394 render->ClearZBuffer(0, 479);
397 memset(chest_cells_map, 0, 144);
399 for (
int items_counter = 0; items_counter < uChestArea; ++items_counter) {
401 int random_chest_pos = 0;
403 random_chest_pos = (
uint8_t)rand();
404 }
while (random_chest_pos >= uChestArea);
406 while (chest_cells_map[random_chest_pos]) {
408 if (random_chest_pos == uChestArea) random_chest_pos = 0;
410 chest_cells_map[random_chest_pos] = items_counter;
413 for (
int items_counter = 0; items_counter < uChestArea; ++items_counter) {
414 int chest_item_id =
vChests[uChestID].igChestItems[items_counter].uItemID;
416 int test_position = 0;
419 if (test_position >= uChestArea)
break;
421 if (test_position < uChestArea) {
424 vChests[uChestID].igChestItems[items_counter].SetIdentified();
429 vChests[uChestID].SetInitialized(
true);
433 if (uChestID >= 0 && uChestID <= 19) {
435 vChests[uChestID].uFlags |= uFlag;
437 vChests[uChestID].uFlags &= ~uFlag;
441 #pragma pack(push, 1)
458 static_assert(
sizeof(
ChestDesc_mm7) == 36,
"Wrong type size");
460 unsigned int num_mm6_chests = data_mm6 ? *(
uint32_t*)data_mm6 : 0;
461 unsigned int num_mm7_chests = data_mm7 ? *(
uint32_t*)data_mm7 : 0;
462 unsigned int num_mm8_chests = data_mm8 ? *(
uint32_t*)data_mm8 : 0;
464 assert(num_mm7_chests);
465 assert(!num_mm8_chests);
468 for (
int i = 0; i < num_mm7_chests; i++) {
474 for (
int i = 0; i < num_mm6_chests; i++) {
480 for (
int i = 0; i < num_mm8_chests; i++) {
487 static_assert(
sizeof(
Chest) == 5324,
"Wrong type size");
490 memcpy(pData, &uNumChests, 4);
493 for (
int i = 0; i < uNumChests; i++) {
496 pData +=
sizeof(
Chest) * uNumChests;
503 memcpy(&uNumChests, pData, 4);
506 for (
int i = 0; i < uNumChests; i++) {
509 pData += uNumChests *
sizeof(
Chest);
525 item_in_slot->
Reset();
527 if (slot_width > 0) {
529 for (
unsigned int x = 0;
x < slot_width;
x++) {
530 for (
unsigned int y = 0;
y < slot_height;
y++) {
549 int invMatrixIndex = inventoryXCoord + (chestheight * inventoryYCoord);
551 if (inventoryYCoord >= 0 && inventoryYCoord < chestheight &&
552 inventoryXCoord >= 0 && inventoryXCoord < chestwidth) {
559 if (chestindex < 0) {
560 invMatrixIndex = (-(chestindex + 1));
565 int itemindex = chestindex - 1;
593 for (
int loop = 0; loop < 140; loop++) {
595 if (chestindex <= 0)
continue;
597 int itemindex = chestindex - 1;
621 if (grabcount > 1 || goldcount > 1) {
623 sprintf(out,
"You found %d item(s) and %d Gold!", grabcount, goldamount);
626 if (grabcount == 0 && goldcount == 0) {
634 for (
int i = 1; i < 20; ++i) {
635 for (
int j = 0; j < 140; ++j) {
638 int additionaItemCount = rand() % 5;
639 additionaItemCount++;
642 int treasureLevelRange = treasureLevelTop - treasureLevelBot + 1;
643 int resultTreasureLevel = treasureLevelBot + rand() % treasureLevelRange;
644 if (resultTreasureLevel < 7) {
645 for (
int k = 0; k < additionaItemCount; k++) {
646 int whatToGenerateProb = rand() % 100;
647 if (whatToGenerateProb < 20) {
649 }
else if (whatToGenerateProb < 60) {
652 switch (resultTreasureLevel) {
654 goldAmount = rand() % 51 + 50;
658 goldAmount = rand() % 101 + 100;
662 goldAmount = rand() % 301 + 200;
666 goldAmount = rand() % 501 + 500;
670 goldAmount = rand() % 1001 + 1000;
674 goldAmount = rand() % 3001 + 2000;
684 for (
int m = 0;
m < 140;
m++) {
686 currItem = &
vChests[i].igChestItems[
m];