MQ.h
Code: Select all
[color=red]
BOOL bKnownLocation;[/color]
BOOL bNoPet;
DWORD SortBy;[color=red]
} SEARCHSPAWN, *PSEARCHSPAWN;
typedef struct _SWHOSORT {
CHAR szName[MAX_STRING];
CHAR szLine[MAX_STRING];
BYTE Level;
DWORD SpawnID;
FLOAT Distance;[/color]
DWORD Class;
DWORD Race;
DWORD GuildID;[color=red]
} SWHOSORT, *PSWHOSORT;[/color]
Code: Select all
[color=red]
VOID SwapSWho (PSWHOSORT pSWho1, PSWHOSORT pSWho2);[/color]
VOID SortSWho (PSWHOSORT pSWhoSort, DWORD SpawnCount, DWORD SortBy = 0);[color=red]
VOID SuperWhoFindPets (PSPAWNINFO pChar, WORD SpawnID);[/color]
Code: Select all
// ***************************************************************************
// Function: SortSWho
// Description: Sorts an array of PSWHOSORT
// ***************************************************************************
VOID SortSWho(PSWHOSORT pSWhoSort, DWORD SpawnCount, DWORD SortBy)
{
DWORD Index1, Index2;
/* -- For reference purposes only
PCHAR szSortBy[] = {
"level", // Default sort by
"name",
"race",
"class",
"distance",
"guild",
"id",
NULL
};
*/
// Pre-sort the entire list by name
for (Index1=0;Index1<SpawnCount;Index1++) {
for (Index2=SpawnCount-1;Index2>Index1;Index2--) {
if (stricmp(pSWhoSort[Index2].szName, pSWhoSort[Index2-1].szName)<0) {
SwapSWho(&pSWhoSort[Index2], &pSWhoSort[Index2-1]);
}
}
}
switch (SortBy) {
case 0:
//Sort by Level
for (Index1=0;Index1<SpawnCount;Index1++) {
for (Index2=SpawnCount-1;Index2>Index1;Index2--) {
if (pSWhoSort[Index2].Level < pSWhoSort[Index2-1].Level) {
SwapSWho(&pSWhoSort[Index2], &pSWhoSort[Index2-1]);
}
}
}
break;
case 1:
//Sort by Name
for (Index1=0;Index1<SpawnCount;Index1++) {
for (Index2=SpawnCount-1;Index2>Index1;Index2--) {
if (stricmp(pSWhoSort[Index2].szName, pSWhoSort[Index2-1].szName)<0) {
SwapSWho(&pSWhoSort[Index2], &pSWhoSort[Index2-1]);
}
}
}
break;
case 2:
//Sort by Race
for (Index1=0;Index1<SpawnCount;Index1++) {
for (Index2=SpawnCount-1;Index2>Index1;Index2--) {
if (stricmp(GetRaceByID(pSWhoSort[Index2].Race), GetRaceByID(pSWhoSort[Index2-1].Race))<0) {
SwapSWho(&pSWhoSort[Index2], &pSWhoSort[Index2-1]);
}
}
}
break;
case 3:
//Sort by Class
for (Index1=0;Index1<SpawnCount;Index1++) {
for (Index2=SpawnCount-1;Index2>Index1;Index2--) {
if (stricmp(GetClassByID(pSWhoSort[Index2].Class), GetClassByID(pSWhoSort[Index2-1].Class))<0) {
SwapSWho(&pSWhoSort[Index2], &pSWhoSort[Index2-1]);
}
}
}
break;
case 4:
//Sort by Distance
for (Index1=0;Index1<SpawnCount;Index1++) {
for (Index2=SpawnCount-1;Index2>Index1;Index2--) {
if (pSWhoSort[Index2].Distance < pSWhoSort[Index2-1].Distance) {
SwapSWho(&pSWhoSort[Index2], &pSWhoSort[Index2-1]);
}
}
}
break;
case 5:
//Sort by Guild
for (Index1=0;Index1<SpawnCount;Index1++) {
for (Index2=SpawnCount-1;Index2>Index1;Index2--) {
if (pSWhoSort[Index2].GuildID < pSWhoSort[Index2-1].GuildID) {
SwapSWho(&pSWhoSort[Index2], &pSWhoSort[Index2-1]);
}
}
}
break;
case 6:
//Sort by Level
for (Index1=0;Index1<SpawnCount;Index1++) {
for (Index2=SpawnCount-1;Index2>Index1;Index2--) {
if (pSWhoSort[Index2].SpawnID < pSWhoSort[Index2-1].SpawnID) {
SwapSWho(&pSWhoSort[Index2], &pSWhoSort[Index2-1]);
}
}
}
break;
}
}
Code: Select all
[color=red]
pSWhoSort[SpawnCount].SpawnID = pSpawn->SpawnID;[/color]
pSWhoSort[SpawnCount].Class = pSpawn->Class;
pSWhoSort[SpawnCount].Race = pSpawn->Race;
pSWhoSort[SpawnCount].GuildID = pSpawn->GuildID;[color=red]
SpawnCount++;
}
if (pFilter) {[/color]
SortSWho(pSWhoSort,SpawnCount,pFilter->SortBy);[color=red]
} else {[/color]
SortSWho(pSWhoSort,SpawnCount,0);[color=red]
}[/color]
Code: Select all
[color=red]
strcat(szOutput,pSWhoSort[Index].szLine);
WriteChatColor(szOutput,Color);[/color]
if ((!pFilter) || (!pFilter->bNoPet)) [color=red]SuperWhoFindPets(pChar, pSWhoSort[Index].SpawnID,(Color!=USERCOLOR_WHO));
}
if (pFilter) {
if (SpawnCount==0) {
[/color]Code: Select all
[color=red]
pSearchSpawn->FromSpawnID = 0;[/color]
pSearchSpawn->bNoPet = FALSE;
pSearchSpawn->SortBy = 0;[color=red]
}[/color]
Code: Select all
[color=red]
} else if (!strcmp(szArg,"nopcnear")) {
GetArg(szArg,szRest,1);
if ((szArg[0]==0) || (0.0f == (pSearchSpawn->Radius = (FLOAT)atof(szArg)))) {
pSearchSpawn->Radius = 200.0f;
} else {
szRest = GetNextArg(szRest,1);
}[/color]
} else if (!strcmp(szArg,"nopet")) {
pSearchSpawn->bNoPet = TRUE;
[color=red]
} else {
strcpy(pSearchSpawn->szName,szArg);
szRest = GetNextArg(szRest,1);
}
}
return szRest;
[/color]Code: Select all
[color=red]
if (pSearchSpawn->bNotNearAlert) {
sprintf(szTemp," NotNearAlert:%d",pSearchSpawn->NotNearAlertList);
strcat(Buffer,szTemp);
}[/color]
if (pSearchSpawn->bNoPet) {
sprintf(szTemp," NoPet:%d",pSearchSpawn->bNoPet);
strcat(Buffer,szTemp);
}[color=red]
if (pSearchSpawn->bTrader) strcat(Buffer," Trader");[/color]
EQLib_Commands.cpp -- SuperWho
Code: Select all
// ***************************************************************************
// Function: SuperWho
// Description: Our '/who' command
// Displays a list of spawns in the zone
// Usage: /who <search string>
// ***************************************************************************
VOID SuperWho(PSPAWNINFO pChar, PCHAR szLine)
{
bRunNextCommand = TRUE;
DWORD Command=0;
CHAR szLLine[MAX_STRING] = {0};
CHAR szArg[MAX_STRING] = {0};
PCHAR szRest = szLLine;
BOOL Parsing = TRUE;
SEARCHSPAWN SearchSpawn;
PCHAR szSortBy[] = {
"level", // Default sort by
"name",
"race",
"class",
"distance",
"guild",
"id",
NULL
};
_strlwr(strcpy(szLLine,szLine));
ClearSearchSpawn(&SearchSpawn);
SearchSpawn.SpawnType = SPAWN_PLAYER;
if ((!stricmp(szLine,"all")) ||
(!strnicmp(szLine,"all ",4)) ||
(!strnicmp(szLine+strlen(szLine)-4," all",4)) ||
(strstr(szLine," all ")))
{
cmdWho(pChar, szLine);
return;
}
if (gFilterMacro == FILTERMACRO_NONE) cmdWho(pChar, szLine);
while (Parsing) {
GetArg(szArg,szRest,1);
szRest = GetNextArg(szRest,1);
if (szArg[0]==0) {
Parsing=FALSE;
} else if (!strcmp(szArg,"sort")) {
GetArg(szArg,szRest,1);
Command=0;
for (Command;szSortBy[Command];Command++) {
if (!strcmp(szArg,szSortBy[Command])) {
SearchSpawn.SortBy = Command;
szRest = GetNextArg(szRest,1);
}
}
} else {
szRest = ParseSearchSpawnArgs(szArg,szRest,&SearchSpawn);
}
}
DebugSpew("SuperWho - filtering %s",SearchSpawn.szName);
SuperWhoDisplay(pChar, &SearchSpawn,NULL);
}
*Re-edited to move the sort parser out of ParseSearchSpawnArgs
*Edited to add FormatSearchSpawn so if no entries are found w/ the nopet option enabled, it will include that in the return string.


