See More

/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */ #include "unitsync.h" #include "unitsync_api.h" #include #include #include #include #include // shared with spring: #include "lib/lua/include/LuaInclude.h" #include "Game/GameVersion.h" #include "Lua/LuaParser.h" #include "Map/MapParser.h" #include "Map/ReadMap.h" #include "Map/SMF/SMFMapFile.h" #include "Sim/Misc/SideParser.h" #include "ExternalAI/Interface/aidefines.h" #include "ExternalAI/LuaAIImplHandler.h" #include "System/Config/ConfigHandler.h" #include "System/FileSystem/Archives/IArchive.h" #include "System/FileSystem/ArchiveLoader.h" #include "System/FileSystem/ArchiveScanner.h" #include "System/FileSystem/DataDirsAccess.h" #include "System/FileSystem/DataDirLocater.h" #include "System/FileSystem/FileHandler.h" #include "System/FileSystem/VFSHandler.h" #include "System/FileSystem/FileSystem.h" #include "System/FileSystem/FileSystemInitializer.h" #include "System/Log/ILog.h" #include "System/Log/Level.h" #include "System/Log/DefaultFilter.h" #include "System/Misc/SpringTime.h" #include "System/Platform/Misc.h" //!! #include "System/Threading/ThreadPool.h" #include "System/Exceptions.h" #include "System/Info.h" #include "System/LogOutput.h" #include "System/Option.h" #include "System/SafeCStrings.h" #include "System/SafeUtil.h" #include "System/StringUtil.h" #include "System/ExportDefines.h" #ifdef WIN32 #include #endif ////////////////////////// ////////////////////////// #define LOG_SECTION_UNITSYNC "unitsync" LOG_REGISTER_SECTION_GLOBAL(LOG_SECTION_UNITSYNC) // use the specific section for all LOG*() calls in this source file #ifdef LOG_SECTION_CURRENT #undef LOG_SECTION_CURRENT #endif #define LOG_SECTION_CURRENT LOG_SECTION_UNITSYNC // avoid including GlobalConstants.h #define SQUARE_SIZE 8 #ifdef WIN32 BOOL CALLING_CONV DllMain(HINSTANCE hInst, DWORD dwReason, LPVOID lpReserved) { return TRUE; } #endif CONFIG(bool, UnitsyncAutoUnLoadMaps).defaultValue(true).description("Automaticly load and unload the required map for some unitsync functions."); CONFIG(bool, UnitsyncAutoUnLoadMapsIsSupported).defaultValue(true).readOnly(true).description("Check for support of UnitsyncAutoUnLoadMaps"); ////////////////////////// ////////////////////////// // function argument checking static bool CheckInit(bool throwException = true) { if (archiveScanner == nullptr || vfsHandler == nullptr) { if (throwException) throw std::logic_error("UnitSync not initialized. Call Init first."); return false; } return true; } static void _CheckNull(void* condition, const char* name) { if (!condition) throw std::invalid_argument("Argument " + std::string(name) + " may not be null."); } static void _CheckNullOrEmpty(const char* condition, const char* name) { if (!condition || *condition == 0) throw std::invalid_argument("Argument " + std::string(name) + " may not be null or empty."); } static void _CheckBounds(int index, int size, const char* name) { if (index < 0 || index >= size) throw std::out_of_range("Argument " + std::string(name) + " out of bounds. Index: " + IntToString(index) + " Array size: " + IntToString(size)); } static void _CheckPositive(int value, const char* name) { if (value <= 0) throw std::out_of_range("Argument " + std::string(name) + " must be positive."); } #define CheckNull(arg) _CheckNull((arg), #arg) #define CheckNullOrEmpty(arg) _CheckNullOrEmpty((arg), #arg) #define CheckBounds(arg, size) _CheckBounds((arg), (size), #arg) #define CheckPositive(arg) _CheckPositive((arg), #arg); struct GameDataUnitDef { std::string name; std::string fullName; }; /** * @brief map related meta-data */ struct InternalMapInfo { std::string description; ///< Description (max 255 chars) std::string author; ///< Creator of the map (max 200 chars) int tidalStrength; ///< Tidal strength int gravity; ///< Gravity float maxMetal; ///< Metal scale factor int extractorRadius; ///< Extractor radius (of metal extractors) int minWind; ///< Minimum wind speed int maxWind; ///< Maximum wind speed int width; ///< Width of the map int height; ///< Height of the map std::vector xPos; ///< Start positions X coordinates defined by the map std::vector zPos; ///< Start positions Z coordinates defined by the map }; static std::vector infoItems; static std::set<:string> infoSet; static std::vector unitDefs; static std::map mapInfos; static std::map openArchives; static std::map openFiles; static std::vector<:string> curFindFiles; // Updated on every call to GetMapCount static std::vector<:string> mapNames; static std::vector<:string> mapArchives; static std::vector