//--------------------------------------------------------------------------- #include #pragma hdrstop #include "KPFormSimpleCode.h" #include "KPLTypes.h" #include "KPLFillModSpecific.h" #include "WriteScript.h" #include "GenerateScript.h" #include "process.h"// For spawnlp #pragma package(smart_init) #pragma resource "*.dfm" //--------------------------------------------------------------------------- TKPLWindowSimple *KPLWindowSimple; //--------------------------------------------------------------------------- __fastcall TKPLWindowSimple::TKPLWindowSimple(TComponent* Owner) : TForm(Owner) { KPLFillModSpecific(); } //--------------------------------------------------------------------------- int GetChosenDifficultyLevel() { if(KPLWindowSimple->RB4VeryHard->Checked) return 4; if(KPLWindowSimple->RB3Hard->Checked) return 3; if(KPLWindowSimple->RB2Medium->Checked) return 2; if(KPLWindowSimple->RB1Easy->Checked) return 1; if(KPLWindowSimple->RB0Spec->Checked) return 0; return -1; } DWORD ProcessID=0; int LaunchSpringExecutable() { HANDLE ProcessHandle; // Check that Spring isn't already running ProcessHandle=OpenProcess(PROCESS_QUERY_INFORMATION,false,ProcessID); if(ProcessHandle!=NULL) { AnsiString caption="Exit last game first!"; AnsiString text=(AnsiString)"Game already in progress. Please exit "+cKPgame::ExecutableFileName+" first."; Application->MessageBox(text.c_str(),caption.c_str(),MB_OK); return 2; } // Create and allocate "game" and its "players" and its "modoptions" cKPgame* game=(cKPgame*)malloc(sizeof(cKPgame)); game->players=(cKPplayer**)malloc(32*sizeof(cKPplayer*)); for(int p=0;p<32;++p) game->players[p]=(cKPplayer*)malloc(sizeof(cKPplayer)); game->ModOptions=(cKPmodoptions*)malloc(sizeof(cKPmodoptions)); // Generate a random script according to difficulty GenerateScript(game,GetChosenDifficultyLevel()); // Writing that script on the disk WriteScript(game); // Running Spring //ShellExecute(NULL,"open",game->ExecutableFileName,game->ScriptFileName,NULL,SW_SHOWNORMAL); ProcessID=spawnl(P_NOWAIT,cKPgame::ExecutableFileName,game->ExecutableFileName,game->ScriptFileName,NULL); // Check that Spring has run ProcessHandle=OpenProcess(PROCESS_QUERY_INFORMATION,false,ProcessID); if(ProcessHandle==NULL) { AnsiString caption=(AnsiString)cKPgame::ExecutableFileName+" not found!"; AnsiString text=caption; Application->MessageBox(text.c_str(),caption.c_str(),MB_OK); return 1; } //Application->Terminate(); return 0; } //--------------------------------------------------------------------------- void __fastcall TKPLWindowSimple::BBOkClick(TObject *Sender) { LaunchSpringExecutable(); } //--------------------------------------------------------------------------- void __fastcall TKPLWindowSimple::BBCancelClick(TObject *Sender) { Application->Terminate(); } //---------------------------------------------------------------------------