annotate Engine/Objects/Chest.cpp @ 2516:56b6d74ce716

.
author Ritor1
date Thu, 02 Oct 2014 22:01:06 +0600
parents 9b96a51011fb
children c7264ab7132f
rev   line source
2497
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
1 #define _CRTDBG_MAP_ALLOC
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
2 #include <stdlib.h>
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
3 #include <crtdbg.h>
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
4
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
5 #define _CRT_SECURE_NO_WARNINGS
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
6 #include <stdio.h>
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
7
2499
68cdef6879a0 engine folder
Ritor1
parents: 2497
diff changeset
8 #include "../ErrorHandling.h"
2497
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
9
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
10 #include "Items.h"
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
11 #include "Chest.h"
2499
68cdef6879a0 engine folder
Ritor1
parents: 2497
diff changeset
12 #include "../Tables/FrameTableInc.h"
68cdef6879a0 engine folder
Ritor1
parents: 2497
diff changeset
13 #include "../LOD.h"
68cdef6879a0 engine folder
Ritor1
parents: 2497
diff changeset
14 #include "../MapInfo.h"
2497
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
15 #include "Actor.h"
2499
68cdef6879a0 engine folder
Ritor1
parents: 2497
diff changeset
16 #include "../Graphics/Outdoor.h"
68cdef6879a0 engine folder
Ritor1
parents: 2497
diff changeset
17 #include "../Graphics/DecorationList.h"
68cdef6879a0 engine folder
Ritor1
parents: 2497
diff changeset
18 #include "../Party.h"
2502
a77c34acdbc9 Media folder
Ritor1
parents: 2499
diff changeset
19 #include "Media/Audio/AudioPlayer.h"
2499
68cdef6879a0 engine folder
Ritor1
parents: 2497
diff changeset
20 #include "../OurMath.h"
68cdef6879a0 engine folder
Ritor1
parents: 2497
diff changeset
21 #include "../Texts.h"
2497
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
22 #include "ObjectList.h"
2502
a77c34acdbc9 Media folder
Ritor1
parents: 2499
diff changeset
23 #include "GUI/GUIWindow.h"
2499
68cdef6879a0 engine folder
Ritor1
parents: 2497
diff changeset
24 #include "../Timer.h"
2497
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
25
2499
68cdef6879a0 engine folder
Ritor1
parents: 2497
diff changeset
26 #include "../MM7.h"
2497
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
27 #include "SpriteObject.h"
2502
a77c34acdbc9 Media folder
Ritor1
parents: 2499
diff changeset
28 #include "IO/Mouse.h"
2499
68cdef6879a0 engine folder
Ritor1
parents: 2497
diff changeset
29 #include "../Graphics/Viewport.h"
68cdef6879a0 engine folder
Ritor1
parents: 2497
diff changeset
30 #include "../Graphics/Level/Decoration.h"
2497
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
31
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
32 size_t uNumChests; // idb
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
33 struct ChestList *pChestList;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
34 std::array<Chest, 20> pChests;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
35
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
36
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
37 const int pChestPixelOffsetX[8] = {42, 18, 18, 42, 42, 42, 18, 42};
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
38 const int pChestPixelOffsetY[8] = {34, 30, 30, 34, 34, 34, 30, 34};
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
39 const int pChestWidthsByType[8] = {9, 9, 9, 9, 9, 9, 9, 9};
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
40 const int pChestHeightsByType[8] = {9, 9, 9, 9, 9, 9, 9, 9};
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
41
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
42
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
43 //----- (0042041E) --------------------------------------------------------
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
44 bool Chest::Open( signed int uChestID )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
45 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
46 unsigned int pMapID; // eax@8
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
47 int pRandom; // edx@16
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
48 int v6; // eax@16
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
49 ODMFace *pODMFace; // eax@19
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
50 BLVFace *pBLVFace; // eax@20
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
51 int pObjectX; // ebx@21
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
52 int pObjectZ; // edi@21
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
53 double dir_x; // st7@23
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
54 double dir_y; // st6@23
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
55 double length_vector; // st7@23
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
56 int pDepth; // ecx@26
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
57 Vec3_int_ v; // ST4C_12@28
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
58 bool flag_shout; // edi@28
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
59 int pSpriteID[4]; // [sp+84h] [bp-40h]@16
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
60 Vec3_int_ pOut; // [sp+A0h] [bp-24h]@28
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
61 int pObjectY; // [sp+B0h] [bp-14h]@21
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
62 int sRotX; // [sp+B4h] [bp-10h]@23
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
63 float dir_z; // [sp+BCh] [bp-8h]@23
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
64 int sRotY; // [sp+C0h] [bp-4h]@8
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
65 SpriteObject pSpellObject; // [sp+14h] [bp-B0h]@28
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
66
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
67 assert( uChestID < 20 );
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
68 if ( ( uChestID < 0 ) && ( uChestID >= 20 ) )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
69 return false;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
70 Chest* chest = &pChests[uChestID];
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
71
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
72 ++pIcons_LOD->uTexturePacksCount;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
73 if (!pIcons_LOD->uNumPrevLoadedFiles)
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
74 pIcons_LOD->uNumPrevLoadedFiles = pIcons_LOD->uNumLoadedFiles;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
75
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
76 if (!chest->Initialized())
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
77 Chest::PlaceItems(uChestID);
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
78
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
79 if ( !uActiveCharacter )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
80 return false;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
81 flag_shout = false;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
82 pMapID = pMapStats->GetMapInfo(pCurrentMapName);
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
83 if ( chest->Trapped() && pMapID )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
84 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
85 if ( pPlayers[uActiveCharacter]->GetDisarmTrap() < 2 * pMapStats->pInfos[pMapID].LockX5 )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
86 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
87 pSpriteID[0] = 811;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
88 pSpriteID[1] = 812;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
89 pSpriteID[2] = 813;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
90 pSpriteID[3] = 814;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
91 pRandom = rand() % 4;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
92 v6 = PID_ID(EvtTargetObj);
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
93 if ( PID_TYPE(EvtTargetObj) == OBJECT_Decoration)
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
94 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
95 pObjectX = pLevelDecorations[v6].vPosition.x;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
96 pObjectY = pLevelDecorations[v6].vPosition.y;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
97 pObjectZ = pLevelDecorations[v6].vPosition.z + ( pDecorationList->pDecorations[pLevelDecorations[v6].uDecorationDescID].uDecorationHeight / 2 );
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
98 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
99 if ( PID_TYPE(EvtTargetObj) == OBJECT_BModel)
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
100 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
101 if ( uCurrentlyLoadedLevelType == LEVEL_Outdoor)
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
102 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
103 pODMFace = &pOutdoor->pBModels[EvtTargetObj >> 9].pFaces[(EvtTargetObj >> 3) & 0x3F];
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
104 pObjectX = ( pODMFace->pBoundingBox.x1 + pODMFace->pBoundingBox.x2 ) / 2;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
105 pObjectY = ( pODMFace->pBoundingBox.y1 + pODMFace->pBoundingBox.y2 ) / 2;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
106 pObjectZ = ( pODMFace->pBoundingBox.z1 + pODMFace->pBoundingBox.z2 ) / 2;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
107 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
108 else//Indoor
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
109 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
110 pBLVFace = &pIndoor->pFaces[v6];
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
111 pObjectX = ( pBLVFace->pBounding.x1 + pBLVFace->pBounding.x2 ) / 2;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
112 pObjectY = ( pBLVFace->pBounding.y1 + pBLVFace->pBounding.y2 ) / 2;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
113 pObjectZ = ( pBLVFace->pBounding.z1 + pBLVFace->pBounding.z2 ) / 2;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
114 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
115 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
116 dir_x = (double)pParty->vPosition.x - (double)pObjectX;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
117 dir_y = (double)pParty->vPosition.y - (double)pObjectY;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
118 dir_z = ( (double)pParty->sEyelevel + (double)pParty->vPosition.z ) - (double)pObjectZ;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
119 length_vector = sqrt( (dir_x * dir_x) + (dir_y * dir_y) + (dir_z * dir_z) );
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
120 if ( length_vector <= 1.0 )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
121 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
122 *(float *)&sRotX = 0.0;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
123 *(float *)&sRotY = 0.0;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
124 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
125 else
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
126 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
127 sRotY = (signed __int64)sqrt(dir_x * dir_x + dir_y * dir_y);
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
128 sRotX = stru_5C6E00->Atan2((signed __int64)dir_x, (signed __int64)dir_y);
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
129 sRotY = stru_5C6E00->Atan2(dir_y * dir_y, (signed __int64)dir_z);
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
130 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
131 pDepth = 256;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
132 if ( length_vector < 256.0 )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
133 pDepth = (signed __int64)length_vector / 4;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
134 v.x = pObjectX;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
135 v.y = pObjectY;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
136 v.z = pObjectZ;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
137 Vec3_int_::Rotate(pDepth, sRotX, sRotY, v, &pOut.x, &pOut.z, &pOut.y);
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
138 SpriteObject::sub_42F7EB_DropItemAt(pSpriteID[pRandom], pOut.x, pOut.z, pOut.y, 0, 1, 0, 48, 0);
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
139
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
140 pSpellObject.stru_24.Reset();
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
141 pSpellObject.spell_skill = 0;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
142 pSpellObject.spell_level = 0;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
143 pSpellObject.spell_id = 0;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
144 pSpellObject.field_54 = 0;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
145 pSpellObject.uType = pSpriteID[pRandom];
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
146 pSpellObject.uObjectDescID = 0;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
147 if ( pObjectList->uNumObjects )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
148 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
149 for ( uint i = 0; i < (signed int)pObjectList->uNumObjects; ++i )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
150 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
151 if ( pSpriteID[pRandom] == pObjectList->pObjects[i].uObjectID )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
152 pSpellObject.uObjectDescID = i;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
153 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
154 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
155 pSpellObject.vPosition.y = pOut.z;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
156 pSpellObject.vPosition.x = pOut.x;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
157 pSpellObject.vPosition.z = pOut.y;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
158 pSpellObject.uSoundID = 0;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
159 pSpellObject.uAttributes = 48;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
160 pSpellObject.uSectorID = pIndoor->GetSector(pOut.x, pOut.z, pOut.y);
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
161 pSpellObject.uSpriteFrameID = 0;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
162 pSpellObject.spell_caster_pid = 0;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
163 pSpellObject.spell_target_pid = 0;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
164 pSpellObject.uFacing = 0;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
165 pSpellObject.Create(0, 0, 0, 0);
2506
9b96a51011fb for sound
Ritor1
parents: 2502
diff changeset
166 pAudioPlayer->PlaySound(SOUND_Explosion, 0, 0, -1, 0, 0, 0, 0);
2497
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
167 pSpellObject.ExplosionTraps();
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
168 chest->uFlags &= 0xFEu;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
169 if ( uActiveCharacter && !_A750D8_player_speech_timer && !OpenedTelekinesis )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
170 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
171 _A750D8_player_speech_timer = 256i64;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
172 PlayerSpeechID = SPEECH_5;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
173 uSpeakingCharacter = uActiveCharacter;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
174 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
175 pIcons_LOD->RemoveTexturesPackFromTextureList();
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
176 OpenedTelekinesis = false;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
177 return false;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
178 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
179 chest->uFlags &= 0xFEu;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
180 flag_shout = true;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
181 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
182 pAudioPlayer->StopChannels(-1, -1);
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
183 pAudioPlayer->PlaySound(SOUND_OpenChest, 0, 0, -1, 0, 0, 0, 0);
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
184 if ( flag_shout == true )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
185 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
186 if ( !OpenedTelekinesis )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
187 pPlayers[uActiveCharacter]->PlaySound(SPEECH_4, 0);
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
188 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
189 OpenedTelekinesis = false;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
190 pChestWindow = pGUIWindow_CurrentMenu = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_Chest, uChestID, 0);
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
191 pBtn_ExitCancel = pChestWindow->CreateButton(471, 445, 169, 35, 1, 0, UIMSG_Escape, 0, 0, pGlobalTXT_LocalizationStrings[79], pIcons_LOD->GetTexture(uExitCancelTextureId), 0);// Exit
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
192 pChestWindow->CreateButton( 7, 8, 460, 343, 1, 0, UIMSG_CHEST_ClickItem, 0, 0, "", 0);
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
193 pCurrentScreen = SCREEN_CHEST;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
194 pEventTimer->Pause();
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
195 return true;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
196 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
197
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
198 //----- (0042038D) --------------------------------------------------------
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
199 void Chest::ChestUI_WritePointedObjectStatusString()
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
200 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
201 int v1; // ecx@2
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
202 POINT cursor; // [sp+8h] [bp-8h]@1
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
203
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
204 pMouse->GetCursorPos(&cursor);
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
205 if ( cursor.y < 350 )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
206 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
207 v1 = pRenderer->pActiveZBuffer[cursor.x + pSRZBufferLineOffsets[cursor.y]];
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
208 if ( v1 != 0 && v1 != -65536 )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
209 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
210 if ( v1 )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
211 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
212 ItemGen* item = &pChests[pChestWindow->par1C].igChestItems[pChests[pChestWindow->par1C].pInventoryIndices[(v1 & 0xFFFF) - 1] - 1];
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
213 GameUI_SetFooterString(item->GetDisplayName());
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
214 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
215 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
216 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
217 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
218
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
219 //----- (0042092D) --------------------------------------------------------
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
220 void Chest::DrawChestUI(signed int uChestID)
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
221 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
222
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
223 int chestBitmapId; // eax@1
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
224 unsigned int v5; // eax@1
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
225 int chest_item_index; // ecx@3
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
226 unsigned int item_texture_id; // eax@4
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
227 Texture *item_texture; // esi@4
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
228 signed int itemPixelWidth; // ecx@4
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
229 signed int itemPixelHeght; // edx@4
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
230 // signed int v11; // eax@4
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
231 int v12; // eax@6
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
232 int v13; // eax@6
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
233 unsigned int itemPixelPosX; // ST34_4@8
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
234 int itemPixelPosY; // edi@8
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
235 int *v16; // [sp+Ch] [bp-28h]@1
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
236 // int v17; // [sp+10h] [bp-24h]@4
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
237 int chest_offs_y; // [sp+14h] [bp-20h]@1
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
238 signed int chestHeghtCells; // [sp+18h] [bp-1Ch]@1
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
239 int chest_offs_x; // [sp+1Ch] [bp-18h]@1
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
240 signed int chestWidthCells; // [sp+20h] [bp-14h]@1
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
241 signed int item_counter; // [sp+30h] [bp-4h]@1
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
242
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
243 v16 = pRenderer->pActiveZBuffer;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
244 pRenderer->ClearZBuffer(0, 479);
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
245 chestBitmapId = pChests[uChestID].uChestBitmapID;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
246 chest_offs_x = pChestPixelOffsetX[chestBitmapId];
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
247 chest_offs_y = pChestPixelOffsetY[chestBitmapId];
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
248 chestWidthCells = pChestWidthsByType[chestBitmapId];
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
249 chestHeghtCells = pChestHeightsByType[chestBitmapId];
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
250 sprintfex(pTmpBuf.data(), "chest%02d", pChestList->pChests[chestBitmapId].uTextureID);
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
251 v5 = pIcons_LOD->LoadTexture(pTmpBuf.data(), TEXTURE_16BIT_PALETTE);
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
252 pRenderer->DrawTextureIndexed(8u, 8u, pIcons_LOD->GetTexture(v5));
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
253
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
254 for (item_counter = 0; item_counter < chestWidthCells * chestHeghtCells; ++item_counter)
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
255 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
256 chest_item_index = pChests[uChestID].pInventoryIndices[item_counter];
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
257 if ( chest_item_index > 0 )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
258 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
259 item_texture_id = pIcons_LOD->LoadTexture(
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
260 //pItemsTable->pItems[*(int *)((char *)&pOtherOverlayList->pOverlays[49].field_4 + 36 * v6 + v3 * 5324)].pIconName,
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
261 pChests[uChestID].igChestItems[chest_item_index - 1].GetIconName(), TEXTURE_16BIT_PALETTE);
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
262 item_texture = pIcons_LOD->GetTexture(item_texture_id);
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
263 itemPixelWidth = item_texture->uTextureWidth;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
264 itemPixelHeght = item_texture->uTextureHeight;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
265 if ( itemPixelWidth < 14 )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
266 itemPixelWidth = 14;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
267 v12 = itemPixelWidth - 14;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
268 v12 = v12 & 0xFFFFFFE0;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
269 v13 = v12 + 32;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
270 if ( itemPixelHeght < 14 )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
271 itemPixelHeght = 14;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
272 itemPixelPosX = chest_offs_x + 32 * (item_counter % chestWidthCells) + ((signed int)(v13 - itemPixelWidth)/2);
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
273 itemPixelPosY = chest_offs_y + 32 * (item_counter / chestHeghtCells) +
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
274 ((signed int)(((itemPixelHeght - 14) & 0xFFFFFFE0) + 32- item_texture->uTextureHeight ) /2);
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
275 pRenderer->DrawTextureTransparent( itemPixelPosX, itemPixelPosY, item_texture);
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
276 ZBuffer_DoFill2(&v16[itemPixelPosX + pSRZBufferLineOffsets[itemPixelPosY]], item_texture, item_counter + 1);
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
277 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
278 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
279 pRenderer->DrawTextureIndexed(pBtn_ExitCancel->uX, pBtn_ExitCancel->uY, pIcons_LOD->GetTexture(uExitCancelTextureId));
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
280 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
281
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
282
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
283 //----- (0041FE71) --------------------------------------------------------
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
284 bool Chest::CanPlaceItemAt( signed int test_cell_position, int item_id, signed int uChestID )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
285 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
286 // int v3; // eax@1
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
287 unsigned int item_texture_id; // eax@1
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
288 Texture *item_texture; // ecx@1
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
289 signed int v6; // eax@1
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
290 // signed int v7; // edi@3
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
291 signed int v8; // eax@3
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
292 int texture_cell_width; // edi@3
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
293 int texture_cell_height; // ebx@5
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
294 int _row; // esi@9
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
295 int _cell_rows; // edx@10
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
296 int _column; // ecx@11
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
297 // char *v14; // eax@12
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
298 int chest_cell_heght; // [sp+Ch] [bp-Ch]@1
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
299 // signed int v17; // [sp+10h] [bp-8h]@1
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
300 signed int chest_cell_width; // [sp+14h] [bp-4h]@1
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
301
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
302 chest_cell_heght = pChestHeightsByType[pChests[uChestID].uChestBitmapID];
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
303 chest_cell_width = pChestWidthsByType[pChests[uChestID].uChestBitmapID];
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
304 item_texture_id = pIcons_LOD->LoadTexture(pItemsTable->pItems[item_id].pIconName, TEXTURE_16BIT_PALETTE);
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
305 item_texture = pIcons_LOD->GetTexture(item_texture_id);
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
306 v6 = item_texture->uTextureWidth;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
307 if ( v6 < 14 )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
308 v6 = 14;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
309 texture_cell_width = ((v6 - 14) >> 5) + 1;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
310 v8 = item_texture->uTextureHeight;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
311 if ( v8 < 14 )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
312 v8 = 14;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
313 texture_cell_height = ((v8 - 14) >> 5) + 1;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
314 if ( !areWeLoadingTexture )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
315 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
316 item_texture->Release();
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
317 pIcons_LOD->SyncLoadedFilesCount();
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
318 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
319 if ( (texture_cell_width + test_cell_position % chest_cell_width <= chest_cell_width) &&
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
320 (texture_cell_height + test_cell_position / chest_cell_width <= chest_cell_heght) )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
321 { //we not put over borders
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
322 _row = 0;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
323 if ( texture_cell_height <= 0 )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
324 return true;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
325 _cell_rows = 0;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
326 while ( 1 )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
327 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
328 _column = 0;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
329 if ( texture_cell_width > 0 )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
330 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
331 while ( pChests[uChestID].pInventoryIndices[test_cell_position + _cell_rows+_column]==0)
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
332 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
333 ++_column;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
334 if ( _column >= texture_cell_width )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
335 break;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
336 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
337 if (pChests[uChestID].pInventoryIndices[test_cell_position + _cell_rows+_column]!=0)
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
338 return false;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
339 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
340 _cell_rows += chest_cell_width;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
341 ++_row;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
342 if ( _row >= texture_cell_height )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
343 return true;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
344 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
345
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
346 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
347 return false;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
348 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
349 // 506128: using guessed type int areWeLoadingTexture;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
350
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
351 //----- (0041FF64) --------------------------------------------------------
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
352 int Chest::CountChestItems(signed int uChestID)
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
353 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
354 signed int item_count; // eax@1
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
355 int max_items; // edx@1
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
356 item_count = 0;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
357 max_items = pChestWidthsByType[pChests[uChestID].uChestBitmapID] * pChestHeightsByType[pChests[uChestID].uChestBitmapID];
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
358 if ( max_items <= 0 )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
359 item_count = -1;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
360 else
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
361 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
362 while ( pChests[uChestID].igChestItems[item_count].uItemID )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
363 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
364 ++item_count;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
365 if ( item_count >= max_items )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
366 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
367 item_count = -1;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
368 break;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
369 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
370 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
371 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
372 return item_count;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
373 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
374
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
375 //----- (0041FFA2) --------------------------------------------------------
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
376 int Chest::PutItemInChest(int position, ItemGen *put_item, signed int uChestID)
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
377 {//(rus: положить предмет в ящик)
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
378 ItemGen *v4; // edi@1
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
379 int v5; // esi@1
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
380 int result; // eax@11
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
381 unsigned int v7; // eax@12
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
382 int v8; // edx@12
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
383 Texture *texture; // ecx@12
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
384 signed int v10; // eax@12
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
385 signed int v11; // edi@14
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
386 unsigned int v12; // esi@14
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
387 int v13; // edi@16
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
388 void *v14; // edi@21
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
389 int v15; // edi@21
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
390 int i; // ecx@21
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
391 ItemGen *Src; // [sp+Ch] [bp-18h]@1
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
392 signed int item_in_chest_count; // [sp+10h] [bp-14h]@2
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
393 int v19; // [sp+14h] [bp-10h]@1
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
394 int v20; // [sp+18h] [bp-Ch]@19
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
395 signed int v21; // [sp+1Ch] [bp-8h]@1
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
396 // signed int v22; // [sp+20h] [bp-4h]@3
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
397 int v23; // [sp+20h] [bp-4h]@19
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
398
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
399 v21 = 0;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
400 v4 = put_item;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
401 v5 = pChestWidthsByType[pChests[uChestID].uChestBitmapID] * pChestHeightsByType[pChests[uChestID].uChestBitmapID];
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
402 Src = put_item;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
403 v19 = pChestWidthsByType[pChests[uChestID].uChestBitmapID];
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
404 if ( position == -1 )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
405 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
406 item_in_chest_count = CountChestItems(uChestID);
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
407 if ( item_in_chest_count == -1 )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
408 return 0;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
409 for( int _i = 0; _i < v5; _i++)
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
410 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
411 if ( Chest::CanPlaceItemAt(_i, v4->uItemID, pChestWindow->par1C) )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
412 v21 = _i;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
413 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
414 if ( v21 == v5 )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
415 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
416 if ( uActiveCharacter )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
417 pPlayers[uActiveCharacter]->PlaySound(SPEECH_NoRoom, 0);
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
418 return 0;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
419 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
420 v7 = pIcons_LOD->LoadTexture(v4->GetIconName(), TEXTURE_16BIT_PALETTE);
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
421 HIWORD(v8) = 0;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
422 texture = pIcons_LOD->GetTexture(v7);
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
423 v10 = texture->uTextureWidth;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
424 if ( texture->uTextureWidth < 14 )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
425 v10 = 14;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
426 v12 = ((v10 - 14) >> 5) + 1;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
427 v11 = texture->uTextureHeight;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
428 if ( texture->uTextureHeight < 14 )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
429 v11 = 14;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
430 v13 = ((v11 - 14) >> 5) + 1;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
431 if ( !areWeLoadingTexture )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
432 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
433 texture->Release();
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
434 pIcons_LOD->SyncLoadedFilesCount();
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
435 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
436 if ( v13 > 0 )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
437 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
438 v23 = 0;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
439 v20 = v13;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
440 do
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
441 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
442 if ( (signed int)v12 > 0 )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
443 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
444 v14 = &pChests[uChestID].pInventoryIndices[v21 + v23];
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
445 LOWORD(v8) = -1 - v21;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
446 v8 <<= 16;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
447 LOWORD(v8) = -1 - v21;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
448 memset32(v14, v8, v12 >> 1);
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
449 v15 = (int)((char *)v14 + 4 * (v12 >> 1));
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
450 for ( i = v12 & 1; i; --i )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
451 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
452 *(short *)v15 = v8;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
453 v15 += 2;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
454 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
455 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
456 v23 += v19;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
457 --v20;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
458 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
459 while ( v20 );
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
460 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
461 pChests[uChestID].pInventoryIndices[v21] = item_in_chest_count + 1;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
462 memcpy(&pChests[uChestID].igChestItems[item_in_chest_count], put_item, sizeof(ItemGen));
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
463 result = v21 + 1;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
464 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
465 else
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
466 result = 1;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
467 return result;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
468 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
469 // 506128: using guessed type int areWeLoadingTexture;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
470
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
471 //----- (0042013E) --------------------------------------------------------
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
472 void Chest::PlaceItemAt( unsigned int put_cell_pos, unsigned int item_at_cell, signed int uChestID )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
473 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
474 int uItemID; // edi@1
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
475 int v6; // edx@4
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
476 unsigned int v7; // eax@5
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
477 Texture *texture; // ecx@5
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
478 signed int v9; // eax@5
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
479 signed int v10; // edi@7
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
480 unsigned int texture_cell_width; // ebx@7
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
481 int textute_cell_height; // edi@9
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
482 int chest_cell_row_pos; // edx@12
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
483 int chest_cell_width; // [sp+10h] [bp-Ch]@11
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
484
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
485 uItemID = pChests[ uChestID].igChestItems[item_at_cell].uItemID;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
486 pItemsTable->SetSpecialBonus(&pChests[ uChestID].igChestItems[item_at_cell]);
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
487 if ( uItemID >= 135 && uItemID <= 159 && !pChests[ uChestID].igChestItems[item_at_cell].uNumCharges)
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
488 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
489 v6 = rand() % 21 + 10;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
490 pChests[ uChestID].igChestItems[item_at_cell].uNumCharges = v6;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
491 pChests[ uChestID].igChestItems[item_at_cell].uMaxCharges = v6;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
492 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
493 v7 = pIcons_LOD->LoadTexture(pItemsTable->pItems[uItemID].pIconName, TEXTURE_16BIT_PALETTE);
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
494 texture = pIcons_LOD->GetTexture(v7);
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
495 v9 = texture->uTextureWidth;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
496 if ( texture->uTextureWidth < 14 )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
497 v9 = 14;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
498 texture_cell_width = ((v9 - 14) >> 5) + 1;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
499 v10 = texture->uTextureHeight;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
500 if ( texture->uTextureHeight < 14 )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
501 v10 = 14;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
502 textute_cell_height = ((v10 - 14) >> 5) + 1;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
503 if ( !areWeLoadingTexture )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
504 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
505 texture->Release();
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
506 pIcons_LOD->SyncLoadedFilesCount();
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
507 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
508 chest_cell_width = pChestWidthsByType[pChests[ uChestID].uChestBitmapID];
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
509 chest_cell_row_pos = 0;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
510 for(int i = 0; i < textute_cell_height; ++i)
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
511 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
512 for (int j = 0; j < texture_cell_width; ++j)
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
513 pChests[uChestID].pInventoryIndices[put_cell_pos + chest_cell_row_pos+j]=(signed __int16)-(put_cell_pos+1);
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
514 chest_cell_row_pos += chest_cell_width;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
515 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
516 pChests[uChestID].pInventoryIndices[put_cell_pos] = item_at_cell + 1;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
517 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
518 // 506128: using guessed type int areWeLoadingTexture;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
519
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
520 //----- (00420284) --------------------------------------------------------
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
521 void Chest::PlaceItems(signed int uChestID )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
522 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
523 int uChestArea; // edi@1
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
524 int random_chest_pos; // eax@2
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
525 int test_position; // ebx@11
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
526 char chest_cells_map[144]; // [sp+Ch] [bp-A0h]@1
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
527 int chest_item_id; // [sp+9Ch] [bp-10h]@10
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
528 unsigned int items_counter; // [sp+A4h] [bp-8h]@8
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
529
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
530 pRenderer->ClearZBuffer(0, 479);
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
531 uChestArea = pChestWidthsByType[pChests[uChestID].uChestBitmapID] * pChestHeightsByType[pChests[uChestID].uChestBitmapID];
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
532 memset(chest_cells_map, 0, 144);
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
533 //fill cell map at random positions
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
534 for ( items_counter = 0; items_counter < uChestArea; ++items_counter )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
535 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
536 //get random position in chest
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
537 do
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
538 random_chest_pos = (unsigned __int8)rand();
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
539 while ( random_chest_pos >= uChestArea );
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
540 //if this pos occupied move to next
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
541 while ( chest_cells_map[random_chest_pos] )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
542 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
543 ++random_chest_pos;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
544 if ( random_chest_pos == uChestArea )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
545 random_chest_pos = 0;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
546 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
547 chest_cells_map[random_chest_pos] = items_counter;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
548 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
549 items_counter = 0;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
550
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
551 for (items_counter = 0; items_counter<uChestArea; ++items_counter)
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
552 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
553 chest_item_id = pChests[uChestID].igChestItems[items_counter].uItemID;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
554 if ( chest_item_id )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
555 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
556 test_position = 0;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
557 while ( !Chest::CanPlaceItemAt((unsigned __int8)chest_cells_map[test_position], chest_item_id, uChestID) )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
558 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
559 ++test_position;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
560 if ( test_position >= uChestArea )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
561 break;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
562 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
563 if(test_position<uChestArea)
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
564 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
565 Chest::PlaceItemAt((unsigned __int8)chest_cells_map[test_position], items_counter, uChestID);
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
566 if ( pChests[uChestID].uFlags & CHEST_OPENED)
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
567 pChests[uChestID].igChestItems[items_counter].SetIdentified();
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
568 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
569 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
570 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
571 pChests[uChestID].SetInitialized(true);
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
572 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
573 // 420284: using guessed type char Dst[144];
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
574
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
575 //----- (00448A17) --------------------------------------------------------
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
576 void Chest::ToggleFlag(signed int uChestID, unsigned __int16 uFlag, unsigned int bToggle)
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
577 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
578 if ( uChestID >= 0 && uChestID <= 19 )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
579 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
580 if ( bToggle )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
581 pChests[uChestID].uFlags |= uFlag;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
582 else
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
583 pChests[uChestID].uFlags &= ~uFlag;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
584 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
585 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
586
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
587 //----- (00458B03) --------------------------------------------------------
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
588 void ChestList::ToFile()
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
589 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
590 FILE *v2; // eax@1
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
591 FILE *v3; // edi@1
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
592
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
593 v2 = fopen("data\\dchest.bin", "wb");
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
594 v3 = v2;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
595 if ( !v2 )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
596 Error("Unable to save dchest.bin!");
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
597
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
598 fwrite(this, 4, 1, v2);
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
599 fwrite(this->pChests, 36, this->uNumChests, v3);
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
600 fclose(v3);
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
601 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
602
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
603
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
604 //----- (00458B4F) --------------------------------------------------------
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
605 void ChestList::FromFile(void *data_mm6, void *data_mm7, void *data_mm8)
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
606 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
607 uint num_mm6_chests = data_mm6 ? *(int *)data_mm6 : 0,
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
608 num_mm7_chests = data_mm7 ? *(int *)data_mm7 : 0,
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
609 num_mm8_chests = data_mm8 ? *(int *)data_mm8 : 0;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
610
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
611 uNumChests = num_mm6_chests + num_mm7_chests + num_mm8_chests;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
612 assert(uNumChests);
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
613 assert(!num_mm8_chests);
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
614
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
615 pChests = (ChestDesc *)malloc(uNumChests * sizeof(ChestDesc));
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
616 memcpy(pChests, (char *)data_mm7 + 4, num_mm7_chests * sizeof(ChestDesc));
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
617 memcpy(pChests + num_mm7_chests, (char *)data_mm6 + 4, num_mm6_chests * sizeof(ChestDesc));
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
618 memcpy(pChests + num_mm6_chests + num_mm7_chests, (char *)data_mm8 + 4, num_mm8_chests * sizeof(ChestDesc));
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
619 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
620
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
621
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
622 //----- (00458B9C) --------------------------------------------------------
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
623 int ChestList::FromFileTxt(const char *Args)
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
624 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
625 //ChestList *v2; // ebx@1
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
626 __int32 v3; // edi@1
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
627 FILE *v4; // eax@1
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
628 unsigned int v5; // esi@3
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
629 const void *v6; // ST18_4@9
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
630 void *v7; // eax@9
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
631 FILE *v8; // ST0C_4@11
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
632 char *i; // eax@11
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
633 char v10; // al@14
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
634 const char *v11; // ST14_4@14
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
635 char v12; // al@14
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
636 const char *v13; // ST10_4@14
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
637 char Buf; // [sp+8h] [bp-2F0h]@3
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
638 FrameTableTxtLine v16; // [sp+1FCh] [bp-FCh]@4
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
639 FrameTableTxtLine v17; // [sp+278h] [bp-80h]@4
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
640 FILE *File; // [sp+2F4h] [bp-4h]@1
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
641 unsigned int Argsa; // [sp+300h] [bp+8h]@3
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
642
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
643 //v2 = this;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
644 free(this->pChests);
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
645 v3 = 0;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
646 this->pChests = 0;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
647 this->uNumChests = 0;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
648 v4 = fopen(Args, "r");
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
649 File = v4;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
650 if ( !v4 )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
651 Error("ChestDescriptionList::load - Unable to open file: %s.");
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
652
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
653 v5 = 0;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
654 Argsa = 0;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
655 if ( fgets(&Buf, 490, v4) )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
656 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
657 do
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
658 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
659 *strchr(&Buf, 10) = 0;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
660 memcpy(&v17, txt_file_frametable_parser(&Buf, &v16), sizeof(v17));
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
661 if ( v17.uPropCount && *v17.pProperties[0] != 47 )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
662 ++Argsa;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
663 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
664 while ( fgets(&Buf, 490, File) );
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
665 v5 = Argsa;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
666 v3 = 0;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
667 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
668 v6 = this->pChests;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
669 this->uNumChests = v5;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
670 v7 = malloc(36 * v5);
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
671 this->pChests = (ChestDesc *)v7;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
672 if ( v7 == (void *)v3 )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
673 Error("ChestDescriptionList::load - Out of Memory!");
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
674
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
675 memset(v7, v3, 36 * this->uNumChests);
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
676 v8 = File;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
677 this->uNumChests = v3;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
678 fseek(v8, v3, v3);
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
679 for ( i = fgets(&Buf, 490, File); i; i = fgets(&Buf, 490, File) )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
680 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
681 *strchr(&Buf, 10) = 0;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
682 memcpy(&v17, txt_file_frametable_parser(&Buf, &v16), sizeof(v17));
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
683 if ( v17.uPropCount && *v17.pProperties[0] != 47 )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
684 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
685 strcpy(this->pChests[this->uNumChests].pName, v17.pProperties[0]);
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
686 v10 = atoi(v17.pProperties[1]);
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
687 v11 = v17.pProperties[2];
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
688 this->pChests[this->uNumChests].uWidth = v10;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
689 v12 = atoi(v11);
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
690 v13 = v17.pProperties[3];
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
691 this->pChests[this->uNumChests].uHeight = v12;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
692 this->pChests[this->uNumChests++].uTextureID = atoi(v13);
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
693 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
694 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
695 fclose(File);
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
696 return 1;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
697 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
698
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
699 //----- (00420B13) --------------------------------------------------------
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
700 void __fastcall sub_420B13(int a1, int a2)
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
701 { //Give item from chest(rus: Взять предмет из ящика)
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
702 void *v2; // eax@1
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
703 unsigned int v4; // eax@1
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
704 Texture *texture; // ecx@1
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
705 signed int v6; // eax@1
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
706 signed int v7; // edi@3
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
707 signed int v8; // eax@3
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
708 int v9; // edi@3
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
709 int v10; // eax@5
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
710 int v11; // esi@8
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
711 unsigned int v12; // ecx@10
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
712 void *v13; // edi@10
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
713 unsigned __int8 v14; // cf@10
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
714 int v15; // edi@10
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
715 int i; // ecx@10
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
716 int v17; // [sp+Ch] [bp-14h]@1
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
717 int v18; // [sp+10h] [bp-10h]@3
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
718 int v21; // [sp+1Ch] [bp-4h]@5
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
719 int v22; // [sp+1Ch] [bp-4h]@8
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
720
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
721 v2 = (void *)(5324 * (int)pChestWindow->ptr_1C);
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
722 v17 = pChestWidthsByType[pChests[(int)pChestWindow->ptr_1C].uChestBitmapID];
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
723 v4 = pIcons_LOD->LoadTexture(pChests[(int)pChestWindow->ptr_1C].igChestItems[a1].GetIconName(), TEXTURE_16BIT_PALETTE);
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
724 texture = pIcons_LOD->GetTexture(v4);
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
725
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
726 v6 = texture->uTextureWidth;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
727 if ( texture->uTextureWidth < 14 )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
728 v6 = 14;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
729 v7 = v6 - 14;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
730 v9 = (v7 >> 5) + 1;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
731 v18 = v9;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
732
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
733 v8 = texture->uTextureHeight;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
734 if ( texture->uTextureHeight < 14 )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
735 v8 = 14;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
736 v10 = ((v8 - 14) >> 5) + 1;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
737 v21 = v10;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
738
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
739 if ( !areWeLoadingTexture )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
740 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
741 texture->Release();
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
742 pIcons_LOD->SyncLoadedFilesCount();
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
743 v10 = v21;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
744 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
745 if ( v10 > 0 )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
746 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
747 v11 = 0;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
748 for ( v22 = v10; v22; --v22 )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
749 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
750 if ( v9 > 0 )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
751 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
752 v12 = v9;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
753 v13 = &pChests[(int)pChestWindow->ptr_1C].pInventoryIndices[a2 + v11];
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
754 v14 = v12 & 1;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
755 v12 >>= 1;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
756 memset(&pChests[(int)pChestWindow->ptr_1C].pInventoryIndices[a2 + v11], 0, 4 * v12);
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
757 v15 = (int)((char *)v13 + 4 * v12);
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
758 for ( i = v14; i; --i )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
759 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
760 *(short *)v15 = 0;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
761 v15 += 2;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
762 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
763 v9 = v18;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
764 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
765 v11 += v17;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
766 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
767 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
768 pChests[(int)pChestWindow->ptr_1C].igChestItems[a1].Reset();
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
769 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
770 // 506128: using guessed type int areWeLoadingTexture;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
771 //----- (00420E01) --------------------------------------------------------
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
772 void Chest::OnChestLeftClick()
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
773 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
774 int v2; // eax@2
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
775 int v3; // ebx@4
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
776 int v4; // esi@6
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
777 POINT cursor; // [sp+84h] [bp-8h]@2
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
778
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
779 SpriteObject v6; // [sp+Ch] [bp-80h]@1
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
780 if ( pParty->pPickedItem.uItemID )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
781 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
782 if ( Chest::PutItemInChest(-1, &pParty->pPickedItem, pGUIWindow_CurrentMenu->par1C) )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
783 pMouse->RemoveHoldingItem();
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
784 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
785 else
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
786 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
787 pMouse->GetCursorPos(&cursor);
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
788 v2 = pRenderer->pActiveZBuffer[cursor.x + pSRZBufferLineOffsets[cursor.y]] & 0xFFFF;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
789 if ( v2 )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
790 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
791 if ( v2 )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
792 v3 = v2 - 1;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
793 else
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
794 v3 = -1;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
795 v4 = pChests[(int)pGUIWindow_CurrentMenu->par1C].pInventoryIndices[v3] - 1;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
796 if ( pChests[(int)pGUIWindow_CurrentMenu->par1C].igChestItems[v4].GetItemEquipType() == EQUIP_GOLD )
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
797 {
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
798 pParty->PartyFindsGold(pChests[(int)pGUIWindow_CurrentMenu->par1C].igChestItems[v4].uSpecEnchantmentType, 0);
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
799 viewparams->bRedrawGameUI = 1;
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
800 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
801 else
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
802 pParty->SetHoldingItem(&pChests[(int)pGUIWindow_CurrentMenu->par1C].igChestItems[v4]);
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
803 sub_420B13(v4, v3);
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
804 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
805 }
82d5d92a097c for MVS2012
Ritor1
parents:
diff changeset
806 }