当前位置: 首页>>代码示例>>C++>>正文


C++ Town::init方法代码示例

本文整理汇总了C++中Town::init方法的典型用法代码示例。如果您正苦于以下问题:C++ Town::init方法的具体用法?C++ Town::init怎么用?C++ Town::init使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Town的用法示例。


在下文中一共展示了Town::init方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: add_town

//----- Begin of function TownArray::add_town -------//
//
// <int> nationRecno - the nation recno
// <int> raceId 	   - the race of the majority of the town poulation
// <int> xLoc, yLoc  - location of the town
//
int TownArray::add_town(int nationRecno, int raceId, int xLoc, int yLoc)
{
	Town* townPtr;

	townPtr = new Town;

	linkin(&townPtr);

	townPtr->town_recno = recno();
	townPtr->init(nationRecno, raceId, xLoc, yLoc);

	nation_array.update_statistic();		// update largest_town_recno

	return recno();
}
开发者ID:brianV,项目名称:7kaa,代码行数:21,代码来源:OTOWNA.cpp

示例2: createFromServer

// -----------------------------------------------------------------
// Name : createFromServer
// -----------------------------------------------------------------
void Map::createFromServer(MapReader * pMapReader, LocalClient * pLocalClient)
{
    m_iWidth = pMapReader->getMapWidth();
    m_iHeight = pMapReader->getMapHeight();
    int * pTiles = pMapReader->getMap();
    m_pTiles = new MapTile**[m_iWidth];
    for (u16 x = 0; x < m_iWidth; x++)
    {
        m_pTiles[x] = new MapTile*[m_iHeight];
        for (u16 y = 0; y < m_iHeight; y++)
        {
            if (IS_VALID_TERRAIN(pTiles[y * m_iWidth + x]))
                m_pTiles[x][y] = new MapTile(pTiles[y * m_iWidth + x], pLocalClient->getServer()->getSolver()->getGlobalSpellsPtr());
            else
            {
                m_pTiles[x][y] = new MapTile(TERRAIN_SEA, pLocalClient->getServer()->getSolver()->getGlobalSpellsPtr());
                char sError[512];
                snprintf(sError, 512, "Invalid terrain type at (%d,%d)", (int)x, (int)y);
                pLocalClient->getDebug()->notifyErrorMessage(sError);
            }
        }
    }
    // Reset used town names and heroes
    Edition * pEdition = pLocalClient->getDataFactory()->getFirstEdition();
    while (pEdition != NULL)
    {
        Ethnicity * pEthn = (Ethnicity*) pEdition->getEthnicities()->getFirst(0);
        while (pEthn != NULL)
        {
            pEthn->resetUsedTownNames();
            pEthn->resetUsedHeroes();
            pEthn = (Ethnicity*) pEdition->getEthnicities()->getNext(0);
        }
        pEdition = pLocalClient->getDataFactory()->getNextEdition();
    }
    // Create towns
    std::vector<TownData> * towns = pMapReader->getTowns();
    for (u16 i = 0; i < towns->size(); i++)
    {
        if (getTileAt((*towns)[i].position)->m_uTerrainType == TERRAIN_SEA)
            continue;
        Edition * pEdition = pLocalClient->getDataFactory()->findEdition((*towns)[i].sEthnEdition);
        if (pEdition != NULL)
        {
            Ethnicity * pEthn = pEdition->findEthnicity((*towns)[i].sEthnId);
            if (pEthn != NULL)
            {
                Town * pTown = new Town((*towns)[i].position, this, pLocalClient->getServer()->getSolver()->getGlobalSpellsPtr());
                pTown->init(m_iNbTowns++, (*towns)[i].size, pEthn, pLocalClient);
                pTown->initServer();
                m_pTownsRef->addLast(pTown);
            }
        }
    }
    // Create temples
    std::vector<TempleData> * temples = pMapReader->getTemples();
    for (u16 i = 0; i < temples->size(); i++)
    {
        if (getTileAt((*temples)[i].position)->m_uTerrainType == TERRAIN_SEA)
            continue;
        Temple * pTemple = new Temple((*temples)[i].position, this, pLocalClient->getServer()->getSolver()->getGlobalSpellsPtr());
        pTemple->init(m_iNbTemples++, (*temples)[i].mana, (*temples)[i].amount);
        m_pTemplesRef->addLast(pTemple);
    }
    // Create special tiles
    std::vector<CoordsMap> * spectiles = pMapReader->getSpecialTiles();
    char pAllTerrains[7][64] = LTERRAIN_NAMES;
    for (u16 i = 0; i < spectiles->size(); i++)
    {
        MapTile * pTile = getTileAt((*spectiles)[i]);
        // First get total frequency
        int totalFreq = 0;
        Edition * pEd = pLocalClient->getDataFactory()->getFirstEdition();
        while (pEd != NULL)
        {
            SpecialTile * pSpec = (SpecialTile*) pEd->getSpecialTiles()->getFirst(0);
            while (pSpec != NULL)
            {
                pSpec->callLuaFunction("isAllowedOn", 1, "s", pAllTerrains[pTile->m_uTerrainType]);
                if (pSpec->getLuaNumber() > 0)
                    totalFreq += pSpec->getFrequency();
                pSpec = (SpecialTile*) pEd->getSpecialTiles()->getNext(0);
            }
            pEd = pLocalClient->getDataFactory()->getNextEdition();
        }
        if (totalFreq > 0)
        {
            bool bBreak = false;
            int iRnd = getRandom(totalFreq);
            pEd = pLocalClient->getDataFactory()->getFirstEdition();
            while (pEd != NULL)
            {
                SpecialTile * pSpec = (SpecialTile*) pEd->getSpecialTiles()->getFirst(0);
                while (pSpec != NULL)
                {
                    pSpec->callLuaFunction("isAllowedOn", 1, "s", pAllTerrains[pTile->m_uTerrainType]);
                    if (pSpec->getLuaNumber() > 0)
//.........这里部分代码省略.........
开发者ID:jotak,项目名称:shahnarman,代码行数:101,代码来源:Map.cpp


注:本文中的Town::init方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。