World* StructureInterface::loadStructure(string fileName, World** external, VECTOR2 Vout) { ifstream fin(fileName); if(fin.fail()) throw(GameError(gameErrorNS::FATAL_ERROR, "Error loading structure")); int width, height; fin>>width; fin>>height; World* W = new World(width, height, imageLibrary); W->getTile() = new Tile**[width]; for(int i=0; i<width; i++) W->getTile(i) = new Tile*[height]; int x = 0, y = 0; char c; fin.get(c); while(!fin.eof() && y < height) { if(!isspace(c)) { assignTile(W, c, x, y, external, Vout); x++; if(x>=width) { x = 0; y++; } } fin.get(c); } int npcCount; fin >> npcCount; for (int i=0; i<npcCount; i++) { int ID, textLines, talkSoundID; string sound; char dir; float x, y; fin >> ID; if(ID <= 1) { Image* img; if (ID == 0) img = &imageLibrary->Character2IM; else img = &imageLibrary->Character1IM; fin >> textLines >> x >> y >> dir >> talkSoundID; x += .5;y += .5; NPC* temp = new NPC(ID, VECTOR2(x,y), img, 0); string* text = new string[textLines]; char buffer[500]; fin.get(); for (int i=0; i<textLines; i++){ fin.getline(buffer,500); text[i] = buffer; if (buffer[0] == '%') { temp->addConditionalLine(i); text[i] = text[i].substr(1); } if(text[i].find("(sword acquired)") != -1) temp->item = "sword"; else if(text[i] == "(learned fireball attack)") temp->item = "fireball"; } temp->setText(text, textLines); switch(dir){ case 'u': temp->setDir(UP); break; case 'd': temp->setDir(DOWN); break; case 'l': temp->setDir(LEFT); break; case 'r': temp->setDir(RIGHT); break; } temp->setTalkSound(getTalkSound(talkSoundID)); W->addEntity(temp, new StationaryAI(temp)); } else if(ID == 2)