本文整理汇总了C++中Map类的典型用法代码示例。如果您正苦于以下问题:C++ Map类的具体用法?C++ Map怎么用?C++ Map使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Map类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Map
/** Packages image and elevation layers as a TMS. */
int TMSExporter::exportTMS(MapNode* mapNode, const std::string& path, std::vector< osgEarth::Bounds >& bounds, const std::string& outEarth, bool overwrite, const std::string& extension)
{
if ( !mapNode )
{
_errorMessage = "Invalid MapNode";
if (_progress.valid()) _progress->onCompleted();
return 0;
}
// folder to which to write the TMS archive.
std::string rootFolder = path;
osg::ref_ptr<osgDB::Options> options = new osgDB::Options(_dbOptions);
// create a folder for the output
osgDB::makeDirectory(rootFolder);
if ( !osgDB::fileExists(rootFolder) )
{
_errorMessage = "Failed to create root output folder";
if (_progress.valid()) _progress->onCompleted();
return 0;
}
Map* map = mapNode->getMap();
// new map for an output earth file if necessary.
osg::ref_ptr<Map> outMap = 0L;
if ( !outEarth.empty() )
{
// copy the options from the source map first
outMap = new Map(map->getInitialMapOptions());
}
// establish the output path of the earth file, if applicable:
std::string outEarthName = osgDB::getSimpleFileName(outEarth);
if (outEarthName.length() > 0 && osgEarth::toLower(osgDB::getFileExtension(outEarthName)) != "earth")
outEarthName += ".earth";
std::string outEarthFile = osgDB::concatPaths(rootFolder, outEarthName);
// semaphore and tasks collection for multithreading
osgEarth::Threading::MultiEvent semaphore;
osgEarth::TaskRequestVector tasks;
int taskCount = 0;
// package any image layers that are enabled and visible
ImageLayerVector imageLayers;
map->getImageLayers( imageLayers );
unsigned imageCount = 0;
for( ImageLayerVector::iterator i = imageLayers.begin(); i != imageLayers.end(); ++i, ++imageCount )
{
ImageLayer* layer = i->get();
if ( layer->getEnabled() && layer->getVisible() )
{
std::string layerFolder = toLegalFileName( layer->getName() );
if ( layerFolder.empty() )
layerFolder = Stringify() << "image_layer_" << imageCount;
ParallelTask<PackageLayer>* task = new ParallelTask<PackageLayer>( &semaphore );
task->init(map, layer, options, rootFolder, layerFolder, true, overwrite, _keepEmpties, _maxLevel, extension, bounds);
task->setProgressCallback(new PackageLayerProgressCallback(this));
tasks.push_back(task);
taskCount++;
}
}
// package any elevation layers that are enabled and visible
ElevationLayerVector elevationLayers;
map->getElevationLayers( elevationLayers );
int elevCount = 0;
for( ElevationLayerVector::iterator i = elevationLayers.begin(); i != elevationLayers.end(); ++i, ++elevCount )
{
ElevationLayer* layer = i->get();
if ( layer->getEnabled() && layer->getVisible() )
{
std::string layerFolder = toLegalFileName( layer->getName() );
if ( layerFolder.empty() )
layerFolder = Stringify() << "elevation_layer_" << elevCount;
ParallelTask<PackageLayer>* task = new ParallelTask<PackageLayer>( &semaphore );
task->init(map, layer, options, rootFolder, layerFolder, true, overwrite, _keepEmpties, _maxLevel, extension, bounds);
task->setProgressCallback(new PackageLayerProgressCallback(this));
tasks.push_back(task);
taskCount++;
}
}
// Run all the tasks in parallel
_totalTasks = taskCount;
_completedTasks = 0;
semaphore.reset( _totalTasks );
//.........这里部分代码省略.........
示例2: instance
void CreatureAI::DoZoneInCombat(Creature* creature /*= NULL*/, float maxRangeToNearestTarget /* = 50.0f*/)
{
if (!creature)
creature = me;
if (!creature->CanHaveThreatList())
return;
Map* map = creature->GetMap();
if (!map->IsDungeon()) //use IsDungeon instead of Instanceable, in case battlegrounds will be instantiated
{
sLog->outError("DoZoneInCombat call for map that isn't an instance (creature entry = %d)", creature->GetTypeId() == TYPEID_UNIT ? creature->ToCreature()->GetEntry() : 0);
return;
}
if (!creature->HasReactState(REACT_PASSIVE) && !creature->getVictim())
{
if (Unit* nearTarget = creature->SelectNearestTarget(maxRangeToNearestTarget))
creature->AI()->AttackStart(nearTarget);
else if (creature->isSummon())
{
if (Unit* summoner = creature->ToTempSummon()->GetSummoner())
{
Unit* target = summoner->getAttackerForHelper();
if (!target && summoner->CanHaveThreatList() && !summoner->getThreatManager().isThreatListEmpty())
target = summoner->getThreatManager().getHostilTarget();
if (target && (creature->IsFriendlyTo(summoner) || creature->IsHostileTo(target)))
creature->AI()->AttackStart(target);
}
}
}
if (!creature->HasReactState(REACT_PASSIVE) && !creature->getVictim())
{
sLog->outError("DoZoneInCombat called for creature that has empty threat list (creature entry = %u)", creature->GetEntry());
return;
}
Map::PlayerList const& playerList = map->GetPlayers();
if (playerList.isEmpty())
return;
for (Map::PlayerList::const_iterator itr = playerList.begin(); itr != playerList.end(); ++itr)
{
if (Player* player = itr->getSource())
{
if (player->isGameMaster())
continue;
if (player->isAlive())
{
creature->SetInCombatWith(player);
player->SetInCombatWith(creature);
creature->AddThreat(player, 0.0f);
}
/* Causes certain things to never leave the threat list (Priest Lightwell, etc):
for (Unit::ControlList::const_iterator itr = player->m_Controlled.begin(); itr != player->m_Controlled.end(); ++itr)
{
creature->SetInCombatWith(*itr);
(*itr)->SetInCombatWith(creature);
creature->AddThreat(*itr, 0.0f);
}*/
}
}
}
示例3:
PropertyStream::Map::Map (std::string const& key, Map& map)
: m_stream (map.stream())
{
m_stream.map_begin (key);
}
示例4: render
void SurfaceItem::render(const Map &map, const Camera &camera)
{
int zone = map.zone(vertices().at(0));
GLuint tex = textureId();
if (zone < 0)
return;
m_program->bind();
m_program->setUniformValue(m_matrixUniform, camera.viewProjectionMatrix());
QSize size = surface()->size();
m_program->setUniformValue(m_pixelSizeUniform, 5. / size.width(), 5. / size.height());
m_program->setUniformValue(m_eyeUniform, camera.viewPos());
m_program->setUniformValue(m_focusColorUniform, GLfloat(m_opacity));
m_program->setUniformValueArray(m_lightsUniform, map.lights(zone).constData(), map.lights(zone).size());
m_program->setUniformValue(m_numLightsUniform, map.lights(zone).size());
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, tex);
QVector<QVector3D> v = vertices();
QVector3D va = v[0];
QVector3D vb = v[1];
QVector3D vc = v[2];
QVector3D vd = v[3];
QVector<QVector3D> vertexBuffer;
vertexBuffer << va << vb << vd << vd << vb << vc;
qreal y1 = 0;
qreal y2 = 1;
if (surface()->origin() == QWaylandSurface::OriginTopLeft)
qSwap(y1, y2);
QVector<QVector2D> texCoordBuffer;
texCoordBuffer << QVector2D(0, y2) << QVector2D(1, y2)
<< QVector2D(0, y1) << QVector2D(0, y1)
<< QVector2D(1, y2) << QVector2D(1, y1);
m_program->setUniformValue(m_normalUniform, -QVector3D::crossProduct(vb - va, vc - va).normalized());
m_program->enableAttributeArray(m_vertexAttr);
m_program->setAttributeArray(m_vertexAttr, vertexBuffer.constData());
m_program->enableAttributeArray(m_texCoordAttr);
m_program->setAttributeArray(m_texCoordAttr, texCoordBuffer.constData());
glEnable(GL_BLEND);
glDisable(GL_CULL_FACE);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
glDrawArrays(GL_TRIANGLES, 0, 6);
glDisable(GL_BLEND);
m_program->disableAttributeArray(m_texCoordAttr);
m_program->disableAttributeArray(m_vertexAttr);
#if 0
QOpenGLPaintDevice device(camera.viewSize());
QPainter p(&device);
va = camera.viewProjectionMatrix().map(va);
vb = camera.viewProjectionMatrix().map(vb);
vc = camera.viewProjectionMatrix().map(vc);
vd = camera.viewProjectionMatrix().map(vd);
QVector3D c(camera.viewSize().width() * 0.5, camera.viewSize().height() * 0.5, 0);
va = c + c * va * QVector3D(1, -1, 0);
vb = c + c * vb * QVector3D(1, -1, 0);
vc = c + c * vc * QVector3D(1, -1, 0);
vd = c + c * vd * QVector3D(1, -1, 0);
QPointF pa(va.x(), va.y());
QPointF pb(vb.x(), vb.y());
QPointF pc(vc.x(), vc.y());
QPointF pd(vd.x(), vd.y());
p.drawLine(pa, pb);
p.drawLine(pb, pc);
p.drawLine(pc, pd);
p.drawLine(pd, pa);
extern QVector3D debug;
QVector3D d = camera.viewProjectionMatrix().map(debug);
d = c + c * d * QVector3D(1, -1, 0);
static QVector3D old;
if (debug != old)
old = debug;
p.setPen(Qt::NoPen);
p.setBrush(Qt::red);
p.drawEllipse(QRectF(d.x() - 2, d.y() - 2, 4, 4));
p.end();
//.........这里部分代码省略.........
示例5: UpdateAI
void UpdateAI(const uint32 diff)
{
//Check if we have a target
if (!UpdateVictim())
{
//No target so we'll use this section to do our random wispers instance wide
//WisperTimer
if (WisperTimer <= diff)
{
Map* map = me->GetMap();
if (!map->IsDungeon())
return;
//Play random sound to the zone
Map::PlayerList const &PlayerList = map->GetPlayers();
if (!PlayerList.isEmpty())
{
for (Map::PlayerList::const_iterator itr = PlayerList.begin(); itr != PlayerList.end(); ++itr)
{
if (Player* pPlr = itr->getSource())
pPlr->PlayDirectSound(RANDOM_SOUND_WHISPER, pPlr);
}
}
//One random wisper every 90 - 300 seconds
WisperTimer = urand(90000, 300000);
} else WisperTimer -= diff;
return;
}
me->SetTarget(0);
//No instance
if (!instance)
return;
uint32 currentPhase = instance->GetData(DATA_CTHUN_PHASE);
if (currentPhase == PHASE_CTHUN_STOMACH || currentPhase == PHASE_CTHUN_WEAK)
{
// EyeTentacleTimer
if (EyeTentacleTimer <= diff)
{
//Spawn the 8 Eye Tentacles in the corret spots
SpawnEyeTentacle(0, 20); //south
SpawnEyeTentacle(10, 10); //south west
SpawnEyeTentacle(20, 0); //west
SpawnEyeTentacle(10, -10); //north west
SpawnEyeTentacle(0, -20); //north
SpawnEyeTentacle(-10, -10); //north east
SpawnEyeTentacle(-20, 0); // east
SpawnEyeTentacle(-10, 10); // south east
EyeTentacleTimer = 30000; // every 30sec in phase 2
} else EyeTentacleTimer -= diff;
}
switch (currentPhase)
{
//Transition phase
case PHASE_CTHUN_TRANSITION:
//PhaseTimer
if (PhaseTimer <= diff)
{
//Switch
instance->SetData(DATA_CTHUN_PHASE, PHASE_CTHUN_STOMACH);
//Switch to c'thun model
me->InterruptNonMeleeSpells(false);
DoCast(me, SPELL_TRANSFORM, false);
me->SetFullHealth();
me->SetVisible(true);
me->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE | UNIT_FLAG_NON_ATTACKABLE);
//Emerging phase
//AttackStart(Unit::GetUnit(*me, HoldpPlayer));
DoZoneInCombat();
//Place all units in threat list on outside of stomach
Stomach_Map.clear();
for (std::list<HostileReference*>::const_iterator i = me->getThreatManager().getThreatList().begin(); i != me->getThreatManager().getThreatList().end(); ++i)
Stomach_Map[(*i)->getUnitGuid()] = false; //Outside stomach
//Spawn 2 flesh tentacles
FleshTentaclesKilled = 0;
//Spawn flesh tentacle
for (uint8 i = 0; i < 2; i++)
{
Creature* spawned = me->SummonCreature(MOB_FLESH_TENTACLE, FleshTentaclePos[i], TEMPSUMMON_CORPSE_DESPAWN);
if (!spawned)
++FleshTentaclesKilled;
}
PhaseTimer = 0;
} else PhaseTimer -= diff;
//.........这里部分代码省略.........
示例6: SetData
void SetData(uint32 type, uint32 data)
{
switch (type)
{
case DATA_RAGEWINTERCHILLEVENT:
Encounters[0] = data;
break;
case DATA_ANETHERONEVENT:
Encounters[1] = data;
break;
case DATA_KAZROGALEVENT:
Encounters[2] = data;
break;
case DATA_AZGALOREVENT:
{
Encounters[3] = data;
if (data == DONE)
{
if (ArchiYell)break;
ArchiYell = true;
Creature* pCreature = instance->GetCreature(Azgalor);
if (pCreature)
{
Creature* pUnit = pCreature->SummonCreature(21987, pCreature->GetPositionX(), pCreature->GetPositionY(), pCreature->GetPositionZ(), 0, TEMPSUMMON_TIMED_DESPAWN, 10000);
Map* pMap = pCreature->GetMap();
if (pMap->IsDungeon() && pUnit)
{
pUnit->SetVisibility(VISIBILITY_OFF);
Map::PlayerList const& PlayerList = pMap->GetPlayers();
if (PlayerList.isEmpty())
return;
for (Map::PlayerList::const_iterator i = PlayerList.begin(); i != PlayerList.end(); ++i)
{
if (i->getSource())
{
WorldPacket data(SMSG_MESSAGECHAT, 200);
pUnit->BuildMonsterChat(&data, CHAT_MSG_MONSTER_YELL, YELL_EFFORTS, 0, YELL_EFFORTS_NAME, i->getSource()->GetGUID());
i->getSource()->GetSession()->SendPacket(&data);
WorldPacket data2(SMSG_PLAY_SOUND, 4);
data2 << 10986;
i->getSource()->GetSession()->SendPacket(&data2);
}
}
}
}
}
}
break;
case DATA_ARCHIMONDEEVENT:
Encounters[4] = data;
break;
case DATA_RESET_TRASH_COUNT:
Trash = 0;
break;
case DATA_TRASH:
if (data) Trash = data;
else Trash--;
UpdateWorldState(WORLD_STATE_ENEMYCOUNT, Trash);
break;
case DATA_ALLIANCE_RETREAT:
allianceRetreat = data;
OpenDoor(HordeGate, true);
SaveToDB();
break;
case DATA_HORDE_RETREAT:
hordeRetreat = data;
OpenDoor(ElfGate, true);
SaveToDB();
break;
case DATA_RAIDDAMAGE:
RaidDamage += data;
if (RaidDamage >= MINRAIDDAMAGE)
RaidDamage = MINRAIDDAMAGE;
break;
case DATA_RESET_RAIDDAMAGE:
RaidDamage = 0;
break;
}
debug_log("OSCR: Instance Hyjal: Instance data updated for event %u (Data=%u)", type, data);
if (data == DONE)
SaveToDB();
}
示例7: HandleWpModifyCommand
static bool HandleWpModifyCommand(ChatHandler* handler, const char* args)
{
if (!*args)
return false;
// first arg: add del text emote spell waittime move
char* show_str = strtok((char*)args, " ");
if (!show_str)
{
return false;
}
std::string show = show_str;
// Check
// Remember: "show" must also be the name of a column!
if ((show != "delay") && (show != "action") && (show != "action_chance")
&& (show != "move_flag") && (show != "del") && (show != "move") && (show != "wpadd")
)
{
return false;
}
// Next arg is: <PATHID> <WPNUM> <ARGUMENT>
char* arg_str = NULL;
// Did user provide a GUID
// or did the user select a creature?
// -> variable lowguid is filled with the GUID of the NPC
uint32 pathid = 0;
uint32 point = 0;
uint32 wpGuid = 0;
Creature* target = handler->getSelectedCreature();
if (!target || target->GetEntry() != VISUAL_WAYPOINT)
{
handler->SendSysMessage("|cffff33ffERROR: You must select a waypoint.|r");
return false;
}
// The visual waypoint
Creature* wpCreature = NULL;
wpGuid = target->GetGUIDLow();
// Did the user select a visual spawnpoint?
if (wpGuid)
wpCreature = handler->GetSession()->GetPlayer()->GetMap()->GetCreature(MAKE_NEW_GUID(wpGuid, VISUAL_WAYPOINT, HIGHGUID_UNIT));
// attempt check creature existence by DB data
else
{
handler->PSendSysMessage(LANG_WAYPOINT_CREATNOTFOUND, wpGuid);
return false;
}
// User did select a visual waypoint?
// Check the creature
if (wpCreature->GetEntry() == VISUAL_WAYPOINT)
{
QueryResult result = WorldDatabase.PQuery("SELECT id, point FROM waypoint_data WHERE wpguid = %u", wpGuid);
if (!result)
{
handler->PSendSysMessage(LANG_WAYPOINT_NOTFOUNDSEARCH, target->GetGUIDLow());
// Select waypoint number from database
// Since we compare float values, we have to deal with
// some difficulties.
// Here we search for all waypoints that only differ in one from 1 thousand
// (0.001) - There is no other way to compare C++ floats with mySQL floats
// See also: http://dev.mysql.com/doc/refman/5.0/en/problems-with-float.html
const char* maxDIFF = "0.01";
result = WorldDatabase.PQuery("SELECT id, point FROM waypoint_data WHERE (abs(position_x - %f) <= %s) and (abs(position_y - %f) <= %s) and (abs(position_z - %f) <= %s)",
wpCreature->GetPositionX(), maxDIFF, wpCreature->GetPositionY(), maxDIFF, wpCreature->GetPositionZ(), maxDIFF);
if (!result)
{
handler->PSendSysMessage(LANG_WAYPOINT_NOTFOUNDDBPROBLEM, wpGuid);
return true;
}
}
do
{
Field* fields = result->Fetch();
pathid = fields[0].GetUInt32();
point = fields[1].GetUInt32();
}
while (result->NextRow());
// We have the waypoint number and the GUID of the "master npc"
// Text is enclosed in "<>", all other arguments not
arg_str = strtok((char*)NULL, " ");
}
// Check for argument
if (show != "del" && show != "move" && arg_str == NULL)
{
handler->PSendSysMessage(LANG_WAYPOINT_ARGUMENTREQ, show_str);
return false;
}
if (show == "del" && target)
{
handler->PSendSysMessage("|cff00ff00DEBUG: wp modify del, PathID: |r|cff00ffff%u|r", pathid);
//.........这里部分代码省略.........
示例8: setPalmTree
void ChunkGenerator::setPalmTree(Map& map, int x, int z, int xi, int zj, int noise) {
// Baummstumpf
int k = noise + 1;
// Baummhöhe
int height = 9;
// Baumstamm
for(int l = 0; l <= height; l++) {
map.getChunk({x, z}).setBlockType({xi, k+l, zj}, BlockType::Wood);
}
// 3th row
k = k + height - 1;
map.getChunk({x, z}).setBlockType({xi-4, k, zj}, BlockType::Sand);
map.getChunk({x, z}).setBlockType({xi-5, k, zj}, BlockType::Sand);
map.getChunk({x, z}).setBlockType({xi-6, k, zj}, BlockType::Sand);
map.getChunk({x, z}).setBlockType({xi+4, k, zj}, BlockType::Sand);
map.getChunk({x, z}).setBlockType({xi+5, k, zj}, BlockType::Sand);
map.getChunk({x, z}).setBlockType({xi+6, k, zj}, BlockType::Sand);
map.getChunk({x, z}).setBlockType({xi-4, k, zj-1}, BlockType::Sand);
map.getChunk({x, z}).setBlockType({xi-5, k, zj-1}, BlockType::Sand);
map.getChunk({x, z}).setBlockType({xi-4, k, zj+1}, BlockType::Sand);
map.getChunk({x, z}).setBlockType({xi-5, k, zj+1}, BlockType::Sand);
map.getChunk({x, z}).setBlockType({xi+4, k, zj-1}, BlockType::Sand);
map.getChunk({x, z}).setBlockType({xi+5, k, zj-1}, BlockType::Sand);
map.getChunk({x, z}).setBlockType({xi+4, k, zj+1}, BlockType::Sand);
map.getChunk({x, z}).setBlockType({xi+5, k, zj+1}, BlockType::Sand);
map.getChunk({x, z}).setBlockType({xi, k, zj-4}, BlockType::Sand);
map.getChunk({x, z}).setBlockType({xi, k, zj-5}, BlockType::Sand);
map.getChunk({x, z}).setBlockType({xi, k, zj-6}, BlockType::Sand);
map.getChunk({x, z}).setBlockType({xi, k, zj+4}, BlockType::Sand);
map.getChunk({x, z}).setBlockType({xi, k, zj+5}, BlockType::Sand);
map.getChunk({x, z}).setBlockType({xi, k, zj+6}, BlockType::Sand);
map.getChunk({x, z}).setBlockType({xi-1, k, zj+4}, BlockType::Sand);
map.getChunk({x, z}).setBlockType({xi-1, k, zj+5}, BlockType::Sand);
map.getChunk({x, z}).setBlockType({xi+1, k, zj+4}, BlockType::Sand);
map.getChunk({x, z}).setBlockType({xi+1, k, zj+5}, BlockType::Sand);
map.getChunk({x, z}).setBlockType({xi-1, k, zj-4}, BlockType::Sand);
map.getChunk({x, z}).setBlockType({xi-1, k, zj-5}, BlockType::Sand);
map.getChunk({x, z}).setBlockType({xi+1, k, zj-4}, BlockType::Sand);
map.getChunk({x, z}).setBlockType({xi+1, k, zj-5}, BlockType::Sand);
// Coconuts
map.getChunk({x, z}).setBlockType({xi+1, k, zj}, BlockType::Stone);
map.getChunk({x, z}).setBlockType({xi-1, k, zj}, BlockType::Stone);
map.getChunk({x, z}).setBlockType({xi-1, k, zj-1}, BlockType::Stone);
map.getChunk({x, z}).setBlockType({xi, k, zj+1}, BlockType::Stone);
// 2nd row
k++;
map.getChunk({x, z}).setBlockType({xi, k, zj}, BlockType::Wood);
map.getChunk({x, z}).setBlockType({xi-1, k, zj}, BlockType::Sand);
map.getChunk({x, z}).setBlockType({xi-2, k, zj}, BlockType::Sand);
map.getChunk({x, z}).setBlockType({xi-3, k, zj}, BlockType::Sand);
map.getChunk({x, z}).setBlockType({xi+1, k, zj}, BlockType::Sand);
map.getChunk({x, z}).setBlockType({xi+2, k, zj}, BlockType::Sand);
map.getChunk({x, z}).setBlockType({xi+3, k, zj}, BlockType::Sand);
map.getChunk({x, z}).setBlockType({xi, k, zj-1}, BlockType::Sand);
map.getChunk({x, z}).setBlockType({xi-1, k, zj-1}, BlockType::Sand);
map.getChunk({x, z}).setBlockType({xi-2, k, zj-1}, BlockType::Sand);
map.getChunk({x, z}).setBlockType({xi-3, k, zj-1}, BlockType::Sand);
map.getChunk({x, z}).setBlockType({xi+1, k, zj-1}, BlockType::Sand);
map.getChunk({x, z}).setBlockType({xi+2, k, zj-1}, BlockType::Sand);
map.getChunk({x, z}).setBlockType({xi+3, k, zj-1}, BlockType::Sand);
map.getChunk({x, z}).setBlockType({xi, k, zj+1}, BlockType::Sand);
map.getChunk({x, z}).setBlockType({xi-1, k, zj+1}, BlockType::Sand);
map.getChunk({x, z}).setBlockType({xi-2, k, zj+1}, BlockType::Sand);
map.getChunk({x, z}).setBlockType({xi-3, k, zj+1}, BlockType::Sand);
map.getChunk({x, z}).setBlockType({xi+1, k, zj+1}, BlockType::Sand);
map.getChunk({x, z}).setBlockType({xi+2, k, zj+1}, BlockType::Sand);
map.getChunk({x, z}).setBlockType({xi+3, k, zj+1}, BlockType::Sand);
map.getChunk({x, z}).setBlockType({xi, k, zj-2}, BlockType::Sand);
map.getChunk({x, z}).setBlockType({xi-1, k, zj-2}, BlockType::Sand);
map.getChunk({x, z}).setBlockType({xi+1, k, zj-2}, BlockType::Sand);
map.getChunk({x, z}).setBlockType({xi, k, zj+2}, BlockType::Sand);
map.getChunk({x, z}).setBlockType({xi-1, k, zj+2}, BlockType::Sand);
map.getChunk({x, z}).setBlockType({xi+1, k, zj+2}, BlockType::Sand);
map.getChunk({x, z}).setBlockType({xi, k, zj-3}, BlockType::Sand);
map.getChunk({x, z}).setBlockType({xi-1, k, zj-3}, BlockType::Sand);
map.getChunk({x, z}).setBlockType({xi+1, k, zj-3}, BlockType::Sand);
//.........这里部分代码省略.........
示例9: setSpruceTree
void ChunkGenerator::setSpruceTree(Map& map, int x, int z, int xi, int zj, int noise) {
// Baummstumpf
int k = noise + 1;
// Baummhöhe
int height = 2;
// Baumstamm
for(int l = 0; l <= height; l++) {
map.getChunk({x, z}).setBlockType({xi, k+l, zj}, BlockType::Spruce);
}
// 4th row
k = k + height;
map.getChunk({x, z}).setBlockType({xi, k+1, zj}, BlockType::Spruce);
map.getChunk({x, z}).setBlockType({xi-1, k+1, zj}, BlockType::SpruceLeaves);
map.getChunk({x, z}).setBlockType({xi+1, k+1, zj}, BlockType::SpruceLeaves);
map.getChunk({x, z}).setBlockType({xi-2, k+1, zj}, BlockType::SpruceLeaves);
map.getChunk({x, z}).setBlockType({xi+2, k+1, zj}, BlockType::SpruceLeaves);
map.getChunk({x, z}).setBlockType({xi, k+1, zj+1}, BlockType::SpruceLeaves);
map.getChunk({x, z}).setBlockType({xi-1, k+1, zj+1}, BlockType::SpruceLeaves);
map.getChunk({x, z}).setBlockType({xi+1, k+1, zj+1}, BlockType::SpruceLeaves);
map.getChunk({x, z}).setBlockType({xi-2, k+1, zj+1}, BlockType::SpruceLeaves);
map.getChunk({x, z}).setBlockType({xi+2, k+1, zj+1}, BlockType::SpruceLeaves);
map.getChunk({x, z}).setBlockType({xi, k+1, zj-1}, BlockType::SpruceLeaves);
map.getChunk({x, z}).setBlockType({xi-1, k+1, zj-1}, BlockType::SpruceLeaves);
map.getChunk({x, z}).setBlockType({xi+1, k+1, zj-1}, BlockType::SpruceLeaves);
map.getChunk({x, z}).setBlockType({xi-2, k+1, zj-1}, BlockType::SpruceLeaves);
map.getChunk({x, z}).setBlockType({xi+2, k+1, zj-1}, BlockType::SpruceLeaves);
map.getChunk({x, z}).setBlockType({xi, k+1, zj-2}, BlockType::SpruceLeaves);
map.getChunk({x, z}).setBlockType({xi-1, k+1, zj-2}, BlockType::SpruceLeaves);
map.getChunk({x, z}).setBlockType({xi+1, k+1, zj-2}, BlockType::SpruceLeaves);
map.getChunk({x, z}).setBlockType({xi, k+1, zj+2}, BlockType::SpruceLeaves);
map.getChunk({x, z}).setBlockType({xi-1, k+1, zj+2}, BlockType::SpruceLeaves);
map.getChunk({x, z}).setBlockType({xi+1, k+1, zj+2}, BlockType::SpruceLeaves);
// 3rd row
k++;
map.getChunk({x, z}).setBlockType({xi, k+1, zj}, BlockType::Spruce);
map.getChunk({x, z}).setBlockType({xi-1, k+1, zj}, BlockType::SpruceLeaves);
map.getChunk({x, z}).setBlockType({xi+1, k+1, zj}, BlockType::SpruceLeaves);
map.getChunk({x, z}).setBlockType({xi, k+1, zj+1}, BlockType::SpruceLeaves);
map.getChunk({x, z}).setBlockType({xi, k+1, zj-1}, BlockType::SpruceLeaves);
// 2nd row
k++;;
map.getChunk({x, z}).setBlockType({xi, k+1, zj}, BlockType::SpruceLeaves);
// 1st row
k++;;
map.getChunk({x, z}).setBlockType({xi, k+1, zj}, BlockType::SpruceLeaves);
map.getChunk({x, z}).setBlockType({xi-1, k+1, zj}, BlockType::SpruceLeaves);
map.getChunk({x, z}).setBlockType({xi+1, k+1, zj}, BlockType::SpruceLeaves);
map.getChunk({x, z}).setBlockType({xi, k+1, zj+1}, BlockType::SpruceLeaves);
map.getChunk({x, z}).setBlockType({xi, k+1, zj-1}, BlockType::SpruceLeaves);
// top row
k++;
map.getChunk({x, z}).setBlockType({xi, k+1, zj}, BlockType::SpruceLeaves);
}
示例10: setCactusTree
void ChunkGenerator::setCactusTree(Map& map, int x, int z, int xi, int zj, int noise) {
// Baummstumpf
int k = noise + 1;
// Baummhöhe
int height = 7;
// Baumstamm
for(int l = 0; l <= height; l++) {
map.getChunk({x, z}).setBlockType({xi, k+l, zj}, BlockType::Cactus);
}
// 1st arm
k += 1;
map.getChunk({x, z}).setBlockType({xi+1, k, zj}, BlockType::Cactus);
map.getChunk({x, z}).setBlockType({xi+2, k, zj}, BlockType::Cactus);
map.getChunk({x, z}).setBlockType({xi+2, k+1, zj}, BlockType::Cactus);
map.getChunk({x, z}).setBlockType({xi+2, k+2, zj}, BlockType::Cactus);
map.getChunk({x, z}).setBlockType({xi+2, k+3, zj}, BlockType::Cactus);
// 2nd arm
map.getChunk({x, z}).setBlockType({xi, k+2, zj+1}, BlockType::Cactus);
map.getChunk({x, z}).setBlockType({xi, k+2, zj+2}, BlockType::Cactus);
map.getChunk({x, z}).setBlockType({xi, k+3, zj+2}, BlockType::Cactus);
map.getChunk({x, z}).setBlockType({xi, k+4, zj+2}, BlockType::Cactus);
// 3rd arm
map.getChunk({x, z}).setBlockType({xi, k+1, zj-1}, BlockType::Cactus);
map.getChunk({x, z}).setBlockType({xi, k+1, zj-2}, BlockType::Cactus);
map.getChunk({x, z}).setBlockType({xi, k+2, zj-2}, BlockType::Cactus);
map.getChunk({x, z}).setBlockType({xi, k+3, zj-2}, BlockType::Cactus);
map.getChunk({x, z}).setBlockType({xi, k+4, zj-2}, BlockType::Cactus);
map.getChunk({x, z}).setBlockType({xi, k+5, zj-2}, BlockType::Cactus);
// 4th arm
map.getChunk({x, z}).setBlockType({xi-1, k+4, zj}, BlockType::Cactus);
map.getChunk({x, z}).setBlockType({xi-2, k+4, zj}, BlockType::Cactus);
map.getChunk({x, z}).setBlockType({xi-2, k+5, zj}, BlockType::Cactus);
}
示例11: chunkGeneration
void ChunkGenerator::chunkGeneration(Map& map, Vec3i spectatorPos, MapView& mapView) {
// chunkPos ist Position des Chunks, in dem der Spectator steht in Chunkkoordinaten
Vec2i chunkPos = map.getChunkPos(spectatorPos);
for(int x = chunkPos.x - 8; x <= chunkPos.x + 8; x++) {
for(int z = chunkPos.y - 8; z <= chunkPos.y + 8; z++) {
if(!map.exists({x * 16, 0, z * 16})) {
map.addChunk({x, z});
Chunk chunk = map.getChunk({x, z});
double simpBiomeNoise = SimplexNoise::noise(0.01*x, 0.01*z, m_biome_seed);
int biomeNoise = SimplexNoise::noiseInt(0, 126, simpBiomeNoise);
if(0 <= biomeNoise && biomeNoise <= 44){
chunk.setBiomeType(BiomeType::Desert);
}
if(45 <= biomeNoise && biomeNoise <= 46){
chunk.setBiomeType(BiomeType::DesertPlain);
}
if(47 <= biomeNoise && biomeNoise <= 54){
chunk.setBiomeType(BiomeType::Plains);
}
if(55 <= biomeNoise && biomeNoise <= 56){
chunk.setBiomeType(BiomeType::PlainForest);
}
if(57 <= biomeNoise && biomeNoise <= 69){
chunk.setBiomeType(BiomeType::Forest);
}
// Biome ohne Wasser
if(!m_setWater) {
if(70 <= biomeNoise && biomeNoise <= 74){
chunk.setBiomeType(BiomeType::Hillside);
}
if(75 <= biomeNoise && biomeNoise <= 126){
chunk.setBiomeType(BiomeType::Mountains);
}
} else {
if(70 <= biomeNoise && biomeNoise <= 74){
chunk.setBiomeType(BiomeType::WaterHillside);
}
if(75 <= biomeNoise && biomeNoise <= 126){
chunk.setBiomeType(BiomeType::WaterMountains);
}
}
setBiomes(map, chunk, x, z, biomeNoise);
Vec2i chuPos = Vec2i(x + 1, z);
if(mapView.exists(chuPos)) {
mapView.deleteChunkView(chuPos);
}
chuPos = Vec2i(x - 1, z);
if(mapView.exists(chuPos)) {
mapView.deleteChunkView(chuPos);
}
chuPos = Vec2i(x, z + 1);
if(mapView.exists(chuPos)) {
mapView.deleteChunkView(chuPos);
}
chuPos = Vec2i(x, z - 1);
if(mapView.exists(chuPos)) {
mapView.deleteChunkView(chuPos);
}
}
}
}
}
示例12: setBlockHeight
void ChunkGenerator::setBlockHeight(Map& map, BiomeType type, int x, int z, int xi, int zj, int noise, int biomeNoise) {
for(int k = 0; k < 128; k++) {
switch(type) {
case BiomeType::Desert:
if(k == noise) {
// Bäume setzen
if(m_setTrees && xi >= 2 && xi <= 13 && zj >= 3 && zj <= 13) {
int treeDist = rand() % 10000;
if(treeDist <= 20) {
setCactusTree(map, x, z, xi, zj, noise);
}
}
// Boden erzeugen
map.getChunk({x, z}).setBlockType({xi, k, zj}, BlockType::Sand);
} else if(k <= noise && k >= noise - 3) {
map.getChunk({x, z}).setBlockType({xi, k, zj}, BlockType::Sand); // Unter dem Noise-Wert gibt es nur Dirt
}
break;
case BiomeType::DesertPlain:
if(k == noise) {
// Bäume setzen
if(m_setTrees && xi >= 2 && xi <= 13 && zj >= 3 && zj <= 13) {
int treeDist = rand() % 10000;
if(treeDist <= 5) {
setCactusTree(map, x, z, xi, zj, noise);
}
}
// Boden erzeugen
int random = rand() % 512;
if(random < 267){
map.getChunk({x, z}).setBlockType({xi, k, zj}, BlockType::Sand);
}else map.getChunk({x, z}).setBlockType({xi, k, zj}, BlockType::Grass);
} else if(k <= noise && k >= noise - 3) {
map.getChunk({x, z}).setBlockType({xi, k, zj}, BlockType::Sand); // Unter dem Noise-Wert gibt es nur Dirt
}
break;
case BiomeType::Plains:
if(k == noise) {
// Bäume setzen
if(m_setTrees && xi >= 6 && xi <= 9 && zj >= 6 && zj <= 9) {
int treeDist = rand() % 10000;
if(treeDist <= 30) {
setPalmTree(map, x, z, xi, zj, noise);
}
}
// Boden erzeugen
map.getChunk({x, z}).setBlockType({xi, k, zj}, BlockType::Grass);
} else if(k <= noise && k >= noise - 3) {
map.getChunk({x, z}).setBlockType({xi, k, zj}, BlockType::Dirt); // Unter dem Noise-Wert gibt es nur Dirt
}
break;
case BiomeType::PlainForest:
if(k == noise) {
// Bäume setzen
bool isTree = ChunkGenerator::isTreeInNeighborhood(map, x, z, xi, zj, noise+1); // Baum in Umgebung?
if(m_setTrees && xi >= 3 && xi <= 13 && zj >= 3 && zj <= 13 && isTree == false) {
int treeDist = rand() % 10000;
if(treeDist <= 100) {
setSpruceTree(map, x, z, xi, zj, noise);
}
if(131 <= treeDist && treeDist <= 160) {
setBirchTree(map, x, z, xi, zj, noise);
}
}
// Boden erzeugen
map.getChunk({x, z}).setBlockType({xi, k, zj}, BlockType::Grass);
} else if(k <= noise && k >= noise - 3) {
map.getChunk({x, z}).setBlockType({xi, k, zj}, BlockType::Dirt); // Unter dem Noise-Wert gibt es nur Dirt
}
break;
case BiomeType::Forest:
if(k == noise) {
// Bäume setzen
bool isTree = ChunkGenerator::isTreeInNeighborhood(map, x, z, xi, zj, noise+1); // Baum in Umgebung?
if(m_setTrees && xi >= 2 && xi <= 13 && zj >= 3 && zj <= 13 && isTree == false) {
int treeDist = rand() % 10000;
if(treeDist <= 100) {
setSpruceTree(map, x, z, xi, zj, noise);
}
if(101 <= treeDist && treeDist <= 200) {
setBirchTree(map, x, z, xi, zj, noise);
}
}
// Boden erzeugen
map.getChunk({x, z}).setBlockType({xi, k, zj}, BlockType::Grass);
// FLussüberlauf
if(55 <= biomeNoise && biomeNoise <= 69 && noise <= m_waterHeight && m_setWater == true) {
for(int i = noise; i <= m_waterHeight; i++) {
map.getChunk({x, z}).setBlockType({xi, i, zj}, BlockType::Water);
}
}
} else if(k <= noise && k >= noise - 3) {
map.getChunk({x, z}).setBlockType({xi, k, zj}, BlockType::Dirt); // Unter dem Noise-Wert gibt es nur Dirt
}
break;
//.........这里部分代码省略.........
示例13: HandleGameObjectAddCommand
//spawn go
static bool HandleGameObjectAddCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
// number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
char* id = handler->extractKeyFromLink((char*)args, "Hgameobject_entry");
if (!id)
return false;
uint32 objectId = atol(id);
if (!objectId)
return false;
char* spawntimeSecs = strtok(NULL, " ");
const GameObjectTemplate* objectInfo = sObjectMgr->GetGameObjectTemplate(objectId);
if (!objectInfo)
{
handler->PSendSysMessage(LANG_GAMEOBJECT_NOT_EXIST, objectId);
handler->SetSentErrorMessage(true);
return false;
}
if (objectInfo->displayId && !sGameObjectDisplayInfoStore.LookupEntry(objectInfo->displayId))
{
// report to DB errors log as in loading case
TC_LOG_ERROR(LOG_FILTER_SQL, "Gameobject (Entry %u GoType: %u) have invalid displayId (%u), not spawned.", objectId, objectInfo->type, objectInfo->displayId);
handler->PSendSysMessage(LANG_GAMEOBJECT_HAVE_INVALID_DATA, objectId);
handler->SetSentErrorMessage(true);
return false;
}
Player* player = handler->GetSession()->GetPlayer();
float x = float(player->GetPositionX());
float y = float(player->GetPositionY());
float z = float(player->GetPositionZ());
float o = float(player->GetOrientation());
Map* map = player->GetMap();
GameObject* object = new GameObject;
uint32 guidLow = sObjectMgr->GenerateLowGuid(HIGHGUID_GAMEOBJECT);
if (!object->Create(guidLow, objectInfo->entry, map, player->GetPhaseMaskForSpawn(), x, y, z, o, 0.0f, 0.0f, 0.0f, 0.0f, 0, GO_STATE_READY))
{
delete object;
return false;
}
if (spawntimeSecs)
{
uint32 value = atoi((char*)spawntimeSecs);
object->SetRespawnTime(value);
}
// fill the gameobject data and save to the db
object->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), player->GetPhaseMaskForSpawn());
// this will generate a new guid if the object is in an instance
if (!object->LoadGameObjectFromDB(guidLow, map))
{
delete object;
return false;
}
/// @todo is it really necessary to add both the real and DB table guid here ?
sObjectMgr->AddGameobjectToGrid(guidLow, sObjectMgr->GetGOData(guidLow));
handler->PSendSysMessage(LANG_GAMEOBJECT_ADD, objectId, objectInfo->name.c_str(), guidLow, x, y, z);
return true;
}
示例14: tr
void CutTool::pathFinished(PathObject* split_path)
{
Map* map = this->map();
// Get path endpoint and check if it is on the area boundary
const MapCoordVector& path_coords = split_path->getRawCoordinateVector();
MapCoord path_end = path_coords.at(path_coords.size() - 1);
PathObject* edited_path = reinterpret_cast<PathObject*>(edit_object);
PathCoord end_path_coord;
float distance_sq;
edited_path->calcClosestPointOnPath(MapCoordF(path_end), distance_sq, end_path_coord);
float click_tolerance_map = 0.001 * edit_widget->getMapView()->pixelToLength(clickTolerance());
if (distance_sq > click_tolerance_map*click_tolerance_map)
{
QMessageBox::warning(window(), tr("Error"), tr("The split line must end on the area boundary!"));
pathAborted();
return;
}
else if (drag_part_index != edited_path->findPartIndexForIndex(end_path_coord.index))
{
QMessageBox::warning(window(), tr("Error"), tr("Start and end of the split line are at different parts of the object!"));
pathAborted();
return;
}
else if (drag_start_len == end_path_coord.clen)
{
QMessageBox::warning(window(), tr("Error"), tr("Start and end of the split line are at the same position!"));
pathAborted();
return;
}
Q_ASSERT(split_path->parts().size() == 1);
split_path->parts().front().setClosed(false);
split_path->setCoordinate(split_path->getCoordinateCount() - 1, MapCoord(end_path_coord.pos));
// Do the splitting
const double split_threshold = 0.01;
MapPart* part = map->getCurrentPart();
AddObjectsUndoStep* add_step = new AddObjectsUndoStep(map);
add_step->addObject(part->findObjectIndex(edited_path), edited_path);
map->removeObjectFromSelection(edited_path, false);
map->deleteObject(edited_path, true);
map->setObjectsDirty();
DeleteObjectsUndoStep* delete_step = new DeleteObjectsUndoStep(map);
PathObject* holes = nullptr; // if the edited path contains holes, they are saved in this temporary object
if (edited_path->parts().size() > 1)
{
holes = edited_path->duplicate()->asPath();
holes->deletePart(0);
}
bool ok; Q_UNUSED(ok); // "ok" is only used in Q_ASSERT.
PathObject* parts[2] = { new PathObject { edited_path->parts().front() }, nullptr };
const PathPart& drag_part = edited_path->parts()[drag_part_index];
if (drag_part.isClosed())
{
parts[1] = new PathObject { *parts[0] };
parts[0]->changePathBounds(drag_part_index, drag_start_len, end_path_coord.clen);
ok = parts[0]->connectIfClose(split_path, split_threshold);
Q_ASSERT(ok);
parts[1]->changePathBounds(drag_part_index, end_path_coord.clen, drag_start_len);
ok = parts[1]->connectIfClose(split_path, split_threshold);
Q_ASSERT(ok);
}
else
{
float min_cut_pos = qMin(drag_start_len, end_path_coord.clen);
float max_cut_pos = qMax(drag_start_len, end_path_coord.clen);
float path_len = drag_part.path_coords.back().clen;
if (min_cut_pos <= 0 && max_cut_pos >= path_len)
{
ok = parts[0]->connectIfClose(split_path, split_threshold);
Q_ASSERT(ok);
parts[1] = new PathObject { *split_path };
parts[1]->setSymbol(edited_path->getSymbol(), false);
}
else if (min_cut_pos <= 0 || max_cut_pos >= path_len)
{
float cut_pos = (min_cut_pos <= 0) ? max_cut_pos : min_cut_pos;
parts[1] = new PathObject { *parts[0] };
parts[0]->changePathBounds(drag_part_index, 0, cut_pos);
ok = parts[0]->connectIfClose(split_path, split_threshold);
Q_ASSERT(ok);
parts[1]->changePathBounds(drag_part_index, cut_pos, path_len);
ok = parts[1]->connectIfClose(split_path, split_threshold);
Q_ASSERT(ok);
}
else
{
parts[1] = new PathObject { *parts[0] };
//.........这里部分代码省略.........
示例15: set_map
/**
* \brief Sets the map of this entity.
*
* Warning: as this function is called when initializing the map,
* the current map of the game is still the old one.
*
* \param map the map
*/
void DynamicTile::set_map(Map &map) {
MapEntity::set_map(map);
this->tile_pattern = &map.get_tileset().get_tile_pattern(tile_pattern_id);
}