Mercurial > mm7
comparison DecorationList.cpp @ 1303:dcc52e17b517
m
author | Ritor1 |
---|---|
date | Sun, 23 Jun 2013 14:02:07 +0600 |
parents | |
children | 13b7be8b06a0 |
comparison
equal
deleted
inserted
replaced
1286:d8033eb56d7e | 1303:dcc52e17b517 |
---|---|
1 #include "DecorationList.h" | |
2 #include <string> | |
3 #include "Allocator.h" | |
4 #include "mm7_data.h" | |
5 #include "Sprites.h" | |
6 #include "FrameTableInc.h" | |
7 | |
8 | |
9 //----- (00458600) -------------------------------------------------------- | |
10 void DecorationList::ToFile() | |
11 { | |
12 DecorationList *v1; // esi@1 | |
13 FILE *v2; // eax@1 | |
14 FILE *v3; // edi@1 | |
15 | |
16 v1 = this; | |
17 v2 = fopen("data\\ddeclist.bin", "wb"); | |
18 v3 = v2; | |
19 if ( !v2 ) | |
20 Abortf("Unable to save ddeclist.bin!"); | |
21 fwrite(v1, 4u, 1u, v2); | |
22 fwrite(v1->pDecorations, 0x54u, v1->uNumDecorations, v3); | |
23 fclose(v3); | |
24 } | |
25 | |
26 //----- (0045864C) -------------------------------------------------------- | |
27 void DecorationList::FromFile(void *pSerialized) | |
28 { | |
29 uNumDecorations = *(int *)pSerialized; | |
30 pDecorations = (DecorationDesc *)pAllocator->AllocNamedChunk(pDecorations, | |
31 84 * uNumDecorations, "Dec Descrip"); | |
32 memcpy(pDecorations, (char *)pSerialized + 4, 84 * uNumDecorations); | |
33 } | |
34 | |
35 //----- (00458693) -------------------------------------------------------- | |
36 void DecorationList::InitializeDecorationSprite(unsigned int uDecID) | |
37 { | |
38 pSpriteFrameTable->InitializeSprite(this->pDecorations[uDecID].uSpriteID); | |
39 } | |
40 | |
41 //----- (004586B0) -------------------------------------------------------- | |
42 bool DecorationList::FromFileTxt(const char *Args) | |
43 { | |
44 DecorationList *v2; // ebx@1 | |
45 FILE *v3; // eax@1 | |
46 unsigned int v4; // esi@3 | |
47 void *v5; // eax@10 | |
48 FILE *v6; // ST18_4@12 | |
49 char *i; // eax@12 | |
50 unsigned __int16 v8; // ax@16 | |
51 const char *v9; // ST20_4@16 | |
52 const char *v10; // ST18_4@16 | |
53 __int16 v11; // ax@16 | |
54 const char *v12; // ST14_4@16 | |
55 unsigned __int16 v13; // ax@16 | |
56 const char *v14; // ST10_4@16 | |
57 __int16 v15; // ax@16 | |
58 const char *v16; // ST0C_4@16 | |
59 unsigned __int8 v17; // al@16 | |
60 const char *v18; // ST08_4@16 | |
61 unsigned __int8 v19; // al@16 | |
62 const char *v20; // ST04_4@16 | |
63 unsigned __int8 v21; // al@16 | |
64 const char *v22; // ST00_4@16 | |
65 unsigned __int8 v23; // zf@16 | |
66 char v24; // sf@16 | |
67 unsigned __int8 v25; // of@16 | |
68 int j; // edi@17 | |
69 const char *v27; // esi@18 | |
70 int v28; // eax@19 | |
71 int v29; // eax@21 | |
72 int v30; // eax@23 | |
73 int v31; // eax@25 | |
74 int v32; // eax@27 | |
75 int v33; // eax@29 | |
76 int v34; // eax@31 | |
77 int v35; // eax@33 | |
78 FrameTableTxtLine v37; // [sp+Ch] [bp-460h]@17 | |
79 FrameTableTxtLine v38; // [sp+88h] [bp-3E4h]@13 | |
80 char Dest; // [sp+104h] [bp-368h]@17 | |
81 char Buf; // [sp+17Ch] [bp-2F0h]@3 | |
82 FrameTableTxtLine v41; // [sp+370h] [bp-FCh]@4 | |
83 FrameTableTxtLine v42; // [sp+3ECh] [bp-80h]@4 | |
84 FILE *File; // [sp+468h] [bp-4h]@1 | |
85 unsigned int Argsa; // [sp+474h] [bp+8h]@3 | |
86 | |
87 v2 = this; | |
88 v3 = fopen(Args, "r"); | |
89 File = v3; | |
90 if ( !v3 ) | |
91 Abortf("DecorationDescriptionList::load - Unable to open file: %s."); | |
92 v4 = 0; | |
93 Argsa = 0; | |
94 if ( fgets(&Buf, 490, v3) ) | |
95 { | |
96 do | |
97 { | |
98 *strchr(&Buf, 10) = 0; | |
99 memcpy(&v42, frame_table_txt_parser(&Buf, &v41), sizeof(v42)); | |
100 if ( v42.uPropCount && *v42.pProperties[0] != 47 && v42.uPropCount >= 3 ) | |
101 ++Argsa; | |
102 } | |
103 while ( fgets(&Buf, 490, File) ); | |
104 v4 = Argsa; | |
105 } | |
106 v2->uNumDecorations = v4; | |
107 v5 = pAllocator->AllocNamedChunk(v2->pDecorations, 84 * v4, "Dec Descrip"); | |
108 v2->pDecorations = (DecorationDesc *)v5; | |
109 if ( !v5 ) | |
110 Abortf("DecorationDescriptionList::load - Out of Memory!"); | |
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 | |
239 //----- (004488B6) -------------------------------------------------------- | |
240 unsigned __int16 DecorationList::GetDecorIdByName(const char *pName) | |
241 { | |
242 DecorationList *v2; // esi@1 | |
243 signed int uID; // edi@2 | |
244 signed int v4; // ebx@3 | |
245 unsigned __int16 result; // ax@6 | |
246 | |
247 v2 = this; | |
248 if ( pName && (uID = 1, (signed int)this->uNumDecorations > 1) ) | |
249 { | |
250 v4 = 1; | |
251 while ( _stricmp(pName, v2->pDecorations[v4].pName) ) | |
252 { | |
253 ++uID; | |
254 ++v4; | |
255 if ( uID >= (signed int)v2->uNumDecorations ) | |
256 goto LABEL_6; | |
257 } | |
258 result = uID; | |
259 } | |
260 else | |
261 { | |
262 LABEL_6: | |
263 result = 0; | |
264 } | |
265 return result; | |
266 } |