本文整理汇总了C++中Spawn类的典型用法代码示例。如果您正苦于以下问题:C++ Spawn类的具体用法?C++ Spawn怎么用?C++ Spawn使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Spawn类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: xmlParseFile
bool Spawns::loadFromXml(const std::string& _filename)
{
if (isLoaded()) {
return true;
}
filename = _filename;
xmlDocPtr doc = xmlParseFile(filename.c_str());
if (doc) {
xmlNodePtr root, spawnNode;
root = xmlDocGetRootElement(doc);
if (xmlStrcmp(root->name, (const xmlChar*)"spawns") != 0) {
xmlFreeDoc(doc);
return false;
}
int32_t intValue;
std::string strValue;
spawnNode = root->children;
while (spawnNode) {
if (xmlStrcmp(spawnNode->name, (const xmlChar*)"spawn") == 0) {
Position centerPos;
int32_t radius = -1;
if (readXMLInteger(spawnNode, "centerx", intValue)) {
centerPos.x = intValue;
} else {
xmlFreeDoc(doc);
return false;
}
if (readXMLInteger(spawnNode, "centery", intValue)) {
centerPos.y = intValue;
} else {
xmlFreeDoc(doc);
return false;
}
if (readXMLInteger(spawnNode, "centerz", intValue)) {
centerPos.z = intValue;
} else {
xmlFreeDoc(doc);
return false;
}
if (readXMLInteger(spawnNode, "radius", intValue)) {
radius = intValue;
} else {
xmlFreeDoc(doc);
return false;
}
Spawn* spawn = new Spawn(centerPos, radius);
spawnList.push_back(spawn);
xmlNodePtr tmpNode = spawnNode->children;
while (tmpNode) {
if (xmlStrcmp(tmpNode->name, (const xmlChar*)"monster") == 0) {
std::string name = "";
Position pos = centerPos;
Direction dir = NORTH;
uint32_t interval = 0;
if (readXMLString(tmpNode, "name", strValue)) {
name = strValue;
} else {
tmpNode = tmpNode->next;
continue;
}
if (readXMLInteger(tmpNode, "direction", intValue)) {
switch (intValue) {
case 0:
dir = NORTH;
break;
case 1:
dir = EAST;
break;
case 2:
dir = SOUTH;
break;
case 3:
dir = WEST;
break;
}
}
if (readXMLInteger(tmpNode, "x", intValue)) {
pos.x += intValue;
} else {
tmpNode = tmpNode->next;
continue;
}
//.........这里部分代码省略.........
示例2: printf
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());
}
}
示例3: spawnConsidered
void SpawnShell::consMessage(const considerStruct * con, uint32_t, uint8_t dir)
{
Item* item;
Spawn* spawn;
if (dir == DIR_CLIENT)
{
if (con->playerid != con->targetid)
{
item = m_spawns.find(con->targetid);
if (item != NULL)
{
spawn = (Spawn*)item;
// note that this spawn has been considered
spawn->setConsidered(true);
emit spawnConsidered(item);
}
}
return;
}
QString lvl("");
QString hps("");
QString cn("");
QString msg("Faction: Your faction standing with ");
//printf("%i, %i, %i, %i\n", con->unknown1[0], con->unknown1[1], con->unknown2[0], con->unknown2[1]);
// is it you that you've conned?
if (con->playerid == con->targetid)
{
// print it's deity
printf("Diety: %s\n", (const char*)m_player->deityName());
// well, this is You
msg += "YOU";
}
else
{
// find the spawn if it exists
item = m_spawns.find(con->targetid);
// has the spawn been seen before?
if (item != NULL)
{
Spawn* spawn = (Spawn*)item;
// yes
printf("Diety: %s\n", (const char*)spawn->deityName());
int changed = tSpawnChangedNone;
/* maxhp and curhp are available when considering players, */
/* but not when considering mobs. */
if (con->maxHp || con->curHp)
{
if (spawn->NPC() == SPAWN_NPC_UNKNOWN)
{
spawn->setNPC(SPAWN_PLAYER); // player
changed |= tSpawnChangedNPC;
}
spawn->setMaxHP(con->maxHp);
spawn->setHP(con->curHp);
changed |= tSpawnChangedHP;
}
else if (item->NPC() == SPAWN_NPC_UNKNOWN)
{
spawn->setNPC(SPAWN_NPC);
changed |= tSpawnChangedNPC;
}
// note the updates if any
if (changed != tSpawnChangedNone)
{
if (updateFilterFlags(item))
changed |= tSpawnChangedFilter;
if (updateRuntimeFilterFlags(item))
changed |= tSpawnChangedRuntimeFilter;
item->updateLastChanged();
emit changeItem(item, changed);
}
// note that this spawn has been considered
spawn->setConsidered(true);
emit spawnConsidered(item);
msg += item->name();
} // end if spawn found
else
msg += "Spawn:" + QString::number(con->targetid, 16);
} // else not yourself
switch (con->level)
{
case 0:
{
//.........这里部分代码省略.........
示例4: Item
Spawn::Spawn(Spawn& s, uint16_t id)
: Item(tSpawn, id)
{
setName(s.name());
setLastName(s.lastName());
Item::setPoint(s.x(), s.y(), s.z());
setPetOwnerID(s.petOwnerID());
setLight(s.light());
setGender(s.gender());
setDeity(s.deity());
setRace(s.race());
setClassVal(s.classVal());
setHP(s.HP());
setMaxHP(s.maxHP());
setGuildID(s.GuildID());
setLevel(s.level());
for (int i = 0; i <= tLastCoreWearSlot; i++)
setEquipment(i, s.equipment(i));
setEquipment(tUnknown1, 0);
setTypeflag(s.typeflag());
setNPC(s.NPC());
setAnimation(s.animation());
setDeltas(s.deltaX(), s.deltaY(), s.deltaZ());
setHeading(s.heading(), s.deltaHeading());
setConsidered(s.considered());
// the new copy will own the spawn track list
m_spawnTrackList.setAutoDelete(false);
m_spawnTrackList = s.m_spawnTrackList;
s.m_spawnTrackList.setAutoDelete(false);
m_spawnTrackList.setAutoDelete(true);
}
示例5: lvl
void MessageShell::consMessage(const uint8_t* data, size_t, uint8_t dir)
{
const considerStruct * con = (const considerStruct*)data;
const Item* item;
QString lvl("");
QString hps("");
QString cn("");
QString deity;
QString msg("Your faction standing with ");
// is it you that you've conned?
if (con->playerid == con->targetid)
{
deity = m_player->deityName();
// well, this is You
msg += m_player->name();
}
else
{
// find the spawn if it exists
item = m_spawnShell->findID(tSpawn, con->targetid);
// has the spawn been seen before?
if (item != NULL)
{
Spawn* spawn = (Spawn*)item;
// yes
deity = spawn->deityName();
msg += item->name();
} // end if spawn found
else
msg += "Spawn:" + QString::number(con->targetid, 16);
} // else not yourself
switch (con->level)
{
case 0:
case 20:
msg += " (even)";
break;
case 2:
msg += " (green)";
break;
case 4:
msg += " (blue)";
break;
case 13:
msg += " (red)";
break;
case 15:
msg += " (yellow)";
break;
case 18:
msg += " (cyan)";
break;
default:
msg += " (unknown: " + QString::number(con->level) + ")";
break;
}
if (!deity.isEmpty())
msg += QString(" [") + deity + "]";
if (con->maxHp || con->curHp)
{
lvl.sprintf(" (%i/%i HP)", con->curHp, con->maxHp);
msg += lvl;
}
msg += QString(" is: ") + print_faction(con->faction) + " ("
+ QString::number(con->faction) + ")!";
m_messages->addMessage(MT_Consider, msg);
} // end consMessage()
示例6: main
int main (int argc, char *argv[])
{
FILE *sdb;
struct dbSpawnStruct dbSpawn;
int count=0;
// CGI Convenience class
CGI cgiconv;
// search variables
QString searchName = "";
QString searchZone = "";
int searchLevel = 0;
QString searchRace = "";
int searchClass = 0;
// are we performing a serch (default = false)
bool doSearch = false;
// process any CGI data
cgiconv.processCGIData();
// If there are form parameters use them for searching
if (cgiconv.getParamCount() != 0)
{
searchName = cgiconv.getParamValue("name");
searchZone = cgiconv.getParamValue("zone");
searchLevel = cgiconv.getParamValue("level").toInt();
searchRace = cgiconv.getParamValue("race");
searchClass = cgiconv.getParamValue("class").toInt();
if (!searchName.isEmpty() || !searchZone.isEmpty() ||
!searchRace.isEmpty() ||
(searchLevel != 0) || (searchClass != 0))
doSearch = true;
}
else if (argc == 2)
{
// use the argument for the name search
searchName = argv[1];
// note that a search is being done.
doSearch = true;
}
// open the output data stream
QTextStream out(stdout, IO_WriteOnly);
out.setEncoding(QTextStream::Latin1);
out.flags(QTextStream::showbase | QTextStream::dec);
const char* header =
"Content-type: text/html; charset=iso-8859-1\n\n"
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">\n"
"<HTML>\n"
" <HEAD>\n"
" <TITLE>ShowEQ Spawn List</TITLE>\n"
" <style type=\"text/css\">\n"
" <!--\n"
" table { border: black 2px solid }\n"
" td { border: black 1px solid }\n"
" th { border: black 1px solid }\n"
" -->\n"
" </style>\n"
" </HEAD>\n"
" <BODY>\n";
/* Print HTML header */
out << header;
const char* footer =
" </BODY>\n"
"</HTML>\n";
// check for browser type
QString userAgent = cgiconv.getHTTPUserAgent();
out << " <!-- Output for UserAgent: " << userAgent << "-->\n";
out << "<FORM method=\"POST\" action=\"" << cgiconv.getScriptName()
<< "\">\n";
// beware Netscape 4.x style sheet brain death
if ((userAgent.contains("Mozilla/4.") == 1) &&
(userAgent.contains("MSIE") == 0))
out << "<TABLE border=2 cellspacing=0 cellpadding=2>\n";
else
out << "<TABLE cellspacing=0 cellpadding=2>\n";
out <<
"<TR>"
"<TH>Name</TH><TH>Zone</TH><TH>Level</TH><TH>Race</TH><TH>Class</TH>\n"
"<TD><INPUT type=\"reset\" value=\"Reset\"/></TD>\n"
"</TR>\n";
out << "<TR>";
// name field
out << "<TD><INPUT type=\"text\" name=\"name\" value=\""
<< searchName << "\"/></TD>\n";
//.........这里部分代码省略.........
示例7: while
//.........这里部分代码省略.........
if (tele)
tele->setDestPos(toPos);
} break;
case 0x80: // Fluids
fgetc(fh);
if (item->isFluidContainer())
item->setItemCountOrSubtype((unsigned char)fgetc(fh));
else
fgetc(fh);
break;
case 0xFF: // End
break;
default: // Unknow/New operators
{
printf("WARNING: Unknown operator loading items: 0x%X!\n",op3);
int len = fgetc(fh);
for (int i = 0; i < len; i++)
fgetc(fh);
} break;
}
} while (op3 < 0xFF);
//item->pos.x = x;
//item->pos.y = y;
//item->pos.z = z;
if (item->isAlwaysOnTop())
t->topItems.push_back(item);
else
t->downItems.push_back(item);
}
} break;
case 0xFF: // End
break;
default: // Unknow/New operators
{
printf("WARNING: Unknown operator loading tiles: 0x%X!\n",op2);
int len = fgetc(fh);
for (int i = 0;i < len; i++)
fgetc(fh);
} break;
}
} while (op2 < 0xFF);
}
std::cout << ":: Total of tiles loaded is " << total << std::endl;
} break;
case 0x50: // Spawns
{
SpawnManager::initialize(&g_game);
Position pos;
int cx, cy, radius, total=0;
long int secs;
std::string cname;
int num = fgetc(fh); num+=fgetc(fh)<<8;
for (int i = 0; i < num; i++)
{
int len = fgetc(fh);
int count;
cname = "";
for (int j = 0;j < len; j++)
cname.push_back(fgetc(fh)); // get the creature name
//std::cout << cname.c_str() << std::endl;
pos.x = fgetc(fh); pos.x += fgetc(fh) << 8;
pos.y = fgetc(fh); pos.y += fgetc(fh) << 8;
pos.z = fgetc(fh);
radius = fgetc(fh) + 1;
count = fgetc(fh); // number of creatures in this respawn
total += count;
secs = fgetc(fh); secs += fgetc(fh) << 8;
Spawn *spawn = new Spawn(&g_game, pos, radius);
SpawnManager::instance()->addSpawn(spawn);
for (int j = 0; j < count; j++)
{
cx = (rand() % (radius * 2)) - radius;
cy = (rand() % (radius * 2)) - radius;
spawn->addMonster(cname, NORTH, cx, cy, secs * 1000);
}
fgetc(fh); // 1 = check for players near, 0 = dont check
}
std::cout << ":: Loaded spawns: " << total << std::endl;
SpawnManager::instance()->startup();
} break;
case 0xF0:
end = true;
break;
}
}
fclose(fh);
return;
}
示例8: seqDebug
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;
/* Commented this out because it wasn't adding shrouded spawns.
Shrouded spawns get deleted from the zone first then added
as a new spawn. leaving this here in case another work-around
needs to be found. (ieatacid - 6-8-2008)
// 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());
}
}
示例9: printf
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(spawn);
updateRuntimeFilterFlags(spawn);
item->updateLastChanged();
if (spawn->GuildID() < MAXGUILDS)
spawn->setGuildTag(m_guildMgr->guildIdToName(spawn->GuildID()));
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() < MAXGUILDS)
spawn->setGuildTag(m_guildMgr->guildIdToName(spawn->GuildID()));
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());
}
if (item->filterFlags() & FILTER_FLAG_ALERT)
emit handleAlert(item, tNewSpawn);
}
示例10: vectorAtoi
bool Spawns::parseSpawnNode(xmlNodePtr p, bool checkDuplicate)
{
if(xmlStrcmp(p->name, (const xmlChar*)"spawn"))
return false;
int32_t intValue;
std::string strValue;
Position centerPos;
if(!readXMLString(p, "centerpos", strValue))
{
if(!readXMLInteger(p, "centerx", intValue))
return false;
centerPos.x = intValue;
if(!readXMLInteger(p, "centery", intValue))
return false;
centerPos.y = intValue;
if(!readXMLInteger(p, "centerz", intValue))
return false;
centerPos.z = intValue;
}
else
{
IntegerVec posVec = vectorAtoi(explodeString(",", strValue));
if(posVec.size() < 3)
return false;
centerPos = Position(posVec[0], posVec[1], posVec[2]);
}
if(!readXMLInteger(p, "radius", intValue))
return false;
int32_t radius = intValue;
Spawn* spawn = new Spawn(centerPos, radius);
if(checkDuplicate)
{
for(SpawnList::iterator it = spawnList.begin(); it != spawnList.end(); ++it)
{
if((*it)->getPosition() == centerPos)
delete *it;
}
}
spawnList.push_back(spawn);
xmlNodePtr tmpNode = p->children;
while(tmpNode)
{
if(!xmlStrcmp(tmpNode->name, (const xmlChar*)"monster"))
{
std::string name;
if(!readXMLString(tmpNode, "name", strValue))
{
tmpNode = tmpNode->next;
continue;
}
name = strValue;
int32_t interval = MINSPAWN_INTERVAL / 1000;
if(readXMLInteger(tmpNode, "spawntime", intValue) || readXMLInteger(tmpNode, "interval", intValue))
{
if(intValue <= interval)
{
std::cout << "[Warning - Spawns::loadFromXml] " << name << " " << centerPos << " spawntime cannot";
std::cout << " be less than " << interval << " seconds." << std::endl;
tmpNode = tmpNode->next;
continue;
}
interval = intValue;
}
interval *= 1000;
Position placePos = centerPos;
if(readXMLInteger(tmpNode, "x", intValue))
placePos.x += intValue;
if(readXMLInteger(tmpNode, "y", intValue))
placePos.y += intValue;
if(readXMLInteger(tmpNode, "z", intValue))
placePos.z /*+*/= intValue;
Direction direction = NORTH;
if(readXMLInteger(tmpNode, "direction", intValue) && direction >= EAST && direction <= WEST)
direction = (Direction)intValue;
spawn->addMonster(name, placePos, direction, interval);
}
else if(!xmlStrcmp(tmpNode->name, (const xmlChar*)"npc"))
{
std::string name;
if(!readXMLString(tmpNode, "name", strValue))
{
tmpNode = tmpNode->next;
continue;
//.........这里部分代码省略.........
示例11: xmlParseFile
bool SpawnManager::loadSpawnsXML(std::string filename)
{
std::transform(filename.begin(), filename.end(), filename.begin(), tolower);
xmlDocPtr doc = xmlParseFile(filename.c_str());
if (doc){
xmlNodePtr root, p;
char* nodeValue = NULL;
root = xmlDocGetRootElement(doc);
root = xmlDocGetRootElement(doc);
if (xmlStrcmp(root->name,(const xmlChar*) "spawns")){
xmlFreeDoc(doc);
return false;
}
p = root->children;
while (p) {
const char* str = (char*)p->name;
if (strcmp(str, "spawn") == 0) {
Position centerpos;
int radius;
nodeValue = (char*)xmlGetProp(p, (const xmlChar *)"centerx");
if(nodeValue) {
centerpos.x = atoi(nodeValue);
xmlFreeOTSERV(nodeValue);
}
else {
xmlFreeOTSERV(nodeValue);
return false;
}
nodeValue = (char*)xmlGetProp(p, (const xmlChar *)"centery");
if(nodeValue) {
centerpos.y = atoi(nodeValue);
xmlFreeOTSERV(nodeValue);
}
else {
xmlFreeOTSERV(nodeValue);
xmlFreeDoc(doc);
return false;
}
nodeValue = (char*)xmlGetProp(p, (const xmlChar *)"centerz");
if(nodeValue) {
centerpos.z = atoi(nodeValue);
xmlFreeOTSERV(nodeValue);
}
else {
xmlFreeOTSERV(nodeValue);
xmlFreeDoc(doc);
return false;
}
nodeValue = (char*)xmlGetProp(p, (const xmlChar *)"radius");
if(nodeValue) {
radius = atoi(nodeValue);
xmlFreeOTSERV(nodeValue);
}
else {
xmlFreeOTSERV(nodeValue);
xmlFreeDoc(doc);
return false;
}
Spawn *spawn = new Spawn(game, centerpos, radius);
spawns.push_back(spawn);
std::string name;
int x, y, spawntime;
Direction direction = NORTH;
int rawdir = 0; //NORTH
xmlNodePtr tmp = p->children;
while (tmp) {
str = (char*)tmp->name;
if (strcmp(str, "monster") == 0) {
nodeValue = (char*)xmlGetProp(tmp, (const xmlChar *)"name");
if(nodeValue) {
name = nodeValue;
xmlFreeOTSERV(nodeValue);
}
else {
tmp = tmp->next;
break;
}
nodeValue = (char*)xmlGetProp(tmp, (const xmlChar *)"direction");
if(nodeValue) {
rawdir = atoi(nodeValue);
xmlFreeOTSERV(nodeValue);
}
nodeValue = (char*)xmlGetProp(tmp, (const xmlChar *)"x");
if(nodeValue) {
x = atoi(nodeValue);
//.........这里部分代码省略.........
示例12: catch
bool SpawnManager::loadSpawnsSQL(std::string identifier)
{
std::string host = g_config.getGlobalString("map_host");
std::string user = g_config.getGlobalString("map_user");
std::string pass = g_config.getGlobalString("map_pass");
std::string db = g_config.getGlobalString("map_db");
#ifdef __DEBUG__
std::cout "host" << host << "user" << user << "pass" << pass << "db" << db << std::endl;
#endif
mysqlpp::Connection con;
try{
con.connect(db.c_str(), host.c_str(), user.c_str(), pass.c_str());
}
catch(mysqlpp::BadQuery e){
std::cout << "MYSQL-ERROR: " << e.error << std::endl;
return false;
}
mysqlpp::Result res;
//Monsters
//Try & Find the Monter's
try{
mysqlpp::Query query = con.query();
query << "SELECT * FROM " << identifier << "_monsters WHERE name !=''";
#ifdef __DEBUG__
std::cout << query.preview() << std::endl;
#endif
res = query.store();
} //End Try
catch(mysqlpp::BadQuery e){
std::cout << "MYSQL-ERROR: " << e.error << std::endl;
return false;
}
std::cout << ":: Found: " << res.size() << " Monsters(s)/Spawn(s)" << std::endl;
if(res.size() < 1){//No Monsters
std::cout << "No Monsters found" << std::endl;
return false;
}
//if there are any monster spawns to load
else{
//Load Monsters
try{
mysqlpp::Result Monster;
mysqlpp::Query query = con.query();
for(int i=1; i <= res.size(); ++i){
query.reset();
query << "SELECT * FROM " << identifier << "_monsters WHERE id = '" << i <<"' and id != ''";
Monster = query.store();
mysqlpp::Row row = *Monster.begin();
//Get the Monster's Position on Map
std::string pos = std::string(row.lookup_by_name("spawnpos"));
boost::char_separator<char> sep(";");
tokenizer spawnpostokens(pos, sep);
tokenizer::iterator spawnposit = spawnpostokens.begin();
Position spawnpos;
spawnpos.x=atoi(spawnposit->c_str()); spawnposit++;
spawnpos.y=atoi(spawnposit->c_str()); spawnposit++;
spawnpos.z=atoi(spawnposit->c_str());
std::string name;
if(std::string(row.lookup_by_name("name")) != ""){name = std::string(row.lookup_by_name("name"));}
int time = row.lookup_by_name("time");
Spawn *spawn = new Spawn(game, spawnpos, 1);
spawns.push_back(spawn);
spawn->addMonster(name, NORTH, 0, 0, time * 1000);
}//End For Loop
}//End Try
catch(mysqlpp::BadQuery e){
std::cout << "MYSQL-ERROR: " << e.error << std::endl;
return false;
}//End Catch
}
//NPC's
//Try & Find the NPC's
try{
mysqlpp::Query query = con.query();
query << "SELECT * FROM " << identifier << "_npcs WHERE name !=''";
#ifdef __DEBUG__
std::cout << query.preview() << std::endl;
#endif
res = query.store();
}//End Try
catch(mysqlpp::BadQuery e){
std::cout << "MYSQL-ERROR: " << e.error << std::endl;
return false;
}
std::cout << ":: Found: " << res.size() << " NPC(s)" << std::endl;
if(res.size() < 1){//No NPC's
//.........这里部分代码省略.........
示例13: centerPos
bool Spawns::loadFromXml(const std::string& _filename)
{
if (loaded) {
return true;
}
pugi::xml_document doc;
pugi::xml_parse_result result = doc.load_file(_filename.c_str());
if (!result) {
std::cout << "[Error - Spawns::loadFromXml] Failed to load " << _filename << ": " << result.description() << std::endl;
return false;
}
filename = _filename;
loaded = true;
for (pugi::xml_node spawnNode = doc.child("spawns").first_child(); spawnNode; spawnNode = spawnNode.next_sibling()) {
Position centerPos(
pugi::cast<uint16_t>(spawnNode.attribute("centerx").value()),
pugi::cast<uint16_t>(spawnNode.attribute("centery").value()),
pugi::cast<uint16_t>(spawnNode.attribute("centerz").value())
);
int32_t radius;
pugi::xml_attribute radiusAttribute = spawnNode.attribute("radius");
if (radiusAttribute) {
radius = pugi::cast<int32_t>(radiusAttribute.value());
} else {
radius = -1;
}
Spawn* spawn = new Spawn(centerPos, radius);
spawnList.push_back(spawn);
for (pugi::xml_node childNode = spawnNode.first_child(); childNode; childNode = childNode.next_sibling()) {
if (strcasecmp(childNode.name(), "monster") == 0) {
pugi::xml_attribute nameAttribute = childNode.attribute("name");
if (!nameAttribute) {
continue;
}
Direction dir;
pugi::xml_attribute directionAttribute = childNode.attribute("direction");
if (directionAttribute) {
dir = static_cast<Direction>(pugi::cast<uint16_t>(directionAttribute.value()));
} else {
dir = NORTH;
}
Position pos(
centerPos.x + pugi::cast<uint16_t>(childNode.attribute("x").value()),
centerPos.y + pugi::cast<uint16_t>(childNode.attribute("y").value()),
centerPos.z
);
uint32_t interval = pugi::cast<uint32_t>(childNode.attribute("spawntime").value()) * 1000;
if (interval > MINSPAWN_INTERVAL) {
spawn->addMonster(nameAttribute.as_string(), pos, dir, interval);
} else {
std::cout << "[Warning - Spawns::loadFromXml] " << nameAttribute.as_string() << ' ' << pos << " spawntime can not be less than " << MINSPAWN_INTERVAL / 1000 << " seconds." << std::endl;
}
} else if (strcasecmp(childNode.name(), "npc") == 0) {
pugi::xml_attribute nameAttribute = childNode.attribute("name");
if (!nameAttribute) {
continue;
}
Npc* npc = Npc::createNpc(nameAttribute.as_string());
if (!npc) {
continue;
}
pugi::xml_attribute directionAttribute = childNode.attribute("direction");
if (directionAttribute) {
npc->setDirection(static_cast<Direction>(pugi::cast<uint16_t>(directionAttribute.value())));
}
npc->setMasterPos(Position(
centerPos.x + pugi::cast<uint16_t>(childNode.attribute("x").value()),
centerPos.y + pugi::cast<uint16_t>(childNode.attribute("y").value()),
centerPos.z
), radius);
npcList.push_back(npc);
}
}
}
return true;
}
示例14: if
void HeroFrog::setHeroStatus(FrogStatus heroStatus){
if (m_heroStatus == heroStatus) {
return;
}
m_heroStatus = heroStatus;
Animation* ani;
Animate* ac;
this->stopAllActions();
ani = AnimationCache::getInstance()->getAnimation(animaName[heroStatus].c_str());
Animation* ani1;
Animate* ac1;
if (heroStatus == frogJumpDown) {
ani1 = AnimationCache::getInstance()->getAnimation(animaName[heroStatus+1].c_str());
}else if (heroStatus == frogJumpUp&& m_isLongJump){
std::string aniName = animaName[8].c_str();
ani = AnimationCache::getInstance()->getAnimation(aniName);
}
Sequence* seq;
float y;
float dis;
float time;
SpriteFrame* deadFrame ;
Spawn* sp;
MoveTo* mvTo;
Point targetPoint;
// CCLOG("---------设置hero状态-----------");
switch (heroStatus) {
case frogStatic:
GameMainHelper::getInstance()->playSound(JUMPOVER);
ac= Animate::create(ani) ;
runAction(RepeatForever::create(ac));
break;
case frogTakeoff:
ac= Animate::create(ani) ;
ani->setDelayPerUnit(0.2);
runAction(RepeatForever::create(ac));
break;
case frogJumpUp:
if(m_isLongJump)
GameMainHelper::getInstance()->playSound(JUMPSTART_1);
else
GameMainHelper::getInstance()->playSound(JUMPSTART_0);
ani->setDelayPerUnit(0.2); //--------待计算
ac= Animate::create(ani);
runAction(RepeatForever::create(ac));
break;
case frogJumpDown:
ani->setDelayPerUnit(downAnimSpeed); //--------待计算
ani1->setDelayPerUnit(0.2);
ac= Animate::create(ani);
ac1 = Animate::create(ani1);
runAction(Sequence::create(ac,Repeat::create(ac1,20), NULL) );
break;
case frogFall:
ani->setDelayPerUnit(downAnimSpeed);
ac= Animate::create(ani);
targetPoint = GameMainHelper::getInstance()->getHeroPostPoint();
time =ani->getDelayPerUnit();
mvTo = MoveTo::create(downAnimSpeed,targetPoint);
sp = Spawn::create(ac,mvTo, NULL);
seq = Sequence::create(sp,CCCallFunc::create(CC_CALLBACK_0(HeroFrog::setHeroStatic, this)) , NULL);
runAction(seq);
break;
case frogDead1:
GameMainHelper::getInstance()->playSound(HEROOVER);
deadFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName("hero_dead2.png");
this->setDisplayFrame(deadFrame);
ac= Animate::create(ani);
y = MIN(GameMainHelper::getInstance()->getEarthH(),getPositionY());
dis = getPositionY()-y;
time = dis/downSpeed;
targetPoint = Point(getPositionX(),y);
mvTo = MoveTo::create(time,targetPoint);
sp = Spawn::create(Repeat::create(ac,(int)(time/(0.2*3))),mvTo, NULL);
sp->setTag(DEAD1TAG);
seq = Sequence::create(DelayTime::create(0.5), sp,CCCallFunc::create(CC_CALLBACK_0(HeroFrog::stopAnimation, this)), NULL);
runAction(seq);
break;
case frogDead2:
GameMainHelper::getInstance()->playSound(HEROOVER);
ac= Animate::create(ani) ;
runAction(RepeatForever::create(ac));
break;
default:
ac= Animate::create(ani);
runAction(RepeatForever::create(ac));
//.........这里部分代码省略.........