1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-17 01:32:21 +02:00

- moved ParseBonus to JsonNode.cpp (linkage errors)

- fixes to CMakeLists - vcmi can be compiled and started with cmake
- gcc\clang warnings fixes
This commit is contained in:
Ivan Savenko
2012-07-19 18:52:44 +00:00
parent 4c0537c420
commit e4c88d5088
13 changed files with 246 additions and 264 deletions

View File

@ -8,5 +8,5 @@ set(emptyAI_SRCS
exp_funcs.cpp exp_funcs.cpp
) )
add_library(emptyAI SHARED ${emptyAI_SRCS}) add_library(EmptyAI SHARED ${emptyAI_SRCS})
target_link_libraries(emptyAI vcmi) target_link_libraries(EmptyAI vcmi)

View File

@ -2391,7 +2391,7 @@ void VCAI::answerQuery(int queryID, int selection)
BNLOG("I'll answer the query %d giving the choice %d", queryID % selection); BNLOG("I'll answer the query %d giving the choice %d", queryID % selection);
if(queryID != -1) if(queryID != -1)
{ {
int requestID = cb->selectionMade(selection, queryID); cb->selectionMade(selection, queryID);
} }
else else
{ {

View File

@ -7,9 +7,12 @@ INCLUDE(CheckLibraryExists)
# where to look for cmake modules # where to look for cmake modules
set(CMAKE_MODULE_PATH ${CMAKE_HOME_DIRECTORY}/cmake_modules) set(CMAKE_MODULE_PATH ${CMAKE_HOME_DIRECTORY}/cmake_modules)
set(CMAKE_BUILD_TYPE Debug) # enable Release mode but only if it was not set
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
find_package(Boost COMPONENTS program_options filesystem system thread iostreams REQUIRED) find_package(Boost 1.46.0 COMPONENTS program_options filesystem system thread iostreams REQUIRED)
find_package(SDL REQUIRED) find_package(SDL REQUIRED)
find_package(SDL_image REQUIRED) find_package(SDL_image REQUIRED)
find_package(SDL_mixer REQUIRED) find_package(SDL_mixer REQUIRED)
@ -29,7 +32,7 @@ if(HAVE_DL_LIB)
endif() endif()
if(CMAKE_CXX_COMPILER MATCHES ".*clang") if(CMAKE_CXX_COMPILER MATCHES ".*clang")
set(CMAKE_COMPILER_IS_CLANGXX 1) set(CMAKE_COMPILER_IS_CLANGXX ON)
endif() endif()
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGXX) if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGXX)
@ -37,12 +40,13 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGXX)
endif() endif()
#define required constants #define required constants
add_definitions(-DM_DATA_DIR="${CMAKE_INSTALL_PREFIX}/share") add_definitions(-DM_DATA_DIR="${CMAKE_INSTALL_PREFIX}/share/vcmi")
add_definitions(-DM_BIN_DIR="${CMAKE_INSTALL_PREFIX}/lib/vcmi") add_definitions(-DM_BIN_DIR="${CMAKE_INSTALL_PREFIX}/bin")
add_definitions(-DM_LIB_DIR="${CMAKE_INSTALL_PREFIX}/bin") add_definitions(-DM_LIB_DIR="${CMAKE_INSTALL_PREFIX}/lib/vcmi")
add_subdirectory(lib) add_subdirectory(lib)
add_subdirectory(client) add_subdirectory(client)
add_subdirectory(server) add_subdirectory(server)
add_subdirectory(AI) add_subdirectory(AI)
add_subdirectory(Scripting/ERM) add_subdirectory(Scripting/ERM)

View File

@ -6,7 +6,6 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/BattleInterface ${CMAKE_CURRENT_
include_directories(${SDL_INCLUDE_DIR} ${SDLIMAGE_INCLUDE_DIR} ${SDLMIXER_INCLUDE_DIR} ${SDLTTF_INCLUDE_DIR}) include_directories(${SDL_INCLUDE_DIR} ${SDLIMAGE_INCLUDE_DIR} ${SDLMIXER_INCLUDE_DIR} ${SDLTTF_INCLUDE_DIR})
include_directories(${Boost_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIR} ${FFMPEG_INCLUDE_DIR}) include_directories(${Boost_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIR} ${FFMPEG_INCLUDE_DIR})
set(client_SRCS set(client_SRCS
../CCallback.cpp ../CCallback.cpp
BattleInterface/CBattleAnimations.cpp BattleInterface/CBattleAnimations.cpp
@ -44,7 +43,6 @@ set(client_SRCS
GUIClasses.cpp GUIClasses.cpp
mapHandler.cpp mapHandler.cpp
NetPacksClient.cpp NetPacksClient.cpp
SDL_framerate.cpp
) )
IF(UNIX) IF(UNIX)
@ -53,4 +51,4 @@ ELSEIF(WIN32)
add_executable(vcmiclient WIN32 ${client_SRCS}) add_executable(vcmiclient WIN32 ${client_SRCS})
ENDIF() ENDIF()
target_link_libraries(vcmiclient vcmi ${Boost_LIBRARIES} ${SDL_LIBRARY} ${SDLIMAGE_LIBRARY} ${SDLMIXER_LIBRARY} ${SDLTTF_LIBRARY} ${ZLIB_LIBRARIES} ${FFMPEG_LIBRARIES}) target_link_libraries(vcmiclient vcmi ${Boost_LIBRARIES} ${SDL_LIBRARY} ${SDLIMAGE_LIBRARY} ${SDLMIXER_LIBRARY} ${SDLTTF_LIBRARY} ${ZLIB_LIBRARIES} ${FFMPEG_LIBRARIES} ${RT_LIB} ${DL_LIB})

View File

@ -141,8 +141,10 @@ void CQuestMinimap::showAll(SDL_Surface * to)
CQuestLog::CQuestLog (const std::vector<QuestInfo> & Quests) : CQuestLog::CQuestLog (const std::vector<QuestInfo> & Quests) :
CWindowObject(PLAYER_COLORED, "QuestLog.pcx"), CWindowObject(PLAYER_COLORED, "QuestLog.pcx"),
quests (Quests), slider (NULL), questIndex(0),
questIndex(0), currentQuest(NULL) currentQuest(NULL),
quests (Quests),
slider(NULL)
{ {
OBJ_CONSTRUCTION_CAPTURING_ALL; OBJ_CONSTRUCTION_CAPTURING_ALL;
init(); init();

View File

@ -5787,8 +5787,7 @@ CInfoBoxPopup::CInfoBoxPopup(Point position, const CGTownInstance * town):
CWindowObject(RCLICK_POPUP | PLAYER_COLORED, "TOWNQVBK", toScreen(position)) CWindowObject(RCLICK_POPUP | PLAYER_COLORED, "TOWNQVBK", toScreen(position))
{ {
InfoAboutTown iah; InfoAboutTown iah;
bool gotInfo = LOCPLINT->cb->getTownInfo(town, iah); LOCPLINT->cb->getTownInfo(town, iah);
assert(gotInfo);
OBJ_CONSTRUCTION_CAPTURING_ALL; OBJ_CONSTRUCTION_CAPTURING_ALL;
new CTownTooltip(Point(9, 10), iah); new CTownTooltip(Point(9, 10), iah);
@ -5798,8 +5797,7 @@ CInfoBoxPopup::CInfoBoxPopup(Point position, const CGHeroInstance * hero):
CWindowObject(RCLICK_POPUP | PLAYER_COLORED, "HEROQVBK", toScreen(position)) CWindowObject(RCLICK_POPUP | PLAYER_COLORED, "HEROQVBK", toScreen(position))
{ {
InfoAboutHero iah; InfoAboutHero iah;
bool gotInfo = LOCPLINT->cb->getHeroInfo(hero, iah); LOCPLINT->cb->getHeroInfo(hero, iah);
assert(gotInfo);
OBJ_CONSTRUCTION_CAPTURING_ALL; OBJ_CONSTRUCTION_CAPTURING_ALL;
new CHeroTooltip(Point(9, 10), iah); new CHeroTooltip(Point(9, 10), iah);
@ -5809,8 +5807,7 @@ CInfoBoxPopup::CInfoBoxPopup(Point position, const CGGarrison * garr):
CWindowObject(RCLICK_POPUP | PLAYER_COLORED, "TOWNQVBK", toScreen(position)) CWindowObject(RCLICK_POPUP | PLAYER_COLORED, "TOWNQVBK", toScreen(position))
{ {
InfoAboutTown iah; InfoAboutTown iah;
bool gotInfo = LOCPLINT->cb->getTownInfo(garr, iah); LOCPLINT->cb->getTownInfo(garr, iah);
assert(gotInfo);
OBJ_CONSTRUCTION_CAPTURING_ALL; OBJ_CONSTRUCTION_CAPTURING_ALL;
new CArmyTooltip(Point(9, 10), iah); new CArmyTooltip(Point(9, 10), iah);

View File

@ -51,39 +51,20 @@ namespace Colors
template<typename IntType> template<typename IntType>
std::string makeNumberShort(IntType number) //the output is a string containing at most 5 characters [4 if positive] (eg. intead 10000 it gives 10k) std::string makeNumberShort(IntType number) //the output is a string containing at most 5 characters [4 if positive] (eg. intead 10000 it gives 10k)
{ {
int initialLength; if (abs(number) < 1000)
bool negative = (number < 0); return boost::lexical_cast<std::string>(number);
std::ostringstream ost, rets;
ost<<number;
initialLength = ost.str().size();
if(negative) std::string symbols = "kMGTPE";
auto iter = symbols.begin();
while (number >= 1000)
{ {
if(initialLength <= 4) number /= 1000;
return ost.str(); iter++;
}
else
{
if(initialLength <= 5)
return ost.str();
}
//make the number int assert(iter != symbols.end());//should be enough even for int64
char symbol[] = {'G', 'M', 'k'};
if(negative) number = (-number); //absolute value
for(int divisor = 1000000000, it = 0; divisor > 1; divisor /= 1000, ++it)
{
if(number >= divisor)
{
if(negative) rets <<'-';
rets << (number / divisor) << symbol[it];
return rets.str();
} }
} return boost::lexical_cast<std::string>(number) + *iter;
throw std::runtime_error("We shouldn't be here - makeNumberShort");
} }
typedef void (*TColorPutter)(Uint8 *&ptr, const Uint8 & R, const Uint8 & G, const Uint8 & B); typedef void (*TColorPutter)(Uint8 *&ptr, const Uint8 & R, const Uint8 & G, const Uint8 & B);

View File

@ -6304,7 +6304,7 @@ void CGKeymasterTent::onHeroVisit( const CGHeroInstance * h ) const
void CGBorderGuard::initObj() void CGBorderGuard::initObj()
{ {
ui32 m13489val = subID; //store color as quest info //ui32 m13489val = subID; //store color as quest info
blockVisit = true; blockVisit = true;
} }

View File

@ -53,6 +53,7 @@ std::vector<BattleHex> CObstacleInstance::getAffectedTiles() const
return getInfo().getBlocked(pos); return getInfo().getBlocked(pos);
default: default:
assert(0); assert(0);
return std::vector<BattleHex>();
} }
} }
@ -105,6 +106,7 @@ bool SpellCreatedObstacle::visibleForSide(ui8 side, bool hasNativeStack) const
return casterSide == side || visibleForAnotherSide || hasNativeStack; return casterSide == side || visibleForAnotherSide || hasNativeStack;
default: default:
assert(0); assert(0);
return false;
} }
} }
@ -121,6 +123,7 @@ std::vector<BattleHex> SpellCreatedObstacle::getAffectedTiles() const
//TODO Fire Wall //TODO Fire Wall
default: default:
assert(0); assert(0);
return std::vector<BattleHex>();
} }
} }

View File

@ -1,8 +1,7 @@
#include "StdInc.h" #include "StdInc.h"
#include "JsonNode.h" #include "JsonNode.h"
#include "HeroBonus.h"
class Bonus;
const JsonNode JsonNode::nullNode; const JsonNode JsonNode::nullNode;
@ -873,3 +872,22 @@ JsonValidator::JsonValidator(JsonNode &root, const JsonNode &schema, bool Minimi
addMessage("Schema not found!"); addMessage("Schema not found!");
tlog3<<errors; tlog3<<errors;
} }
Bonus * ParseBonus (const JsonVector &ability_vec) //TODO: merge with AddAbility, create universal parser for all bonus properties
{
Bonus * b = new Bonus();
std::string type = ability_vec[0].String();
auto it = bonusNameMap.find(type);
if (it == bonusNameMap.end())
{
tlog1 << "Error: invalid ability type " << type << " in creatures.txt" << std::endl;
return b;
}
b->type = it->second;
b->val = ability_vec[1].Float();
b->subtype = ability_vec[2].Float();
b->additionalInfo = ability_vec[3].Float();
b->duration = Bonus::PERMANENT;
b->turnsRemain = 0;
return b;
}

View File

@ -1,12 +1,10 @@
#pragma once #pragma once
#include "HeroBonus.h"
class JsonNode; class JsonNode;
typedef std::map <std::string, JsonNode> JsonMap; typedef std::map <std::string, JsonNode> JsonMap;
typedef std::vector <JsonNode> JsonVector; typedef std::vector <JsonNode> JsonVector;
class Bonus; struct Bonus;
class DLL_LINKAGE JsonNode class DLL_LINKAGE JsonNode
{ {
@ -199,23 +197,4 @@ public:
JsonValidator(JsonNode &root, const JsonNode &schema, bool minimize=false); JsonValidator(JsonNode &root, const JsonNode &schema, bool minimize=false);
}; };
//Bonus * ParseBonus (const JsonVector &ability_vec); DLL_LINKAGE Bonus * ParseBonus (const JsonVector &ability_vec);
static Bonus * ParseBonus (const JsonVector &ability_vec) //TODO: merge with AddAbility, create universal parser for all bonus properties
{
Bonus * b = new Bonus();
std::string type = ability_vec[0].String();
auto it = bonusNameMap.find(type);
if (it == bonusNameMap.end())
{
tlog1 << "Error: invalid ability type " << type << " in creatures.txt" << std::endl;
return b;
}
b->type = it->second;
b->val = ability_vec[1].Float();
b->subtype = ability_vec[2].Float();
b->additionalInfo = ability_vec[3].Float();
b->duration = Bonus::PERMANENT;
b->turnsRemain = 0;
return b;
}

View File

@ -16,4 +16,4 @@ ELSEIF(WIN32)
add_executable(vcmiserver WIN32 ${server_SRCS}) add_executable(vcmiserver WIN32 ${server_SRCS})
ENDIF() ENDIF()
target_link_libraries(vcmiserver vcmi ${Boost_LIBRARIES}) target_link_libraries(vcmiserver vcmi ${Boost_LIBRARIES} ${RT_LIB} ${DL_LIB})