void SpawnShell::restoreSpawns(void) { QString fileName = showeq_params->saveRestoreBaseFilename + "Spawns.dat"; QFile keyFile(fileName); if (keyFile.open(IO_ReadOnly)) { size_t i; size_t testVal; uint16_t id; Spawn* item; QDataStream d(&keyFile); // check the magic string uint32_t magicTest; d >> magicTest; if (magicTest != *magic) { fprintf(stderr, "Failure loading %s: Bad magic string!\n", (const char*)fileName); return; } // check the test value at the top of the file d >> testVal; if (testVal != sizeof(spawnStruct)) { fprintf(stderr, "Failure loading %s: Bad spawnStruct size!\n", (const char*)fileName); return; } // read the expected number of elements d >> testVal; // read in the spawns for (i = 0; i < testVal; i++) { // get the spawn id d >> id; // re-create the spawn item = new Spawn(d, id); // filter and add it to the list updateFilterFlags(item); updateRuntimeFilterFlags(item); m_spawns.insert(id, item); emit addItem(item); } emit numSpawns(m_spawns.count()); fprintf(stderr, "Restored SPAWNS: count=%d!\n", m_spawns.count()); }
void SpawnShell::newSpawn(const spawnStruct& s) { #ifdef SPAWNSHELL_DIAG printf("SpawnShell::newSpawn(spawnStruct *(name='%s'), bSelected=%s)\n", s.name, bSelected?"true":"false"); #endif // if this is the SPAWN_SELF it's the player if (s.NPC == SPAWN_SELF) return; // not the player, so check if it's a recently deleted spawn for (int i =0; i < m_cntDeadSpawnIDs; i++) { if ((m_deadSpawnID[i] != 0) && (m_deadSpawnID[i] == s.spawnId)) { // found a match, remove it from the deleted spawn list m_deadSpawnID[i] = 0; // let the user know what's going on printf("%s(%d) has already been removed from the zone before we processed it.\n", s.name, s.spawnId); // and stop the attempt to add the spawn. return; } } Item* item = m_spawns.find(s.spawnId); if (item != NULL) { Spawn* spawn = (Spawn*)item; spawn->update(&s); updateFilterFlags(item); updateRuntimeFilterFlags(item); item->updateLastChanged(); emit changeItem(item, tSpawnChangedALL); } else { item = new Spawn(&s); updateFilterFlags(item); updateRuntimeFilterFlags(item); m_spawns.insert(s.spawnId, item); emit addItem(item); // send notification of new spawn count emit numSpawns(m_spawns.count()); } if (item->filterFlags() & FILTER_FLAG_ALERT) emit handleAlert(item, tNewSpawn); }
void SpawnShell::deleteItem(spawnItemType type, int id) { #ifdef SPAWNSHELL_DIAG seqDebug("SpawnShell::deleteItem()"); #endif ItemMap& theMap = getMap(type); Item* item = theMap.find(id); if (item != NULL) { emit delItem(item); theMap.remove(id); // send notifcation of new spawn count emit numSpawns(m_spawns.count()); } }
void SpawnShell::deleteItem(itemType type, int id) { #ifdef SPAWNSHELL_DIAG printf ("SpawnShell::deleteItem()\n"); #endif ItemMap& theMap = getMap(type); Item* item = theMap.find(id); if (item != NULL) { if (item->filterFlags() & FILTER_FLAG_ALERT) emit handleAlert(item, tDelSpawn); emit delItem(item); theMap.remove(id); // send notifcation of new spawn count emit numSpawns(m_spawns.count()); } }
void SpawnShell::newSpawn(const spawnStruct& s) { #ifdef SPAWNSHELL_DIAG seqDebug("SpawnShell::newSpawn(spawnStruct *(name='%s'))", s.name); #endif // if this is the SPAWN_SELF it's the player if (s.NPC == SPAWN_SELF) return; // not the player, so check if it's a recently deleted spawn for (int i =0; i < m_cntDeadSpawnIDs; i++) { if ((m_deadSpawnID[i] != 0) && (m_deadSpawnID[i] == s.spawnId)) { // found a match, remove it from the deleted spawn list m_deadSpawnID[i] = 0; // let the user know what's going on seqInfo("%s(%d) has already been removed from the zone before we processed it.", s.name, s.spawnId); // and stop the attempt to add the spawn. return; } } Item* item = m_spawns.find(s.spawnId); if (item != NULL) { Spawn* spawn = (Spawn*)item; spawn->update(&s); updateFilterFlags(spawn); updateRuntimeFilterFlags(spawn); item->updateLastChanged(); if (spawn->guildID() < MAX_GUILDS) spawn->setGuildTag(m_guildMgr->guildIdToName(spawn->guildID())); else spawn->setGuildTag(""); if (!showeq_params->fast_machine) item->setDistanceToPlayer(m_player->calcDist2DInt(*item)); else item->setDistanceToPlayer(m_player->calcDist(*item)); emit changeItem(item, tSpawnChangedALL); } else { item = new Spawn(&s); Spawn* spawn = (Spawn*)item; updateFilterFlags(spawn); updateRuntimeFilterFlags(spawn); m_spawns.insert(s.spawnId, item); if (spawn->guildID() < MAX_GUILDS) spawn->setGuildTag(m_guildMgr->guildIdToName(spawn->guildID())); else spawn->setGuildTag(""); if (!showeq_params->fast_machine) item->setDistanceToPlayer(m_player->calcDist2DInt(*item)); else item->setDistanceToPlayer(m_player->calcDist(*item)); emit addItem(item); // send notification of new spawn count emit numSpawns(m_spawns.count()); } }
void SpawnShell::updateSpawn(uint16_t id, int16_t x, int16_t y, int16_t z, int16_t xVel, int16_t yVel, int16_t zVel, int8_t heading, int8_t deltaHeading, uint8_t animation) { #ifdef SPAWNSHELL_DIAG printf("SpawnShell::updateSpawn(id=%d, x=%d, y=%d, z=%d, xVel=%d, yVel=%d, zVel=%d)\n", id, x, y, z, xVel, yVel, zVel); #endif Item* item = m_spawns.find(id); if (item != NULL) { Spawn* spawn = (Spawn*)item; spawn->setPos(x, y, z, showeq_params->walkpathrecord, showeq_params->walkpathlength); spawn->setAnimation(animation); if ((animation != 0) && (animation != 66)) { spawn->setDeltas(xVel, yVel, zVel); spawn->setHeading(heading, deltaHeading); } else { spawn->setDeltas(0, 0, 0); spawn->setHeading(heading, 0); } spawn->updateLast(); item->updateLastChanged(); emit changeItem(item, tSpawnChangedPosition); } else if (showeq_params->createUnknownSpawns) { // not the player, so check if it's a recently deleted spawn for (int i =0; i < m_cntDeadSpawnIDs; i++) { // check dead spawn list for spawnID, if it was deleted, shouldn't // see new position updates, so therefore this is probably // for a new spawn (spawn ID being reused) if ((m_deadSpawnID[i] != 0) && (m_deadSpawnID[i] == id)) { // found a match, ignore it m_deadSpawnID[i] = 0; printf("\a(%d) had been removed from the zone, but saw a position update on it, so assuming bogus update.\n", id); return; } } item = new Spawn(id, x, y, z, xVel, yVel, zVel, heading, deltaHeading, animation); updateFilterFlags(item); updateRuntimeFilterFlags(item); m_spawns.insert(id, item); emit addItem(item); // send notification of new spawn count emit numSpawns(m_spawns.count()); } }