annotate DecorationList.cpp @ 1304:9d99e7b76cdc

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