diff --git a/TacticalAI/AIMain.cpp b/TacticalAI/AIMain.cpp index d6f4878b..ae1aee21 100644 --- a/TacticalAI/AIMain.cpp +++ b/TacticalAI/AIMain.cpp @@ -52,6 +52,7 @@ #include "Queen Command.h" #include "points.h" #include "Soldier Functions.h" // added by SANDRO +#include "Text.h" // sevenfm #endif #include "connect.h" @@ -81,9 +82,6 @@ extern BOOLEAN gfWaitingForTriggerTimer; UINT8 gubAICounter; -extern STR16 gStrAction[]; -extern STR szAction[]; - // // Commented out/ to fix: // lots of other stuff, I think @@ -703,7 +701,7 @@ void HandleSoldierAI( SOLDIERTYPE *pSoldier ) // FIXME - this function is named // ATE: Display message that deadlock occured... LiveMessage( "Breaking Deadlock" ); - //ScreenMsg(FONT_MCOLOR_LTRED, MSG_INTERFACE, L"Aborting AI deadlock for [%d] %s data %d", pSoldier->ubID, gStrAction[pSoldier->aiData.bAction], pSoldier->aiData.usActionData); + ScreenMsg(FONT_MCOLOR_LTRED, MSG_INTERFACE, L"Aborting AI deadlock for [%d] %s %s data %d", pSoldier->ubID, pSoldier->GetName(), utf8_to_wstring(std::string(szAction[pSoldier->aiData.bAction])), pSoldier->aiData.usActionData); DebugAI(String("Aborting AI deadlock for [%d] %s data %d", pSoldier->ubID, szAction[pSoldier->aiData.bAction], pSoldier->aiData.usActionData)); #ifdef JA2TESTVERSION @@ -1906,7 +1904,7 @@ INT8 ExecuteAction(SOLDIERTYPE *pSoldier) { INT32 iRetCode; //NumMessage("ExecuteAction - Guy#",pSoldier->ubID); - + //ScreenMsg(FONT_MCOLOR_LTRED, MSG_INTERFACE, L"Execute action: [%d] %s %s data %d", pSoldier->ubID, pSoldier->GetName(), utf8_to_wstring(std::string(szAction[pSoldier->aiData.bAction])), pSoldier->aiData.usActionData); // in most cases, merc will change location, or may cause damage to opponents, // so a new cover check will be necessary. Exceptions handled individually. diff --git a/Utils/Text Utils.cpp b/Utils/Text Utils.cpp index 65900d55..93bb693c 100644 --- a/Utils/Text Utils.cpp +++ b/Utils/Text Utils.cpp @@ -4,6 +4,9 @@ #include "text.h" #include "Fileman.h" #include "GameSettings.h" + // sevenfm + #include + #include #endif BOOLEAN LoadItemInfo(UINT16 ubIndex, STR16 pNameString, STR16 pInfoString ) @@ -1300,3 +1303,27 @@ void ParseCommandLine ( ++*numargs; } +inline std::string narrow(std::wstring const& text) +{ + std::locale const loc(""); + wchar_t const* from = text.c_str(); + std::size_t const len = text.size(); + std::vector buffer(len + 1); + std::use_facet >(loc).narrow(from, from + len, '_', &buffer[0]); + + return std::string(&buffer[0], &buffer[len]); +} + +// convert UTF-8 string to wstring +std::wstring utf8_to_wstring(const std::string& str) +{ + std::wstring_convert> myconv; + return myconv.from_bytes(str); +} + +// convert wstring to UTF-8 string +std::string wstring_to_utf8(const std::wstring& str) +{ + std::wstring_convert> myconv; + return myconv.to_bytes(str); +} diff --git a/Utils/Text.h b/Utils/Text.h index 37113db9..5b1418d0 100644 --- a/Utils/Text.h +++ b/Utils/Text.h @@ -1799,6 +1799,13 @@ BOOLEAN LoadItemProsAndCons( UINT16 usIndex, STR16 pProsString, STR16 pConsStrin BOOLEAN LoadBRDesc(UINT16 ubIndex, STR16 pDescString ); BOOLEAN LoadBRName(UINT16 ubIndex, STR16 pNameString ); +// sevenfm +inline std::string narrow(std::wstring const& text); +// convert UTF-8 string to wstring +std::wstring utf8_to_wstring(const std::string& str); +// convert wstring to UTF-8 string +std::string wstring_to_utf8(const std::wstring& str); + enum { //Coordinating simultaneous arrival dialog strings