Mercurial > mm7
annotate DecorationList.cpp @ 2081:70c45d12d9ca
Merge
author | Ritor1 |
---|---|
date | Wed, 04 Dec 2013 00:45:18 +0600 |
parents | 75fafd8ced59 |
children | aff7a7b072b7 |
rev | line source |
---|---|
1297 | 1 #include "Sprites.h" |
2 #include "DecorationList.h" | |
3 #include "MM7.h" | |
4 #include "FrameTableInc.h" | |
5 #include "mm7_data.h" | |
6 #include "Indoor.h" | |
1545 | 7 #include "ErrorHandling.h" |
1297 | 8 |
9 //----- (0045864C) -------------------------------------------------------- | |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1421
diff
changeset
|
10 void DecorationList::FromFile(void *data_mm6, void *data_mm7, void *data_mm8) |
1297 | 11 { |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1421
diff
changeset
|
12 uint num_mm6_decs = data_mm6 ? *(int *)data_mm6 : 0, |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1421
diff
changeset
|
13 num_mm7_decs = data_mm7 ? *(int *)data_mm7 : 0, |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1421
diff
changeset
|
14 num_mm8_decs = data_mm8 ? *(int *)data_mm8 : 0; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1421
diff
changeset
|
15 |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1421
diff
changeset
|
16 uNumDecorations = num_mm6_decs + num_mm7_decs + num_mm8_decs; |
1545 | 17 Assert(uNumDecorations); |
18 Assert(!num_mm8_decs); | |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1421
diff
changeset
|
19 |
1583 | 20 pDecorations = (DecorationDesc *)malloc(uNumDecorations * sizeof(DecorationDesc)); |
1477
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1421
diff
changeset
|
21 memcpy(pDecorations, (char *)data_mm7 + 4, num_mm7_decs * sizeof(DecorationDesc)); |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1421
diff
changeset
|
22 for (uint i = 0; i < num_mm6_decs; ++i) |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1421
diff
changeset
|
23 { |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1421
diff
changeset
|
24 memcpy(pDecorations + num_mm7_decs + i, (char *)data_mm6 + 4 + i * sizeof(DecorationDesc_mm6), sizeof(DecorationDesc_mm6)); |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1421
diff
changeset
|
25 pDecorations[num_mm7_decs + i].uColoredLightRed = 255; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1421
diff
changeset
|
26 pDecorations[num_mm7_decs + i].uColoredLightGreen = 255; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1421
diff
changeset
|
27 pDecorations[num_mm7_decs + i].uColoredLightBlue = 255; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1421
diff
changeset
|
28 pDecorations[num_mm7_decs + i].__padding = 255; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1421
diff
changeset
|
29 } |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1421
diff
changeset
|
30 memcpy(pDecorations + num_mm6_decs + num_mm7_decs, (char *)data_mm8 + 4, num_mm8_decs * sizeof(DecorationDesc)); |
1297 | 31 } |
32 | |
33 //----- (00458693) -------------------------------------------------------- | |
34 void DecorationList::InitializeDecorationSprite(unsigned int uDecID) | |
35 { | |
36 pSpriteFrameTable->InitializeSprite(this->pDecorations[uDecID].uSpriteID); | |
37 } | |
38 | |
39 //----- (004586B0) -------------------------------------------------------- | |
40 bool DecorationList::FromFileTxt(const char *Args) | |
41 { | |
42 DecorationList *v2; // ebx@1 | |
43 FILE *v3; // eax@1 | |
44 unsigned int v4; // esi@3 | |
45 void *v5; // eax@10 | |
46 FILE *v6; // ST18_4@12 | |
47 char *i; // eax@12 | |
48 unsigned __int16 v8; // ax@16 | |
49 const char *v9; // ST20_4@16 | |
50 const char *v10; // ST18_4@16 | |
51 __int16 v11; // ax@16 | |
52 const char *v12; // ST14_4@16 | |
53 unsigned __int16 v13; // ax@16 | |
54 const char *v14; // ST10_4@16 | |
55 __int16 v15; // ax@16 | |
56 const char *v16; // ST0C_4@16 | |
57 unsigned __int8 v17; // al@16 | |
58 const char *v18; // ST08_4@16 | |
59 unsigned __int8 v19; // al@16 | |
60 const char *v20; // ST04_4@16 | |
61 unsigned __int8 v21; // al@16 | |
62 const char *v22; // ST00_4@16 | |
63 unsigned __int8 v23; // zf@16 | |
64 char v24; // sf@16 | |
65 unsigned __int8 v25; // of@16 | |
66 int j; // edi@17 | |
67 const char *v27; // esi@18 | |
68 int v28; // eax@19 | |
69 int v29; // eax@21 | |
70 int v30; // eax@23 | |
71 int v31; // eax@25 | |
72 int v32; // eax@27 | |
73 int v33; // eax@29 | |
74 int v34; // eax@31 | |
75 int v35; // eax@33 | |
76 FrameTableTxtLine v37; // [sp+Ch] [bp-460h]@17 | |
77 FrameTableTxtLine v38; // [sp+88h] [bp-3E4h]@13 | |
78 char Dest; // [sp+104h] [bp-368h]@17 | |
79 char Buf; // [sp+17Ch] [bp-2F0h]@3 | |
80 FrameTableTxtLine v41; // [sp+370h] [bp-FCh]@4 | |
81 FrameTableTxtLine v42; // [sp+3ECh] [bp-80h]@4 | |
82 FILE *File; // [sp+468h] [bp-4h]@1 | |
83 unsigned int Argsa; // [sp+474h] [bp+8h]@3 | |
84 | |
85 v2 = this; | |
86 v3 = fopen(Args, "r"); | |
87 File = v3; | |
88 if ( !v3 ) | |
1545 | 89 Error("DecorationDescriptionList::load - Unable to open file: %s."); |
90 | |
1297 | 91 v4 = 0; |
92 Argsa = 0; | |
93 if ( fgets(&Buf, 490, v3) ) | |
94 { | |
95 do | |
96 { | |
97 *strchr(&Buf, 10) = 0; | |
98 memcpy(&v42, frame_table_txt_parser(&Buf, &v41), sizeof(v42)); | |
99 if ( v42.uPropCount && *v42.pProperties[0] != 47 && v42.uPropCount >= 3 ) | |
100 ++Argsa; | |
101 } | |
102 while ( fgets(&Buf, 490, File) ); | |
103 v4 = Argsa; | |
104 } | |
105 v2->uNumDecorations = v4; | |
1583 | 106 v5 = malloc(84 * v4); |
1297 | 107 v2->pDecorations = (DecorationDesc *)v5; |
108 if ( !v5 ) | |
1545 | 109 Error("DecorationDescriptionList::load - Out of Memory!"); |
110 | |
1297 | 111 v6 = File; |
112 v2->uNumDecorations = 0; | |
113 fseek(v6, 0, 0); | |
114 for ( i = fgets(&Buf, 490, File); i; i = fgets(&Buf, 490, File) ) | |
115 { | |
116 *strchr(&Buf, 10) = 0; | |
117 memcpy(&v42, frame_table_txt_parser(&Buf, &v38), sizeof(v42)); | |
118 if ( v42.uPropCount && *v42.pProperties[0] != 47 && v42.uPropCount >= 3 ) | |
119 { | |
120 strcpy(v2->pDecorations[v2->uNumDecorations].pName, v42.pProperties[1]); | |
121 v8 = pSpriteFrameTable->FastFindSprite(v2->pDecorations[v2->uNumDecorations].pName); | |
122 v9 = v42.pProperties[2]; | |
123 v2->pDecorations[v2->uNumDecorations].uSpriteID = v8; | |
124 strcpy(v2->pDecorations[v2->uNumDecorations].field_20, v9); | |
125 v10 = v42.pProperties[3]; | |
126 v2->pDecorations[v2->uNumDecorations].uType = 0; | |
127 v11 = atoi(v10); | |
128 v12 = v42.pProperties[4]; | |
129 v2->pDecorations[v2->uNumDecorations].uRadius = v11; | |
130 v13 = atoi(v12); | |
131 v14 = v42.pProperties[5]; | |
132 v2->pDecorations[v2->uNumDecorations].uDecorationHeight = v13; | |
133 v15 = atoi(v14); | |
134 v16 = v42.pProperties[6]; | |
135 v2->pDecorations[v2->uNumDecorations].uLightRadius = v15; | |
136 v17 = atoi(v16); | |
137 v18 = v42.pProperties[7]; | |
138 v2->pDecorations[v2->uNumDecorations].uColoredLightRed = v17; | |
139 v19 = atoi(v18); | |
140 v20 = v42.pProperties[8]; | |
141 v2->pDecorations[v2->uNumDecorations].uColoredLightGreen = v19; | |
142 v21 = atoi(v20); | |
143 v22 = v42.pProperties[9]; | |
144 v2->pDecorations[v2->uNumDecorations].uColoredLightBlue = v21; | |
145 v2->pDecorations[v2->uNumDecorations].uSoundID = atoi(v22); | |
146 v25 = __OFSUB__(v42.uPropCount, 10); | |
147 v23 = v42.uPropCount == 10; | |
148 v24 = v42.uPropCount - 10 < 0; | |
149 v2->pDecorations[v2->uNumDecorations].uFlags = 0; | |
150 if ( !((unsigned __int8)(v24 ^ v25) | v23) ) | |
151 { | |
152 strcpy(&Dest, v42.pProperties[10]); | |
153 memcpy(&v41, frame_table_txt_parser(&Dest, &v37), sizeof(v41)); | |
154 for ( j = 0; j < v41.uPropCount; ++j ) | |
155 { | |
156 v27 = v41.pProperties[j]; | |
157 if ( _stricmp(v41.pProperties[j], "NBM") ) | |
158 { | |
159 if ( _stricmp(v27, "Invisible") ) | |
160 { | |
161 if ( _stricmp(v27, "FS") ) | |
162 { | |
163 if ( _stricmp(v27, "FM") ) | |
164 { | |
165 if ( _stricmp(v27, "FF") ) | |
166 { | |
167 if ( _stricmp(v27, "Marker") ) | |
168 { | |
169 if ( _stricmp(v27, "LoopSlow") ) | |
170 { | |
171 if ( _stricmp(v27, "EmitFire") ) | |
172 { | |
173 if ( _stricmp(v27, "Dawn") ) | |
174 { | |
175 if ( !_stricmp(v27, "Dusk") ) | |
176 HIBYTE(v2->pDecorations[v2->uNumDecorations].uFlags) |= 2u; | |
177 } | |
178 else | |
179 { | |
180 HIBYTE(v2->pDecorations[v2->uNumDecorations].uFlags) |= 1u; | |
181 } | |
182 } | |
183 else | |
184 { | |
185 v35 = (int)&v2->pDecorations[v2->uNumDecorations].uFlags; | |
186 *(char *)v35 |= 0x80u; | |
187 } | |
188 } | |
189 else | |
190 { | |
191 v34 = (int)&v2->pDecorations[v2->uNumDecorations].uFlags; | |
192 *(char *)v34 |= 0x40u; | |
193 } | |
194 } | |
195 else | |
196 { | |
197 v33 = (int)&v2->pDecorations[v2->uNumDecorations].uFlags; | |
198 *(char *)v33 |= 0x20u; | |
199 } | |
200 } | |
201 else | |
202 { | |
203 v32 = (int)&v2->pDecorations[v2->uNumDecorations].uFlags; | |
204 *(char *)v32 |= 0x10u; | |
205 } | |
206 } | |
207 else | |
208 { | |
209 v31 = (int)&v2->pDecorations[v2->uNumDecorations].uFlags; | |
210 *(char *)v31 |= 8u; | |
211 } | |
212 } | |
213 else | |
214 { | |
215 v30 = (int)&v2->pDecorations[v2->uNumDecorations].uFlags; | |
216 *(char *)v30 |= 4u; | |
217 } | |
218 } | |
219 else | |
220 { | |
221 v29 = (int)&v2->pDecorations[v2->uNumDecorations].uFlags; | |
222 *(char *)v29 |= 2u; | |
223 } | |
224 } | |
225 else | |
226 { | |
227 v28 = (int)&v2->pDecorations[v2->uNumDecorations].uFlags; | |
228 *(char *)v28 |= 1u; | |
229 } | |
230 } | |
231 } | |
232 ++v2->uNumDecorations; | |
233 } | |
234 } | |
235 fclose(File); | |
236 return 1; | |
237 } | |
238 //----- (00458600) -------------------------------------------------------- | |
239 void DecorationList::ToFile() | |
240 { | |
241 DecorationList *v1; // esi@1 | |
242 FILE *v2; // eax@1 | |
243 FILE *v3; // edi@1 | |
244 | |
245 v1 = this; | |
246 v2 = fopen("data\\ddeclist.bin", "wb"); | |
247 v3 = v2; | |
248 if ( !v2 ) | |
1545 | 249 Error("Unable to save ddeclist.bin!"); |
250 | |
1297 | 251 fwrite(v1, 4u, 1u, v2); |
252 fwrite(v1->pDecorations, 0x54u, v1->uNumDecorations, v3); | |
253 fclose(v3); | |
254 } | |
255 //----- (004488B6) -------------------------------------------------------- | |
256 unsigned __int16 DecorationList::GetDecorIdByName(const char *pName) | |
257 { | |
258 DecorationList *v2; // esi@1 | |
259 signed int uID; // edi@2 | |
260 signed int v4; // ebx@3 | |
261 unsigned __int16 result; // ax@6 | |
262 | |
263 v2 = this; | |
264 if ( pName && (uID = 1, (signed int)this->uNumDecorations > 1) ) | |
265 { | |
266 v4 = 1; | |
267 while ( _stricmp(pName, v2->pDecorations[v4].pName) ) | |
268 { | |
269 ++uID; | |
270 ++v4; | |
271 if ( uID >= (signed int)v2->uNumDecorations ) | |
1421 | 272 return 0; |
1297 | 273 } |
274 result = uID; | |
275 } | |
276 else | |
277 { | |
278 result = 0; | |
279 } | |
280 return result; | |
281 } |