'itoa' is not recognized

2

I'm trying to compile the code below with GCC 4.7.4, but I always get the error

  

error: 'itoa' was not declared in this scope

#include "otpch.h"
#include <iomanip>
#include <stdlib.h>
#include <boost/config.hpp>
#include <boost/bind.hpp>

#include "iomap.h"
#include "map.h"
#include "tile.h"

#include "creature.h"
#include "player.h"
#include "combat.h"

#include "iomapserialize.h"
#include "items.h"

#include "game.h"
#include "configmanager.h"

[...]

    bool Map::placeCreature(const Position& centerPos, Creature* creature, bool extendedPos /*= false*/, bool forced /*= false*/)
{
    Monster* monster = creature->getMonster();
    if(monster && g_config.getBool(ConfigManager::MONSTER_HAS_LEVEL))
    {
        uint8_t level;
        if(!monster->getMonsterType()->hideLevel)
        {
            if(monster->isSummon())
            {
                std::string value;
                monster->getMaster()->getStorage((std::string)"monster_level", value);

                uint8_t intValue = atoi(value.c_str());
                if(intValue || value == "0")
                    level = intValue;
                else
                    level = 1;
            }
            else
                level = monster->level;

            char buffer [10];
            monster->name = monster->getName() + " [PDL : " + itoa(level, buffer, 10) + "]";
        }
    }
    bool foundTile = false, placeInPz = false;
    Tile* tile = getTile(centerPos);
    if(tile && !extendedPos)
    {
        placeInPz = tile->hasFlag(TILESTATE_PROTECTIONZONE);
        uint32_t flags = FLAG_IGNOREBLOCKITEM;
        if(creature->isAccountManager())
            flags |= FLAG_IGNOREBLOCKCREATURE;

        ReturnValue ret = tile->__queryAdd(0, creature, 1, flags);
        if(forced || ret == RET_NOERROR || ret == RET_PLAYERISNOTINVITED)
            foundTile = true;
    }

    size_t shufflePos = 0;
    PairVector relList;
    if(extendedPos)
    {
        shufflePos = 8;
        relList.push_back(PositionPair(-2, 0));
        relList.push_back(PositionPair(0, -2));
        relList.push_back(PositionPair(0, 2));
        relList.push_back(PositionPair(2, 0));
        std::random_shuffle(relList.begin(), relList.end());
    }

    relList.push_back(PositionPair(-1, -1));
    relList.push_back(PositionPair(-1, 0));
    relList.push_back(PositionPair(-1, 1));
    relList.push_back(PositionPair(0, -1));
    relList.push_back(PositionPair(0, 1));
    relList.push_back(PositionPair(1, -1));
    relList.push_back(PositionPair(1, 0));
    relList.push_back(PositionPair(1, 1));
    std::random_shuffle(relList.begin() + shufflePos, relList.end());

    uint32_t radius = 1;
    Position tryPos;
    for(uint32_t n = 1; n <= radius && !foundTile; ++n)
    {
        for(PairVector::iterator it = relList.begin(); it != relList.end() && !foundTile; ++it)
        {
            int32_t dx = it->first * n, dy = it->second * n;
            tryPos = centerPos;

            tryPos.x = tryPos.x + dx;
            tryPos.y = tryPos.y + dy;
            if(!(tile = getTile(tryPos)) || (placeInPz && !tile->hasFlag(TILESTATE_PROTECTIONZONE)))
                continue;

            if(tile->__queryAdd(0, creature, 1, 0) == RET_NOERROR)
            {
                if(!extendedPos)
                {
                    foundTile = true;
                    break;
                }

                if(isSightClear(centerPos, tryPos, false))
                {
                    foundTile = true;
                    break;
                }
            }
        }
    }

    if(!foundTile)
        return false;

    int32_t index = 0;
    uint32_t flags = 0;

    Item* toItem = NULL;
    if(Cylinder* toCylinder = tile->__queryDestination(index, creature, &toItem, flags))
    {
        toCylinder->__internalAddThing(creature);
        if(Tile* toTile = toCylinder->getTile())
            toTile->qt_node->addCreature(creature);
    }

    return true;
}
    
asked by anonymous 26.03.2015 / 19:42

1 answer

1

I will respond based on the information you are passing. I do not know if you will be able to apply since you are having very basic difficulties to use the compiler.

It looks like you're using a new version that's enough to use better features available in the language. So instead of using itoa , use std::to_string() , then replace

itoa(level, buffer, 10)

by

std::to_string(level)

And the atoi can also be replaced by std::stoi() then replace:

atoi(value.c_str());

by

std::stoi(value)

Remembering that the answer works if the information passed is correct. If I can improve the information of the question I can improve the answer.

    
26.03.2015 / 20:12