Mercurial > mm7
annotate DecorationList.cpp @ 1514:965af46e8793
Rename LevelDecoration::field_16_event_id to LevelDecoration::uEventID.
author | yoctozepto |
---|---|
date | Tue, 03 Sep 2013 15:09:07 +0200 |
parents | 61451d5980bf |
children | c4ab816fcc5e |
rev | line source |
---|---|
1297 | 1 #include "Sprites.h" |
2 #include "DecorationList.h" | |
3 #include "Allocator.h" | |
4 #include "MM7.h" | |
5 #include "FrameTableInc.h" | |
6 #include "mm7_data.h" | |
7 #include "Indoor.h" | |
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; |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1421
diff
changeset
|
17 assert(uNumDecorations); |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1421
diff
changeset
|
18 assert(!num_mm8_decs); |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1421
diff
changeset
|
19 |
7ef4b64f6329
* LODFile::LoadBitmaps & LODFile::LoadIconsOrEvents are merged into LODFile::Load
Nomad
parents:
1421
diff
changeset
|
20 pDecorations = (DecorationDesc *)pAllocator->AllocNamedChunk(pDecorations, uNumDecorations * sizeof(DecorationDesc), "Dec Descrip"); |
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 ) | |
89 Abortf("DecorationDescriptionList::load - Unable to open file: %s."); | |
90 v4 = 0; | |
91 Argsa = 0; | |
92 if ( fgets(&Buf, 490, v3) ) | |
93 { | |
94 do | |
95 { | |
96 *strchr(&Buf, 10) = 0; | |
97 memcpy(&v42, frame_table_txt_parser(&Buf, &v41), sizeof(v42)); | |
98 if ( v42.uPropCount && *v42.pProperties[0] != 47 && v42.uPropCount >= 3 ) | |
99 ++Argsa; | |
100 } | |
101 while ( fgets(&Buf, 490, File) ); | |
102 v4 = Argsa; | |
103 } | |
104 v2->uNumDecorations = v4; | |
105 v5 = pAllocator->AllocNamedChunk(v2->pDecorations, 84 * v4, "Dec Descrip"); | |
106 v2->pDecorations = (DecorationDesc *)v5; | |
107 if ( !v5 ) | |
108 Abortf("DecorationDescriptionList::load - Out of Memory!"); | |
109 v6 = File; | |
110 v2->uNumDecorations = 0; | |
111 fseek(v6, 0, 0); | |
112 for ( i = fgets(&Buf, 490, File); i; i = fgets(&Buf, 490, File) ) | |
113 { | |
114 *strchr(&Buf, 10) = 0; | |
115 memcpy(&v42, frame_table_txt_parser(&Buf, &v38), sizeof(v42)); | |
116 if ( v42.uPropCount && *v42.pProperties[0] != 47 && v42.uPropCount >= 3 ) | |
117 { | |
118 strcpy(v2->pDecorations[v2->uNumDecorations].pName, v42.pProperties[1]); | |
119 v8 = pSpriteFrameTable->FastFindSprite(v2->pDecorations[v2->uNumDecorations].pName); | |
120 v9 = v42.pProperties[2]; | |
121 v2->pDecorations[v2->uNumDecorations].uSpriteID = v8; | |
122 strcpy(v2->pDecorations[v2->uNumDecorations].field_20, v9); | |
123 v10 = v42.pProperties[3]; | |
124 v2->pDecorations[v2->uNumDecorations].uType = 0; | |
125 v11 = atoi(v10); | |
126 v12 = v42.pProperties[4]; | |
127 v2->pDecorations[v2->uNumDecorations].uRadius = v11; | |
128 v13 = atoi(v12); | |
129 v14 = v42.pProperties[5]; | |
130 v2->pDecorations[v2->uNumDecorations].uDecorationHeight = v13; | |
131 v15 = atoi(v14); | |
132 v16 = v42.pProperties[6]; | |
133 v2->pDecorations[v2->uNumDecorations].uLightRadius = v15; | |
134 v17 = atoi(v16); | |
135 v18 = v42.pProperties[7]; | |
136 v2->pDecorations[v2->uNumDecorations].uColoredLightRed = v17; | |
137 v19 = atoi(v18); | |
138 v20 = v42.pProperties[8]; | |
139 v2->pDecorations[v2->uNumDecorations].uColoredLightGreen = v19; | |
140 v21 = atoi(v20); | |
141 v22 = v42.pProperties[9]; | |
142 v2->pDecorations[v2->uNumDecorations].uColoredLightBlue = v21; | |
143 v2->pDecorations[v2->uNumDecorations].uSoundID = atoi(v22); | |
144 v25 = __OFSUB__(v42.uPropCount, 10); | |
145 v23 = v42.uPropCount == 10; | |
146 v24 = v42.uPropCount - 10 < 0; | |
147 v2->pDecorations[v2->uNumDecorations].uFlags = 0; | |
148 if ( !((unsigned __int8)(v24 ^ v25) | v23) ) | |
149 { | |
150 strcpy(&Dest, v42.pProperties[10]); | |
151 memcpy(&v41, frame_table_txt_parser(&Dest, &v37), sizeof(v41)); | |
152 for ( j = 0; j < v41.uPropCount; ++j ) | |
153 { | |
154 v27 = v41.pProperties[j]; | |
155 if ( _stricmp(v41.pProperties[j], "NBM") ) | |
156 { | |
157 if ( _stricmp(v27, "Invisible") ) | |
158 { | |
159 if ( _stricmp(v27, "FS") ) | |
160 { | |
161 if ( _stricmp(v27, "FM") ) | |
162 { | |
163 if ( _stricmp(v27, "FF") ) | |
164 { | |
165 if ( _stricmp(v27, "Marker") ) | |
166 { | |
167 if ( _stricmp(v27, "LoopSlow") ) | |
168 { | |
169 if ( _stricmp(v27, "EmitFire") ) | |
170 { | |
171 if ( _stricmp(v27, "Dawn") ) | |
172 { | |
173 if ( !_stricmp(v27, "Dusk") ) | |
174 HIBYTE(v2->pDecorations[v2->uNumDecorations].uFlags) |= 2u; | |
175 } | |
176 else | |
177 { | |
178 HIBYTE(v2->pDecorations[v2->uNumDecorations].uFlags) |= 1u; | |
179 } | |
180 } | |
181 else | |
182 { | |
183 v35 = (int)&v2->pDecorations[v2->uNumDecorations].uFlags; | |
184 *(char *)v35 |= 0x80u; | |
185 } | |
186 } | |
187 else | |
188 { | |
189 v34 = (int)&v2->pDecorations[v2->uNumDecorations].uFlags; | |
190 *(char *)v34 |= 0x40u; | |
191 } | |
192 } | |
193 else | |
194 { | |
195 v33 = (int)&v2->pDecorations[v2->uNumDecorations].uFlags; | |
196 *(char *)v33 |= 0x20u; | |
197 } | |
198 } | |
199 else | |
200 { | |
201 v32 = (int)&v2->pDecorations[v2->uNumDecorations].uFlags; | |
202 *(char *)v32 |= 0x10u; | |
203 } | |
204 } | |
205 else | |
206 { | |
207 v31 = (int)&v2->pDecorations[v2->uNumDecorations].uFlags; | |
208 *(char *)v31 |= 8u; | |
209 } | |
210 } | |
211 else | |
212 { | |
213 v30 = (int)&v2->pDecorations[v2->uNumDecorations].uFlags; | |
214 *(char *)v30 |= 4u; | |
215 } | |
216 } | |
217 else | |
218 { | |
219 v29 = (int)&v2->pDecorations[v2->uNumDecorations].uFlags; | |
220 *(char *)v29 |= 2u; | |
221 } | |
222 } | |
223 else | |
224 { | |
225 v28 = (int)&v2->pDecorations[v2->uNumDecorations].uFlags; | |
226 *(char *)v28 |= 1u; | |
227 } | |
228 } | |
229 } | |
230 ++v2->uNumDecorations; | |
231 } | |
232 } | |
233 fclose(File); | |
234 return 1; | |
235 } | |
236 //----- (00458600) -------------------------------------------------------- | |
237 void DecorationList::ToFile() | |
238 { | |
239 DecorationList *v1; // esi@1 | |
240 FILE *v2; // eax@1 | |
241 FILE *v3; // edi@1 | |
242 | |
243 v1 = this; | |
244 v2 = fopen("data\\ddeclist.bin", "wb"); | |
245 v3 = v2; | |
246 if ( !v2 ) | |
247 Abortf("Unable to save ddeclist.bin!"); | |
248 fwrite(v1, 4u, 1u, v2); | |
249 fwrite(v1->pDecorations, 0x54u, v1->uNumDecorations, v3); | |
250 fclose(v3); | |
251 } | |
252 //----- (004488B6) -------------------------------------------------------- | |
253 unsigned __int16 DecorationList::GetDecorIdByName(const char *pName) | |
254 { | |
255 DecorationList *v2; // esi@1 | |
256 signed int uID; // edi@2 | |
257 signed int v4; // ebx@3 | |
258 unsigned __int16 result; // ax@6 | |
259 | |
260 v2 = this; | |
261 if ( pName && (uID = 1, (signed int)this->uNumDecorations > 1) ) | |
262 { | |
263 v4 = 1; | |
264 while ( _stricmp(pName, v2->pDecorations[v4].pName) ) | |
265 { | |
266 ++uID; | |
267 ++v4; | |
268 if ( uID >= (signed int)v2->uNumDecorations ) | |
1421 | 269 return 0; |
1297 | 270 } |
271 result = uID; | |
272 } | |
273 else | |
274 { | |
275 result = 0; | |
276 } | |
277 return result; | |
278 } |