From 99e45d697e90f0fe8e2f3f15ba640df292229ba4 Mon Sep 17 00:00:00 2001 From: Overhaul Date: Sat, 14 Jul 2007 04:25:07 +0000 Subject: [PATCH] Fix to make soldier continue towards destination if previous path ended with a special move Re-integrated LUA and console. Still many things to finish though. git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@1048 3b4a5df2-a311-0410-b5c6-a8a6f20db521 --- Console/Console.cpp | 20 ++++++++++++++------ Console/Console.h | 4 +++- Standard Gaming Platform/sgp.cpp | 23 ++++++++++++++++++++++- Tactical/Soldier Ani.cpp | 10 +++++++++- lua/Lua Interpreter.h | 2 +- lua/lua.cpp | 28 +++++++++++++++++++++++++--- 6 files changed, 74 insertions(+), 13 deletions(-) diff --git a/Console/Console.cpp b/Console/Console.cpp index a9457cc0..a66b50fe 100644 --- a/Console/Console.cpp +++ b/Console/Console.cpp @@ -244,9 +244,10 @@ Console::Console(LPCTSTR pszConfigFile, LPCTSTR pszShellCmdLine, LPCTSTR pszCons ::SetStdHandle( STD_OUTPUT_HANDLE, myOut); ::SetStdHandle( STD_ERROR_HANDLE, myOut); - int hConHandle = _open_osfhandle((long)myOut, _O_WTEXT); + int hConHandle = _open_osfhandle((long)myOut, _O_BINARY); //_O_WTEXT); FILE *fp = _fdopen( hConHandle, "w" ); *stdout = *fp; + *stderr = *fp; setvbuf( stdout, NULL, _IONBF, 0 ); // create text monitor thread @@ -282,8 +283,10 @@ Console::~Console() { ///////////////////////////////////////////////////////////////////////////// // creates and shows Console window -BOOL Console::Create(TCHAR* pszConfigPath) { +BOOL Console::Create(HWND notify) { + m_notifyhWnd = notify; + if (m_hWnd) { ::ShowWindow( m_hWnd, SW_SHOW); @@ -727,7 +730,6 @@ void Console::OnLButtonDown(UINT uiFlags, POINTS points) { } } #endif - wcout << "Test" << endl; } ///////////////////////////////////////////////////////////////////////////// @@ -947,6 +949,9 @@ void Console::OnChar(WORD myChar) { text[1] = '\r'; text[2] = 0; Input += '\n'; + SendTextToConsole( text); + SendMessage( m_notifyhWnd, WM_INPUTREADY, 0, (LPARAM) &Input); + return; } else { @@ -4534,13 +4539,16 @@ DWORD Console::MonitorThread() { ///////////////////////////////////////////////////////////////////////////// void Console::AddOutput() { DWORD bytesRead; - wchar_t buf[801]; + char buf[801]; + wchar_t wbuf[801]; + ::ReadFile( m_hStdOut, buf, sizeof(buf)/sizeof(wchar_t)-1, &bytesRead, NULL); if (bytesRead == 0) { return; } - buf[bytesRead/sizeof(wchar_t)] = 0; - SendTextToConsole( buf); + buf[bytesRead] = 0; + MultiByteToWideChar( CP_UTF8, 0, buf, -1, wbuf, sizeof(wbuf)/sizeof(wbuf[0])); + SendTextToConsole( wbuf); } ///////////////////////////////////////////////////////////////////////////// diff --git a/Console/Console.h b/Console/Console.h index 4f85c778..0a3076d2 100644 --- a/Console/Console.h +++ b/Console/Console.h @@ -130,7 +130,7 @@ class Console { public: // creates and shows Console window - BOOL Create(TCHAR* pszConfigPath); + BOOL Create(HWND notify); private: @@ -441,6 +441,8 @@ class Console { // Console window handle HWND m_hWnd; + HWND m_notifyhWnd; + // console colors COLORREF m_arrConsoleColors[16]; diff --git a/Standard Gaming Platform/sgp.cpp b/Standard Gaming Platform/sgp.cpp index d5b6f81e..ba6c9f75 100644 --- a/Standard Gaming Platform/sgp.cpp +++ b/Standard Gaming Platform/sgp.cpp @@ -38,11 +38,14 @@ #include "zmouse.h" +#include + #include "ExceptionHandling.h" #include "dbt.h" #include "INIReader.h" #include "Console.h" +#include "Lua Interpreter.h" #ifdef JA2 #include "BuildDefines.h" @@ -454,7 +457,25 @@ INT32 FAR PASCAL WindowProcedure(HWND hWindow, UINT16 Message, WPARAM wParam, LP if (wParam == '\\' && lParam && KF_ALTDOWN) { - g_Console.Create(NULL); + g_Console.Create(ghWindow); + cout << "LUA console ready" << endl; + cout << "> "; + } + break; + + case WM_INPUTREADY: + { + wstring *tstr = (wstring*) lParam; + if (EvalLua( tstr->c_str())) + { + tstr->erase(); + } + else + { + cout << ">"; + } + + cout << "> "; } break; default diff --git a/Tactical/Soldier Ani.cpp b/Tactical/Soldier Ani.cpp index d56c045f..503dc588 100644 --- a/Tactical/Soldier Ani.cpp +++ b/Tactical/Soldier Ani.cpp @@ -2109,8 +2109,16 @@ BOOLEAN AdjustToNextAnimationFrame( SOLDIERTYPE *pSoldier ) if ( pSoldier->usPathIndex == pSoldier->usPathDataSize ) { -pSoldier->usPathIndex = pSoldier->usPathDataSize; // Stop, don't do anything..... + // 0verhaul: Only if not at the final destination + // Another reason for rebuilding the animation system. This should be part of a common + // path continuation code so that any other bug fixes won't need to be duplicated in other areas. + if ( pSoldier->sGridNo != pSoldier->sFinalDestination) + { + if ( !EVENT_InternalGetNewSoldierPath( pSoldier, pSoldier->sFinalDestination, pSoldier->usUIMovementMode, 2, FALSE ) ) + { + } + } } else { diff --git a/lua/Lua Interpreter.h b/lua/Lua Interpreter.h index ce0ca538..293712f1 100644 --- a/lua/Lua Interpreter.h +++ b/lua/Lua Interpreter.h @@ -14,6 +14,6 @@ typedef struct { } LuaAttrib; void InitializeLua( ); -void EvalLua (STR8 buff) ; +int EvalLua (const wchar_t* buff) ; // The return value is whether to clear the input line, not whether the call succeeded. void ShutdownLua( ); diff --git a/lua/lua.cpp b/lua/lua.cpp index b2fb7fa6..2f17aea5 100644 --- a/lua/lua.cpp +++ b/lua/lua.cpp @@ -1,5 +1,6 @@ #include #include +#include #include "Lua Interpreter.h" #include "lwstring.h" @@ -317,14 +318,35 @@ void InitializeLua( ) lua_setglobal( L, "Soldiers" ); } -void EvalLua (STR8 buff) { +int EvalLua (const wchar_t* buff) { int error; - error = luaL_loadbuffer(L, buff, strlen(buff), "line") || + int newlen; + STR8 newstr = NULL; + + // Since we get wide chars coming in, we need to convert to UTF8 + newlen = WideCharToMultiByte( CP_UTF8, 0, buff, -1, newstr, 0, NULL, NULL); + newstr = (STR8) MemAlloc( newlen); + WideCharToMultiByte( CP_UTF8, 0, buff, -1, newstr, newlen, NULL, NULL); + + error = luaL_loadbuffer(L, newstr, newlen-1, "line") || lua_pcall(L, 0, 0, 0); + + MemFree( newstr); + if (error) { - fprintf(stderr, "%s", lua_tostring(L, -1)); + const char *error = lua_tostring(L, -1); + int len = strlen( error); + if (len >= 7 && !strcmp( error + len - 7, "''")) + { + lua_pop(L, 1); /* pop error message from the stack */ + return FALSE; + } + cout << lua_tostring(L, -1) << endl; lua_pop(L, 1); /* pop error message from the stack */ + return TRUE; } + + return TRUE; } void ShutdownLua( ) {