static void InsertAlias(PriorQue ** PQ, EDA_LibComponentStruct *LibEntry, int *NumOfParts) /********************************************************************/ /* create in library (in list PQ) aliases of the "root" component LibEntry*/ { EDA_LibCmpAliasStruct *AliasEntry; unsigned ii; if(LibEntry->m_AliasList.GetCount() == 0) return; /* No alias for this component */ for( ii = 0; ii < LibEntry->m_AliasList.GetCount(); ii++ ) { AliasEntry = new EDA_LibCmpAliasStruct(LibEntry->m_AliasList[ii], LibEntry->m_Name.m_Text.GetData()); ++*NumOfParts; PQInsert(PQ, AliasEntry); } }
bool Map::ShortestPath(uint8 sx, uint8 sy, uint8 tx, uint8 ty, Creature *runner, int32 dangerFactor, uint16 *ThePath) { int32 xy, i, c; int16 x, y, nx, ny; static int16 Dist[256][256]; static uint16 Parent[256][256]; if (!ThePath) ThePath = ::ThePath; ASSERT(InBounds(sx,sy)) ASSERT(InBounds(tx,ty)) PHead = NULL; bool Incor = runner->HasMFlag(M_INCOR) || runner->HasStati(PHASED); bool Meld = runner->HasAbility(CA_EARTHMELD); for (x=0;x!=256;x++) for(y=0;y!=256;y++) { Dist[x][y] = 30000; Parent[x][y] = 0; } Dist[sx][sy] = 0; PQInsert(sx+sy*256,0); while ((xy = PQPeekMin()) != -1) { PQPopMin(); x = xy % 256; y = xy / 256; for (i=0;i!=8;i++) { nx = x + DirX[i]; ny = y + DirY[i]; /* KLUDGE: We consider (0,0) to be offmap so that we can use node 0 as a special empty/unmarked value. */ if (nx == 0 && ny == 0) continue; if (!InBounds(nx,ny)) continue; int baseCost = RunOver(nx,ny,true,runner,dangerFactor,Incor,Meld); if (!baseCost) continue; if (DirX[i] && DirY[i]) baseCost = (baseCost * 3) / 2; if (Dist[x][y] + baseCost < Dist[nx][ny]) { Dist[nx][ny] = min(30000,Dist[x][y] + baseCost); Parent[nx][ny] = x+y*256; PQInsert(nx+ny*256,Dist[nx][ny]); } } } x = tx; y = ty; c = 0; if (Dist[tx][ty] == 30000) { #ifdef DEBUG_DJIKSTRA for (x = min(0,sx-30);x!=max(127,sx+30);x++) for (y = min(0,sx-30);y!=max(127,sy+30);y++) if (Dist[x][y] != 30000) { At(x,y).Glyph = GLYPH_FLOOR2 | (EMERALD*256); At(x,y).Memory = GLYPH_FLOOR2 | (EMERALD*256); At(x,y).Shade = false; } #endif return false; } do { c++; xy = Parent[x][y]; x = xy % 256; y = xy / 256; } while (xy); x = tx; y = ty; i = 0; c--; do { ThePath[c - i] = x + y*256; xy = Parent[x][y]; x = xy % 256; y = xy / 256; i++; } while (xy); ThePath[c+1] = 0; #ifdef DEBUG_DJIKSTRA for (i=0;i==0 || ThePath[i];i++) { At(ThePath[i]%256,ThePath[i]/256).Glyph = GLYPH_FLOOR2 | (MAGENTA*256); At(ThePath[i]%256,ThePath[i]/256).Memory = GLYPH_FLOOR2 | (MAGENTA*256); At(ThePath[i]%256,ThePath[i]/256).Shade = false; } #endif return true; }
/***************************************************************************** * Routine to load a library from given open file. * *****************************************************************************/ PriorQue *LoadLibraryAux(WinEDA_DrawFrame * frame, LibraryStruct * Library, FILE *libfile, int *NumOfParts) { int LineNum = 0; char Line[1024]; PriorQue *PQ = NULL; EDA_LibComponentStruct *LibEntry; wxString msg; wxBusyCursor ShowWait; // Display a Busy Cursor.. *NumOfParts = 0; if ( GetLine(libfile, Line, &LineNum, sizeof(Line) ) == NULL) { msg = _("File <") + Library->m_Name + _("> is empty!"); DisplayError(frame, msg); return NULL; } if( strnicmp(Line, LIBFILE_IDENT, 10) != 0) { msg = _("File <") + Library->m_Name + _("> is NOT EESCHEMA library!"); DisplayError(frame, msg); return NULL; } if ( Library ) Library->m_Header = CONV_FROM_UTF8(Line); PQInit(&PQ); PQCompFunc((PQCompFuncType) LibraryEntryCompare); while (GetLine(libfile, Line, &LineNum, sizeof(Line)) ) { if (strnicmp(Line, "$HEADER", 7) == 0) { if ( Library ) { if ( ! Library->ReadHeader(libfile, &LineNum) ) { msg = _("Library <") + Library->m_Name + _("> header read error"); DisplayError(frame, msg, 30); } } continue; } if (strnicmp(Line, "DEF", 3) == 0) { /* Read one DEF/ENDDEF part entry from library: */ LibEntry = Read_Component_Definition(frame, Line, libfile, &LineNum); if ( LibEntry ) { /* If we are here, this part is O.k. - put it in: */ ++*NumOfParts; PQInsert(&PQ, LibEntry); InsertAlias(&PQ, LibEntry, NumOfParts); } } } return PQ; }