comparison ObjectList.cpp @ 1545:c4ab816fcc5e

assert, Abortf, AbortWithError -> Assert, Error refactors here and there
author Nomad
date Sat, 07 Sep 2013 20:05:20 +0200
parents 7ef4b64f6329
children 75fafd8ced59
comparison
equal deleted inserted replaced
1544:499761153844 1545:c4ab816fcc5e
1 #include "ObjectList.h" 1 #include "ObjectList.h"
2 #include "mm7_data.h" 2 #include "mm7_data.h"
3 #include "Sprites.h" 3 #include "Sprites.h"
4 #include "FrameTableInc.h" 4 #include "FrameTableInc.h"
5 #include "Allocator.h" 5 #include "Allocator.h"
6 #include "ErrorHandling.h"
6 7
7 //----- (0042EB42) -------------------------------------------------------- 8 //----- (0042EB42) --------------------------------------------------------
8 __int16 ObjectList::ObjectIDByItemID(unsigned __int16 uItemID) 9 __int16 ObjectList::ObjectIDByItemID(unsigned __int16 uItemID)
9 { 10 {
10 unsigned int v2; // edx@1 11 unsigned int v2; // edx@1
47 48
48 v1 = this; 49 v1 = this;
49 v2 = fopen("data\\dobjlist.bin", "wb"); 50 v2 = fopen("data\\dobjlist.bin", "wb");
50 v3 = v2; 51 v3 = v2;
51 if ( !v2 ) 52 if ( !v2 )
52 Abortf("Unable to save dobjlist.bin!"); 53 Error("Unable to save dobjlist.bin!");
53 fwrite(v1, 4u, 1u, v2); 54 fwrite(v1, 4u, 1u, v2);
54 fwrite(v1->pObjects, 0x38u, v1->uNumObjects, v3); 55 fwrite(v1->pObjects, 0x38u, v1->uNumObjects, v3);
55 fclose(v3); 56 fclose(v3);
56 } 57 }
57 58
61 uint num_mm6_objs = data_mm6 ? *(int *)data_mm6 : 0, 62 uint num_mm6_objs = data_mm6 ? *(int *)data_mm6 : 0,
62 num_mm7_objs = data_mm7 ? *(int *)data_mm7 : 0, 63 num_mm7_objs = data_mm7 ? *(int *)data_mm7 : 0,
63 num_mm8_objs = data_mm8 ? *(int *)data_mm8 : 0; 64 num_mm8_objs = data_mm8 ? *(int *)data_mm8 : 0;
64 65
65 uNumObjects = num_mm6_objs + num_mm7_objs + num_mm8_objs; 66 uNumObjects = num_mm6_objs + num_mm7_objs + num_mm8_objs;
66 assert(uNumObjects); 67 Assert(uNumObjects);
67 assert(!num_mm8_objs); 68 Assert(!num_mm8_objs);
68 69
69 pObjects = (ObjectDesc *)pAllocator->AllocNamedChunk(pObjects, uNumObjects * sizeof(ObjectDesc), "Obj Descrip"); 70 pObjects = (ObjectDesc *)pAllocator->AllocNamedChunk(pObjects, uNumObjects * sizeof(ObjectDesc), "Obj Descrip");
70 memcpy(pObjects, (char *)data_mm7 + 4, num_mm7_objs * sizeof(ObjectDesc)); 71 memcpy(pObjects, (char *)data_mm7 + 4, num_mm7_objs * sizeof(ObjectDesc));
71 for (uint i = 0; i < num_mm6_objs; ++i) 72 for (uint i = 0; i < num_mm6_objs; ++i)
72 { 73 {
146 v2->pObjects = 0; 147 v2->pObjects = 0;
147 v2->uNumObjects = 0; 148 v2->uNumObjects = 0;
148 v4 = fopen(Args, "r"); 149 v4 = fopen(Args, "r");
149 File = v4; 150 File = v4;
150 if ( !v4 ) 151 if ( !v4 )
151 Abortf("ObjectDescriptionList::load - Unable to open file: %s."); 152 Error("ObjectDescriptionList::load - Unable to open file: %s.");
153
152 v5 = 0; 154 v5 = 0;
153 Argsa = 0; 155 Argsa = 0;
154 if ( fgets(&Buf, 490, v4) ) 156 if ( fgets(&Buf, 490, v4) )
155 { 157 {
156 do 158 do
166 } 168 }
167 v2->uNumObjects = v5; 169 v2->uNumObjects = v5;
168 v6 = pAllocator->AllocNamedChunk(v2->pObjects, 56 * v5, "Obj Descrip"); 170 v6 = pAllocator->AllocNamedChunk(v2->pObjects, 56 * v5, "Obj Descrip");
169 v2->pObjects = (ObjectDesc *)v6; 171 v2->pObjects = (ObjectDesc *)v6;
170 if ( v6 == (void *)v3 ) 172 if ( v6 == (void *)v3 )
171 Abortf("ObjectDescriptionList::load - Out of Memory!"); 173 Error("ObjectDescriptionList::load - Out of Memory!");
174
172 memset(v6, v3, 56 * v2->uNumObjects); 175 memset(v6, v3, 56 * v2->uNumObjects);
173 v7 = File; 176 v7 = File;
174 v2->uNumObjects = v3; 177 v2->uNumObjects = v3;
175 fseek(v7, v3, v3); 178 fseek(v7, v3, v3);
176 for ( i = fgets(&Buf, 490, File); i; i = fgets(&Buf, 490, File) ) 179 for ( i = fgets(&Buf, 490, File); i; i = fgets(&Buf, 490, File) )