From 1adb40e0248f8b9c9f29390bdb3c8710882509b6 Mon Sep 17 00:00:00 2001 From: SoftCoder Date: Thu, 26 Dec 2013 23:39:17 -0800 Subject: [PATCH 1/7] - added export ignore directives to tell git which files to ignore on export - updated build script version # --- .gitattributes | 3 +++ mk/linux/mg-version.sh | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.gitattributes b/.gitattributes index a573c569..3cbdf410 100644 --- a/.gitattributes +++ b/.gitattributes @@ -27,3 +27,6 @@ *.xcf -text -diff *.blend -text -diff *.blend1 -text -diff +.gitattributes export-ignore +.gitignore export-ignore +.gitmodules export-ignore diff --git a/mk/linux/mg-version.sh b/mk/linux/mg-version.sh index 82e7b081..021829d4 100755 --- a/mk/linux/mg-version.sh +++ b/mk/linux/mg-version.sh @@ -4,9 +4,9 @@ # Written by Mark Vejvoda # Copyright (c) 2011 Mark Vejvoda under GNU GPL v3.0+ -OLD_MG_VERSION=3.7.1 -OLD_MG_VERSION_BINARY=3.7.1 -MG_VERSION=3.9.0 +OLD_MG_VERSION=3.9.0 +OLD_MG_VERSION_BINARY=3.9.0 +MG_VERSION=3.9.1-dev if [ "$1" = "--oldversion" ]; then echo "$OLD_MG_VERSION" From 7b7a5943595741a19bfc97fb3831bd9df8fbc29f Mon Sep 17 00:00:00 2001 From: SoftCoder Date: Fri, 27 Dec 2013 21:58:29 -0800 Subject: [PATCH 2/7] - updated some release scripts to use git instead of svn --- mk/linux/make-data-archive.sh | 53 ++++++++++++--- mk/linux/makedata-source.sh | 16 +++-- mk/linux/makedata.sh | 109 ++++++++++++++++++++++++------- mk/linux/makerelease-embedded.sh | 26 ++++++-- mk/linux/makerelease.sh | 96 +++++++++++++++++++-------- 5 files changed, 229 insertions(+), 71 deletions(-) diff --git a/mk/linux/make-data-archive.sh b/mk/linux/make-data-archive.sh index d1017284..bdbb713b 100755 --- a/mk/linux/make-data-archive.sh +++ b/mk/linux/make-data-archive.sh @@ -15,6 +15,7 @@ CURRENTDIR="$(dirname $(readlink -f $0))" #RELEASEDIR="$CURRENTDIR/release/$RELEASENAME-$VERSION/megaglest-$VERSION" RELEASEDIR="$CURRENTDIR/release/$RELEASENAME-$VERSION" PROJDIR="$CURRENTDIR/../../" +REPODIR="$CURRENTDIR/../../" echo "Creating data package in $RELEASEDIR" @@ -38,25 +39,56 @@ echo "copying data ..." #svn export --force "$CURRENTDIR/../../data/glest_game/glestkeys.ini" "$RELEASEDIR/glestkeys.ini" mkdir -p "$RELEASEDIR/data/" -svn export --force "$CURRENTDIR/../../data/glest_game/data" "$RELEASEDIR/data/" +cd "$RELEASEDIR/data/" +#svn export --force "$CURRENTDIR/../../data/glest_game/data" "$RELEASEDIR/data/" +git archive --remote ${REPODIR}/data/glest_game/ HEAD:data | tar x + +cd "$RELEASEDIR" mkdir -p "$RELEASEDIR/docs/" -svn export --force "$CURRENTDIR/../../data/glest_game/docs" "$RELEASEDIR/docs/" -svn export --force "$CURRENTDIR/../../docs/CHANGELOG.txt" "$RELEASEDIR/docs/CHANGELOG.txt" -svn export --force "$CURRENTDIR/../../docs/README.txt" "$RELEASEDIR/docs/README.txt" +cd "$RELEASEDIR/docs/" +#svn export --force "$CURRENTDIR/../../data/glest_game/docs" "$RELEASEDIR/docs/" +#svn export --force "$CURRENTDIR/../../docs/CHANGELOG.txt" "$RELEASEDIR/docs/CHANGELOG.txt" +#svn export --force "$CURRENTDIR/../../docs/README.txt" "$RELEASEDIR/docs/README.txt" +git archive --remote ${REPODIR}/data/glest_game/ HEAD:docs | tar x +git archive --remote ${REPODIR} HEAD:docs/ CHANGELOG.txt | tar x +git archive --remote ${REPODIR} HEAD:docs/ README.txt | tar x + +cd "$RELEASEDIR" mkdir -p "$RELEASEDIR/maps/" -svn export --force "$CURRENTDIR/../../data/glest_game/maps" "$RELEASEDIR/maps/" +cd "$RELEASEDIR/maps/" +#svn export --force "$CURRENTDIR/../../data/glest_game/maps" "$RELEASEDIR/maps/" +git archive --remote ${REPODIR}/data/glest_game/ HEAD:maps | tar x + +cd "$RELEASEDIR" mkdir -p "$RELEASEDIR/scenarios/" -svn export --force "$CURRENTDIR/../../data/glest_game/scenarios" "$RELEASEDIR/scenarios/" +cd "$RELEASEDIR/scenarios/" +#svn export --force "$CURRENTDIR/../../data/glest_game/scenarios" "$RELEASEDIR/scenarios/" +git archive --remote ${REPODIR}/data/glest_game/ HEAD:scenarios | tar x + +cd "$RELEASEDIR" mkdir -p "$RELEASEDIR/techs/" -svn export --force "$CURRENTDIR/../../data/glest_game/techs" "$RELEASEDIR/techs/" +cd "$RELEASEDIR/techs/" +#svn export --force "$CURRENTDIR/../../data/glest_game/techs" "$RELEASEDIR/techs/" +git archive --remote ${REPODIR}/data/glest_game/ HEAD:techs | tar x + +cd "$RELEASEDIR" mkdir -p "$RELEASEDIR/tilesets/" -svn export --force "$CURRENTDIR/../../data/glest_game/tilesets" "$RELEASEDIR/tilesets/" +cd "$RELEASEDIR/tilesets/" +#svn export --force "$CURRENTDIR/../../data/glest_game/tilesets" "$RELEASEDIR/tilesets/" +git archive --remote ${REPODIR}/data/glest_game/ HEAD:tilesets | tar x + +cd "$RELEASEDIR" mkdir -p "$RELEASEDIR/tutorials/" -svn export --force "$CURRENTDIR/../../data/glest_game/tutorials" "$RELEASEDIR/tutorials/" +cd "$RELEASEDIR/tutorials/" +#svn export --force "$CURRENTDIR/../../data/glest_game/tutorials" "$RELEASEDIR/tutorials/" +git archive --remote ${REPODIR}/data/glest_game/ HEAD:tutorials | tar x # special export for flag images +cd "$RELEASEDIR" mkdir -p "$RELEASEDIR/data/core/misc_textures/flags/" -svn export --force "$CURRENTDIR/../../source/masterserver/flags" "$RELEASEDIR/data/core/misc_textures/flags/" +cd "$RELEASEDIR/data/core/misc_textures/flags/" +# svn export --force "$CURRENTDIR/../../source/masterserver/flags" "$RELEASEDIR/data/core/misc_textures/flags/" +git archive --remote ${REPODIR}/source/masterserver/ HEAD:flags | tar x #svn export --force "$CURRENTDIR/../../data/glest_game/CMakeLists.txt" "$RELEASEDIR/CMakeLists.txt" @@ -65,6 +97,7 @@ svn export --force "$CURRENTDIR/../../source/masterserver/flags" "$RELEASEDIR/da #rm -rf "$RELEASEDIR/data/core/fonts" # END +cd "$CURRENTDIR" echo "creating data archive: $PACKAGE" [[ -f "$release/$PACKAGE" ]] && rm "release/$PACKAGE" #tar cJf "release/$PACKAGE" -C "$CURRENTDIR/release/" "$RELEASENAME-$VERSION" diff --git a/mk/linux/makedata-source.sh b/mk/linux/makedata-source.sh index 3f5b22c7..52a43032 100755 --- a/mk/linux/makedata-source.sh +++ b/mk/linux/makedata-source.sh @@ -14,6 +14,7 @@ PACKAGE="$RELEASENAME-$VERSION.tar.xz" CURRENTDIR="$(dirname $(readlink -f $0))" RELEASEDIR="$CURRENTDIR/release/$RELEASENAME-$VERSION/megaglest-$VERSION" SOURCEDIR="$CURRENTDIR/../../source/" +REPODIR="$CURRENTDIR/../../../git-data-source/" echo "Creating data package in $RELEASEDIR" @@ -22,17 +23,22 @@ mkdir -p "$RELEASEDIR" project_parent_dir="$(basename $(readlink -f -- "$(dirname -- "$0")/../../") )" # echo "$project_parent_dir" -if [[ $project_parent_dir == trunk* ]] ; +if [[ $project_parent_dir == git* ]] ; then - echo 'this is the trunk!' + echo 'This is the master branch' else - echo '*NOTE: This script currently only works on the trunk, aborting!' + echo '*NOTE: This script currently only works on the master HEAD, aborting!' exit fi -# copy data -svn export --force "$CURRENTDIR/../../../trunk-data-source" "$RELEASEDIR/data-source/" +# copy data +mkdir -p "$RELEASEDIR/data-source" +cd "$RELEASEDIR/data-source" +#svn export --force "$CURRENTDIR/../../../git-data-source" "$RELEASEDIR/data-source/" +git archive --remote ${REPODIR}/megaglest-data-source/ HEAD: | tar x + +cd "$CURRENTDIR" echo "creating $PACKAGE" [[ -f "$release/$PACKAGE" ]] && rm "release/$PACKAGE" #tar cJf "release/$PACKAGE" -C "$CURRENTDIR/release/" "$RELEASENAME-$VERSION" diff --git a/mk/linux/makedata.sh b/mk/linux/makedata.sh index 4727d3ab..bcb4707a 100755 --- a/mk/linux/makedata.sh +++ b/mk/linux/makedata.sh @@ -14,6 +14,7 @@ PACKAGE="$RELEASENAME-$VERSION.tar.xz" CURRENTDIR="$(dirname $(readlink -f $0))" RELEASEDIR="$CURRENTDIR/release/$RELEASENAME-$VERSION/megaglest-$VERSION" SOURCEDIR="$CURRENTDIR/../../source/" +REPODIR="$CURRENTDIR/../../" echo "Creating data package in $RELEASEDIR" @@ -21,43 +22,105 @@ echo "Creating data package in $RELEASEDIR" mkdir -p "$RELEASEDIR" # copy data -svn export --force "$CURRENTDIR/../../mk/linux/megaglest.bmp" "$RELEASEDIR/megaglest.bmp" -svn export --force "$CURRENTDIR/../../mk/linux/megaglest.desktop" "$RELEASEDIR/megaglest.desktop" -svn export --force "$CURRENTDIR/../../mk/linux/megaglest.png" "$RELEASEDIR/megaglest.png" -svn export --force "$CURRENTDIR/../../mk/linux/megaglest.xpm" "$RELEASEDIR/megaglest.xpm" -svn export --force "$CURRENTDIR/../../mk/linux/glest.ico" "$RELEASEDIR/glest.ico" -svn export --force "$CURRENTDIR/../../mk/linux/configuration.xml" "$RELEASEDIR/configuration.xml" -svn export --force "$CURRENTDIR/../../data/glest_game/megaglest.ico" "$RELEASEDIR/megaglest.ico" -svn export --force "$CURRENTDIR/../../data/glest_game/g3dviewer.ico" "$RELEASEDIR/g3dviewer.ico" -svn export --force "$CURRENTDIR/../../data/glest_game/editor.ico" "$RELEASEDIR/editor.ico" -svn export --force "$CURRENTDIR/../../data/glest_game/servers.ini" "$RELEASEDIR/servers.ini" -svn export --force "$CURRENTDIR/../../data/glest_game/glest.ini" "$RELEASEDIR/glest_windows.ini" -svn export --force "$CURRENTDIR/../../mk/linux/glest.ini" "$RELEASEDIR/glest_linux.ini" -svn export --force "$CURRENTDIR/../../data/glest_game/glestkeys.ini" "$RELEASEDIR/glestkeys.ini" +echo "Exporting image and ini files ..." +cd "$RELEASEDIR" +# svn export --force "$CURRENTDIR/../../mk/linux/megaglest.bmp" "$RELEASEDIR/megaglest.bmp" +# svn export --force "$CURRENTDIR/../../mk/linux/megaglest.desktop" "$RELEASEDIR/megaglest.desktop" +# svn export --force "$CURRENTDIR/../../mk/linux/megaglest.png" "$RELEASEDIR/megaglest.png" +# svn export --force "$CURRENTDIR/../../mk/linux/megaglest.xpm" "$RELEASEDIR/megaglest.xpm" +# svn export --force "$CURRENTDIR/../../mk/linux/glest.ico" "$RELEASEDIR/glest.ico" +# svn export --force "$CURRENTDIR/../../mk/linux/configuration.xml" "$RELEASEDIR/configuration.xml" +# svn export --force "$CURRENTDIR/../../data/glest_game/megaglest.ico" "$RELEASEDIR/megaglest.ico" +# svn export --force "$CURRENTDIR/../../data/glest_game/g3dviewer.ico" "$RELEASEDIR/g3dviewer.ico" +# svn export --force "$CURRENTDIR/../../data/glest_game/editor.ico" "$RELEASEDIR/editor.ico" +# svn export --force "$CURRENTDIR/../../data/glest_game/servers.ini" "$RELEASEDIR/servers.ini" +# svn export --force "$CURRENTDIR/../../data/glest_game/glest.ini" "$RELEASEDIR/glest_windows.ini" +# svn export --force "$CURRENTDIR/../../mk/linux/glest.ini" "$RELEASEDIR/glest_linux.ini" +# svn export --force "$CURRENTDIR/../../data/glest_game/glestkeys.ini" "$RELEASEDIR/glestkeys.ini" +git archive --remote ${REPODIR}/data/glest_game/ HEAD: CMakeLists.txt | tar x +git archive --remote ${REPODIR} HEAD:mk/linux/ megaglest.bmp | tar x +git archive --remote ${REPODIR} HEAD:mk/linux/ megaglest.desktop | tar x +git archive --remote ${REPODIR} HEAD:mk/linux/ megaglest.png | tar x +git archive --remote ${REPODIR} HEAD:mk/linux/ megaglest.xpm | tar x +git archive --remote ${REPODIR} HEAD:mk/linux/ glest.ico | tar x +git archive --remote ${REPODIR} HEAD:mk/linux/ glest.ini | tar x +mv glest.ini glest_linux.ini +git archive --remote ${REPODIR}/data/glest_game/ HEAD: megaglest.ico | tar x +git archive --remote ${REPODIR}/data/glest_game/ HEAD: g3dviewer.ico | tar x +git archive --remote ${REPODIR}/data/glest_game/ HEAD: editor.ico | tar x +git archive --remote ${REPODIR}/data/glest_game/ HEAD: servers.ini | tar x +git archive --remote ${REPODIR}/data/glest_game/ HEAD: glest.ini | tar x +git archive --remote ${REPODIR}/data/glest_game/ HEAD: glestkeys.ini | tar x +mv glest.ini glest_windows.ini + +echo "Exporting game data files ..." +cd "$RELEASEDIR" mkdir -p "$RELEASEDIR/data/" -svn export --force "$CURRENTDIR/../../data/glest_game/data" "$RELEASEDIR/data/" +cd "$RELEASEDIR/data/" +# svn export --force "$CURRENTDIR/../../data/glest_game/data" "$RELEASEDIR/data/" +git archive --remote ${REPODIR}/data/glest_game/ HEAD:data | tar x + +echo "Exporting doc files ..." +cd "$RELEASEDIR" mkdir -p "$RELEASEDIR/docs/" -svn export --force "$CURRENTDIR/../../data/glest_game/docs" "$RELEASEDIR/docs/" -svn export --force "$CURRENTDIR/../../docs/CHANGELOG.txt" "$RELEASEDIR/docs/CHANGELOG.txt" -svn export --force "$CURRENTDIR/../../docs/README.txt" "$RELEASEDIR/docs/README.txt" +cd "$RELEASEDIR/docs/" +#svn export --force "$CURRENTDIR/../../data/glest_game/docs" "$RELEASEDIR/docs/" +git archive --remote ${REPODIR}/data/glest_game/ HEAD:docs | tar x + +cd "$RELEASEDIR/docs/" +#svn export --force "$CURRENTDIR/../../docs/CHANGELOG.txt" "$RELEASEDIR/docs/CHANGELOG.txt" +git archive --remote ${REPODIR} HEAD:docs/ CHANGELOG.txt | tar x + +cd "$RELEASEDIR/docs/" +#svn export --force "$CURRENTDIR/../../docs/README.txt" "$RELEASEDIR/docs/README.txt" +git archive --remote ${REPODIR} HEAD:docs/ README.txt | tar x + +echo "Exporting map files ..." +cd "$RELEASEDIR" mkdir -p "$RELEASEDIR/maps/" -svn export --force "$CURRENTDIR/../../data/glest_game/maps" "$RELEASEDIR/maps/" +cd "$RELEASEDIR/maps/" +#svn export --force "$CURRENTDIR/../../data/glest_game/maps" "$RELEASEDIR/maps/" +git archive --remote ${REPODIR}/data/glest_game/ HEAD:maps | tar x + +echo "Exporting scenario files ..." +cd "$RELEASEDIR" mkdir -p "$RELEASEDIR/scenarios/" -svn export --force "$CURRENTDIR/../../data/glest_game/scenarios" "$RELEASEDIR/scenarios/" +cd "$RELEASEDIR/scenarios/" +#svn export --force "$CURRENTDIR/../../data/glest_game/scenarios" "$RELEASEDIR/scenarios/" +git archive --remote ${REPODIR}/data/glest_game/ HEAD:scenarios | tar x + +echo "Exporting tech files ..." +cd "$RELEASEDIR" mkdir -p "$RELEASEDIR/techs/" -svn export --force "$CURRENTDIR/../../data/glest_game/techs" "$RELEASEDIR/techs/" +cd "$RELEASEDIR/techs/" +#svn export --force "$CURRENTDIR/../../data/glest_game/techs" "$RELEASEDIR/techs/" +git archive --remote ${REPODIR}/data/glest_game/ HEAD:techs | tar x + +echo "Exporting tileset files ..." +cd "$RELEASEDIR" mkdir -p "$RELEASEDIR/tilesets/" -svn export --force "$CURRENTDIR/../../data/glest_game/tilesets" "$RELEASEDIR/tilesets/" +cd "$RELEASEDIR/tilesets/" +#svn export --force "$CURRENTDIR/../../data/glest_game/tilesets" "$RELEASEDIR/tilesets/" +git archive --remote ${REPODIR}/data/glest_game/ HEAD:tilesets | tar x + +echo "Exporting tutorial files ..." +cd "$RELEASEDIR" mkdir -p "$RELEASEDIR/tutorials/" -svn export --force "$CURRENTDIR/../../data/glest_game/tutorials" "$RELEASEDIR/tutorials/" +cd "$RELEASEDIR/tutorials/" +# svn export --force "$CURRENTDIR/../../data/glest_game/tutorials" "$RELEASEDIR/tutorials/" +git archive --remote ${REPODIR}/data/glest_game/ HEAD:tutorials | tar x # special export for flag images # mkdir -p "$RELEASEDIR/data/core/misc_textures/flags/" # svn export --force "$CURRENTDIR/../../source/masterserver/flags" "$RELEASEDIR/data/core/misc_textures/flags/" -svn export --force "$CURRENTDIR/../../data/glest_game/CMakeLists.txt" "$RELEASEDIR/CMakeLists.txt" +# cd "$RELEASEDIR" +#svn export --force "$CURRENTDIR/../../data/glest_game/CMakeLists.txt" "$RELEASEDIR/CMakeLists.txt" +# git archive --remote ${REPODIR}/data/glest_game/ HEAD: CMakeLists.txt | tar x +echo "Removing non required files ..." +cd "$CURRENTDIR" # START # remove embedded data rm -rf "$RELEASEDIR/data/core/fonts" diff --git a/mk/linux/makerelease-embedded.sh b/mk/linux/makerelease-embedded.sh index 5ea3a7ad..b027cc7b 100755 --- a/mk/linux/makerelease-embedded.sh +++ b/mk/linux/makerelease-embedded.sh @@ -11,6 +11,7 @@ PACKAGE="$RELEASENAME-$VERSION.tar.xz" CURRENTDIR="$(dirname $(readlink -f $0))" RELEASEDIR="$CURRENTDIR/release/$RELEASENAME-$VERSION/megaglest-$VERSION" SOURCEDIR="$CURRENTDIR/../../source/" +REPODIR="$CURRENTDIR/../../" echo "Creating source package in $RELEASEDIR" @@ -19,13 +20,21 @@ mkdir -p "$RELEASEDIR" mkdir -p "$RELEASEDIR/source/shared_lib/sources/libircclient/" mkdir -p "$RELEASEDIR/source/shared_lib/include/libircclient/" -svn export --force "$SOURCEDIR/shared_lib/sources/libircclient" "$RELEASEDIR/source/shared_lib/sources/libircclient" -svn export --force "$SOURCEDIR/shared_lib/include/libircclient" "$RELEASEDIR/source/shared_lib/include/libircclient" +cd "$RELEASEDIR/source/shared_lib/sources/libircclient/" +#svn export --force "$SOURCEDIR/shared_lib/sources/libircclient" "$RELEASEDIR/source/shared_lib/sources/libircclient" +git archive --remote ${REPODIR} HEAD:source/shared_lib/sources/libircclient | tar x +cd "$RELEASEDIR/source/shared_lib/include/libircclient/" +#svn export --force "$SOURCEDIR/shared_lib/include/libircclient" "$RELEASEDIR/source/shared_lib/include/libircclient" +git archive --remote ${REPODIR} HEAD:source/shared_lib/include/libircclient | tar x mkdir -p "$RELEASEDIR/source/shared_lib/sources/platform/miniupnpc/" mkdir -p "$RELEASEDIR/source/shared_lib/include/platform/miniupnpc/" -svn export --force "$SOURCEDIR/shared_lib/sources/platform/miniupnpc" "$RELEASEDIR/source/shared_lib/sources/platform/miniupnpc" -svn export --force "$SOURCEDIR/shared_lib/include/platform/miniupnpc" "$RELEASEDIR/source/shared_lib/include/platform/miniupnpc" +cd "$RELEASEDIR/source/shared_lib/sources/platform/miniupnpc/" +#svn export --force "$SOURCEDIR/shared_lib/sources/platform/miniupnpc" "$RELEASEDIR/source/shared_lib/sources/platform/miniupnpc" +git archive --remote ${REPODIR} HEAD:source/shared_lib/sources/platform/miniupnpc | tar x +cd "$RELEASEDIR/source/shared_lib/include/platform/miniupnpc/" +#svn export --force "$SOURCEDIR/shared_lib/include/platform/miniupnpc" "$RELEASEDIR/source/shared_lib/include/platform/miniupnpc" +git archive --remote ${REPODIR} HEAD:source/shared_lib/include/platform/miniupnpc | tar x #mkdir -p "$RELEASEDIR/source/shared_lib/sources/streflop/" #mkdir -p "$RELEASEDIR/source/shared_lib/include/streflop/" @@ -33,11 +42,16 @@ svn export --force "$SOURCEDIR/shared_lib/include/platform/miniupnpc" "$RELEASED #svn export --force "$SOURCEDIR/shared_lib/include/streflop" "$RELEASEDIR/source/shared_lib/include/streflop" mkdir -p "$RELEASEDIR/source/masterserver/flags/" -svn export --force "$SOURCEDIR/masterserver/flags" "$RELEASEDIR/source/masterserver/flags" +cd "$RELEASEDIR/source/masterserver/flags/" +#svn export --force "$SOURCEDIR/masterserver/flags" "$RELEASEDIR/source/masterserver/flags" +git archive --remote ${REPODIR} HEAD:source/masterserver/flags | tar x mkdir -p "$RELEASEDIR/data/core/fonts/" -svn export --force "$SOURCEDIR/../data/glest_game/data/core/fonts" "$RELEASEDIR/data/core/fonts" +cd "$RELEASEDIR/data/core/fonts/" +#svn export --force "$SOURCEDIR/../data/glest_game/data/core/fonts" "$RELEASEDIR/data/core/fonts" +git archive --remote ${REPODIR}/data/glest_game/ HEAD:data/core/fonts | tar x +cd "$CURRENTDIR" echo "Creating $PACKAGE" [[ -f "$release/$PACKAGE" ]] && rm "release/$PACKAGE" tar cJf "release/$PACKAGE" -C "$CURRENTDIR/release/$RELEASENAME-$VERSION" "megaglest-$VERSION" diff --git a/mk/linux/makerelease.sh b/mk/linux/makerelease.sh index f617c227..9a0e7b7b 100755 --- a/mk/linux/makerelease.sh +++ b/mk/linux/makerelease.sh @@ -10,49 +10,90 @@ PACKAGE="$RELEASENAME-$VERSION.tar.xz" CURRENTDIR="$(dirname $(readlink -f $0))" RELEASEDIR="$CURRENTDIR/release/$RELEASENAME-$VERSION/megaglest-$VERSION" SOURCEDIR="$CURRENTDIR/../../source/" +REPODIR="$CURRENTDIR/../../" -echo "Creating source package in $RELEASEDIR" +echo "Creating source package in: ${RELEASEDIR} git REPO is in: ${REPODIR}" +# exit 1 [[ -d "$RELEASEDIR" ]] && rm -rf "$RELEASEDIR" mkdir -p "$RELEASEDIR" -svn export --force "$SOURCEDIR" "$RELEASEDIR/source" +echo "Exporting source ..." +# svn export --force "$SOURCEDIR" "$RELEASEDIR/source" +cd "$RELEASEDIR" +mkdir source +cd source +git archive --remote ${REPODIR} HEAD:source | tar x +cd "$RELEASEDIR" -mkdir -p "$RELEASEDIR/mk/cmake/" -svn export --force "$CURRENTDIR/../cmake/" "$RELEASEDIR/mk/cmake/" -mkdir -p "$RELEASEDIR/mk/macosx/" -svn export --force "$CURRENTDIR/../macosx/" "$RELEASEDIR/mk/macosx/" -mkdir -p "$RELEASEDIR/mk/windoze/" -svn export --force "$CURRENTDIR/../windoze/" "$RELEASEDIR/mk/windoze/" +echo "Exporting mk ..." +# mkdir -p "$RELEASEDIR/mk/cmake/" +# svn export --force "$CURRENTDIR/../cmake/" "$RELEASEDIR/mk/cmake/" +# mkdir -p "$RELEASEDIR/mk/macosx/" +# svn export --force "$CURRENTDIR/../macosx/" "$RELEASEDIR/mk/macosx/" +# mkdir -p "$RELEASEDIR/mk/windoze/" +# svn export --force "$CURRENTDIR/../windoze/" "$RELEASEDIR/mk/windoze/" +mkdir -p mk +cd mk +git archive --remote ${REPODIR} HEAD:mk | tar x +cd "$RELEASEDIR" -svn export --force "$CURRENTDIR/../../docs" $RELEASEDIR +echo "Exporting docs ..." +# svn export --force "$CURRENTDIR/../../docs" $RELEASEDIR +mkdir docs +cd docs +git archive --remote ${REPODIR} HEAD:docs | tar x +cd "$RELEASEDIR" -svn export --force "$CURRENTDIR/glest.ini" $RELEASEDIR/glest.ini -svn export --force "$CURRENTDIR/glestkeys.ini" $RELEASEDIR/glestkeys.ini -svn export --force "$CURRENTDIR/servers.ini" $RELEASEDIR/servers.ini -svn export --force "$CURRENTDIR/glest.ico" $RELEASEDIR/glest.ico -svn export --force "$CURRENTDIR/megaglest.bmp" $RELEASEDIR/megaglest.bmp -svn export --force "$CURRENTDIR/megaglest.png" $RELEASEDIR/megaglest.png -svn export --force "$CURRENTDIR/megaglest.xpm" $RELEASEDIR/megaglest.xpm -svn export --force "$CURRENTDIR/megaglest.desktop" $RELEASEDIR/megaglest.desktop -svn export --force "$CURRENTDIR/megaglest_editor.desktop" $RELEASEDIR/megaglest_editor.desktop -svn export --force "$CURRENTDIR/megaglest_g3dviewer.desktop" $RELEASEDIR/megaglest_g3dviewer.desktop +echo "Exporting files in mk/linux ..." +# svn export --force "$CURRENTDIR/glest.ini" $RELEASEDIR/glest.ini +# svn export --force "$CURRENTDIR/glestkeys.ini" $RELEASEDIR/glestkeys.ini +# svn export --force "$CURRENTDIR/servers.ini" $RELEASEDIR/servers.ini +# svn export --force "$CURRENTDIR/glest.ico" $RELEASEDIR/glest.ico +# svn export --force "$CURRENTDIR/megaglest.bmp" $RELEASEDIR/megaglest.bmp +# svn export --force "$CURRENTDIR/megaglest.png" $RELEASEDIR/megaglest.png +# svn export --force "$CURRENTDIR/megaglest.xpm" $RELEASEDIR/megaglest.xpm +# svn export --force "$CURRENTDIR/megaglest.desktop" $RELEASEDIR/megaglest.desktop +# svn export --force "$CURRENTDIR/megaglest_editor.desktop" $RELEASEDIR/megaglest_editor.desktop +# svn export --force "$CURRENTDIR/megaglest_g3dviewer.desktop" $RELEASEDIR/megaglest_g3dviewer.desktop +git archive --remote ${REPODIR} HEAD:mk/linux/ glest.ini | tar x +git archive --remote ${REPODIR} HEAD:mk/linux/ glestkeys.ini | tar x +git archive --remote ${REPODIR} HEAD:mk/linux/ servers.ini | tar x +git archive --remote ${REPODIR} HEAD:mk/linux/ glest.ico | tar x +git archive --remote ${REPODIR} HEAD:mk/linux/ megaglest.bmp | tar x +git archive --remote ${REPODIR} HEAD:mk/linux/ megaglest.png | tar x +git archive --remote ${REPODIR} HEAD:mk/linux/ megaglest.xpm | tar x +git archive --remote ${REPODIR} HEAD:mk/linux/ megaglest.desktop | tar x +git archive --remote ${REPODIR} HEAD:mk/linux/ megaglest_editor.desktop | tar x +git archive --remote ${REPODIR} HEAD:mk/linux/ megaglest_g3dviewer.desktop | tar x # The mnpages are auto generated by the build process so no need to ship with source # svn export --force "$CURRENTDIR/megaglest.6" $RELEASEDIR/megaglest.6 # svn export --force "$CURRENTDIR/megaglest_editor.6" $RELEASEDIR/megaglest_editor.6 # svn export --force "$CURRENTDIR/megaglest_g3dviewer.6" $RELEASEDIR/megaglest_g3dviewer.6 -svn export --force "$CURRENTDIR/../../data/glest_game/megaglest.ico" $RELEASEDIR/megaglest.ico -svn export --force "$CURRENTDIR/../../data/glest_game/g3dviewer.ico" $RELEASEDIR/g3dviewer.ico -svn export --force "$CURRENTDIR/../../data/glest_game/editor.ico" $RELEASEDIR/editor.ico -svn export --force "$CURRENTDIR/start_megaglest" $RELEASEDIR/start_megaglest -svn export --force "$CURRENTDIR/start_megaglest_g3dviewer" $RELEASEDIR/start_megaglest_g3dviewer -svn export --force "$CURRENTDIR/start_megaglest_mapeditor" $RELEASEDIR/start_megaglest_mapeditor -svn export --force "$CURRENTDIR/setupBuildDeps.sh" $RELEASEDIR/setupBuildDeps.sh -svn export --force "$CURRENTDIR/../../CMakeLists.txt" $RELEASEDIR/CMakeLists.txt +echo "Exporting files in data/glest_game ..." +# svn export --force "$CURRENTDIR/../../data/glest_game/megaglest.ico" $RELEASEDIR/megaglest.ico +# svn export --force "$CURRENTDIR/../../data/glest_game/g3dviewer.ico" $RELEASEDIR/g3dviewer.ico +# svn export --force "$CURRENTDIR/../../data/glest_game/editor.ico" $RELEASEDIR/editor.ico +# svn export --force "$CURRENTDIR/start_megaglest" $RELEASEDIR/start_megaglest +# svn export --force "$CURRENTDIR/start_megaglest_g3dviewer" $RELEASEDIR/start_megaglest_g3dviewer +# svn export --force "$CURRENTDIR/start_megaglest_mapeditor" $RELEASEDIR/start_megaglest_mapeditor +# svn export --force "$CURRENTDIR/setupBuildDeps.sh" $RELEASEDIR/setupBuildDeps.sh +# svn export --force "$CURRENTDIR/../../CMakeLists.txt" $RELEASEDIR/CMakeLists.txt +git archive --remote ${REPODIR}/data/glest_game/ HEAD: megaglest.ico | tar x +git archive --remote ${REPODIR}/data/glest_game/ HEAD: g3dviewer.ico | tar x +git archive --remote ${REPODIR}/data/glest_game/ HEAD: editor.ico | tar x +git archive --remote ${REPODIR} HEAD:mk/linux/ start_megaglest | tar x +git archive --remote ${REPODIR} HEAD:mk/linux/ start_megaglest_g3dviewer | tar x +git archive --remote ${REPODIR} HEAD:mk/linux/ start_megaglest_mapeditor | tar x +git archive --remote ${REPODIR} HEAD:mk/linux/ setupBuildDeps.sh | tar x +git archive --remote ${REPODIR} HEAD: CMakeLists.txt | tar x + +# exit 1 # START +echo "Removing non required files ..." # remove embedded library code as that will be packaged in a seperate archive rm -rf "$RELEASEDIR/source/shared_lib/sources/libircclient/" rm -rf "$RELEASEDIR/source/shared_lib/include/libircclient/" @@ -63,6 +104,7 @@ rm -rf "$RELEASEDIR/source/shared_lib/include/platform/miniupnpc/" rm -rf "$RELEASEDIR/source/masterserver/flags/" # END +cd ${CURRENTDIR} echo "Creating $PACKAGE" [[ -f "$release/$PACKAGE" ]] && rm "release/$PACKAGE" tar cJf "release/$PACKAGE" -C "$CURRENTDIR/release/$RELEASENAME-$VERSION" "megaglest-$VERSION" From 62821793c070f287e55152cba144ceeb40ea9031 Mon Sep 17 00:00:00 2001 From: SoftCoder Date: Fri, 27 Dec 2013 22:00:29 -0800 Subject: [PATCH 3/7] - moved core game data asset loading into lazy load methods to try to improve the startup speed of megaglest. --- source/glest_game/global/core_data.cpp | 1029 +++++++++-------- source/glest_game/global/core_data.h | 102 +- source/glest_game/graphics/renderer.cpp | 2 +- source/glest_game/main/program.cpp | 2 +- .../sources/graphics/gl/texture_gl.cpp | 4 +- 5 files changed, 611 insertions(+), 528 deletions(-) diff --git a/source/glest_game/global/core_data.cpp b/source/glest_game/global/core_data.cpp index e3fb222d..f4ba4015 100644 --- a/source/glest_game/global/core_data.cpp +++ b/source/glest_game/global/core_data.cpp @@ -193,509 +193,585 @@ void CoreData::cleanupTexture(Texture2D **texture) { *texture=NULL; } -void CoreData::loadTextures(string data_path) { - Renderer &renderer= Renderer::getInstance(); +void CoreData::loadTextureIfRequired(Texture2D **tex,string data_path, + string uniqueFilePath, int texSystemId, + bool setMipMap, bool setAlpha, + bool loadUniqueFilePath, bool compressionDisabled) { + if(*tex == NULL) { + bool attemptToLoadTexture = (texSystemId == tsyst_NONE); + if(attemptToLoadTexture == false && + itemLoadAttempted.find(texSystemId) == itemLoadAttempted.end()) { - //textures - backgroundTexture = renderer.newTexture2D(rsGlobal); - if (backgroundTexture) { - backgroundTexture->setMipmap(false); - try { - backgroundTexture->getPixmap()->load( - getGameCustomCoreDataPath(data_path, - CORE_MENU_TEXTURES_PATH + "back.tga")); - backgroundTexture->setTextureSystemId(tsyst_backgroundTexture); - } catch (const megaglest_runtime_error& ex) { - message(ex.what(), - GlobalStaticFlags::getIsNonGraphicalModeEnabled(), - tempDataLocation); - cleanupTexture (&backgroundTexture); + attemptToLoadTexture = true; + itemLoadAttempted[texSystemId] = true; } - } - fireTexture = renderer.newTexture2D(rsGlobal); - if (fireTexture) { - fireTexture->setFormat(Texture::fAlpha); - fireTexture->getPixmap()->init(1); - try { - fireTexture->getPixmap()->load( - getGameCustomCoreDataPath(data_path, - CORE_MISC_TEXTURES_PATH + "fire_particle.tga")); - fireTexture->setTextureSystemId(tsyst_fireTexture); - } catch (const megaglest_runtime_error& ex) { - message(ex.what(), - GlobalStaticFlags::getIsNonGraphicalModeEnabled(), - tempDataLocation); - cleanupTexture (&fireTexture); - } - } - teamColorTexture = renderer.newTexture2D(rsGlobal); - if (teamColorTexture) { - teamColorTexture->setFormat(Texture::fAlpha); - teamColorTexture->getPixmap()->init(1); - try { - teamColorTexture->getPixmap()->load( - getGameCustomCoreDataPath(data_path, - CORE_MISC_TEXTURES_PATH - + "team_color_texture.tga")); - teamColorTexture->setTextureSystemId(tsyst_teamColorTexture); - } catch (const megaglest_runtime_error& ex) { - message(ex.what(), - GlobalStaticFlags::getIsNonGraphicalModeEnabled(), - tempDataLocation); - cleanupTexture (&teamColorTexture); - } - } - snowTexture = renderer.newTexture2D(rsGlobal); - if (snowTexture) { - snowTexture->setMipmap(false); - snowTexture->setFormat(Texture::fAlpha); - snowTexture->getPixmap()->init(1); - try { - snowTexture->getPixmap()->load( - getGameCustomCoreDataPath(data_path, - CORE_MISC_TEXTURES_PATH + "snow_particle.tga")); - snowTexture->setTextureSystemId(tsyst_snowTexture); - } catch (const megaglest_runtime_error& ex) { - message(ex.what(), - GlobalStaticFlags::getIsNonGraphicalModeEnabled(), - tempDataLocation); - cleanupTexture (&snowTexture); - } - } - statusReadyTexture = renderer.newTexture2D(rsGlobal); - if (statusReadyTexture) { - try { - statusReadyTexture->getPixmap()->load( - getGameCustomCoreDataPath(data_path, - CORE_MENU_TEXTURES_PATH + "status_ready.png")); - statusReadyTexture->setTextureSystemId(tsyst_statusReadyTexture); - } catch (const megaglest_runtime_error& ex) { - message(ex.what(), - GlobalStaticFlags::getIsNonGraphicalModeEnabled(), - tempDataLocation); - cleanupTexture (&statusReadyTexture); - } - } - statusNotReadyTexture = renderer.newTexture2D(rsGlobal); - if (statusNotReadyTexture) { - try { - statusNotReadyTexture->getPixmap()->load( - getGameCustomCoreDataPath(data_path, - CORE_MENU_TEXTURES_PATH + "status_notready.png")); - statusNotReadyTexture->setTextureSystemId( - tsyst_statusNotReadyTexture); - } catch (const megaglest_runtime_error& ex) { - message(ex.what(), - GlobalStaticFlags::getIsNonGraphicalModeEnabled(), - tempDataLocation); - cleanupTexture (&statusNotReadyTexture); - } - } - statusBRBTexture = renderer.newTexture2D(rsGlobal); - if (statusBRBTexture) { - try { - statusBRBTexture->getPixmap()->load( - getGameCustomCoreDataPath(data_path, - CORE_MENU_TEXTURES_PATH + "status_brb.png")); - statusBRBTexture->setTextureSystemId(tsyst_statusBRBTexture); - } catch (const megaglest_runtime_error& ex) { - message(ex.what(), - GlobalStaticFlags::getIsNonGraphicalModeEnabled(), - tempDataLocation); - cleanupTexture (&statusBRBTexture); - } - } - customTexture = renderer.newTexture2D(rsGlobal); - if (customTexture) { - try { - customTexture->getPixmap()->load( - getGameCustomCoreDataPath(data_path, - CORE_MENU_TEXTURES_PATH + "custom_texture.tga")); - customTexture->setTextureSystemId(tsyst_customTexture); - } catch (const megaglest_runtime_error& ex) { - message(ex.what(), - GlobalStaticFlags::getIsNonGraphicalModeEnabled(), - tempDataLocation); - cleanupTexture (&customTexture); - } - } - notOnServerTexture = renderer.newTexture2D(rsGlobal); - if (notOnServerTexture) { - try { - notOnServerTexture->getPixmap()->load( - getGameCustomCoreDataPath(data_path, - CORE_MENU_TEXTURES_PATH + "not_on_server.tga")); - notOnServerTexture->setTextureSystemId(tsyst_notOnServerTexture); - } catch (const megaglest_runtime_error& ex) { - message(ex.what(), - GlobalStaticFlags::getIsNonGraphicalModeEnabled(), - tempDataLocation); - cleanupTexture (¬OnServerTexture); - } - } - onServerDifferentTexture = renderer.newTexture2D(rsGlobal); - if (onServerDifferentTexture) { - try { - onServerDifferentTexture->getPixmap()->load( - getGameCustomCoreDataPath(data_path, - CORE_MENU_TEXTURES_PATH - + "on_server_different.tga")); - onServerDifferentTexture->setTextureSystemId( - tsyst_onServerDifferentTexture); - } catch (const megaglest_runtime_error& ex) { - message(ex.what(), - GlobalStaticFlags::getIsNonGraphicalModeEnabled(), - tempDataLocation); - cleanupTexture (&onServerDifferentTexture); - } - onServerTexture = renderer.newTexture2D(rsGlobal); - try { - onServerTexture->getPixmap()->load( - getGameCustomCoreDataPath(data_path, - CORE_MENU_TEXTURES_PATH + "on_server.tga")); - onServerTexture->setTextureSystemId(tsyst_onServerTexture); - } catch (const megaglest_runtime_error& ex) { - message(ex.what(), - GlobalStaticFlags::getIsNonGraphicalModeEnabled(), - tempDataLocation); - cleanupTexture (&onServerTexture); - } - onServerInstalledTexture = renderer.newTexture2D(rsGlobal); - try { - onServerInstalledTexture->getPixmap()->load( - getGameCustomCoreDataPath(data_path, - CORE_MENU_TEXTURES_PATH - + "on_server_installed.tga")); - onServerInstalledTexture->setTextureSystemId( - tsyst_onServerInstalledTexture); - } catch (const megaglest_runtime_error& ex) { - message(ex.what(), - GlobalStaticFlags::getIsNonGraphicalModeEnabled(), - tempDataLocation); - cleanupTexture (&onServerInstalledTexture); - } - } - logoTexture = renderer.newTexture2D(rsGlobal); - if (logoTexture) { - logoTexture->setMipmap(false); - try { - logoTexture->getPixmap()->load( - getGameCustomCoreDataPath(data_path, - CORE_MENU_TEXTURES_PATH + "logo.tga")); - logoTexture->setTextureSystemId(tsyst_logoTexture); - } catch (const megaglest_runtime_error& ex) { - message(ex.what(), - GlobalStaticFlags::getIsNonGraphicalModeEnabled(), - tempDataLocation); - cleanupTexture (&logoTexture); - } - } - logoTextureList.clear(); - string logosPath = getGameCustomCoreDataPath(data_path, "") - + CORE_MENU_TEXTURES_PATH + "logo*.*"; - vector logoFilenames; - findAll(logosPath, logoFilenames, false, false); - for (int i = 0; i < (int)logoFilenames.size(); ++i) { - string logo = logoFilenames[i]; - if (strcmp("logo.tga", logo.c_str()) != 0) { - Texture2D* logoTextureExtra = renderer.newTexture2D(rsGlobal); - if (logoTextureExtra) { - logoTextureExtra->setMipmap(true); - try { - logoTextureExtra->getPixmap()->load( - getGameCustomCoreDataPath(data_path, "") - + CORE_MENU_TEXTURES_PATH + logo); - logoTextureList.push_back(logoTextureExtra); - } catch (const megaglest_runtime_error& ex) { - message(ex.what(), - GlobalStaticFlags::getIsNonGraphicalModeEnabled(), - tempDataLocation); - cleanupTexture(&logoTextureExtra); + + Renderer &renderer = Renderer::getInstance(); + *tex = renderer.newTexture2D(rsGlobal); + if (*tex) { + + (*tex)->setForceCompressionDisabled(compressionDisabled); + (*tex)->setMipmap(setMipMap); + if(setAlpha == true) { + + (*tex)->setFormat(Texture::fAlpha); + (*tex)->getPixmap()->init(1); + } + + try { + string fileToLoad = uniqueFilePath; + if(loadUniqueFilePath == false) { + + fileToLoad = getGameCustomCoreDataPath(data_path,uniqueFilePath); } + (*tex)->getPixmap()->load(fileToLoad); + (*tex)->setTextureSystemId(texSystemId); + + renderer.initTexture(rsGlobal,*tex); + } + catch (const megaglest_runtime_error& ex) { + message(ex.what(),GlobalStaticFlags::getIsNonGraphicalModeEnabled(), + tempDataLocation); + cleanupTexture (tex); } } } - if (logoTextureList.empty() == true) { - logosPath = data_path + CORE_MENU_TEXTURES_PATH + "logo*.*"; +} + +string CoreData::getDataPath() { + string data_path = getGameReadWritePath(GameConstants::path_data_CacheLookupKey); + if(data_path != "") { + endPathWithSlash(data_path); + } + return data_path; +} + +Texture2D * CoreData::getBackgroundTexture() { + string data_path = getDataPath(); + loadTextureIfRequired(&backgroundTexture, getDataPath(), + CORE_MENU_TEXTURES_PATH + "back.tga", tsyst_backgroundTexture, + false, false, false); + + return backgroundTexture; +} +Texture2D *CoreData::getFireTexture() { + string data_path = getDataPath(); + loadTextureIfRequired(&fireTexture,data_path, + CORE_MISC_TEXTURES_PATH + "fire_particle.tga", tsyst_fireTexture, + true, true, false); + + return fireTexture; +} +Texture2D *CoreData::getTeamColorTexture() { + string data_path = getDataPath(); + loadTextureIfRequired(&teamColorTexture,data_path, + CORE_MISC_TEXTURES_PATH + "team_color_texture.tga", tsyst_teamColorTexture, + true, true, false); + + return teamColorTexture; +} +Texture2D *CoreData::getSnowTexture() { + string data_path = getDataPath(); + loadTextureIfRequired(&snowTexture,data_path, + CORE_MISC_TEXTURES_PATH + "snow_particle.tga", tsyst_snowTexture, + false, true, false); + + return snowTexture; +} +Texture2D *CoreData::getLogoTexture() { + string data_path = getDataPath(); + loadTextureIfRequired(&logoTexture,data_path, + CORE_MENU_TEXTURES_PATH + "logo.tga", tsyst_logoTexture, + false, false, false); + + return logoTexture; +} +Texture2D *CoreData::getWaterSplashTexture() { + string data_path = getDataPath(); + loadTextureIfRequired(&waterSplashTexture,data_path, + CORE_MISC_TEXTURES_PATH + "water_splash.tga", tsyst_waterSplashTexture, + true, true, false); + + return waterSplashTexture; +} +Texture2D *CoreData::getCustomTexture() { + string data_path = getDataPath(); + loadTextureIfRequired(&customTexture,data_path, + CORE_MENU_TEXTURES_PATH + "custom_texture.tga", tsyst_customTexture, + true, false, false); + + return customTexture; +} +Texture2D *CoreData::getButtonSmallTexture() { + string data_path = getDataPath(); + loadTextureIfRequired(&buttonSmallTexture,data_path, + CORE_MENU_TEXTURES_PATH + "button_small.tga", tsyst_buttonSmallTexture, + true, false, false, true); + + return buttonSmallTexture; +} +Texture2D *CoreData::getButtonBigTexture() { + string data_path = getDataPath(); + loadTextureIfRequired(&buttonBigTexture,data_path, + CORE_MENU_TEXTURES_PATH + "button_big.tga", tsyst_buttonBigTexture, + true, false, false, true); + + return buttonBigTexture; +} +Texture2D *CoreData::getHorizontalLineTexture() { + string data_path = getDataPath(); + loadTextureIfRequired(&horizontalLineTexture,data_path, + CORE_MENU_TEXTURES_PATH + "line_horizontal.tga", tsyst_horizontalLineTexture, + true, false, false, true); + + return horizontalLineTexture; +} +Texture2D *CoreData::getVerticalLineTexture() { + string data_path = getDataPath(); + loadTextureIfRequired(&verticalLineTexture,data_path, + CORE_MENU_TEXTURES_PATH + "line_vertical.tga", tsyst_verticalLineTexture, + true, false, false, true); + + return verticalLineTexture; +} +Texture2D *CoreData::getCheckBoxTexture() { + string data_path = getDataPath(); + loadTextureIfRequired(&checkBoxTexture,data_path, + CORE_MENU_TEXTURES_PATH + "checkbox.tga", tsyst_checkBoxTexture, + true, false, false, true); + + return checkBoxTexture; +} +Texture2D *CoreData::getCheckedCheckBoxTexture() { + string data_path = getDataPath(); + loadTextureIfRequired(&checkedCheckBoxTexture,data_path, + CORE_MENU_TEXTURES_PATH + "checkbox_checked.tga", tsyst_checkedCheckBoxTexture, + true, false, false, true); + + return checkedCheckBoxTexture; +} +Texture2D *CoreData::getNotOnServerTexture() { + string data_path = getDataPath(); + loadTextureIfRequired(¬OnServerTexture,data_path, + CORE_MENU_TEXTURES_PATH + "not_on_server.tga", tsyst_notOnServerTexture, + true, false, false); + + return notOnServerTexture; +} +Texture2D *CoreData::getOnServerDifferentTexture() { + string data_path = getDataPath(); + loadTextureIfRequired(&onServerDifferentTexture,data_path, + CORE_MENU_TEXTURES_PATH + "on_server_different.tga", tsyst_onServerDifferentTexture, + true, false, false); + + return onServerDifferentTexture; +} +Texture2D *CoreData::getOnServerTexture() { + string data_path = getDataPath(); + loadTextureIfRequired(&onServerTexture,data_path, + CORE_MENU_TEXTURES_PATH + "on_server.tga", tsyst_onServerTexture, + true, false, false); + + return onServerTexture; +} +Texture2D *CoreData::getOnServerInstalledTexture() { + string data_path = getDataPath(); + loadTextureIfRequired(&onServerInstalledTexture,data_path, + CORE_MENU_TEXTURES_PATH + "on_server_installed.tga", tsyst_onServerInstalledTexture, + true, false, false); + + return onServerInstalledTexture; +} +Texture2D *CoreData::getStatusReadyTexture() { + string data_path = getDataPath(); + loadTextureIfRequired(&statusReadyTexture,data_path, + CORE_MENU_TEXTURES_PATH + "status_ready.png", tsyst_statusReadyTexture, + true, false, false); + + return statusReadyTexture; +} +Texture2D *CoreData::getStatusNotReadyTexture() { + string data_path = getDataPath(); + loadTextureIfRequired(&statusNotReadyTexture,data_path, + CORE_MENU_TEXTURES_PATH + "status_notready.png", tsyst_statusNotReadyTexture, + true, false, false); + + return statusNotReadyTexture; +} +Texture2D *CoreData::getStatusBRBTexture() { + string data_path = getDataPath(); + loadTextureIfRequired(&statusBRBTexture,data_path, + CORE_MENU_TEXTURES_PATH + "status_brb.png", tsyst_statusBRBTexture, + true, false, false); + + return statusBRBTexture; +} +Texture2D *CoreData::getGameWinnerTexture() { + string data_path = getDataPath(); + loadTextureIfRequired(&gameWinnerTexture,data_path, + CORE_MISC_TEXTURES_PATH + "game_winner.png", tsyst_gameWinnerTexture, + true, false, false, true); + + return gameWinnerTexture; +} + +void CoreData::loadLogoTextureExtraIfRequired() { + int loadAttemptLookupKey = tsyst_COUNT + 1; + if(itemLoadAttempted.find(loadAttemptLookupKey) == itemLoadAttempted.end()) { + + itemLoadAttempted[loadAttemptLookupKey] = true; + + string data_path = getDataPath(); + logoTextureList.clear(); + string logosPath = getGameCustomCoreDataPath(data_path, "") + + CORE_MENU_TEXTURES_PATH + "logo*.*"; vector logoFilenames; findAll(logosPath, logoFilenames, false, false); - for (int i = 0; i < (int)logoFilenames.size(); ++i) { - string logo = logoFilenames[i]; + for (int index = 0; index < (int)logoFilenames.size(); ++index) { + + string logo = logoFilenames[index]; if (strcmp("logo.tga", logo.c_str()) != 0) { - Texture2D* logoTextureExtra = renderer.newTexture2D(rsGlobal); - if (logoTextureExtra) { - logoTextureExtra->setMipmap(true); - try { - logoTextureExtra->getPixmap()->load( - data_path + CORE_MENU_TEXTURES_PATH + logo); - logoTextureList.push_back(logoTextureExtra); - } catch (const megaglest_runtime_error& ex) { - message(ex.what(), - GlobalStaticFlags::getIsNonGraphicalModeEnabled(), - tempDataLocation); - cleanupTexture(&logoTextureExtra); - } + + Texture2D* logoTextureExtra = NULL; + loadTextureIfRequired(&logoTextureExtra,data_path, + getGameCustomCoreDataPath(data_path, "") + + CORE_MENU_TEXTURES_PATH + logo, tsyst_NONE, + true, false, true); + } + } + if (logoTextureList.empty() == true) { + + logosPath = data_path + CORE_MENU_TEXTURES_PATH + "logo*.*"; + vector logoFilenames; + findAll(logosPath, logoFilenames, false, false); + for (int index = 0; index < (int)logoFilenames.size(); ++index) { + + string logo = logoFilenames[index]; + if (strcmp("logo.tga", logo.c_str()) != 0) { + + Texture2D* logoTextureExtra = NULL; + loadTextureIfRequired(&logoTextureExtra,data_path, + data_path + CORE_MENU_TEXTURES_PATH + logo, tsyst_NONE, + true, false, true); } } } } - miscTextureList.clear(); - string introPath = getGameCustomCoreDataPath(data_path, "") - + CORE_MENU_TEXTURES_PATH + "intro*.*"; - vector introFilenames; - findAll(introPath, introFilenames, false, false); - for (int i = 0; i < (int)introFilenames.size(); ++i) { - string logo = introFilenames[i]; - //if(strcmp("logo.tga",logo.c_str()) != 0) { - Texture2D* logoTextureExtra = renderer.newTexture2D(rsGlobal); - if (logoTextureExtra) { - logoTextureExtra->setMipmap(true); - try { - logoTextureExtra->getPixmap()->load( - getGameCustomCoreDataPath(data_path, "") - + CORE_MENU_TEXTURES_PATH + logo); - miscTextureList.push_back(logoTextureExtra); - } catch (const megaglest_runtime_error& ex) { - message(ex.what(), - GlobalStaticFlags::getIsNonGraphicalModeEnabled(), - tempDataLocation); - cleanupTexture(&logoTextureExtra); - } - } - //} - } - if (miscTextureList.empty() == true) { - introPath = data_path + CORE_MENU_TEXTURES_PATH + "intro*.*"; +} +size_t CoreData::getLogoTextureExtraCount() { + loadLogoTextureExtraIfRequired(); + return logoTextureList.size(); +} +Texture2D *CoreData::getLogoTextureExtra(int idx) { + loadLogoTextureExtraIfRequired(); + return logoTextureList[idx]; +} + +void CoreData::loadMiscTextureListIfRequired() { + int loadAttemptLookupKey = tsyst_COUNT + 2; + if(itemLoadAttempted.find(loadAttemptLookupKey) == itemLoadAttempted.end()) { + + itemLoadAttempted[loadAttemptLookupKey] = true; + + string data_path = getDataPath(); + + miscTextureList.clear(); + string introPath = getGameCustomCoreDataPath(data_path, "") + + CORE_MENU_TEXTURES_PATH + "intro*.*"; vector introFilenames; findAll(introPath, introFilenames, false, false); for (int i = 0; i < (int)introFilenames.size(); ++i) { string logo = introFilenames[i]; - //if(strcmp("logo.tga",logo.c_str()) != 0) { - Texture2D* logoTextureExtra = renderer.newTexture2D(rsGlobal); - if (logoTextureExtra) { - logoTextureExtra->setMipmap(true); + + Texture2D* logoTextureExtra = NULL; + loadTextureIfRequired(&logoTextureExtra,data_path, + getGameCustomCoreDataPath(data_path, "") + CORE_MENU_TEXTURES_PATH + + logo, tsyst_NONE, + true, false, true); + + } + if (miscTextureList.empty() == true) { + introPath = data_path + CORE_MENU_TEXTURES_PATH + "intro*.*"; + vector introFilenames; + findAll(introPath, introFilenames, false, false); + for (int i = 0; i < (int)introFilenames.size(); ++i) { + string logo = introFilenames[i]; + + Texture2D* logoTextureExtra = NULL; + loadTextureIfRequired(&logoTextureExtra,data_path, + data_path + CORE_MENU_TEXTURES_PATH + logo, tsyst_NONE, + true, false, true); + } + } + + } +} + +std::vector & CoreData::getMiscTextureList() { + loadMiscTextureListIfRequired(); + return miscTextureList; +} + +void CoreData::loadTextures(string data_path) { + // Required to be loaded at program startup as they may be accessed in + // threads or some other dangerous way so lazy loading is not an option + getCustomTexture(); +} + +StaticSound *CoreData::getClickSoundA() { + int loadAttemptLookupKey = tsyst_COUNT + 3; + if(itemLoadAttempted.find(loadAttemptLookupKey) == itemLoadAttempted.end()) { + + itemLoadAttempted[loadAttemptLookupKey] = true; + + try { + string data_path = getDataPath(); + clickSoundA.load(getGameCustomCoreDataPath(data_path, + CORE_MENU_SOUND_PATH + "click_a.wav")); + } + catch (const megaglest_runtime_error& ex) { + message(ex.what(), GlobalStaticFlags::getIsNonGraphicalModeEnabled(), + tempDataLocation); + } + } + return &clickSoundA; +} + +StaticSound *CoreData::getClickSoundB() { + int loadAttemptLookupKey = tsyst_COUNT + 4; + if(itemLoadAttempted.find(loadAttemptLookupKey) == itemLoadAttempted.end()) { + + itemLoadAttempted[loadAttemptLookupKey] = true; + + try { + string data_path = getDataPath(); + clickSoundB.load(getGameCustomCoreDataPath(data_path, + CORE_MENU_SOUND_PATH + "click_b.wav")); + } + catch (const megaglest_runtime_error& ex) { + message(ex.what(), GlobalStaticFlags::getIsNonGraphicalModeEnabled(), + tempDataLocation); + } + } + + return &clickSoundB; +} +StaticSound *CoreData::getClickSoundC() { + int loadAttemptLookupKey = tsyst_COUNT + 5; + if(itemLoadAttempted.find(loadAttemptLookupKey) == itemLoadAttempted.end()) { + + itemLoadAttempted[loadAttemptLookupKey] = true; + + try { + string data_path = getDataPath(); + clickSoundC.load(getGameCustomCoreDataPath(data_path, + CORE_MENU_SOUND_PATH + "click_c.wav")); + } + catch (const megaglest_runtime_error& ex) { + message(ex.what(), GlobalStaticFlags::getIsNonGraphicalModeEnabled(), + tempDataLocation); + } + } + + return &clickSoundC; +} +StaticSound *CoreData::getAttentionSound() { + int loadAttemptLookupKey = tsyst_COUNT + 6; + if(itemLoadAttempted.find(loadAttemptLookupKey) == itemLoadAttempted.end()) { + + itemLoadAttempted[loadAttemptLookupKey] = true; + + try { + string data_path = getDataPath(); + attentionSound.load(getGameCustomCoreDataPath(data_path, + CORE_MENU_SOUND_PATH + "attention.wav")); + } + catch (const megaglest_runtime_error& ex) { + message(ex.what(), GlobalStaticFlags::getIsNonGraphicalModeEnabled(), + tempDataLocation); + } + } + + return &attentionSound; +} +StaticSound *CoreData::getHighlightSound() { + int loadAttemptLookupKey = tsyst_COUNT + 7; + if(itemLoadAttempted.find(loadAttemptLookupKey) == itemLoadAttempted.end()) { + + itemLoadAttempted[loadAttemptLookupKey] = true; + + try { + string data_path = getDataPath(); + highlightSound.load(getGameCustomCoreDataPath(data_path, + CORE_MENU_SOUND_PATH + "highlight.wav")); + } + catch (const megaglest_runtime_error& ex) { + message(ex.what(), GlobalStaticFlags::getIsNonGraphicalModeEnabled(), + tempDataLocation); + } + } + + return &highlightSound; +} +StaticSound *CoreData::getMarkerSound() { + int loadAttemptLookupKey = tsyst_COUNT + 8; + if(itemLoadAttempted.find(loadAttemptLookupKey) == itemLoadAttempted.end()) { + + itemLoadAttempted[loadAttemptLookupKey] = true; + + try { + string data_path = getDataPath(); + markerSound.load(getGameCustomCoreDataPath(data_path, + CORE_MENU_SOUND_PATH + "sonar.wav")); + } + catch (const megaglest_runtime_error& ex) { + message(ex.what(), GlobalStaticFlags::getIsNonGraphicalModeEnabled(), + tempDataLocation); + } + } + + return &markerSound; +} + +void CoreData::loadWaterSoundsIfRequired() { + int loadAttemptLookupKey = tsyst_COUNT + 9; + if(itemLoadAttempted.find(loadAttemptLookupKey) == itemLoadAttempted.end()) { + + itemLoadAttempted[loadAttemptLookupKey] = true; + + string data_path = getDataPath(); + cleanup(); + waterSounds.resize(6); + + for (int index = 0; index < 6; ++index) { + waterSounds[index] = new StaticSound(); + if (waterSounds[index] != NULL) { try { - logoTextureExtra->getPixmap()->load( - data_path + CORE_MENU_TEXTURES_PATH + logo); - miscTextureList.push_back(logoTextureExtra); - } catch (const megaglest_runtime_error& ex) { + waterSounds[index]->load(getGameCustomCoreDataPath(data_path, + CORE_WATER_SOUNDS_PATH + + "water" + intToStr(index) + ".wav")); + } + catch (const megaglest_runtime_error& ex) { message(ex.what(), GlobalStaticFlags::getIsNonGraphicalModeEnabled(), tempDataLocation); - cleanupTexture(&logoTextureExtra); } } - //} - } - } - waterSplashTexture = renderer.newTexture2D(rsGlobal); - if (waterSplashTexture) { - waterSplashTexture->setFormat(Texture::fAlpha); - waterSplashTexture->getPixmap()->init(1); - try { - waterSplashTexture->getPixmap()->load( - getGameCustomCoreDataPath(data_path, - CORE_MISC_TEXTURES_PATH + "water_splash.tga")); - waterSplashTexture->setTextureSystemId(tsyst_waterSplashTexture); - } catch (const megaglest_runtime_error& ex) { - message(ex.what(), - GlobalStaticFlags::getIsNonGraphicalModeEnabled(), - tempDataLocation); - cleanupTexture (&waterSplashTexture); - } - } - buttonSmallTexture = renderer.newTexture2D(rsGlobal); - if (buttonSmallTexture) { - buttonSmallTexture->setForceCompressionDisabled(true); - try { - buttonSmallTexture->getPixmap()->load( - getGameCustomCoreDataPath(data_path, - CORE_MENU_TEXTURES_PATH + "button_small.tga")); - buttonSmallTexture->setTextureSystemId(tsyst_buttonSmallTexture); - } catch (const megaglest_runtime_error& ex) { - message(ex.what(), - GlobalStaticFlags::getIsNonGraphicalModeEnabled(), - tempDataLocation); - cleanupTexture (&buttonSmallTexture); - } - } - buttonBigTexture = renderer.newTexture2D(rsGlobal); - if (buttonBigTexture) { - buttonBigTexture->setForceCompressionDisabled(true); - try { - buttonBigTexture->getPixmap()->load( - getGameCustomCoreDataPath(data_path, - CORE_MENU_TEXTURES_PATH + "button_big.tga")); - buttonBigTexture->setTextureSystemId(tsyst_buttonBigTexture); - } catch (const megaglest_runtime_error& ex) { - message(ex.what(), - GlobalStaticFlags::getIsNonGraphicalModeEnabled(), - tempDataLocation); - cleanupTexture (&buttonBigTexture); - } - } - horizontalLineTexture = renderer.newTexture2D(rsGlobal); - if (horizontalLineTexture) { - horizontalLineTexture->setForceCompressionDisabled(true); - try { - horizontalLineTexture->getPixmap()->load( - getGameCustomCoreDataPath(data_path, - CORE_MENU_TEXTURES_PATH + "line_horizontal.tga")); - horizontalLineTexture->setTextureSystemId( - tsyst_horizontalLineTexture); - } catch (const megaglest_runtime_error& ex) { - message(ex.what(), - GlobalStaticFlags::getIsNonGraphicalModeEnabled(), - tempDataLocation); - cleanupTexture (&horizontalLineTexture); - } - } - verticalLineTexture = renderer.newTexture2D(rsGlobal); - if (verticalLineTexture) { - verticalLineTexture->setForceCompressionDisabled(true); - try { - verticalLineTexture->getPixmap()->load( - getGameCustomCoreDataPath(data_path, - CORE_MENU_TEXTURES_PATH + "line_vertical.tga")); - verticalLineTexture->setTextureSystemId(tsyst_verticalLineTexture); - } catch (const megaglest_runtime_error& ex) { - message(ex.what(), - GlobalStaticFlags::getIsNonGraphicalModeEnabled(), - tempDataLocation); - cleanupTexture (&verticalLineTexture); - } - } - checkBoxTexture = renderer.newTexture2D(rsGlobal); - if (checkBoxTexture) { - checkBoxTexture->setForceCompressionDisabled(true); - try { - checkBoxTexture->getPixmap()->load( - getGameCustomCoreDataPath(data_path, - CORE_MENU_TEXTURES_PATH + "checkbox.tga")); - checkBoxTexture->setTextureSystemId(tsyst_checkBoxTexture); - } catch (const megaglest_runtime_error& ex) { - message(ex.what(), - GlobalStaticFlags::getIsNonGraphicalModeEnabled(), - tempDataLocation); - cleanupTexture (&checkBoxTexture); - } - } - checkedCheckBoxTexture = renderer.newTexture2D(rsGlobal); - if (checkedCheckBoxTexture) { - checkedCheckBoxTexture->setForceCompressionDisabled(true); - try { - checkedCheckBoxTexture->getPixmap()->load( - getGameCustomCoreDataPath(data_path, - CORE_MENU_TEXTURES_PATH + "checkbox_checked.tga")); - checkedCheckBoxTexture->setTextureSystemId( - tsyst_checkedCheckBoxTexture); - } catch (const megaglest_runtime_error& ex) { - message(ex.what(), - GlobalStaticFlags::getIsNonGraphicalModeEnabled(), - tempDataLocation); - cleanupTexture (&checkedCheckBoxTexture); - } - } - gameWinnerTexture = renderer.newTexture2D(rsGlobal); - if (gameWinnerTexture) { - gameWinnerTexture->setForceCompressionDisabled(true); - try { - gameWinnerTexture->getPixmap()->load( - getGameCustomCoreDataPath(data_path, - CORE_MISC_TEXTURES_PATH + "game_winner.png")); - gameWinnerTexture->setTextureSystemId(tsyst_gameWinnerTexture); - } catch (const megaglest_runtime_error& ex) { - message(ex.what(), - GlobalStaticFlags::getIsNonGraphicalModeEnabled(), - tempDataLocation); - cleanupTexture (&gameWinnerTexture); } } } +StaticSound *CoreData::getWaterSound() { + loadWaterSoundsIfRequired(); + return waterSounds.getRandSound(); +} + void CoreData::loadSounds(string data_path) { // sounds - try { - clickSoundA.load( - getGameCustomCoreDataPath(data_path, - CORE_MENU_SOUND_PATH + "click_a.wav")); - clickSoundB.load( - getGameCustomCoreDataPath(data_path, - CORE_MENU_SOUND_PATH + "click_b.wav")); - clickSoundC.load( - getGameCustomCoreDataPath(data_path, - CORE_MENU_SOUND_PATH + "click_c.wav")); - attentionSound.load( - getGameCustomCoreDataPath(data_path, - CORE_MENU_SOUND_PATH + "attention.wav")); - highlightSound.load( - getGameCustomCoreDataPath(data_path, - CORE_MENU_SOUND_PATH + "highlight.wav")); - markerSound.load( - getGameCustomCoreDataPath(data_path, - CORE_MENU_SOUND_PATH + "sonar.wav")); - } - catch (const megaglest_runtime_error& ex) { - message(ex.what(), GlobalStaticFlags::getIsNonGraphicalModeEnabled(), - tempDataLocation); - } - cleanup(); - waterSounds.resize(6); +// try { +// clickSoundA.load( +// getGameCustomCoreDataPath(data_path, +// CORE_MENU_SOUND_PATH + "click_a.wav")); +// clickSoundB.load( +// getGameCustomCoreDataPath(data_path, +// CORE_MENU_SOUND_PATH + "click_b.wav")); +// clickSoundC.load( +// getGameCustomCoreDataPath(data_path, +// CORE_MENU_SOUND_PATH + "click_c.wav")); +// attentionSound.load( +// getGameCustomCoreDataPath(data_path, +// CORE_MENU_SOUND_PATH + "attention.wav")); +// highlightSound.load( +// getGameCustomCoreDataPath(data_path, +// CORE_MENU_SOUND_PATH + "highlight.wav")); +// markerSound.load( +// getGameCustomCoreDataPath(data_path, +// CORE_MENU_SOUND_PATH + "sonar.wav")); +// } +// catch (const megaglest_runtime_error& ex) { +// message(ex.what(), GlobalStaticFlags::getIsNonGraphicalModeEnabled(), +// tempDataLocation); +// } - for (int i = 0; i < 6; ++i) { - waterSounds[i] = new StaticSound(); - if (waterSounds[i]) { - try { - waterSounds[i]->load( - getGameCustomCoreDataPath(data_path, - CORE_WATER_SOUNDS_PATH + "water" + intToStr(i) - + ".wav")); - } catch (const megaglest_runtime_error& ex) { - message(ex.what(), - GlobalStaticFlags::getIsNonGraphicalModeEnabled(), - tempDataLocation); - } +// cleanup(); +// waterSounds.resize(6); +// +// for (int i = 0; i < 6; ++i) { +// waterSounds[i] = new StaticSound(); +// if (waterSounds[i]) { +// try { +// waterSounds[i]->load( +// getGameCustomCoreDataPath(data_path, +// CORE_WATER_SOUNDS_PATH + "water" + intToStr(i) +// + ".wav")); +// } catch (const megaglest_runtime_error& ex) { +// message(ex.what(), +// GlobalStaticFlags::getIsNonGraphicalModeEnabled(), +// tempDataLocation); +// } +// } +// } +} + + +void CoreData::loadMusicIfRequired() { + int loadAttemptLookupKey = tsyst_COUNT + 10; + if(itemLoadAttempted.find(loadAttemptLookupKey) == itemLoadAttempted.end()) { + + itemLoadAttempted[loadAttemptLookupKey] = true; + + string data_path = getDataPath(); + + XmlTree xmlTree; + xmlTree.load( + getGameCustomCoreDataPath(data_path, CORE_MENU_PATH + "menu.xml"), + Properties::getTagReplacementValues()); + const XmlNode* menuNode = xmlTree.getRootNode(); + string menuMusicPath = "/menu/music/"; + string menuIntroMusicFile = "intro_music.ogg"; + string menuMusicFile = "menu_music.ogg"; + if (menuNode->hasChild("intro") == true) { + const XmlNode* introNode = menuNode->getChild("intro"); + // intro info + const XmlNode* menuPathNode = introNode->getChild("menu-music-path"); + menuMusicPath = + menuPathNode->getAttribute("value")->getRestrictedValue(); + const XmlNode* menuIntroMusicNode = introNode->getChild( + "menu-intro-music"); + menuIntroMusicFile = + menuIntroMusicNode->getAttribute("value")->getRestrictedValue(); + const XmlNode* menuMusicNode = introNode->getChild("menu-music"); + menuMusicFile = + menuMusicNode->getAttribute("value")->getRestrictedValue(); + } + try { + introMusic.open( + getGameCustomCoreDataPath(data_path, + CORE_PATH + menuMusicPath + menuIntroMusicFile)); + introMusic.setNext(&menuMusic); + menuMusic.open( + getGameCustomCoreDataPath(data_path, + CORE_PATH + menuMusicPath + menuMusicFile)); + menuMusic.setNext(&menuMusic); + } + catch (const megaglest_runtime_error& ex) { + message(ex.what(), GlobalStaticFlags::getIsNonGraphicalModeEnabled(), + tempDataLocation); } } } +StrSound *CoreData::getIntroMusic() { + loadMusicIfRequired(); + return &introMusic; +} + +StrSound *CoreData::getMenuMusic() { + loadMusicIfRequired(); + return &menuMusic; +} + void CoreData::loadMusic(string data_path) { - XmlTree xmlTree; - //string data_path = getGameReadWritePath(GameConstants::path_data_CacheLookupKey); - xmlTree.load( - getGameCustomCoreDataPath(data_path, CORE_MENU_PATH + "menu.xml"), - Properties::getTagReplacementValues()); - const XmlNode* menuNode = xmlTree.getRootNode(); - string menuMusicPath = "/menu/music/"; - string menuIntroMusicFile = "intro_music.ogg"; - string menuMusicFile = "menu_music.ogg"; - if (menuNode->hasChild("intro") == true) { - const XmlNode* introNode = menuNode->getChild("intro"); - // intro info - const XmlNode* menuPathNode = introNode->getChild("menu-music-path"); - menuMusicPath = - menuPathNode->getAttribute("value")->getRestrictedValue(); - const XmlNode* menuIntroMusicNode = introNode->getChild( - "menu-intro-music"); - menuIntroMusicFile = - menuIntroMusicNode->getAttribute("value")->getRestrictedValue(); - const XmlNode* menuMusicNode = introNode->getChild("menu-music"); - menuMusicFile = - menuMusicNode->getAttribute("value")->getRestrictedValue(); - } - try { - introMusic.open( - getGameCustomCoreDataPath(data_path, - CORE_PATH + menuMusicPath + menuIntroMusicFile)); - introMusic.setNext(&menuMusic); - menuMusic.open( - getGameCustomCoreDataPath(data_path, - CORE_PATH + menuMusicPath + menuMusicFile)); - menuMusic.setNext(&menuMusic); - } catch (const megaglest_runtime_error& ex) { - message(ex.what(), GlobalStaticFlags::getIsNonGraphicalModeEnabled(), - tempDataLocation); - } } void CoreData::loadIntroMedia(string data_path) { @@ -998,12 +1074,8 @@ void CoreData::loadBattleEndMedia(string data_path) { } void CoreData::load() { - string data_path = getGameReadWritePath(GameConstants::path_data_CacheLookupKey); - if(data_path != "") { - endPathWithSlash(data_path); - } + string data_path = CoreData::getDataPath(); - //const string dir = data_path + "data/core"; Logger::getInstance().add(Lang::getInstance().getString("LogScreenCoreDataLoading","",true)); // textures @@ -1021,8 +1093,6 @@ void CoreData::load() { if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false && Shared::Graphics::VideoPlayer::hasBackEndVideoPlayer() == true) { - string data_path = getGameReadWritePath(GameConstants::path_data_CacheLookupKey); - loadIntroMedia(data_path); loadMainMenuMedia(data_path); @@ -1032,19 +1102,16 @@ void CoreData::load() { } bool CoreData::hasIntroVideoFilename() const { - //bool result = (introVideoFilename != "" && fileExists(introVideoFilename) == true); bool result = (introVideoFilename != ""); return result; } bool CoreData::hasMainMenuVideoFilename() const { - //bool result = (mainMenuVideoFilename != "" && fileExists(mainMenuVideoFilename) == true); bool result = (mainMenuVideoFilename != ""); return result; } bool CoreData::hasBattleEndVideoFilename(bool won) const { - //bool result = (mainMenuVideoFilename != "" && fileExists(mainMenuVideoFilename) == true); bool result = false; if(won == true) { result =(battleEndWinVideoFilename != ""); @@ -1066,8 +1133,6 @@ void CoreData::loadFonts() { string displayFontNamePostfix = config.getString("FontDisplayPostfix"); int displayFontSize = computeFontSize(config.getInt("FontDisplayBaseSize")); - //printf("Checking if langfile has custom FontDisplayPostfix\n"); - if(lang.hasString("FontDisplayPrefix") == true) { displayFontNamePrefix = lang.getString("FontDisplayPrefix"); } @@ -1078,8 +1143,6 @@ void CoreData::loadFonts() { displayFontSize = computeFontSize(strToInt(lang.getString("FontDisplayBaseSize"))); } - //printf("displayFontNamePostfix [%s]\n",displayFontNamePostfix.c_str()); - string displayFontName = displayFontNamePrefix + intToStr(displayFontSize) + displayFontNamePostfix; if(displayFont) { @@ -1279,8 +1342,6 @@ void CoreData::loadFonts() { } } - //printf("CoreData menuFontVeryBig3D [%d] menuFontVeryBig3D [%p]\n",menuFontVeryBig3D->getSize(),menuFontVeryBig3D); - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] menuFontNameVeryBig = [%s] menuFontNameVeryBigSize = %d\n",__FILE__,__FUNCTION__,__LINE__,menuFontNameVeryBig.c_str(),menuFontNameVeryBigSize); //console font diff --git a/source/glest_game/global/core_data.h b/source/glest_game/global/core_data.h index 50060b98..82306bac 100644 --- a/source/glest_game/global/core_data.h +++ b/source/glest_game/global/core_data.h @@ -43,6 +43,8 @@ class GameSettings; class CoreData { private: + std::map itemLoadAttempted; + StrSound introMusic; StrSound menuMusic; StaticSound clickSoundA; @@ -131,8 +133,9 @@ public: tsyst_onServerInstalledTexture, tsyst_statusReadyTexture, tsyst_statusNotReadyTexture, - tsyst_statusBRBTexture + tsyst_statusBRBTexture, + tsyst_COUNT //std::vector miscTextureList; }; @@ -145,46 +148,49 @@ public: void cleanup(); void loadFonts(); + // Textures Texture2D *getTextureBySystemId(TextureSystemType type) const; - Texture2D *getBackgroundTexture() const {return backgroundTexture;} - Texture2D *getFireTexture() const {return fireTexture;} - Texture2D *getTeamColorTexture() const {return teamColorTexture;} - Texture2D *getSnowTexture() const {return snowTexture;} - Texture2D *getLogoTexture() const {return logoTexture;} - Texture2D *getWaterSplashTexture() const {return waterSplashTexture;} - Texture2D *getCustomTexture() const {return customTexture;} - Texture2D *getButtonSmallTexture() const {return buttonSmallTexture;} - Texture2D *getButtonBigTexture() const {return buttonBigTexture;} - Texture2D *getHorizontalLineTexture() const {return horizontalLineTexture;} - Texture2D *getVerticalLineTexture() const {return verticalLineTexture;} - Texture2D *getCheckBoxTexture() const {return checkBoxTexture;} - Texture2D *getCheckedCheckBoxTexture() const {return checkedCheckBoxTexture;} - Texture2D *getNotOnServerTexture() const {return notOnServerTexture;} - Texture2D *getOnServerDifferentTexture() const {return onServerDifferentTexture;} - Texture2D *getOnServerTexture() const {return onServerTexture;} - Texture2D *getOnServerInstalledTexture() const {return onServerInstalledTexture;} - Texture2D *getStatusReadyTexture() const {return statusReadyTexture;} - Texture2D *getStatusNotReadyTexture() const {return statusNotReadyTexture;} - Texture2D *getStatusBRBTexture() const {return statusBRBTexture;} + Texture2D *getBackgroundTexture(); + Texture2D *getFireTexture(); + Texture2D *getTeamColorTexture(); + Texture2D *getSnowTexture(); + Texture2D *getLogoTexture(); + Texture2D *getWaterSplashTexture(); + Texture2D *getCustomTexture(); + Texture2D *getButtonSmallTexture(); + Texture2D *getButtonBigTexture(); + Texture2D *getHorizontalLineTexture(); + Texture2D *getVerticalLineTexture(); + Texture2D *getCheckBoxTexture(); + Texture2D *getCheckedCheckBoxTexture(); + Texture2D *getNotOnServerTexture(); + Texture2D *getOnServerDifferentTexture(); + Texture2D *getOnServerTexture(); + Texture2D *getOnServerInstalledTexture(); + Texture2D *getStatusReadyTexture(); + Texture2D *getStatusNotReadyTexture(); + Texture2D *getStatusBRBTexture(); + Texture2D *getGameWinnerTexture(); - Texture2D *getGameWinnerTexture() const {return gameWinnerTexture;} + size_t getLogoTextureExtraCount(); + Texture2D *getLogoTextureExtra(int idx); - size_t getLogoTextureExtraCount() const {return logoTextureList.size();} - Texture2D *getLogoTextureExtra(int idx) const {return logoTextureList[idx];} + std::vector & getMiscTextureList(); - std::vector & getMiscTextureList() { return miscTextureList; } + // Sounds and Music + StrSound *getIntroMusic(); + StrSound *getMenuMusic(); - StrSound *getIntroMusic() {return &introMusic;} - StrSound *getMenuMusic() {return &menuMusic;} - StaticSound *getClickSoundA() {return &clickSoundA;} - StaticSound *getClickSoundB() {return &clickSoundB;} - StaticSound *getClickSoundC() {return &clickSoundC;} - StaticSound *getAttentionSound() {return &attentionSound;} - StaticSound *getHighlightSound() {return &highlightSound;} - StaticSound *getMarkerSound() {return &markerSound;} - StaticSound *getWaterSound() {return waterSounds.getRandSound();} + StaticSound *getClickSoundA(); + StaticSound *getClickSoundB(); + StaticSound *getClickSoundC(); + StaticSound *getAttentionSound(); + StaticSound *getHighlightSound(); + StaticSound *getMarkerSound(); + StaticSound *getWaterSound(); + // Fonts Font2D *getDisplayFont() const {return displayFont;} Font2D *getDisplayFontSmall() const {return displayFontSmall;} Font2D *getMenuFontNormal() const {return menuFontNormal;} @@ -199,27 +205,29 @@ public: Font3D *getMenuFontVeryBig3D() const {return menuFontVeryBig3D;} Font3D *getConsoleFont3D() const {return consoleFont3D;} - string getMainMenuVideoFilename() const { return mainMenuVideoFilename; } + // Helper functions + string getMainMenuVideoFilename() const { return mainMenuVideoFilename; } bool hasMainMenuVideoFilename() const; - string getMainMenuVideoFilenameFallback() const { return mainMenuVideoFilenameFallback; } + string getMainMenuVideoFilenameFallback() const { return mainMenuVideoFilenameFallback; } bool hasMainMenuVideoFilenameFallback() const; - string getIntroVideoFilename() const { return introVideoFilename; } + string getIntroVideoFilename() const { return introVideoFilename; } bool hasIntroVideoFilename() const; - string getIntroVideoFilenameFallback() const { return introVideoFilenameFallback; } + string getIntroVideoFilenameFallback() const { return introVideoFilenameFallback; } bool hasIntroVideoFilenameFallback() const; - string getBattleEndVideoFilename(bool won) const { return won == true ? battleEndWinVideoFilename : battleEndLoseVideoFilename; } + string getBattleEndVideoFilename(bool won) const { return won == true ? battleEndWinVideoFilename : battleEndLoseVideoFilename; } bool hasBattleEndVideoFilename(bool won) const; - string getBattleEndVideoFilenameFallback(bool won) const { return won == true ? battleEndWinVideoFilenameFallback : battleEndLoseVideoFilenameFallback; } + string getBattleEndVideoFilenameFallback(bool won) const { return won == true ? battleEndWinVideoFilenameFallback : battleEndLoseVideoFilenameFallback; } bool hasBattleEndVideoFilenameFallback(bool won) const; - string getBattleEndMusicFilename(bool won) const { return won == true ? battleEndWinMusicFilename : battleEndLoseMusicFilename; } + string getBattleEndMusicFilename(bool won) const { return won == true ? battleEndWinMusicFilename : battleEndLoseMusicFilename; } void saveGameSettingsToFile(std::string fileName, GameSettings *gameSettings,int advancedIndex=0); bool loadGameSettingsFromFile(std::string fileName, GameSettings *gameSettings); private: + CoreData(); int computeFontSize(int size); @@ -230,6 +238,18 @@ private: void loadIntroMedia(string data_path); void loadMainMenuMedia(string data_path); void loadBattleEndMedia(string data_path); + + string getDataPath(); + void loadTextureIfRequired(Texture2D **tex,string data_path, + string uniqueFilePath, int texSystemId, bool setMipMap, + bool setAlpha, bool loadUniqueFilePath, + bool compressionDisabled = false); + + void loadLogoTextureExtraIfRequired(); + void loadMiscTextureListIfRequired(); + + void loadWaterSoundsIfRequired(); + void loadMusicIfRequired(); }; }} //end namespace diff --git a/source/glest_game/graphics/renderer.cpp b/source/glest_game/graphics/renderer.cpp index 0904fdbe..2c05d21c 100644 --- a/source/glest_game/graphics/renderer.cpp +++ b/source/glest_game/graphics/renderer.cpp @@ -5509,7 +5509,7 @@ void Renderer::renderWaterEffects(){ const World *world= game->getWorld(); const WaterEffects *we= world->getWaterEffects(); const Map *map= world->getMap(); - const CoreData &coreData= CoreData::getInstance(); + CoreData &coreData= CoreData::getInstance(); float height= map->getWaterLevel()+0.001f; assertGl(); diff --git a/source/glest_game/main/program.cpp b/source/glest_game/main/program.cpp index 06da06b0..04e55725 100644 --- a/source/glest_game/main/program.cpp +++ b/source/glest_game/main/program.cpp @@ -834,7 +834,7 @@ void Program::init(WindowGl *window, bool initSound, bool toggleFullScreen){ // END if(initOk == false) { - string sError = "Sound System could not be initialzed!"; + string sError = "Sound System could not be initialized!"; this->showMessage(sError.c_str()); } diff --git a/source/shared_lib/sources/graphics/gl/texture_gl.cpp b/source/shared_lib/sources/graphics/gl/texture_gl.cpp index e02538e7..dac42ec7 100644 --- a/source/shared_lib/sources/graphics/gl/texture_gl.cpp +++ b/source/shared_lib/sources/graphics/gl/texture_gl.cpp @@ -763,6 +763,7 @@ void Texture2DGl::init(Filter filter, int maxAnisotropy) { assertGl(); if(inited == false) { + assertGl(); //params GLint wrap= toWrapModeGl(wrapMode); GLint glFormat= toFormatGl(format, pixmap.getComponents()); @@ -772,6 +773,7 @@ void Texture2DGl::init(Filter filter, int maxAnisotropy) { glCompressionFormat = glInternalFormat; } + assertGl(); //pixel init var const uint8* pixels= pixmapInit? pixmap.getPixels(): NULL; @@ -793,7 +795,7 @@ void Texture2DGl::init(Filter filter, int maxAnisotropy) { } if(mipmap) { - GLuint glFilter= filter==fTrilinear? GL_LINEAR_MIPMAP_LINEAR: GL_LINEAR_MIPMAP_NEAREST; + GLuint glFilter= (filter == fTrilinear ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR_MIPMAP_NEAREST); //build mipmaps glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, glFilter); From c442328b5846bfa78ac28e46198d85e3766227ec Mon Sep 17 00:00:00 2001 From: SoftCoder Date: Fri, 27 Dec 2013 22:08:51 -0800 Subject: [PATCH 4/7] - small bugfix for lazy loading textures --- source/glest_game/global/core_data.cpp | 48 ++++++++++++++------------ 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/source/glest_game/global/core_data.cpp b/source/glest_game/global/core_data.cpp index f4ba4015..175f917c 100644 --- a/source/glest_game/global/core_data.cpp +++ b/source/glest_game/global/core_data.cpp @@ -206,33 +206,35 @@ void CoreData::loadTextureIfRequired(Texture2D **tex,string data_path, itemLoadAttempted[texSystemId] = true; } - Renderer &renderer = Renderer::getInstance(); - *tex = renderer.newTexture2D(rsGlobal); - if (*tex) { + if(attemptToLoadTexture == true) { + Renderer &renderer = Renderer::getInstance(); + *tex = renderer.newTexture2D(rsGlobal); + if (*tex) { - (*tex)->setForceCompressionDisabled(compressionDisabled); - (*tex)->setMipmap(setMipMap); - if(setAlpha == true) { + (*tex)->setForceCompressionDisabled(compressionDisabled); + (*tex)->setMipmap(setMipMap); + if(setAlpha == true) { - (*tex)->setFormat(Texture::fAlpha); - (*tex)->getPixmap()->init(1); - } - - try { - string fileToLoad = uniqueFilePath; - if(loadUniqueFilePath == false) { - - fileToLoad = getGameCustomCoreDataPath(data_path,uniqueFilePath); + (*tex)->setFormat(Texture::fAlpha); + (*tex)->getPixmap()->init(1); } - (*tex)->getPixmap()->load(fileToLoad); - (*tex)->setTextureSystemId(texSystemId); - renderer.initTexture(rsGlobal,*tex); - } - catch (const megaglest_runtime_error& ex) { - message(ex.what(),GlobalStaticFlags::getIsNonGraphicalModeEnabled(), - tempDataLocation); - cleanupTexture (tex); + try { + string fileToLoad = uniqueFilePath; + if(loadUniqueFilePath == false) { + + fileToLoad = getGameCustomCoreDataPath(data_path,uniqueFilePath); + } + (*tex)->getPixmap()->load(fileToLoad); + (*tex)->setTextureSystemId(texSystemId); + + renderer.initTexture(rsGlobal,*tex); + } + catch (const megaglest_runtime_error& ex) { + message(ex.what(),GlobalStaticFlags::getIsNonGraphicalModeEnabled(), + tempDataLocation); + cleanupTexture (tex); + } } } } From 163a5a173acacb3bb66b28bb2f7af3b61695d5d6 Mon Sep 17 00:00:00 2001 From: SoftCoder Date: Fri, 27 Dec 2013 22:32:58 -0800 Subject: [PATCH 5/7] - bugfix when user has no sound device --- .../sources/sound/openal/sound_player_openal.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/source/shared_lib/sources/sound/openal/sound_player_openal.cpp b/source/shared_lib/sources/sound/openal/sound_player_openal.cpp index 1934af37..bec98732 100644 --- a/source/shared_lib/sources/sound/openal/sound_player_openal.cpp +++ b/source/shared_lib/sources/sound/openal/sound_player_openal.cpp @@ -455,9 +455,10 @@ void SoundPlayerOpenAL::end() { if(SystemFlags::getSystemSettingType(SystemFlags::debugSound).enabled) SystemFlags::OutputDebug(SystemFlags::debugSound,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); - alcMakeContextCurrent( NULL ); - SoundPlayerOpenAL::checkAlcError(string(__FILE__) + string(" ") + string(__FUNCTION__) + string(" ") + intToStr(__LINE__)); - + if(context != 0) { + alcMakeContextCurrent( NULL ); + SoundPlayerOpenAL::checkAlcError(string(__FILE__) + string(" ") + string(__FUNCTION__) + string(" ") + intToStr(__LINE__)); + } if(SystemFlags::getSystemSettingType(SystemFlags::debugSound).enabled) SystemFlags::OutputDebug(SystemFlags::debugSound,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); if(context != 0) { From b6cd75125076c7906ea6ca925a26aa8fa4d84b1e Mon Sep 17 00:00:00 2001 From: SoftCoder Date: Fri, 27 Dec 2013 23:05:20 -0800 Subject: [PATCH 6/7] - bugfixes on windows platform when some folders and files are missing, do not crash hard. --- source/glest_game/global/core_data.cpp | 2 +- source/glest_game/menu/menu_state_about.cpp | 2 +- source/shared_lib/include/graphics/FileReader.h | 12 ++++++------ source/shared_lib/sources/map/map_preview.cpp | 4 ++-- source/shared_lib/sources/util/leak_dumper.cpp | 2 +- source/shared_lib/sources/util/properties.cpp | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/source/glest_game/global/core_data.cpp b/source/glest_game/global/core_data.cpp index 175f917c..4ccc5f31 100644 --- a/source/glest_game/global/core_data.cpp +++ b/source/glest_game/global/core_data.cpp @@ -1470,7 +1470,7 @@ void CoreData::saveGameSettingsToFile(std::string fileName, GameSettings *gameSe } #if defined(WIN32) && !defined(__MINGW32__) - fclose(fp); + if(fp) fclose(fp); #endif if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); } diff --git a/source/glest_game/menu/menu_state_about.cpp b/source/glest_game/menu/menu_state_about.cpp index bc19a36c..15f913bf 100644 --- a/source/glest_game/menu/menu_state_about.cpp +++ b/source/glest_game/menu/menu_state_about.cpp @@ -200,7 +200,7 @@ string MenuStateAbout::loadAdditionalCredits(){ std::cout << buffer << std::endl; file.close(); #if defined(WIN32) && !defined(__MINGW32__) - fclose(fp); + if(fp) fclose(fp); #endif } return result; diff --git a/source/shared_lib/include/graphics/FileReader.h b/source/shared_lib/include/graphics/FileReader.h index 9a910987..2b06d7ec 100644 --- a/source/shared_lib/include/graphics/FileReader.h +++ b/source/shared_lib/include/graphics/FileReader.h @@ -171,14 +171,14 @@ static inline T* readFromFileReaders(vector const *>* readers, con if (ret != NULL) { file.close(); #if defined(WIN32) && !defined(__MINGW32__) - fclose(fp); + if(fp) fclose(fp); #endif return ret; } } file.close(); #if defined(WIN32) && !defined(__MINGW32__) - fclose(fp); + if(fp) fclose(fp); #endif return NULL; @@ -223,14 +223,14 @@ static inline T* readFromFileReaders(vector const *>* readers, con if (ret != NULL) { file.close(); #if defined(WIN32) && !defined(__MINGW32__) - fclose(fp); + if(fp) fclose(fp); #endif return ret; } } file.close(); #if defined(WIN32) && !defined(__MINGW32__) - fclose(fp); + if(fp) fclose(fp); #endif return NULL; } @@ -368,7 +368,7 @@ T* FileReader::read(const string& filepath) const { T* ret = read(file,filepath); file.close(); #if defined(WIN32) && !defined(__MINGW32__) - fclose(fp); + if(fp) fclose(fp); #endif return ret; @@ -393,7 +393,7 @@ T* FileReader::read(const string& filepath, T* object) const { T* ret = read(file,filepath,object); file.close(); #if defined(WIN32) && !defined(__MINGW32__) - fclose(fp); + if(fp) fclose(fp); #endif return ret; diff --git a/source/shared_lib/sources/map/map_preview.cpp b/source/shared_lib/sources/map/map_preview.cpp index 63701398..cc9fd782 100644 --- a/source/shared_lib/sources/map/map_preview.cpp +++ b/source/shared_lib/sources/map/map_preview.cpp @@ -883,7 +883,7 @@ void MapPreview::loadFromFile(const string &path) { } } - fclose(f1); + if(f1) fclose(f1); fileLoaded = true; mapFileLoaded = path; @@ -964,7 +964,7 @@ void MapPreview::saveToFile(const string &path) { } } - fclose(f1); + if(f1) fclose(f1); hasChanged = false; } diff --git a/source/shared_lib/sources/util/leak_dumper.cpp b/source/shared_lib/sources/util/leak_dumper.cpp index 09b9dc55..54799b21 100644 --- a/source/shared_lib/sources/util/leak_dumper.cpp +++ b/source/shared_lib/sources/util/leak_dumper.cpp @@ -63,7 +63,7 @@ void AllocRegistry::dump(const char *path) { fprintf(f, "Total allocations: %d, " MG_SIZE_T_SPECIFIER " bytes\n", allocCount, allocBytes); fprintf(f, "Not monitored allocations: %d, " MG_SIZE_T_SPECIFIER " bytes\n", nonMonitoredCount, nonMonitoredBytes); - fclose(f); + if(f) fclose(f); printf("Memory leak dump summary at: %s\n",szBuf2); printf("Total leaks: %d, " MG_SIZE_T_SPECIFIER " bytes\n", leakCount, leakBytes); diff --git a/source/shared_lib/sources/util/properties.cpp b/source/shared_lib/sources/util/properties.cpp index 254cf2da..6c5fc99f 100644 --- a/source/shared_lib/sources/util/properties.cpp +++ b/source/shared_lib/sources/util/properties.cpp @@ -376,7 +376,7 @@ void Properties::save(const string &path){ fileStream.close(); #if defined(WIN32) && !defined(__MINGW32__) - fclose(fp); + if(fp) fclose(fp); #endif } From fda53f47d1837912eb4e18b1d73d7a43e3f7155c Mon Sep 17 00:00:00 2001 From: SoftCoder Date: Mon, 30 Dec 2013 02:01:47 -0800 Subject: [PATCH 7/7] - bugfix for loading scenarios with their own techs - all scenario errors are now caught and shown in a messagebox and game can continue. --- source/glest_game/game/script_manager.cpp | 2837 +++++++++++++---- source/glest_game/game/script_manager.h | 1 + source/glest_game/global/config.cpp | 4 + .../glest_game/menu/menu_state_scenario.cpp | 2 + .../platform/common/simple_threads.cpp | 126 +- 5 files changed, 2359 insertions(+), 611 deletions(-) diff --git a/source/glest_game/game/script_manager.cpp b/source/glest_game/game/script_manager.cpp index b799cc74..ba88e772 100644 --- a/source/glest_game/game/script_manager.cpp +++ b/source/glest_game/game/script_manager.cpp @@ -203,9 +203,9 @@ ScriptManager::~ScriptManager() { } void ScriptManager::init(World* world, GameCamera *gameCamera, const XmlNode *rootNode) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); - //printf("In [%s::%s Line: %d] rootNode [%p][%s]\n",__FILE__,__FUNCTION__,__LINE__,rootNode,(rootNode != NULL ? rootNode->getName().c_str() : "none")); + //printf("In [%s::%s Line: %d] rootNode [%p][%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,rootNode,(rootNode != NULL ? rootNode->getName().c_str() : "none")); this->rootNode = rootNode; const Scenario* scenario= world->getScenario(); @@ -215,12 +215,12 @@ void ScriptManager::init(World* world, GameCamera *gameCamera, const XmlNode *ro //set static instance thisScriptManager= this; - //printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + //printf("In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); currentEventId = 1; CellTriggerEventList.clear(); TimerTriggerEventList.clear(); - //printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + //printf("In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); //register functions luaScript.registerFunction(networkShowMessageForFaction, "networkShowMessageForFaction"); @@ -426,7 +426,7 @@ void ScriptManager::init(World* world, GameCamera *gameCamera, const XmlNode *ro gameOver= false; gameWon = false; - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); try { // Setup global functions and vars here @@ -447,22 +447,22 @@ void ScriptManager::init(World* world, GameCamera *gameCamera, const XmlNode *ro //string sErrBuf = ""; //if(ex.wantStackTrace() == true) { char szErrBuf[8096]=""; - snprintf(szErrBuf,8096,"In [%s::%s %d]",__FILE__,__FUNCTION__,__LINE__); + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); //} SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); - messageQueue.push_back(ScriptManagerMessage(sErrBuf.c_str(), "error")); - onMessageBoxOk(false); + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); } - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); } // ========================== events =============================================== void ScriptManager::onMessageBoxOk(bool popFront) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); Lang &lang= Lang::getInstance(); @@ -491,7 +491,7 @@ void ScriptManager::onMessageBoxOk(bool popFront) { } void ScriptManager::onResourceHarvested(){ - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); if(this->rootNode == NULL) { luaScript.beginCall("resourceHarvested"); @@ -500,7 +500,7 @@ void ScriptManager::onResourceHarvested(){ } void ScriptManager::onUnitCreated(const Unit* unit){ - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); if(this->rootNode == NULL) { lastCreatedUnitName= unit->getType()->getName(false); @@ -513,7 +513,7 @@ void ScriptManager::onUnitCreated(const Unit* unit){ } void ScriptManager::onUnitDied(const Unit* unit){ - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); if(this->rootNode == NULL) { if(unit->getLastAttackerUnitId() >= 0) { @@ -545,7 +545,7 @@ void ScriptManager::onUnitDied(const Unit* unit){ } void ScriptManager::onUnitAttacked(const Unit* unit) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); if(this->rootNode == NULL) { lastAttackedUnitName= unit->getType()->getName(false); @@ -556,7 +556,7 @@ void ScriptManager::onUnitAttacked(const Unit* unit) { } void ScriptManager::onUnitAttacking(const Unit* unit) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); if(this->rootNode == NULL) { lastAttackingUnitName= unit->getType()->getName(false); @@ -567,7 +567,7 @@ void ScriptManager::onUnitAttacking(const Unit* unit) { } void ScriptManager::onGameOver(bool won) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); gameWon = won; luaScript.beginCall("gameOver"); @@ -581,7 +581,7 @@ void ScriptManager::onTimerTriggerEvent() { if(this->rootNode != NULL) { return; } - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] TimerTriggerEventList.size() = %d\n",__FILE__,__FUNCTION__,__LINE__,TimerTriggerEventList.size()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] TimerTriggerEventList.size() = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,TimerTriggerEventList.size()); for(std::map::iterator iterMap = TimerTriggerEventList.begin(); iterMap != TimerTriggerEventList.end(); ++iterMap) { @@ -592,7 +592,7 @@ void ScriptManager::onTimerTriggerEvent() { __FILE__,__FUNCTION__,__LINE__,event.running,(long long int)event.startFrame,(long long int)event.endFrame,(event.endFrame - event.startFrame)); if(event.running == true) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); // If using an efficient timer, check if its time to trigger // on the elapsed check @@ -622,7 +622,7 @@ void ScriptManager::onCellTriggerEvent(Unit *movingUnit) { return; } - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] movingUnit = %p, CellTriggerEventList.size() = %d\n",__FILE__,__FUNCTION__,__LINE__,movingUnit,CellTriggerEventList.size()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] movingUnit = %p, CellTriggerEventList.size() = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,movingUnit,CellTriggerEventList.size()); // remove any delayed removals unregisterCellTriggerEvent(-1); @@ -654,7 +654,7 @@ void ScriptManager::onCellTriggerEvent(Unit *movingUnit) { __FILE__,__FUNCTION__,__LINE__,movingUnit->getId(), event.type,movingUnit->getPos().getString().c_str(),event.sourceId,event.destId, event.destPos.getString().c_str(), destUnit->getPos().getString().c_str(),srcInDst); if(srcInDst == true) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); } else { srcInDst = world->getMap()->isNextToUnitTypeCells(destUnit->getType(), destUnit->getPos(),movingUnit->getPos()); @@ -677,7 +677,7 @@ void ScriptManager::onCellTriggerEvent(Unit *movingUnit) { __FILE__,__FUNCTION__,__LINE__,movingUnit->getId(),event.type,movingUnit->getPos().getString().c_str(),event.sourceId,event.destId,event.destPos.getString().c_str(),srcInDst); if(srcInDst == true) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); } triggerEvent = srcInDst; @@ -717,7 +717,7 @@ void ScriptManager::onCellTriggerEvent(Unit *movingUnit) { } if(srcInDst == true) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); } triggerEvent = srcInDst; if(triggerEvent == true) { @@ -737,7 +737,7 @@ void ScriptManager::onCellTriggerEvent(Unit *movingUnit) { __FILE__,__FUNCTION__,__LINE__,movingUnit->getId(),event.type,movingUnit->getPos().getString().c_str(),event.sourceId,event.destId,event.destPos.getString().c_str(),srcInDst); if(srcInDst == true) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); } else { srcInDst = world->getMap()->isNextToUnitTypeCells(destUnit->getType(), destUnit->getPos(),movingUnit->getPos()); @@ -759,7 +759,7 @@ void ScriptManager::onCellTriggerEvent(Unit *movingUnit) { bool srcInDst = world->getMap()->isInUnitTypeCells(movingUnit->getType(), event.destPos,movingUnit->getPos()); if(srcInDst == true) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); } triggerEvent = srcInDst; if(triggerEvent == true) { @@ -793,7 +793,7 @@ void ScriptManager::onCellTriggerEvent(Unit *movingUnit) { srcInDst = world->getMap()->isInUnitTypeCells(movingUnit->getType(), Vec2i(x,y),movingUnit->getPos()); if(srcInDst == true) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); } } } @@ -822,7 +822,7 @@ void ScriptManager::onCellTriggerEvent(Unit *movingUnit) { srcInDst = world->getMap()->isInUnitTypeCells(movingUnit->getType(), Vec2i(x,y),movingUnit->getPos()); if(srcInDst == true) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); currentCellTriggeredEventAreaEntryUnitId = movingUnit->getId(); event.eventStateInfo[movingUnit->getId()] = Vec2i(x,y).getString(); @@ -842,7 +842,7 @@ void ScriptManager::onCellTriggerEvent(Unit *movingUnit) { srcInDst = world->getMap()->isInUnitTypeCells(movingUnit->getType(), Vec2i(x,y),movingUnit->getPos()); if(srcInDst == true) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); //event.eventStateInfo[movingUnit->getId()] = Vec2i(x,y); } @@ -865,7 +865,7 @@ void ScriptManager::onCellTriggerEvent(Unit *movingUnit) { } if(triggerEvent == true) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); currentCellTriggeredEventId = iterMap->first; event.triggerCount++; @@ -907,17 +907,17 @@ string ScriptManager::wrapString(const string &str, int wrapCount) { void ScriptManager::networkShowMessageForFaction(const string &text, const string &header,int factionIndex) { messageQueue.push_back(ScriptManagerMessage(text, header, factionIndex)); - onMessageBoxOk(false); + thisScriptManager->onMessageBoxOk(false); } void ScriptManager::networkShowMessageForTeam(const string &text, const string &header,int teamIndex) { // Team indexes are 0 based internally (but 1 based in the lua script) so convert teamIndex--; messageQueue.push_back(ScriptManagerMessage(text, header, -1, teamIndex)); - onMessageBoxOk(false); + thisScriptManager->onMessageBoxOk(false); } void ScriptManager::networkSetCameraPositionForFaction(int factionIndex, const Vec2i &pos) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); if(factionIndex == this->world->getThisFactionIndex()) { gameCamera->centerXZ(pos.x, pos.y); @@ -925,7 +925,7 @@ void ScriptManager::networkSetCameraPositionForFaction(int factionIndex, const V } void ScriptManager::networkSetCameraPositionForTeam(int teamIndex, const Vec2i &pos) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); if(teamIndex == this->world->getThisTeamIndex()) { gameCamera->centerXZ(pos.x, pos.y); @@ -934,7 +934,7 @@ void ScriptManager::networkSetCameraPositionForTeam(int teamIndex, const Vec2i & void ScriptManager::showMessage(const string &text, const string &header){ messageQueue.push_back(ScriptManagerMessage(text, header)); - onMessageBoxOk(false); + thisScriptManager->onMessageBoxOk(false); } void ScriptManager::clearDisplayText(){ @@ -949,7 +949,7 @@ void ScriptManager::addConsoleText(const string &text){ world->addConsoleText(text); } void ScriptManager::addConsoleLangText(const char *fmt, ...){ - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); va_list argList; va_start(argList, fmt); @@ -964,7 +964,7 @@ void ScriptManager::addConsoleLangText(const char *fmt, ...){ } void ScriptManager::DisplayFormattedText(const char *fmt, ...) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); va_list argList; va_start(argList, fmt); @@ -978,7 +978,7 @@ void ScriptManager::DisplayFormattedText(const char *fmt, ...) { va_end(argList); } void ScriptManager::DisplayFormattedLangText(const char *fmt, ...) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); va_list argList; va_start(argList, fmt); @@ -992,23 +992,23 @@ void ScriptManager::DisplayFormattedLangText(const char *fmt, ...) { va_end(argList); } void ScriptManager::setCameraPosition(const Vec2i &pos){ - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); gameCamera->centerXZ(pos.x, pos.y); } void ScriptManager::createUnit(const string &unitName, int factionIndex, Vec2i pos){ - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] unit [%s] factionIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,unitName.c_str(),factionIndex); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] unit [%s] factionIndex = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,unitName.c_str(),factionIndex); world->createUnit(unitName, factionIndex, pos); } void ScriptManager::createUnitNoSpacing(const string &unitName, int factionIndex, Vec2i pos){ - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] unit [%s] factionIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,unitName.c_str(),factionIndex); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] unit [%s] factionIndex = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,unitName.c_str(),factionIndex); world->createUnit(unitName, factionIndex, pos, false); } void ScriptManager::destroyUnit(int unitId){ - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] unit [%d]\n",__FILE__,__FUNCTION__,__LINE__,unitId); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] unit [%d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,unitId); Unit *unit = world->findUnitById(unitId); if(unit != NULL) { // Make sure they die @@ -1022,7 +1022,7 @@ void ScriptManager::destroyUnit(int unitId){ } } void ScriptManager::giveKills (int unitId, int amount){ - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] unit [%d]\n",__FILE__,__FUNCTION__,__LINE__,unitId); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] unit [%d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,unitId); Unit *unit = world->findUnitById(unitId); if(unit != NULL) { for(int i = 1; i <= amount; i++) { @@ -1032,98 +1032,98 @@ void ScriptManager::giveKills (int unitId, int amount){ } void ScriptManager::playStaticSound(const string &playSound) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] playSound [%s]\n",__FILE__,__FUNCTION__,__LINE__,playSound.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] playSound [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,playSound.c_str()); world->playStaticSound(playSound); } void ScriptManager::playStreamingSound(const string &playSound) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] playSound [%s]\n",__FILE__,__FUNCTION__,__LINE__,playSound.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] playSound [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,playSound.c_str()); world->playStreamingSound(playSound); } void ScriptManager::stopStreamingSound(const string &playSound) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] playSound [%s]\n",__FILE__,__FUNCTION__,__LINE__,playSound.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] playSound [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,playSound.c_str()); world->stopStreamingSound(playSound); } void ScriptManager::stopAllSound() { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); world->stopAllSound(); } void ScriptManager::playStaticVideo(const string &playVideo) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] playVideo [%s]\n",__FILE__,__FUNCTION__,__LINE__,playVideo.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] playVideo [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,playVideo.c_str()); world->playStaticVideo(playVideo); } void ScriptManager::playStreamingVideo(const string &playVideo) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] playVideo [%s]\n",__FILE__,__FUNCTION__,__LINE__,playVideo.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] playVideo [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,playVideo.c_str()); world->playStreamingVideo(playVideo); } void ScriptManager::stopStreamingVideo(const string &playVideo) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] playVideo [%s]\n",__FILE__,__FUNCTION__,__LINE__,playVideo.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] playVideo [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,playVideo.c_str()); world->stopStreamingVideo(playVideo); } void ScriptManager::stopAllVideo() { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); world->stopAllVideo(); } void ScriptManager::togglePauseGame(int pauseStatus) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] pauseStatus = %d\n",__FILE__,__FUNCTION__,__LINE__,pauseStatus); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] pauseStatus = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,pauseStatus); world->togglePauseGame((pauseStatus != 0),true); } void ScriptManager::morphToUnit(int unitId,const string &morphName, int ignoreRequirements) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] unit [%d] morphName [%s] forceUpgradesIfRequired = %d\n",__FILE__,__FUNCTION__,__LINE__,unitId,morphName.c_str(),ignoreRequirements); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] unit [%d] morphName [%s] forceUpgradesIfRequired = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,unitId,morphName.c_str(),ignoreRequirements); world->morphToUnit(unitId,morphName,(ignoreRequirements == 1)); } void ScriptManager::moveToUnit(int unitId,int destUnitId) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] unit [%d] destUnitId [%d]\n",__FILE__,__FUNCTION__,__LINE__,unitId,destUnitId); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] unit [%d] destUnitId [%d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,unitId,destUnitId); world->moveToUnit(unitId,destUnitId); } void ScriptManager::giveResource(const string &resourceName, int factionIndex, int amount){ - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); world->giveResource(resourceName, factionIndex, amount); } void ScriptManager::givePositionCommand(int unitId, const string &commandName, const Vec2i &pos){ - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); world->givePositionCommand(unitId, commandName, pos); } void ScriptManager::giveAttackCommand(int unitId, int unitToAttackId) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); world->giveAttackCommand(unitId, unitToAttackId); } void ScriptManager::giveProductionCommand(int unitId, const string &producedName){ - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); world->giveProductionCommand(unitId, producedName); } void ScriptManager::giveUpgradeCommand(int unitId, const string &producedName){ - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); world->giveUpgradeCommand(unitId, producedName); } void ScriptManager::giveAttackStoppedCommand(int unitId, const string &itemName,int ignoreRequirements) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); world->giveAttackStoppedCommand(unitId, itemName, (ignoreRequirements == 1)); } void ScriptManager::disableAi(int factionIndex){ - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); if(factionIndexgetStartLocation(factionIndex); } Vec2i ScriptManager::getUnitPosition(int unitId) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); Vec2i result = world->getUnitPosition(unitId); @@ -1453,54 +1453,54 @@ Vec2i ScriptManager::getUnitPosition(int unitId) { } void ScriptManager::setUnitPosition(int unitId, Vec2i pos) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); return world->setUnitPosition(unitId,pos); } void ScriptManager::addCellMarker(Vec2i pos, int factionIndex, const string ¬e, const string &textureFile) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); world->addCellMarker(pos,factionIndex, note, textureFile); } void ScriptManager::removeCellMarker(Vec2i pos, int factionIndex) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); return world->removeCellMarker(pos,factionIndex); } void ScriptManager::showMarker(Vec2i pos, int factionIndex, const string ¬e, const string &textureFile, int flashCount) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); world->showMarker(pos,factionIndex, note, textureFile, flashCount); } int ScriptManager::getIsUnitAlive(int unitId) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); return world->getIsUnitAlive(unitId); } int ScriptManager::getUnitFaction(int unitId) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); return world->getUnitFactionIndex(unitId); } const string ScriptManager::getUnitName(int unitId) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); return world->getUnitName(unitId); } int ScriptManager::getResourceAmount(const string &resourceName, int factionIndex) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); return world->getResourceAmount(resourceName, factionIndex); } const string &ScriptManager::getLastCreatedUnitName() { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); return lastCreatedUnitName; } @@ -1556,112 +1556,112 @@ bool ScriptManager::getIsGameOver() const { } int ScriptManager::getLastCreatedUnitId() { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); return lastCreatedUnitId; } const string &ScriptManager::getLastDeadUnitName() { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); return lastDeadUnitName; } int ScriptManager::getLastDeadUnitId() { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); return lastDeadUnitId; } int ScriptManager::getLastDeadUnitCauseOfDeath() { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); return lastDeadUnitCauseOfDeath; } const string &ScriptManager::getLastDeadUnitKillerName() { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); return lastDeadUnitKillerName; } int ScriptManager::getLastDeadUnitKillerId() { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); return lastDeadUnitKillerId; } const string &ScriptManager::getLastAttackedUnitName() { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); return lastAttackedUnitName; } int ScriptManager::getLastAttackedUnitId() { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); return lastAttackedUnitId; } const string &ScriptManager::getLastAttackingUnitName() { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); return lastAttackingUnitName; } int ScriptManager::getLastAttackingUnitId() { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); return lastAttackingUnitId; } int ScriptManager::getUnitCount(int factionIndex) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); return world->getUnitCount(factionIndex); } int ScriptManager::getUnitCountOfType(int factionIndex, const string &typeName) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); return world->getUnitCountOfType(factionIndex, typeName); } const string ScriptManager::getSystemMacroValue(const string &key) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); return world->getSystemMacroValue(key); } const string ScriptManager::getPlayerName(int factionIndex) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); return world->getPlayerName(factionIndex); } void ScriptManager::loadScenario(const string &name, bool keepFactions) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); world->setQueuedScenario(name,keepFactions); } vector ScriptManager::getUnitsForFaction(int factionIndex,const string& commandTypeName, int field) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); return world->getUnitsForFaction(factionIndex,commandTypeName, field); } int ScriptManager::getUnitCurrentField(int unitId) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); return world->getUnitCurrentField(unitId); } int ScriptManager::isFreeCellsOrHasUnit(int field, int unitId, Vec2i pos) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); Unit* unit= world->findUnitById(unitId); @@ -1676,7 +1676,7 @@ int ScriptManager::isFreeCellsOrHasUnit(int field, int unitId, Vec2i pos) { } int ScriptManager::isFreeCells(int unitSize, int field, Vec2i pos) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); int result = world->getMap()->isFreeCellsOrHasUnit(pos,unitSize,static_cast(field),NULL,NULL,true); @@ -1687,67 +1687,67 @@ int ScriptManager::isFreeCells(int unitSize, int field, Vec2i pos) { } int ScriptManager::getHumanFactionId() { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); return this->world->getThisFactionIndex(); } void ScriptManager::highlightUnit(int unitId, float radius, float thickness, Vec4f color) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); world->highlightUnit(unitId, radius, thickness, color); } void ScriptManager::unhighlightUnit(int unitId) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); world->unhighlightUnit(unitId); } void ScriptManager::giveStopCommand(int unitId) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); world->giveStopCommand(unitId); } bool ScriptManager::selectUnit(int unitId) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); return world->selectUnit(unitId); } void ScriptManager::unselectUnit(int unitId) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); world->unselectUnit(unitId); } void ScriptManager::addUnitToGroupSelection(int unitId,int groupIndex) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); world->addUnitToGroupSelection(unitId,groupIndex); } void ScriptManager::recallGroupSelection(int groupIndex) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); world->recallGroupSelection(groupIndex); } void ScriptManager::removeUnitFromGroupSelection(int unitId,int groupIndex) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); world->removeUnitFromGroupSelection(unitId,groupIndex); } void ScriptManager::setAttackWarningsEnabled(bool enabled) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); world->setAttackWarningsEnabled(enabled); } bool ScriptManager::getAttackWarningsEnabled() { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); return world->getAttackWarningsEnabled(); } @@ -1902,7 +1902,7 @@ void ScriptManager::onDayNightTriggerEvent() { } int ScriptManager::getIsDayTime() { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); const TimeFlow *tf= world->getTimeFlow(); @@ -1912,7 +1912,7 @@ int ScriptManager::getIsDayTime() { return tf->isDay(); } int ScriptManager::getIsNightTime() { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); const TimeFlow *tf= world->getTimeFlow(); @@ -1924,7 +1924,7 @@ int ScriptManager::getIsNightTime() { float ScriptManager::getTimeOfDay() { //printf("File: %s line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__); - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); const TimeFlow *tf= world->getTimeFlow(); @@ -1955,6 +1955,9 @@ bool ScriptManager::getSpeedChangeEnabled() { return world->getGame()->getDisableSpeedChange(); } +void ScriptManager::addMessageToQueue(ScriptManagerMessage msg) { + messageQueue.push_back(msg); +} // ========================== lua callbacks =============================================== int ScriptManager::showMessage(LuaHandle* luaHandle){ @@ -1965,715 +1968,1961 @@ int ScriptManager::showMessage(LuaHandle* luaHandle){ int ScriptManager::networkShowMessageForFaction(LuaHandle* luaHandle){ LuaArguments luaArguments(luaHandle); - thisScriptManager->networkShowMessageForFaction(luaArguments.getString(-3), luaArguments.getString(-2), luaArguments.getInt(-1)); + + try { + thisScriptManager->networkShowMessageForFaction(luaArguments.getString(-3), luaArguments.getString(-2), luaArguments.getInt(-1)); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::networkShowMessageForTeam(LuaHandle* luaHandle){ LuaArguments luaArguments(luaHandle); - thisScriptManager->networkShowMessageForTeam(luaArguments.getString(-3), luaArguments.getString(-2), luaArguments.getInt(-1)); + + try { + thisScriptManager->networkShowMessageForTeam(luaArguments.getString(-3), luaArguments.getString(-2), luaArguments.getInt(-1)); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::networkSetCameraPositionForFaction(LuaHandle* luaHandle){ LuaArguments luaArguments(luaHandle); - thisScriptManager->networkSetCameraPositionForFaction(luaArguments.getInt(-2), luaArguments.getVec2i(-1)); + + try { + thisScriptManager->networkSetCameraPositionForFaction(luaArguments.getInt(-2), luaArguments.getVec2i(-1)); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::networkSetCameraPositionForTeam(LuaHandle* luaHandle){ LuaArguments luaArguments(luaHandle); - thisScriptManager->networkSetCameraPositionForTeam(luaArguments.getInt(-2), luaArguments.getVec2i(-1)); + + try { + thisScriptManager->networkSetCameraPositionForTeam(luaArguments.getInt(-2), luaArguments.getVec2i(-1)); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::setDisplayText(LuaHandle* luaHandle){ LuaArguments luaArguments(luaHandle); - thisScriptManager->setDisplayText(luaArguments.getString(-1)); + + try { + thisScriptManager->setDisplayText(luaArguments.getString(-1)); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::addConsoleText(LuaHandle* luaHandle){ LuaArguments luaArguments(luaHandle); - thisScriptManager->addConsoleText(luaArguments.getString(-1)); + + try { + thisScriptManager->addConsoleText(luaArguments.getString(-1)); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::clearDisplayText(LuaHandle* luaHandle){ LuaArguments luaArguments(luaHandle); - thisScriptManager->clearDisplayText(); + + try { + thisScriptManager->clearDisplayText(); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::setCameraPosition(LuaHandle* luaHandle){ LuaArguments luaArguments(luaHandle); - thisScriptManager->setCameraPosition(Vec2i(luaArguments.getVec2i(-1))); + + try { + thisScriptManager->setCameraPosition(Vec2i(luaArguments.getVec2i(-1))); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::createUnit(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] unit [%s] factionIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,luaArguments.getString(-3).c_str(),luaArguments.getInt(-2)); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] unit [%s] factionIndex = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,luaArguments.getString(-3).c_str(),luaArguments.getInt(-2)); + + try { + thisScriptManager->createUnit( + luaArguments.getString(-3), + luaArguments.getInt(-2), + luaArguments.getVec2i(-1)); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } - thisScriptManager->createUnit( - luaArguments.getString(-3), - luaArguments.getInt(-2), - luaArguments.getVec2i(-1)); return luaArguments.getReturnCount(); } int ScriptManager::createUnitNoSpacing(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] unit [%s] factionIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,luaArguments.getString(-3).c_str(),luaArguments.getInt(-2)); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] unit [%s] factionIndex = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,luaArguments.getString(-3).c_str(),luaArguments.getInt(-2)); + + try { + thisScriptManager->createUnitNoSpacing( + luaArguments.getString(-3), + luaArguments.getInt(-2), + luaArguments.getVec2i(-1)); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } - thisScriptManager->createUnitNoSpacing( - luaArguments.getString(-3), - luaArguments.getInt(-2), - luaArguments.getVec2i(-1)); return luaArguments.getReturnCount(); } int ScriptManager::destroyUnit(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] unit [%d]\n",__FILE__,__FUNCTION__,__LINE__,luaArguments.getInt(-1)); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] unit [%d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,luaArguments.getInt(-1)); + + try { + thisScriptManager->destroyUnit(luaArguments.getInt(-1)); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } - thisScriptManager->destroyUnit(luaArguments.getInt(-1)); return luaArguments.getReturnCount(); } int ScriptManager::giveKills(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] unit [%d]\n",__FILE__,__FUNCTION__,__LINE__,luaArguments.getInt(-1)); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] unit [%d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,luaArguments.getInt(-1)); + + try { + thisScriptManager->giveKills(luaArguments.getInt(-2),luaArguments.getInt(-1)); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } - thisScriptManager->giveKills(luaArguments.getInt(-2),luaArguments.getInt(-1)); return luaArguments.getReturnCount(); } int ScriptManager::morphToUnit(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] unit [%d] morphName [%s] forceUpgrade = %d\n",__FILE__,__FUNCTION__,__LINE__,luaArguments.getInt(-3),luaArguments.getString(-2).c_str(),luaArguments.getInt(-1)); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] unit [%d] morphName [%s] forceUpgrade = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,luaArguments.getInt(-3),luaArguments.getString(-2).c_str(),luaArguments.getInt(-1)); + + try { + thisScriptManager->morphToUnit(luaArguments.getInt(-3),luaArguments.getString(-2),luaArguments.getInt(-1)); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } - thisScriptManager->morphToUnit(luaArguments.getInt(-3),luaArguments.getString(-2),luaArguments.getInt(-1)); return luaArguments.getReturnCount(); } int ScriptManager::moveToUnit(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] unit [%d] dest unit [%d]\n",__FILE__,__FUNCTION__,__LINE__,luaArguments.getInt(-2),luaArguments.getInt(-1)); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] unit [%d] dest unit [%d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,luaArguments.getInt(-2),luaArguments.getInt(-1)); + + try { + thisScriptManager->moveToUnit(luaArguments.getInt(-2),luaArguments.getInt(-1)); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } - thisScriptManager->moveToUnit(luaArguments.getInt(-2),luaArguments.getInt(-1)); return luaArguments.getReturnCount(); } int ScriptManager::playStaticSound(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] sound [%s]\n",__FILE__,__FUNCTION__,__LINE__,luaArguments.getString(-1).c_str()); - thisScriptManager->playStaticSound(luaArguments.getString(-1)); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] sound [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,luaArguments.getString(-1).c_str()); + + try { + thisScriptManager->playStaticSound(luaArguments.getString(-1)); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::playStreamingSound(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] sound [%s]\n",__FILE__,__FUNCTION__,__LINE__,luaArguments.getString(-1).c_str()); - thisScriptManager->playStreamingSound(luaArguments.getString(-1)); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] sound [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,luaArguments.getString(-1).c_str()); + + try { + thisScriptManager->playStreamingSound(luaArguments.getString(-1)); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::stopStreamingSound(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] sound [%s]\n",__FILE__,__FUNCTION__,__LINE__,luaArguments.getString(-1).c_str()); - thisScriptManager->stopStreamingSound(luaArguments.getString(-1)); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] sound [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,luaArguments.getString(-1).c_str()); + + try { + thisScriptManager->stopStreamingSound(luaArguments.getString(-1)); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::stopAllSound(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - thisScriptManager->stopAllSound(); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + + try { + thisScriptManager->stopAllSound(); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } - - int ScriptManager::playStaticVideo(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] sound [%s]\n",__FILE__,__FUNCTION__,__LINE__,luaArguments.getString(-1).c_str()); - thisScriptManager->playStaticVideo(luaArguments.getString(-1)); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] sound [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,luaArguments.getString(-1).c_str()); + + try { + thisScriptManager->playStaticVideo(luaArguments.getString(-1)); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::playStreamingVideo(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] sound [%s]\n",__FILE__,__FUNCTION__,__LINE__,luaArguments.getString(-1).c_str()); - thisScriptManager->playStreamingVideo(luaArguments.getString(-1)); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] sound [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,luaArguments.getString(-1).c_str()); + + try { + thisScriptManager->playStreamingVideo(luaArguments.getString(-1)); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::stopStreamingVideo(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] sound [%s]\n",__FILE__,__FUNCTION__,__LINE__,luaArguments.getString(-1).c_str()); - thisScriptManager->stopStreamingVideo(luaArguments.getString(-1)); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] sound [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,luaArguments.getString(-1).c_str()); + + try { + thisScriptManager->stopStreamingVideo(luaArguments.getString(-1)); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::stopAllVideo(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - thisScriptManager->stopAllVideo(); + + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + + try { + thisScriptManager->stopAllVideo(); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } - - int ScriptManager::togglePauseGame(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] value = %d\n",__FILE__,__FUNCTION__,__LINE__,luaArguments.getInt(-1)); - thisScriptManager->togglePauseGame(luaArguments.getInt(-1)); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] value = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,luaArguments.getInt(-1)); + + try { + thisScriptManager->togglePauseGame(luaArguments.getInt(-1)); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::giveResource(LuaHandle* luaHandle){ LuaArguments luaArguments(luaHandle); - thisScriptManager->giveResource(luaArguments.getString(-3), luaArguments.getInt(-2), luaArguments.getInt(-1)); + try { + thisScriptManager->giveResource(luaArguments.getString(-3), luaArguments.getInt(-2), luaArguments.getInt(-1)); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::givePositionCommand(LuaHandle* luaHandle){ LuaArguments luaArguments(luaHandle); - thisScriptManager->givePositionCommand( - luaArguments.getInt(-3), - luaArguments.getString(-2), - luaArguments.getVec2i(-1)); + try { + thisScriptManager->givePositionCommand( + luaArguments.getInt(-3), + luaArguments.getString(-2), + luaArguments.getVec2i(-1)); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::giveAttackCommand(LuaHandle* luaHandle){ LuaArguments luaArguments(luaHandle); - thisScriptManager->giveAttackCommand( - luaArguments.getInt(-2), - luaArguments.getInt(-1)); + try { + thisScriptManager->giveAttackCommand( + luaArguments.getInt(-2), + luaArguments.getInt(-1)); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::giveProductionCommand(LuaHandle* luaHandle){ LuaArguments luaArguments(luaHandle); - thisScriptManager->giveProductionCommand( - luaArguments.getInt(-2), - luaArguments.getString(-1)); + try { + thisScriptManager->giveProductionCommand( + luaArguments.getInt(-2), + luaArguments.getString(-1)); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::giveUpgradeCommand(LuaHandle* luaHandle){ LuaArguments luaArguments(luaHandle); - thisScriptManager->giveUpgradeCommand( - luaArguments.getInt(-2), - luaArguments.getString(-1)); + try { + thisScriptManager->giveUpgradeCommand( + luaArguments.getInt(-2), + luaArguments.getString(-1)); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::giveAttackStoppedCommand(LuaHandle* luaHandle){ LuaArguments luaArguments(luaHandle); - thisScriptManager->giveAttackStoppedCommand( - luaArguments.getInt(-3), - luaArguments.getString(-2), - luaArguments.getInt(-1)); + try { + thisScriptManager->giveAttackStoppedCommand( + luaArguments.getInt(-3), + luaArguments.getString(-2), + luaArguments.getInt(-1)); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::disableAi(LuaHandle* luaHandle){ LuaArguments luaArguments(luaHandle); - thisScriptManager->disableAi(luaArguments.getInt(-1)); + try { + thisScriptManager->disableAi(luaArguments.getInt(-1)); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::enableAi(LuaHandle* luaHandle){ LuaArguments luaArguments(luaHandle); - thisScriptManager->enableAi(luaArguments.getInt(-1)); + try { + thisScriptManager->enableAi(luaArguments.getInt(-1)); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::getAiEnabled(LuaHandle* luaHandle){ LuaArguments luaArguments(luaHandle); - bool result = thisScriptManager->getAiEnabled(luaArguments.getInt(-1)); - luaArguments.returnInt(result); + try { + bool result = thisScriptManager->getAiEnabled(luaArguments.getInt(-1)); + luaArguments.returnInt(result); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::disableConsume(LuaHandle* luaHandle){ LuaArguments luaArguments(luaHandle); - thisScriptManager->disableConsume(luaArguments.getInt(-1)); + try { + thisScriptManager->disableConsume(luaArguments.getInt(-1)); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::enableConsume(LuaHandle* luaHandle){ LuaArguments luaArguments(luaHandle); - thisScriptManager->enableConsume(luaArguments.getInt(-1)); + try { + thisScriptManager->enableConsume(luaArguments.getInt(-1)); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::getConsumeEnabled(LuaHandle* luaHandle){ LuaArguments luaArguments(luaHandle); - bool result = thisScriptManager->getConsumeEnabled(luaArguments.getInt(-1)); - luaArguments.returnInt(result); + try { + bool result = thisScriptManager->getConsumeEnabled(luaArguments.getInt(-1)); + luaArguments.returnInt(result); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::registerCellTriggerEventForUnitToUnit(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - int result = thisScriptManager->registerCellTriggerEventForUnitToUnit(luaArguments.getInt(-2),luaArguments.getInt(-1)); - luaArguments.returnInt(result); + try { + int result = thisScriptManager->registerCellTriggerEventForUnitToUnit(luaArguments.getInt(-2),luaArguments.getInt(-1)); + luaArguments.returnInt(result); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::registerCellTriggerEventForUnitToLocation(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - int result = thisScriptManager->registerCellTriggerEventForUnitToLocation(luaArguments.getInt(-2),luaArguments.getVec2i(-1)); - luaArguments.returnInt(result); + try { + int result = thisScriptManager->registerCellTriggerEventForUnitToLocation(luaArguments.getInt(-2),luaArguments.getVec2i(-1)); + luaArguments.returnInt(result); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::registerCellAreaTriggerEventForUnitToLocation(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - int result = thisScriptManager->registerCellAreaTriggerEventForUnitToLocation(luaArguments.getInt(-2),luaArguments.getVec4i(-1)); - luaArguments.returnInt(result); + try { + int result = thisScriptManager->registerCellAreaTriggerEventForUnitToLocation(luaArguments.getInt(-2),luaArguments.getVec4i(-1)); + luaArguments.returnInt(result); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::registerCellTriggerEventForFactionToUnit(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - int result = thisScriptManager->registerCellTriggerEventForFactionToUnit(luaArguments.getInt(-2),luaArguments.getInt(-1)); - luaArguments.returnInt(result); + try { + int result = thisScriptManager->registerCellTriggerEventForFactionToUnit(luaArguments.getInt(-2),luaArguments.getInt(-1)); + luaArguments.returnInt(result); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::registerCellTriggerEventForFactionToLocation(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - int result = thisScriptManager->registerCellTriggerEventForFactionToLocation(luaArguments.getInt(-2),luaArguments.getVec2i(-1)); - luaArguments.returnInt(result); + try { + int result = thisScriptManager->registerCellTriggerEventForFactionToLocation(luaArguments.getInt(-2),luaArguments.getVec2i(-1)); + luaArguments.returnInt(result); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::registerCellAreaTriggerEventForFactionToLocation(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - int result = thisScriptManager->registerCellAreaTriggerEventForFactionToLocation(luaArguments.getInt(-2),luaArguments.getVec4i(-1)); - luaArguments.returnInt(result); + try { + int result = thisScriptManager->registerCellAreaTriggerEventForFactionToLocation(luaArguments.getInt(-2),luaArguments.getVec4i(-1)); + luaArguments.returnInt(result); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::registerCellAreaTriggerEvent(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - int result = thisScriptManager->registerCellAreaTriggerEvent(luaArguments.getVec4i(-1)); - luaArguments.returnInt(result); + try { + int result = thisScriptManager->registerCellAreaTriggerEvent(luaArguments.getVec4i(-1)); + luaArguments.returnInt(result); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::getCellTriggerEventCount(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - int result = thisScriptManager->getCellTriggerEventCount(luaArguments.getInt(-1)); - luaArguments.returnInt(result); + try { + int result = thisScriptManager->getCellTriggerEventCount(luaArguments.getInt(-1)); + luaArguments.returnInt(result); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::unregisterCellTriggerEvent(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - thisScriptManager->unregisterCellTriggerEvent(luaArguments.getInt(-1)); + try { + thisScriptManager->unregisterCellTriggerEvent(luaArguments.getInt(-1)); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::startTimerEvent(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - int result = thisScriptManager->startTimerEvent(); - luaArguments.returnInt(result); + try { + int result = thisScriptManager->startTimerEvent(); + luaArguments.returnInt(result); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::startEfficientTimerEvent(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - int result = thisScriptManager->startEfficientTimerEvent(luaArguments.getInt(-1)); - luaArguments.returnInt(result); + try { + int result = thisScriptManager->startEfficientTimerEvent(luaArguments.getInt(-1)); + luaArguments.returnInt(result); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::stopTimerEvent(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - int result = thisScriptManager->stopTimerEvent(luaArguments.getInt(-1)); - luaArguments.returnInt(result); + try { + int result = thisScriptManager->stopTimerEvent(luaArguments.getInt(-1)); + luaArguments.returnInt(result); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::resetTimerEvent(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - int result = thisScriptManager->resetTimerEvent(luaArguments.getInt(-1)); - luaArguments.returnInt(result); + try { + int result = thisScriptManager->resetTimerEvent(luaArguments.getInt(-1)); + luaArguments.returnInt(result); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::getTimerEventSecondsElapsed(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - int result = thisScriptManager->getTimerEventSecondsElapsed(luaArguments.getInt(-1)); - luaArguments.returnInt(result); + try { + int result = thisScriptManager->getTimerEventSecondsElapsed(luaArguments.getInt(-1)); + luaArguments.returnInt(result); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::setPlayerAsWinner(LuaHandle* luaHandle){ LuaArguments luaArguments(luaHandle); - thisScriptManager->setPlayerAsWinner(luaArguments.getInt(-1)); + try { + thisScriptManager->setPlayerAsWinner(luaArguments.getInt(-1)); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::endGame(LuaHandle* luaHandle){ LuaArguments luaArguments(luaHandle); - thisScriptManager->endGame(); + try { + thisScriptManager->endGame(); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::startPerformanceTimer(LuaHandle* luaHandle){ LuaArguments luaArguments(luaHandle); - thisScriptManager->startPerformanceTimer(); + try { + thisScriptManager->startPerformanceTimer(); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::endPerformanceTimer(LuaHandle* luaHandle){ LuaArguments luaArguments(luaHandle); - thisScriptManager->endPerformanceTimer(); + try { + thisScriptManager->endPerformanceTimer(); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::getPerformanceTimerResults(LuaHandle* luaHandle){ LuaArguments luaArguments(luaHandle); - Vec2i results= thisScriptManager->getPerformanceTimerResults(); - luaArguments.returnVec2i(results); + try { + Vec2i results= thisScriptManager->getPerformanceTimerResults(); + luaArguments.returnVec2i(results); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::getStartLocation(LuaHandle* luaHandle){ LuaArguments luaArguments(luaHandle); - Vec2i pos= thisScriptManager->getStartLocation(luaArguments.getInt(-1)); - luaArguments.returnVec2i(pos); + try { + Vec2i pos= thisScriptManager->getStartLocation(luaArguments.getInt(-1)); + luaArguments.returnVec2i(pos); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::getUnitPosition(LuaHandle* luaHandle){ LuaArguments luaArguments(luaHandle); - Vec2i pos= thisScriptManager->getUnitPosition(luaArguments.getInt(-1)); - luaArguments.returnVec2i(pos); + try { + Vec2i pos= thisScriptManager->getUnitPosition(luaArguments.getInt(-1)); + luaArguments.returnVec2i(pos); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::setUnitPosition(LuaHandle* luaHandle){ LuaArguments luaArguments(luaHandle); - thisScriptManager->setUnitPosition(luaArguments.getInt(-2),luaArguments.getVec2i(-1)); + try { + thisScriptManager->setUnitPosition(luaArguments.getInt(-2),luaArguments.getVec2i(-1)); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::addCellMarker(LuaHandle* luaHandle){ LuaArguments luaArguments(luaHandle); - //printf("LUA addCellMarker --> START\n"); + try { + //printf("LUA addCellMarker --> START\n"); - int factionIndex = luaArguments.getInt(-4); + int factionIndex = luaArguments.getInt(-4); - //printf("LUA addCellMarker --> START 1\n"); + //printf("LUA addCellMarker --> START 1\n"); - Vec2i pos = luaArguments.getVec2i(-1); + Vec2i pos = luaArguments.getVec2i(-1); - //printf("LUA addCellMarker --> START 2\n"); + //printf("LUA addCellMarker --> START 2\n"); - string note = luaArguments.getString(-3); + string note = luaArguments.getString(-3); - //printf("LUA addCellMarker --> START 3\n"); + //printf("LUA addCellMarker --> START 3\n"); - string texture = luaArguments.getString(-2); + string texture = luaArguments.getString(-2); - //printf("LUA addCellMarker --> faction [%d] pos [%s] note [%s] texture [%s]\n",factionIndex,pos.getString().c_str(),note.c_str(),texture.c_str()); + //printf("LUA addCellMarker --> faction [%d] pos [%s] note [%s] texture [%s]\n",factionIndex,pos.getString().c_str(),note.c_str(),texture.c_str()); + + thisScriptManager->addCellMarker(pos,factionIndex,note,texture); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } - thisScriptManager->addCellMarker(pos,factionIndex,note,texture); return luaArguments.getReturnCount(); } int ScriptManager::removeCellMarker(LuaHandle* luaHandle){ LuaArguments luaArguments(luaHandle); - int factionIndex = luaArguments.getInt(-2); - Vec2i pos = luaArguments.getVec2i(-1); + try { + int factionIndex = luaArguments.getInt(-2); + Vec2i pos = luaArguments.getVec2i(-1); + + thisScriptManager->removeCellMarker(pos,factionIndex); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } - thisScriptManager->removeCellMarker(pos,factionIndex); return luaArguments.getReturnCount(); } int ScriptManager::showMarker(LuaHandle* luaHandle){ LuaArguments luaArguments(luaHandle); - int flashCount = luaArguments.getInt(-5); - //printf("LUA addCellMarker --> START\n"); + try { + int flashCount = luaArguments.getInt(-5); + //printf("LUA addCellMarker --> START\n"); - int factionIndex = luaArguments.getInt(-4); + int factionIndex = luaArguments.getInt(-4); - //printf("LUA addCellMarker --> START 1\n"); + //printf("LUA addCellMarker --> START 1\n"); - Vec2i pos = luaArguments.getVec2i(-1); + Vec2i pos = luaArguments.getVec2i(-1); - //printf("LUA addCellMarker --> START 2\n"); + //printf("LUA addCellMarker --> START 2\n"); - string note = luaArguments.getString(-3); + string note = luaArguments.getString(-3); - //printf("LUA addCellMarker --> START 3\n"); + //printf("LUA addCellMarker --> START 3\n"); - string texture = luaArguments.getString(-2); + string texture = luaArguments.getString(-2); - //printf("LUA addCellMarker --> faction [%d] pos [%s] note [%s] texture [%s]\n",factionIndex,pos.getString().c_str(),note.c_str(),texture.c_str()); + //printf("LUA addCellMarker --> faction [%d] pos [%s] note [%s] texture [%s]\n",factionIndex,pos.getString().c_str(),note.c_str(),texture.c_str()); + + thisScriptManager->showMarker(pos,factionIndex,note,texture,flashCount); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } - thisScriptManager->showMarker(pos,factionIndex,note,texture,flashCount); return luaArguments.getReturnCount(); } int ScriptManager::getUnitFaction(LuaHandle* luaHandle){ LuaArguments luaArguments(luaHandle); - int factionIndex= thisScriptManager->getUnitFaction(luaArguments.getInt(-1)); - luaArguments.returnInt(factionIndex); + try { + int factionIndex= thisScriptManager->getUnitFaction(luaArguments.getInt(-1)); + luaArguments.returnInt(factionIndex); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::getUnitName(LuaHandle* luaHandle){ LuaArguments luaArguments(luaHandle); - const string unitname = thisScriptManager->getUnitName(luaArguments.getInt(-1)); - luaArguments.returnString(unitname); + try { + const string unitname = thisScriptManager->getUnitName(luaArguments.getInt(-1)); + luaArguments.returnString(unitname); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::getResourceAmount(LuaHandle* luaHandle){ LuaArguments luaArguments(luaHandle); - luaArguments.returnInt(thisScriptManager->getResourceAmount(luaArguments.getString(-2), luaArguments.getInt(-1))); + try { + luaArguments.returnInt(thisScriptManager->getResourceAmount(luaArguments.getString(-2), luaArguments.getInt(-1))); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::getLastCreatedUnitName(LuaHandle* luaHandle){ LuaArguments luaArguments(luaHandle); - luaArguments.returnString(thisScriptManager->getLastCreatedUnitName()); + try { + luaArguments.returnString(thisScriptManager->getLastCreatedUnitName()); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::getLastCreatedUnitId(LuaHandle* luaHandle){ LuaArguments luaArguments(luaHandle); - luaArguments.returnInt(thisScriptManager->getLastCreatedUnitId()); + try { + luaArguments.returnInt(thisScriptManager->getLastCreatedUnitId()); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::getCellTriggeredEventId(LuaHandle* luaHandle){ LuaArguments luaArguments(luaHandle); - luaArguments.returnInt(thisScriptManager->getCellTriggeredEventId()); + try { + luaArguments.returnInt(thisScriptManager->getCellTriggeredEventId()); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::getTimerTriggeredEventId(LuaHandle* luaHandle){ LuaArguments luaArguments(luaHandle); - luaArguments.returnInt(thisScriptManager->getTimerTriggeredEventId()); + try { + luaArguments.returnInt(thisScriptManager->getTimerTriggeredEventId()); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::getCellTriggeredEventAreaEntryUnitId(LuaHandle* luaHandle){ LuaArguments luaArguments(luaHandle); - luaArguments.returnInt(thisScriptManager->getCellTriggeredEventAreaEntryUnitId()); + try { + luaArguments.returnInt(thisScriptManager->getCellTriggeredEventAreaEntryUnitId()); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::getCellTriggeredEventAreaExitUnitId(LuaHandle* luaHandle){ LuaArguments luaArguments(luaHandle); - luaArguments.returnInt(thisScriptManager->getCellTriggeredEventAreaExitUnitId()); + try { + luaArguments.returnInt(thisScriptManager->getCellTriggeredEventAreaExitUnitId()); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::getCellTriggeredEventUnitId(LuaHandle* luaHandle){ LuaArguments luaArguments(luaHandle); - luaArguments.returnInt(thisScriptManager->getCellTriggeredEventUnitId()); + try { + luaArguments.returnInt(thisScriptManager->getCellTriggeredEventUnitId()); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::setRandomGenInit(LuaHandle* luaHandle){ LuaArguments luaArguments(luaHandle); - thisScriptManager->setRandomGenInit(luaArguments.getInt(-1)); + try { + thisScriptManager->setRandomGenInit(luaArguments.getInt(-1)); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::getRandomGen(LuaHandle* luaHandle){ LuaArguments luaArguments(luaHandle); - luaArguments.returnInt(thisScriptManager->getRandomGen(luaArguments.getInt(-2),luaArguments.getInt(-1))); + try { + luaArguments.returnInt(thisScriptManager->getRandomGen(luaArguments.getInt(-2),luaArguments.getInt(-1))); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::getWorldFrameCount(LuaHandle* luaHandle){ LuaArguments luaArguments(luaHandle); - luaArguments.returnInt(thisScriptManager->getWorldFrameCount()); + try { + luaArguments.returnInt(thisScriptManager->getWorldFrameCount()); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::getLastDeadUnitName(LuaHandle* luaHandle){ LuaArguments luaArguments(luaHandle); - luaArguments.returnString(thisScriptManager->getLastDeadUnitName()); + try { + luaArguments.returnString(thisScriptManager->getLastDeadUnitName()); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::getLastDeadUnitId(LuaHandle* luaHandle){ LuaArguments luaArguments(luaHandle); - luaArguments.returnInt(thisScriptManager->getLastDeadUnitId()); + try { + luaArguments.returnInt(thisScriptManager->getLastDeadUnitId()); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::getLastDeadUnitCauseOfDeath(LuaHandle* luaHandle){ LuaArguments luaArguments(luaHandle); - luaArguments.returnInt(thisScriptManager->getLastDeadUnitCauseOfDeath()); + try { + luaArguments.returnInt(thisScriptManager->getLastDeadUnitCauseOfDeath()); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::getLastDeadUnitKillerName(LuaHandle* luaHandle){ LuaArguments luaArguments(luaHandle); - luaArguments.returnString(thisScriptManager->getLastDeadUnitKillerName()); + try { + luaArguments.returnString(thisScriptManager->getLastDeadUnitKillerName()); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::getLastDeadUnitKillerId(LuaHandle* luaHandle){ LuaArguments luaArguments(luaHandle); - luaArguments.returnInt(thisScriptManager->getLastDeadUnitKillerId()); + try { + luaArguments.returnInt(thisScriptManager->getLastDeadUnitKillerId()); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::getLastAttackedUnitName(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - luaArguments.returnString(thisScriptManager->getLastAttackedUnitName()); + try { + luaArguments.returnString(thisScriptManager->getLastAttackedUnitName()); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::getLastAttackedUnitId(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - luaArguments.returnInt(thisScriptManager->getLastAttackedUnitId()); + try { + luaArguments.returnInt(thisScriptManager->getLastAttackedUnitId()); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::getLastAttackingUnitName(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - luaArguments.returnString(thisScriptManager->getLastAttackingUnitName()); + try { + luaArguments.returnString(thisScriptManager->getLastAttackingUnitName()); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::getLastAttackingUnitId(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - luaArguments.returnInt(thisScriptManager->getLastAttackingUnitId()); + try { + luaArguments.returnInt(thisScriptManager->getLastAttackingUnitId()); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::getSystemMacroValue(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - luaArguments.returnString(thisScriptManager->getSystemMacroValue(luaArguments.getString(-1))); + try { + luaArguments.returnString(thisScriptManager->getSystemMacroValue(luaArguments.getString(-1))); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::scenarioDir(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - luaArguments.returnString(thisScriptManager->getSystemMacroValue("$SCENARIO_PATH")); + try { + luaArguments.returnString(thisScriptManager->getSystemMacroValue("$SCENARIO_PATH")); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::getPlayerName(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - luaArguments.returnString(thisScriptManager->getPlayerName(luaArguments.getInt(-1))); + try { + luaArguments.returnString(thisScriptManager->getPlayerName(luaArguments.getInt(-1))); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::getUnitCount(LuaHandle* luaHandle){ LuaArguments luaArguments(luaHandle); - luaArguments.returnInt(thisScriptManager->getUnitCount(luaArguments.getInt(-1))); + try { + luaArguments.returnInt(thisScriptManager->getUnitCount(luaArguments.getInt(-1))); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::getUnitCountOfType(LuaHandle* luaHandle){ LuaArguments luaArguments(luaHandle); - luaArguments.returnInt(thisScriptManager->getUnitCountOfType(luaArguments.getInt(-2), luaArguments.getString(-1))); + try { + luaArguments.returnInt(thisScriptManager->getUnitCountOfType(luaArguments.getInt(-2), luaArguments.getString(-1))); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::DisplayFormattedText(LuaHandle* luaHandle) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); - //const char *ret; - //lua_lock(luaHandle); - //luaC_checkGC(luaHandle); + try { + //const char *ret; + //lua_lock(luaHandle); + //luaC_checkGC(luaHandle); - int args = lua_gettop(luaHandle); - if(lua_checkstack(luaHandle, args+1)) { - LuaArguments luaArguments(luaHandle); - string fmt = luaArguments.getString(-args); - //va_list argList; - //va_start(argList, fmt.c_str() ); + int args = lua_gettop(luaHandle); + if(lua_checkstack(luaHandle, args+1)) { + LuaArguments luaArguments(luaHandle); + string fmt = luaArguments.getString(-args); + //va_list argList; + //va_start(argList, fmt.c_str() ); - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"DisplayFormattedText args = %d!\n",args); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"DisplayFormattedText args = %d!\n",args); - const int max_args_allowed = 8; - if(args == 1) { - thisScriptManager->DisplayFormattedText(fmt.c_str()); - } - else if(args == 2) { - thisScriptManager->DisplayFormattedText(fmt.c_str(), - luaArguments.getGenericData(-args+1)); - } - else if(args == 3) { - thisScriptManager->DisplayFormattedText(fmt.c_str(), - luaArguments.getGenericData(-args+1), - luaArguments.getGenericData(-args+2)); - } - else if(args == 4) { - thisScriptManager->DisplayFormattedText(fmt.c_str(), - luaArguments.getGenericData(-args+1), - luaArguments.getGenericData(-args+2), - luaArguments.getGenericData(-args+3)); - } - else if(args == 5) { - thisScriptManager->DisplayFormattedText(fmt.c_str(), - luaArguments.getGenericData(-args+1), - luaArguments.getGenericData(-args+2), - luaArguments.getGenericData(-args+3), - luaArguments.getGenericData(-args+4)); - } - else if(args == 6) { - thisScriptManager->DisplayFormattedText(fmt.c_str(), - luaArguments.getGenericData(-args+1), - luaArguments.getGenericData(-args+2), - luaArguments.getGenericData(-args+3), - luaArguments.getGenericData(-args+4), - luaArguments.getGenericData(-args+5)); - } - else if(args == 7) { - thisScriptManager->DisplayFormattedText(fmt.c_str(), - luaArguments.getGenericData(-args+1), - luaArguments.getGenericData(-args+2), - luaArguments.getGenericData(-args+3), - luaArguments.getGenericData(-args+4), - luaArguments.getGenericData(-args+5), - luaArguments.getGenericData(-args+6)); - } - else if(args == max_args_allowed) { - thisScriptManager->DisplayFormattedText(fmt.c_str(), - luaArguments.getGenericData(-args+1), - luaArguments.getGenericData(-args+2), - luaArguments.getGenericData(-args+3), - luaArguments.getGenericData(-args+4), - luaArguments.getGenericData(-args+5), - luaArguments.getGenericData(-args+6), - luaArguments.getGenericData(-args+7)); - } - else { - char szBuf[8096]=""; - snprintf(szBuf,8096,"Invalid parameter count in method [%s] args = %d [argument count must be between 1 and %d]",__FUNCTION__,args,max_args_allowed); - throw megaglest_runtime_error(szBuf); - } + const int max_args_allowed = 8; + if(args == 1) { + thisScriptManager->DisplayFormattedText(fmt.c_str()); + } + else if(args == 2) { + thisScriptManager->DisplayFormattedText(fmt.c_str(), + luaArguments.getGenericData(-args+1)); + } + else if(args == 3) { + thisScriptManager->DisplayFormattedText(fmt.c_str(), + luaArguments.getGenericData(-args+1), + luaArguments.getGenericData(-args+2)); + } + else if(args == 4) { + thisScriptManager->DisplayFormattedText(fmt.c_str(), + luaArguments.getGenericData(-args+1), + luaArguments.getGenericData(-args+2), + luaArguments.getGenericData(-args+3)); + } + else if(args == 5) { + thisScriptManager->DisplayFormattedText(fmt.c_str(), + luaArguments.getGenericData(-args+1), + luaArguments.getGenericData(-args+2), + luaArguments.getGenericData(-args+3), + luaArguments.getGenericData(-args+4)); + } + else if(args == 6) { + thisScriptManager->DisplayFormattedText(fmt.c_str(), + luaArguments.getGenericData(-args+1), + luaArguments.getGenericData(-args+2), + luaArguments.getGenericData(-args+3), + luaArguments.getGenericData(-args+4), + luaArguments.getGenericData(-args+5)); + } + else if(args == 7) { + thisScriptManager->DisplayFormattedText(fmt.c_str(), + luaArguments.getGenericData(-args+1), + luaArguments.getGenericData(-args+2), + luaArguments.getGenericData(-args+3), + luaArguments.getGenericData(-args+4), + luaArguments.getGenericData(-args+5), + luaArguments.getGenericData(-args+6)); + } + else if(args == max_args_allowed) { + thisScriptManager->DisplayFormattedText(fmt.c_str(), + luaArguments.getGenericData(-args+1), + luaArguments.getGenericData(-args+2), + luaArguments.getGenericData(-args+3), + luaArguments.getGenericData(-args+4), + luaArguments.getGenericData(-args+5), + luaArguments.getGenericData(-args+6), + luaArguments.getGenericData(-args+7)); + } + else { + char szBuf[8096]=""; + snprintf(szBuf,8096,"Invalid parameter count in method [%s] args = %d [argument count must be between 1 and %d]",__FUNCTION__,args,max_args_allowed); + throw megaglest_runtime_error(szBuf); + } - //va_end(argList); - } - //lua_unlock(luaHandle); - return 1; + //va_end(argList); + } + //lua_unlock(luaHandle); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + + return 1; /* int args=lua_gettop(luaHandle); @@ -2703,370 +3952,862 @@ int ScriptManager::DisplayFormattedText(LuaHandle* luaHandle) { return 0; */ } + int ScriptManager::addConsoleLangText(LuaHandle* luaHandle){ -if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); - //const char *ret; - //lua_lock(luaHandle); - //luaC_checkGC(luaHandle); + try { + //const char *ret; + //lua_lock(luaHandle); + //luaC_checkGC(luaHandle); - int args = lua_gettop(luaHandle); - if(lua_checkstack(luaHandle, args+1)) { - LuaArguments luaArguments(luaHandle); - string fmt = luaArguments.getString(-args); - //va_list argList; - //va_start(argList, fmt.c_str() ); + int args = lua_gettop(luaHandle); + if(lua_checkstack(luaHandle, args+1)) { + LuaArguments luaArguments(luaHandle); + string fmt = luaArguments.getString(-args); + //va_list argList; + //va_start(argList, fmt.c_str() ); - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"DisplayFormattedText args = %d!\n",args); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"DisplayFormattedText args = %d!\n",args); - const int max_args_allowed = 8; - if(args == 1) { - thisScriptManager->addConsoleLangText(Lang::getInstance().getScenarioString(fmt).c_str()); - } - else if(args == 2) { - thisScriptManager->addConsoleLangText(Lang::getInstance().getScenarioString(fmt).c_str(), - luaArguments.getGenericData(-args+1)); - } - else if(args == 3) { - thisScriptManager->addConsoleLangText(Lang::getInstance().getScenarioString(fmt).c_str(), - luaArguments.getGenericData(-args+1), - luaArguments.getGenericData(-args+2)); - } - else if(args == 4) { - thisScriptManager->addConsoleLangText(Lang::getInstance().getScenarioString(fmt).c_str(), - luaArguments.getGenericData(-args+1), - luaArguments.getGenericData(-args+2), - luaArguments.getGenericData(-args+3)); - } - else if(args == 5) { - thisScriptManager->addConsoleLangText(Lang::getInstance().getScenarioString(fmt).c_str(), - luaArguments.getGenericData(-args+1), - luaArguments.getGenericData(-args+2), - luaArguments.getGenericData(-args+3), - luaArguments.getGenericData(-args+4)); - } - else if(args == 6) { - thisScriptManager->addConsoleLangText(Lang::getInstance().getScenarioString(fmt).c_str(), - luaArguments.getGenericData(-args+1), - luaArguments.getGenericData(-args+2), - luaArguments.getGenericData(-args+3), - luaArguments.getGenericData(-args+4), - luaArguments.getGenericData(-args+5)); - } - else if(args == 7) { - thisScriptManager->addConsoleLangText(Lang::getInstance().getScenarioString(fmt).c_str(), - luaArguments.getGenericData(-args+1), - luaArguments.getGenericData(-args+2), - luaArguments.getGenericData(-args+3), - luaArguments.getGenericData(-args+4), - luaArguments.getGenericData(-args+5), - luaArguments.getGenericData(-args+6)); - } - else if(args == max_args_allowed) { - thisScriptManager->addConsoleLangText(Lang::getInstance().getScenarioString(fmt).c_str(), - luaArguments.getGenericData(-args+1), - luaArguments.getGenericData(-args+2), - luaArguments.getGenericData(-args+3), - luaArguments.getGenericData(-args+4), - luaArguments.getGenericData(-args+5), - luaArguments.getGenericData(-args+6), - luaArguments.getGenericData(-args+7)); - } - else { - char szBuf[8096]=""; - snprintf(szBuf,8096,"Invalid parameter count in method [%s] args = %d [argument count must be between 1 and %d]",__FUNCTION__,args,max_args_allowed); - throw megaglest_runtime_error(szBuf); - } + const int max_args_allowed = 8; + if(args == 1) { + thisScriptManager->addConsoleLangText(Lang::getInstance().getScenarioString(fmt).c_str()); + } + else if(args == 2) { + thisScriptManager->addConsoleLangText(Lang::getInstance().getScenarioString(fmt).c_str(), + luaArguments.getGenericData(-args+1)); + } + else if(args == 3) { + thisScriptManager->addConsoleLangText(Lang::getInstance().getScenarioString(fmt).c_str(), + luaArguments.getGenericData(-args+1), + luaArguments.getGenericData(-args+2)); + } + else if(args == 4) { + thisScriptManager->addConsoleLangText(Lang::getInstance().getScenarioString(fmt).c_str(), + luaArguments.getGenericData(-args+1), + luaArguments.getGenericData(-args+2), + luaArguments.getGenericData(-args+3)); + } + else if(args == 5) { + thisScriptManager->addConsoleLangText(Lang::getInstance().getScenarioString(fmt).c_str(), + luaArguments.getGenericData(-args+1), + luaArguments.getGenericData(-args+2), + luaArguments.getGenericData(-args+3), + luaArguments.getGenericData(-args+4)); + } + else if(args == 6) { + thisScriptManager->addConsoleLangText(Lang::getInstance().getScenarioString(fmt).c_str(), + luaArguments.getGenericData(-args+1), + luaArguments.getGenericData(-args+2), + luaArguments.getGenericData(-args+3), + luaArguments.getGenericData(-args+4), + luaArguments.getGenericData(-args+5)); + } + else if(args == 7) { + thisScriptManager->addConsoleLangText(Lang::getInstance().getScenarioString(fmt).c_str(), + luaArguments.getGenericData(-args+1), + luaArguments.getGenericData(-args+2), + luaArguments.getGenericData(-args+3), + luaArguments.getGenericData(-args+4), + luaArguments.getGenericData(-args+5), + luaArguments.getGenericData(-args+6)); + } + else if(args == max_args_allowed) { + thisScriptManager->addConsoleLangText(Lang::getInstance().getScenarioString(fmt).c_str(), + luaArguments.getGenericData(-args+1), + luaArguments.getGenericData(-args+2), + luaArguments.getGenericData(-args+3), + luaArguments.getGenericData(-args+4), + luaArguments.getGenericData(-args+5), + luaArguments.getGenericData(-args+6), + luaArguments.getGenericData(-args+7)); + } + else { + char szBuf[8096]=""; + snprintf(szBuf,8096,"Invalid parameter count in method [%s] args = %d [argument count must be between 1 and %d]",__FUNCTION__,args,max_args_allowed); + throw megaglest_runtime_error(szBuf); + } - //va_end(argList); - } - //lua_unlock(luaHandle); - return 1; + //va_end(argList); + } + //lua_unlock(luaHandle); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + + return 1; } + int ScriptManager::DisplayFormattedLangText(LuaHandle* luaHandle) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); - //const char *ret; - //lua_lock(luaHandle); - //luaC_checkGC(luaHandle); + try { + //const char *ret; + //lua_lock(luaHandle); + //luaC_checkGC(luaHandle); - int args = lua_gettop(luaHandle); - if(lua_checkstack(luaHandle, args+1)) { - LuaArguments luaArguments(luaHandle); - string fmt = luaArguments.getString(-args); - //va_list argList; - //va_start(argList, fmt.c_str() ); + int args = lua_gettop(luaHandle); + if(lua_checkstack(luaHandle, args+1)) { + LuaArguments luaArguments(luaHandle); + string fmt = luaArguments.getString(-args); + //va_list argList; + //va_start(argList, fmt.c_str() ); - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"DisplayFormattedText args = %d!\n",args); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"DisplayFormattedText args = %d!\n",args); - const int max_args_allowed = 8; - if(args == 1) { - thisScriptManager->DisplayFormattedLangText(Lang::getInstance().getScenarioString(fmt).c_str()); - } - else if(args == 2) { - thisScriptManager->DisplayFormattedLangText(Lang::getInstance().getScenarioString(fmt).c_str(), - luaArguments.getGenericData(-args+1)); - } - else if(args == 3) { - thisScriptManager->DisplayFormattedLangText(Lang::getInstance().getScenarioString(fmt).c_str(), - luaArguments.getGenericData(-args+1), - luaArguments.getGenericData(-args+2)); - } - else if(args == 4) { - thisScriptManager->DisplayFormattedLangText(Lang::getInstance().getScenarioString(fmt).c_str(), - luaArguments.getGenericData(-args+1), - luaArguments.getGenericData(-args+2), - luaArguments.getGenericData(-args+3)); - } - else if(args == 5) { - thisScriptManager->DisplayFormattedLangText(Lang::getInstance().getScenarioString(fmt).c_str(), - luaArguments.getGenericData(-args+1), - luaArguments.getGenericData(-args+2), - luaArguments.getGenericData(-args+3), - luaArguments.getGenericData(-args+4)); - } - else if(args == 6) { - thisScriptManager->DisplayFormattedLangText(Lang::getInstance().getScenarioString(fmt).c_str(), - luaArguments.getGenericData(-args+1), - luaArguments.getGenericData(-args+2), - luaArguments.getGenericData(-args+3), - luaArguments.getGenericData(-args+4), - luaArguments.getGenericData(-args+5)); - } - else if(args == 7) { - thisScriptManager->DisplayFormattedLangText(Lang::getInstance().getScenarioString(fmt).c_str(), - luaArguments.getGenericData(-args+1), - luaArguments.getGenericData(-args+2), - luaArguments.getGenericData(-args+3), - luaArguments.getGenericData(-args+4), - luaArguments.getGenericData(-args+5), - luaArguments.getGenericData(-args+6)); - } - else if(args == max_args_allowed) { - thisScriptManager->DisplayFormattedLangText(Lang::getInstance().getScenarioString(fmt).c_str(), - luaArguments.getGenericData(-args+1), - luaArguments.getGenericData(-args+2), - luaArguments.getGenericData(-args+3), - luaArguments.getGenericData(-args+4), - luaArguments.getGenericData(-args+5), - luaArguments.getGenericData(-args+6), - luaArguments.getGenericData(-args+7)); - } - else { - char szBuf[8096]=""; - snprintf(szBuf,8096,"Invalid parameter count in method [%s] args = %d [argument count must be between 1 and %d]",__FUNCTION__,args,max_args_allowed); - throw megaglest_runtime_error(szBuf); - } + const int max_args_allowed = 8; + if(args == 1) { + thisScriptManager->DisplayFormattedLangText(Lang::getInstance().getScenarioString(fmt).c_str()); + } + else if(args == 2) { + thisScriptManager->DisplayFormattedLangText(Lang::getInstance().getScenarioString(fmt).c_str(), + luaArguments.getGenericData(-args+1)); + } + else if(args == 3) { + thisScriptManager->DisplayFormattedLangText(Lang::getInstance().getScenarioString(fmt).c_str(), + luaArguments.getGenericData(-args+1), + luaArguments.getGenericData(-args+2)); + } + else if(args == 4) { + thisScriptManager->DisplayFormattedLangText(Lang::getInstance().getScenarioString(fmt).c_str(), + luaArguments.getGenericData(-args+1), + luaArguments.getGenericData(-args+2), + luaArguments.getGenericData(-args+3)); + } + else if(args == 5) { + thisScriptManager->DisplayFormattedLangText(Lang::getInstance().getScenarioString(fmt).c_str(), + luaArguments.getGenericData(-args+1), + luaArguments.getGenericData(-args+2), + luaArguments.getGenericData(-args+3), + luaArguments.getGenericData(-args+4)); + } + else if(args == 6) { + thisScriptManager->DisplayFormattedLangText(Lang::getInstance().getScenarioString(fmt).c_str(), + luaArguments.getGenericData(-args+1), + luaArguments.getGenericData(-args+2), + luaArguments.getGenericData(-args+3), + luaArguments.getGenericData(-args+4), + luaArguments.getGenericData(-args+5)); + } + else if(args == 7) { + thisScriptManager->DisplayFormattedLangText(Lang::getInstance().getScenarioString(fmt).c_str(), + luaArguments.getGenericData(-args+1), + luaArguments.getGenericData(-args+2), + luaArguments.getGenericData(-args+3), + luaArguments.getGenericData(-args+4), + luaArguments.getGenericData(-args+5), + luaArguments.getGenericData(-args+6)); + } + else if(args == max_args_allowed) { + thisScriptManager->DisplayFormattedLangText(Lang::getInstance().getScenarioString(fmt).c_str(), + luaArguments.getGenericData(-args+1), + luaArguments.getGenericData(-args+2), + luaArguments.getGenericData(-args+3), + luaArguments.getGenericData(-args+4), + luaArguments.getGenericData(-args+5), + luaArguments.getGenericData(-args+6), + luaArguments.getGenericData(-args+7)); + } + else { + char szBuf[8096]=""; + snprintf(szBuf,8096,"Invalid parameter count in method [%s] args = %d [argument count must be between 1 and %d]",__FUNCTION__,args,max_args_allowed); + throw megaglest_runtime_error(szBuf); + } - //va_end(argList); - } - //lua_unlock(luaHandle); - return 1; + //va_end(argList); + } + //lua_unlock(luaHandle); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + + return 1; } + int ScriptManager::getGameWon(LuaHandle* luaHandle){ LuaArguments luaArguments(luaHandle); - luaArguments.returnInt(thisScriptManager->getGameWon()); + try { + luaArguments.returnInt(thisScriptManager->getGameWon()); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::getIsGameOver(LuaHandle* luaHandle){ LuaArguments luaArguments(luaHandle); - luaArguments.returnInt(thisScriptManager->getIsGameOver()); + try { + luaArguments.returnInt(thisScriptManager->getIsGameOver()); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::loadScenario(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - thisScriptManager->loadScenario(luaArguments.getString(-2),luaArguments.getInt(-1) != 0); + try { + thisScriptManager->loadScenario(luaArguments.getString(-2),luaArguments.getInt(-1) != 0); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::getUnitsForFaction(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - vector units= thisScriptManager->getUnitsForFaction(luaArguments.getInt(-3),luaArguments.getString(-2), luaArguments.getInt(-1)); - luaArguments.returnVectorInt(units); + try { + vector units= thisScriptManager->getUnitsForFaction(luaArguments.getInt(-3),luaArguments.getString(-2), luaArguments.getInt(-1)); + luaArguments.returnVectorInt(units); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::getUnitCurrentField(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - luaArguments.returnInt(thisScriptManager->getUnitCurrentField(luaArguments.getInt(-1))); + try { + luaArguments.returnInt(thisScriptManager->getUnitCurrentField(luaArguments.getInt(-1))); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::getIsUnitAlive(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - luaArguments.returnInt(thisScriptManager->getIsUnitAlive(luaArguments.getInt(-1))); + try { + luaArguments.returnInt(thisScriptManager->getIsUnitAlive(luaArguments.getInt(-1))); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::isFreeCellsOrHasUnit(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - int result= thisScriptManager->isFreeCellsOrHasUnit( - luaArguments.getInt(-3), - luaArguments.getInt(-2), - luaArguments.getVec2i(-1)); + try { + int result= thisScriptManager->isFreeCellsOrHasUnit( + luaArguments.getInt(-3), + luaArguments.getInt(-2), + luaArguments.getVec2i(-1)); + + luaArguments.returnInt(result); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } - luaArguments.returnInt(result); return luaArguments.getReturnCount(); } int ScriptManager::isFreeCells(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - int result= thisScriptManager->isFreeCells( - luaArguments.getInt(-3), - luaArguments.getInt(-2), - luaArguments.getVec2i(-1)); + try { + int result= thisScriptManager->isFreeCells( + luaArguments.getInt(-3), + luaArguments.getInt(-2), + luaArguments.getVec2i(-1)); + + luaArguments.returnInt(result); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } - luaArguments.returnInt(result); return luaArguments.getReturnCount(); } int ScriptManager::getHumanFactionId(LuaHandle* luaHandle) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); LuaArguments luaArguments(luaHandle); - luaArguments.returnInt(thisScriptManager->getHumanFactionId()); + try { + luaArguments.returnInt(thisScriptManager->getHumanFactionId()); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::highlightUnit(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - thisScriptManager->highlightUnit(luaArguments.getInt(-4), luaArguments.getFloat(-3), luaArguments.getFloat(-2), luaArguments.getVec4f(-1)); + try { + thisScriptManager->highlightUnit(luaArguments.getInt(-4), luaArguments.getFloat(-3), luaArguments.getFloat(-2), luaArguments.getVec4f(-1)); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::unhighlightUnit(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - thisScriptManager->unhighlightUnit(luaArguments.getInt(-1)); + try { + thisScriptManager->unhighlightUnit(luaArguments.getInt(-1)); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::giveStopCommand(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - thisScriptManager->giveStopCommand(luaArguments.getInt(-1)); + try { + thisScriptManager->giveStopCommand(luaArguments.getInt(-1)); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::selectUnit(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - luaArguments.returnInt(thisScriptManager->selectUnit(luaArguments.getInt(-1))); + try { + luaArguments.returnInt(thisScriptManager->selectUnit(luaArguments.getInt(-1))); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::unselectUnit(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - thisScriptManager->unselectUnit(luaArguments.getInt(-1)); + try { + thisScriptManager->unselectUnit(luaArguments.getInt(-1)); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::addUnitToGroupSelection(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - thisScriptManager->addUnitToGroupSelection(luaArguments.getInt(-2),luaArguments.getInt(-1)); + try { + thisScriptManager->addUnitToGroupSelection(luaArguments.getInt(-2),luaArguments.getInt(-1)); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::recallGroupSelection(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - thisScriptManager->recallGroupSelection(luaArguments.getInt(-1)); + try { + thisScriptManager->recallGroupSelection(luaArguments.getInt(-1)); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::removeUnitFromGroupSelection(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - thisScriptManager->removeUnitFromGroupSelection(luaArguments.getInt(-2),luaArguments.getInt(-1)); + try { + thisScriptManager->removeUnitFromGroupSelection(luaArguments.getInt(-2),luaArguments.getInt(-1)); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::setAttackWarningsEnabled(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - thisScriptManager->setAttackWarningsEnabled((luaArguments.getInt(-1) == 0 ? false : true)); + try { + thisScriptManager->setAttackWarningsEnabled((luaArguments.getInt(-1) == 0 ? false : true)); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::getAttackWarningsEnabled(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - luaArguments.returnInt(thisScriptManager->getAttackWarningsEnabled()); + try { + luaArguments.returnInt(thisScriptManager->getAttackWarningsEnabled()); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::getIsDayTime(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - luaArguments.returnInt(thisScriptManager->getIsDayTime()); + try { + luaArguments.returnInt(thisScriptManager->getIsDayTime()); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::getIsNightTime(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - luaArguments.returnInt(thisScriptManager->getIsNightTime()); + try { + luaArguments.returnInt(thisScriptManager->getIsNightTime()); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::getTimeOfDay(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - luaArguments.returnFloat(thisScriptManager->getTimeOfDay()); + try { + luaArguments.returnFloat(thisScriptManager->getTimeOfDay()); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::registerDayNightEvent(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - thisScriptManager->registerDayNightEvent(); + try { + thisScriptManager->registerDayNightEvent(); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::unregisterDayNightEvent(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - thisScriptManager->unregisterDayNightEvent(); + try { + thisScriptManager->unregisterDayNightEvent(); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::registerUnitTriggerEvent(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - thisScriptManager->registerUnitTriggerEvent(luaArguments.getInt(-1)); + try { + thisScriptManager->registerUnitTriggerEvent(luaArguments.getInt(-1)); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::unregisterUnitTriggerEvent(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - thisScriptManager->unregisterUnitTriggerEvent(luaArguments.getInt(-1)); + try { + thisScriptManager->unregisterUnitTriggerEvent(luaArguments.getInt(-1)); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::getLastUnitTriggerEventUnitId(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - luaArguments.returnInt(thisScriptManager->getLastUnitTriggerEventUnitId()); + try { + luaArguments.returnInt(thisScriptManager->getLastUnitTriggerEventUnitId()); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::getLastUnitTriggerEventType(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - luaArguments.returnInt(static_cast(thisScriptManager->getLastUnitTriggerEventType())); + try { + luaArguments.returnInt(static_cast(thisScriptManager->getLastUnitTriggerEventType())); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::getUnitProperty(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - int value = thisScriptManager->getUnitProperty(luaArguments.getInt(-2),static_cast(luaArguments.getInt(-1))); - luaArguments.returnInt(value); + try { + int value = thisScriptManager->getUnitProperty(luaArguments.getInt(-2),static_cast(luaArguments.getInt(-1))); + luaArguments.returnInt(value); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::getUnitPropertyName(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - const string unitname = thisScriptManager->getUnitPropertyName(luaArguments.getInt(-2),static_cast(luaArguments.getInt(-1))); - luaArguments.returnString(unitname); + try { + const string unitname = thisScriptManager->getUnitPropertyName(luaArguments.getInt(-2),static_cast(luaArguments.getInt(-1))); + luaArguments.returnString(unitname); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::disableSpeedChange(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - thisScriptManager->disableSpeedChange(); + try { + thisScriptManager->disableSpeedChange(); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::enableSpeedChange(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - thisScriptManager->enableSpeedChange(); + try { + thisScriptManager->enableSpeedChange(); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } int ScriptManager::getSpeedChangeEnabled(LuaHandle* luaHandle) { LuaArguments luaArguments(luaHandle); - luaArguments.returnInt(thisScriptManager->getSpeedChangeEnabled()); + try { + luaArguments.returnInt(thisScriptManager->getSpeedChangeEnabled()); + } + catch(const megaglest_runtime_error &ex) { + char szErrBuf[8096]=""; + snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n"); + + SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str()); + + thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error")); + thisScriptManager->onMessageBoxOk(false); + } + return luaArguments.getReturnCount(); } diff --git a/source/glest_game/game/script_manager.h b/source/glest_game/game/script_manager.h index 903b6a37..6de1f58d 100644 --- a/source/glest_game/game/script_manager.h +++ b/source/glest_game/game/script_manager.h @@ -230,6 +230,7 @@ public: void init(World* world, GameCamera *gameCamera,const XmlNode *rootNode); //message box functions + void addMessageToQueue(ScriptManagerMessage msg); bool getMessageBoxEnabled() const {return !messageQueue.empty();} GraphicMessageBox* getMessageBox() {return &messageBox;} string getDisplayText() const {return displayText;} diff --git a/source/glest_game/global/config.cpp b/source/glest_game/global/config.cpp index f0672e97..6130dfe7 100644 --- a/source/glest_game/global/config.cpp +++ b/source/glest_game/global/config.cpp @@ -748,6 +748,10 @@ vector Config::getPathListForType(PathType type, string scenarioDir) { } } if(scenarioDir != "") { + if(EndsWith(scenarioDir, ".xml") == true) { + scenarioDir = extractDirectoryPathFromFile(scenarioDir); + } + //string scenarioLocation = data_path + scenarioDir; string scenarioLocation = scenarioDir; if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Scenario path [%s]\n",scenarioLocation.c_str()); diff --git a/source/glest_game/menu/menu_state_scenario.cpp b/source/glest_game/menu/menu_state_scenario.cpp index a44b7446..2a6e8fd1 100644 --- a/source/glest_game/menu/menu_state_scenario.cpp +++ b/source/glest_game/menu/menu_state_scenario.cpp @@ -379,6 +379,8 @@ void MenuStateScenario::launchGame() { GameSettings gameSettings; loadGameSettings(&scenarioInfo, &gameSettings); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] gameSettings.getScenarioDir() [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,gameSettings.getScenarioDir().c_str()); + const vector pathTechList = Config::getInstance().getPathListForType(ptTechs,gameSettings.getScenarioDir()); if(TechTree::exists(gameSettings.getTech(), pathTechList) == false) { char szBuf[8096]=""; diff --git a/source/shared_lib/sources/platform/common/simple_threads.cpp b/source/shared_lib/sources/platform/common/simple_threads.cpp index 75233952..4f61d32c 100644 --- a/source/shared_lib/sources/platform/common/simple_threads.cpp +++ b/source/shared_lib/sources/platform/common/simple_threads.cpp @@ -97,7 +97,7 @@ bool FileCRCPreCacheThread::canShutdown(bool deleteSelfIfShutdownDelayed) { void FileCRCPreCacheThread::execute() { { RunningStatusSafeWrapper runningStatus(this); - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); if(getQuitStatus() == true) { deleteSelfIfRequired(); @@ -126,20 +126,20 @@ void FileCRCPreCacheThread::execute() { techPaths.erase(iterFindMegaPack); techPaths.insert(techPaths.begin(),megapackTechtreeName); - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] Found megapack techtree and placing it at the TOP of the list\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] Found megapack techtree and placing it at the TOP of the list\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); } unsigned int techsPerWorker = ((unsigned int)techPaths.size() / (unsigned int)MAX_FileCRCPreCacheThread_WORKER_THREADS); if(techPaths.size() % MAX_FileCRCPreCacheThread_WORKER_THREADS != 0) { techsPerWorker++; } - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] techsPerWorker = %u, MAX_FileCRCPreCacheThread_WORKER_THREADS = %d, techPaths.size() = %d\n",__FILE__,__FUNCTION__,__LINE__,techsPerWorker,MAX_FileCRCPreCacheThread_WORKER_THREADS,(int)techPaths.size()); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] techsPerWorker = %u, MAX_FileCRCPreCacheThread_WORKER_THREADS = %d, techPaths.size() = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,techsPerWorker,MAX_FileCRCPreCacheThread_WORKER_THREADS,(int)techPaths.size()); try { unsigned int consumedWorkers = 0; for(unsigned int workerIdx = 0; workerIdx < (unsigned int)MAX_FileCRCPreCacheThread_WORKER_THREADS; ++workerIdx) { if(getQuitStatus() == true) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); break; } @@ -154,10 +154,10 @@ void FileCRCPreCacheThread::execute() { string techName = techPaths[idx]; workerTechList.push_back(techName); - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] Spawning CRC thread for Tech [%s] [%d of %d]\n",__FILE__,__FUNCTION__,__LINE__,techName.c_str(),idx+1,(int)techPaths.size()); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] Spawning CRC thread for Tech [%s] [%d of %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,techName.c_str(),idx+1,(int)techPaths.size()); } - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] workerIdx = %u, currentWorkerMax = %u, endConsumerIndex = %u\n",__FILE__,__FUNCTION__,__LINE__,workerIdx,currentWorkerMax,endConsumerIndex); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] workerIdx = %u, currentWorkerMax = %u, endConsumerIndex = %u\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,workerIdx,currentWorkerMax,endConsumerIndex); // Pause before launching this worker thread if(SystemFlags::VERBOSE_MODE_ENABLED) printf("About to process CRC for factions waiting...\n"); @@ -168,7 +168,7 @@ void FileCRCPreCacheThread::execute() { sleep(25); } if(getQuitStatus() == true) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); break; } @@ -190,7 +190,7 @@ void FileCRCPreCacheThread::execute() { consumedWorkers += currentWorkerMax; - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] Spawning CRC thread, preCacheWorkerThreadList.size() = %d\n",__FILE__,__FUNCTION__,__LINE__,(int)preCacheWorkerThreadList.size()); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] Spawning CRC thread, preCacheWorkerThreadList.size() = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,(int)preCacheWorkerThreadList.size()); if(consumedWorkers >= techPaths.size()) { break; @@ -198,16 +198,16 @@ void FileCRCPreCacheThread::execute() { } } catch(const exception &ex) { - SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); + SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] error [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what()); } catch(...) { - SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] UNKNOWN Error\n",__FILE__,__FUNCTION__,__LINE__); - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] unknown error\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] UNKNOWN Error\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] unknown error\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); } sleep(0); - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] Waiting for Spawned CRC threads to complete, preCacheWorkerThreadList.size() = %d\n",__FILE__,__FUNCTION__,__LINE__,(int)preCacheWorkerThreadList.size()); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] Waiting for Spawned CRC threads to complete, preCacheWorkerThreadList.size() = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,(int)preCacheWorkerThreadList.size()); try { bool hasRunningWorkerThread = true; @@ -254,12 +254,12 @@ void FileCRCPreCacheThread::execute() { } } catch(const exception &ex) { - SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); + SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] error [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what()); } catch(...) { - SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] UNKNOWN Error\n",__FILE__,__FUNCTION__,__LINE__); - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] unknown error\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] UNKNOWN Error\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] unknown error\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); } if(SystemFlags::VERBOSE_MODE_ENABLED) printf("********************** CRC Controller thread took %.2f seconds END **********************\n",difftime(time(NULL),elapsedTime)); @@ -275,8 +275,8 @@ void FileCRCPreCacheThread::execute() { break; } //if(SystemFlags::VERBOSE_MODE_ENABLED) printf("--------------------- CRC worker thread START for tech [%s] ---------------------------\n",techName.c_str()); - //if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] caching CRC value for Tech [%s]\n",__FILE__,__FUNCTION__,__LINE__,techName.c_str()); - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] caching CRC value for Tech [%s]\n",__FILE__,__FUNCTION__,__LINE__,techName.c_str()); + //if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] caching CRC value for Tech [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,techName.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] caching CRC value for Tech [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,techName.c_str()); time_t elapsedTime = time(NULL); // Clear existing CRC to force a CRC refresh @@ -308,8 +308,8 @@ void FileCRCPreCacheThread::execute() { uint32 techCRC = getFolderTreeContentsCheckSumRecursively(techDataPaths, string("/") + techName + string("/*"), ".xml", NULL, true); - //if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] cached CRC value for Tech [%s] is [%d] took %.3f seconds.\n",__FILE__,__FUNCTION__,__LINE__,techName.c_str(),techCRC,difftime(time(NULL),elapsedTime)); - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] cached CRC value for Tech [%s] is [%u] took %.3f seconds.\n",__FILE__,__FUNCTION__,__LINE__,techName.c_str(),techCRC,difftime(time(NULL),elapsedTime)); + //if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] cached CRC value for Tech [%s] is [%d] took %.3f seconds.\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,techName.c_str(),techCRC,difftime(time(NULL),elapsedTime)); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] cached CRC value for Tech [%s] is [%u] took %.3f seconds.\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,techName.c_str(),techCRC,difftime(time(NULL),elapsedTime)); vector results; for(unsigned int idx = 0; idx < techDataPaths.size(); idx++) { @@ -348,8 +348,8 @@ void FileCRCPreCacheThread::execute() { } } - //if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] cached CRC value for Tech [%s] is [%d] took %.3f seconds.\n",__FILE__,__FUNCTION__,__LINE__,techName.c_str(),techCRC,difftime(time(NULL),elapsedTime)); - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] cached CRC value for Tech [%s] is [%d] took %.3f seconds.\n",__FILE__,__FUNCTION__,__LINE__,techName.c_str(),techCRC,difftime(time(NULL),elapsedTime)); + //if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] cached CRC value for Tech [%s] is [%d] took %.3f seconds.\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,techName.c_str(),techCRC,difftime(time(NULL),elapsedTime)); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] cached CRC value for Tech [%s] is [%d] took %.3f seconds.\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,techName.c_str(),techCRC,difftime(time(NULL),elapsedTime)); } if(SystemFlags::VERBOSE_MODE_ENABLED) printf("--------------------- CRC worker thread END for tech [%s] ---------------------------\n",techName.c_str()); @@ -360,26 +360,26 @@ void FileCRCPreCacheThread::execute() { } } catch(const exception &ex) { - SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); + SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] error [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what()); } catch(...) { - SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] UNKNOWN Error\n",__FILE__,__FUNCTION__,__LINE__); - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] unknown error\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] UNKNOWN Error\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] unknown error\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); } } } catch(const exception &ex) { - SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); + SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] error [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what()); } catch(...) { - SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] UNKNOWN Error\n",__FILE__,__FUNCTION__,__LINE__); - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] unknown error\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] UNKNOWN Error\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] unknown error\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); } - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] FILE CRC PreCache thread is exiting...\n",__FILE__,__FUNCTION__,__LINE__); - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] FILE CRC PreCache thread is exiting...\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] FILE CRC PreCache thread is exiting...\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] FILE CRC PreCache thread is exiting...\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); } deleteSelfIfRequired(); } @@ -441,8 +441,8 @@ SimpleTaskThread::~SimpleTaskThread() { } catch(const exception &ex) { - SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] uniqueID [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->getUniqueID().c_str()); + SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] uniqueID [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,this->getUniqueID().c_str()); throw megaglest_runtime_error(ex.what()); //abort(); @@ -515,20 +515,20 @@ void SimpleTaskThread::setSimpleTaskInterfaceValid(bool value) { } void SimpleTaskThread::execute() { - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); void *ptr_cpy = this->ptr; bool mustDeleteSelf = false; { { RunningStatusSafeWrapper runningStatus(this); try { - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); if(getQuitStatus() == true) { return; } - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] uniqueID [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->getUniqueID().c_str()); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] uniqueID [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,this->getUniqueID().c_str()); unsigned int idx = 0; for(;this->simpleTaskInterface != NULL;) { @@ -548,15 +548,15 @@ void SimpleTaskThread::execute() { } if(getQuitStatus() == true) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] uniqueID [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->getUniqueID().c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] uniqueID [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,this->getUniqueID().c_str()); break; } else if(runTask == true) { if(getQuitStatus() == false) { ExecutingTaskSafeWrapper safeExecutingTaskMutex(this); - //if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + //if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); this->simpleTaskInterface->simpleTask(this,this->userdata); - //if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + //if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); if(getQuitStatus() == true) { break; @@ -576,23 +576,23 @@ void SimpleTaskThread::execute() { } } if(getQuitStatus() == true) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] uniqueID [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->getUniqueID().c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] uniqueID [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,this->getUniqueID().c_str()); break; } sleep(this->millisecsBetweenExecutions); } - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] uniqueID [%s] END\n",__FILE__,__FUNCTION__,__LINE__,this->getUniqueID().c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] uniqueID [%s] END\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,this->getUniqueID().c_str()); mustDeleteSelf = getDeleteSelfOnExecutionDone(); - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); } catch(const exception &ex) { - SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] uniqueID [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->getUniqueID().c_str()); + SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] uniqueID [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,this->getUniqueID().c_str()); - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] uniqueID [%s] END\n",__FILE__,__FUNCTION__,__LINE__,this->getUniqueID().c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] uniqueID [%s] END\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,this->getUniqueID().c_str()); mustDeleteSelf = getDeleteSelfOnExecutionDone(); throw megaglest_runtime_error(ex.what()); @@ -600,11 +600,11 @@ void SimpleTaskThread::execute() { } } - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); if(mustDeleteSelf == true) { - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); if(isThreadDeleted(ptr_cpy) == false) { - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); this->setDeleteAfterExecute(true); } return; @@ -644,7 +644,7 @@ LogFileThread::~LogFileThread() { delete mutexLogList; mutexLogList = NULL; - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("#1 In [%s::%s Line: %d] LogFile thread is deleting\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("#1 In [%s::%s Line: %d] LogFile thread is deleting\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); } void LogFileThread::addLogEntry(SystemFlags::DebugType type, string logEntry) { @@ -677,15 +677,15 @@ void LogFileThread::execute() { bool mustDeleteSelf = false; { RunningStatusSafeWrapper runningStatus(this); - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); if(getQuitStatus() == true) { deleteSelfIfRequired(); return; } - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"LogFile thread is running\n"); try { @@ -701,24 +701,24 @@ void LogFileThread::execute() { } // Ensure remaining entryies are logged to disk on shutdown - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); saveToDisk(true,false); - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); } catch(const exception &ex) { - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] Error [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what()); } catch(...) { - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] UNKNOWN Error\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] UNKNOWN Error\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); } - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] LogFile thread is starting to exit\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] LogFile thread is starting to exit\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); mustDeleteSelf = getDeleteSelfOnExecutionDone(); - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] LogFile thread is exiting, mustDeleteSelf = %d\n",__FILE__,__FUNCTION__,__LINE__,mustDeleteSelf); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] LogFile thread is exiting, mustDeleteSelf = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,mustDeleteSelf); } if(mustDeleteSelf == true) { - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] LogFile thread is deleting self\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] LogFile thread is deleting self\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); if(isThreadDeleted(ptr_cpy) == false) { this->setDeleteAfterExecute(true); }