TerrainType MapDataManager::getTerrainType(int x, int y)
{
    x = (x < 0)?0:x;
    x = (x > mMapSize -1)?mMapSize -1:x;
    y = (y < 0)?0:y;
    y = (y > mMapSize -1)?mMapSize -1:y;
    int index = getGridId(x, y);
    TerrainType terraintype;
    std::string datapath=str(boost::format("GameData/BattleData/MapData/Map/M%1%/TerrainType")%index);
    DataLibrary::getSingleton().getData(datapath,terraintype);
    return terraintype;
}
GroundType MapDataManager::getGroundType(int x, int y)
{
    x = (x < 0)?0:x;
    x = (x > mMapSize -1)?mMapSize -1:x;
    y = (y < 0)?0:y;
    y = (y > mMapSize -1)?mMapSize -1:y;
    int index = getGridId(x, y);
    GroundType groundtype;
    char datapathtemp[128];
    sprintf_s(datapathtemp, 128, "GameData/BattleData/MapData/Map/M%d/GroundType", index);
    DataLibrary::getSingleton().getData(datapathtemp,groundtype);
    return groundtype;
}
示例#3
0
//------------------------------------------------------------------------------
void InitialFromImage::initializeLocal()
{

    double rScale = 0.02;
    VEC3 shift;
    for(int d=0; d<dim;d++)
        shift[d] = domain.dom[d][1] - domain.dom[d][0];

    VEC3 v;
    VEC3 rx;
    VEC3 rz;

    vector<VEC3> _r;
    _r.push_back( VEC3() );

    int id = 0;
    switch(dim){
    case 3:

        if(gType == gridType::FCC){
            _r.push_back( VEC3() );
            _r.push_back( VEC3() );
        }

        if(gType == gridType::FCC)
        {
            rx = {0.5*spacing, 0.5*spacing, 0};
            rz = {0, 0.5*spacing, 0.5*spacing};
        }

        for(int i=0; i<nXYZ[0]; i++)
        {
            for(int j=0; j<nXYZ[1]; j++)
            {
                for(int k=0; k<nXYZ[2]; k++)
                {
                    arma::vec deviation  = deviationS0*arma::randn(dim + 1);
                    double s = s0*(1 +  deviation(0));
                    v = {0, 0, 0};
                    _r[0] = { spacing*(i + 0.25 + rScale * deviation(1))
                           , spacing*(j + 0.25 + rScale * deviation(2))
                           , spacing*(k + 0.25 + rScale * deviation(3)) };

                    if(gType == gridType::FCC)
                    {
                        _r[1] = _r[0] + rx;
                        _r[2] = _r[0] + rz;
                    }


                    for(VEC3 r:_r)
                    {
                        r = periodicBoundary( r, shift );

                        // Adding particles to the correct domain
#ifdef USE_MPI
                        if( BLOCK_OWNER(getGridId(r), nNodes, totalNumberOfgridpoints) == myRank )
                        {
                            Particle *P = new Particle(id, rho, s, volume, r, r, v);
                            particles.push_back(P);
                        }
#else
                        Particle *P = new Particle(id, rho, s, volume, r, r, v);
                        particles.push_back(P);
#endif
                        id++;
                    }
                }
            }
        }
        break;
    default:
        cerr << "dim =" << dim << " not implemented for coniguration:' Box'" << endl;
        exit(EXIT_FAILURE);
        break;
    }

    domain.setParticles(particles);
    domain.update();
//    exit(EXIT_FAILURE);
}
bool MapDataManager::getPassable(int x, int y, int faction)
{
    //PROFILE_FUNC();
    if(x < 0 || x >= mMapSize || y < 0 || y >= mMapSize)
        return false;
    DataLibrary* datalib = DataLibrary::getSingletonPtr();
    int maxpassable;
    int minpassable;
    int passable;
    int id;
    std::string path = std::string("GameData/BattleData/MapData/Map/M") + Ogre::StringConverter::toString(getGridId(x, y));
    bool re = datalib->getData(path + std::string("/GroundType"), id);
    std::string ground;
    datalib->getData(str(boost::format("GameData/BattleData/MapData/Ground/G%1%")%id),ground);
    re = datalib->getData(str(boost::format("StaticData/GroundData/%1%/GroundModifier/Passable")%ground), passable);
    maxpassable = passable;
    minpassable = passable;
    re = datalib->getData(path + std::string("/TerrainType"), id);
    re = datalib->getData(std::string("StaticData/TerrainData/Terrain") + Ogre::StringConverter::toString(id) + std::string("/GroundModifier/Passable"), passable);
    maxpassable = (maxpassable > passable)? maxpassable:passable;
    minpassable = (minpassable < passable)? minpassable:passable;
    std::string groundobj;
    re = datalib->getData(path + std::string("/MapObjType"), groundobj,true);
    if(re)
    {
        path = str(boost::format("StaticData/MapObjType/%1%/GroundModifier/Passable")%groundobj);
        re = datalib->getData(path, passable);
        maxpassable = (maxpassable > passable)? maxpassable:passable;
        minpassable = (minpassable < passable)? minpassable:passable;
    }

    //¶îÍâÐÞÕý

    //С¶Ó×èµ²
    if(faction >= 0)
    {
        BattleSquadManager* battlesquadmanager = BattleSquadManager::getSingletonPtr();
// 		BattleSquadManager::BattleSquadIte ite;
// 		for(ite = battlesquadmanager->mSquadList.begin(); ite != battlesquadmanager->mSquadList.end(); ite++)
// 		{
// 			int xx = ite->second->getGridX();
// 			int yy = ite->second->getGridY();
// 			if(xx ==x && yy == y)
// 				return false;
// 		}
        BattleSquad* squad = battlesquadmanager->getBattleSquadAt(x, y, faction, true);
        if(squad)
            return false;
    }

    if(maxpassable == 2)
        return true;
    if(minpassable == 0)
        return false;
    return true;
}
float MapDataManager::getCovert(int x, int y, int faction)
{
    TerrainType t = getTerrainType(x,y);
    GroundType g = getGroundType(x,y);
    float terraincost;
    float groundcost;
    std::string ground;
    DataLibrary::getSingleton().getData(str(boost::format("GameData/BattleData/MapData/Ground/G%1%")%g),ground);
    bool re = DataLibrary::getSingleton().getData(str(boost::format("StaticData/GroundData/%1%/GroundModifier/Covert")%ground), groundcost);
    re = DataLibrary::getSingleton().getData(std::string("StaticData/TerrainData/Terrain") + Ogre::StringConverter::toString(t) + std::string("/GroundModifier/Covert"), terraincost);
    DataLibrary* datalib = DataLibrary::getSingletonPtr();
    std::string path =  std::string("GameData/BattleData/MapData/Map/M") + Ogre::StringConverter::toString(getGridId(x, y));
    std::string groundobj;
    float groundobjcost = 0.0f;
    re = datalib->getData(path + std::string("/MapObjType"), groundobj, true);
    if(re)
    {
        path = str(boost::format("StaticData/MapObjType/%1%/GroundModifier/Covert")%groundobj);
        re = datalib->getData(path, groundobjcost);
    }
    return groundcost + terraincost + groundobjcost;
}