mirror of
https://github.com/1dot13/source.git
synced 2026-07-29 13:52:17 +02:00
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
This commit is contained in:
+14
-6
@@ -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);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
+3
-1
@@ -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];
|
||||
|
||||
|
||||
@@ -38,11 +38,14 @@
|
||||
#include "zmouse.h"
|
||||
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#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
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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( );
|
||||
|
||||
|
||||
+25
-3
@@ -1,5 +1,6 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <iostream>
|
||||
#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, "'<eof>'"))
|
||||
{
|
||||
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( ) {
|
||||
|
||||
Reference in New Issue
Block a user