mirror of
https://github.com/glest/glest-source.git
synced 2025-02-26 12:43:06 +01:00
- added new commandline option --map-preview=x where x is the mapname (without extension)
This commit is contained in:
parent
aee6c948a2
commit
8f0db3e30d
@ -784,6 +784,10 @@ void Game::init(bool initForPreviewOnly)
|
||||
Window::handleEvent();
|
||||
SDL_PumpEvents();
|
||||
|
||||
if(world.getFactionCount() == 1 && world.getFaction(0)->getType()->getPersonalityType() == fpt_Observer) {
|
||||
withRainEffect = false;
|
||||
}
|
||||
|
||||
if(withRainEffect){
|
||||
//weather particle systems
|
||||
if(world.getTileset()->getWeather() == wRainy){
|
||||
@ -2296,7 +2300,17 @@ void Game::checkWinnerStandard() {
|
||||
}
|
||||
|
||||
scriptManager.onGameOver(true);
|
||||
showWinMessageBox();
|
||||
|
||||
if(world.getFactionCount() == 1 && world.getFaction(0)->getType()->getPersonalityType() == fpt_Observer) {
|
||||
//printf("!!!!!!!!!!!!!!!!!!!!");
|
||||
|
||||
//gameCamera.setMoveY(100.0);
|
||||
gameCamera.zoom(-300);
|
||||
//gameCamera.update();
|
||||
}
|
||||
else {
|
||||
showWinMessageBox();
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -103,6 +103,7 @@ const char *GAME_ARGS[] = {
|
||||
"--connecthost",
|
||||
"--starthost",
|
||||
"--load-scenario",
|
||||
"--preview-map",
|
||||
"--version",
|
||||
"--opengl-info",
|
||||
"--sdl-info",
|
||||
@ -145,6 +146,7 @@ enum GAME_ARG_TYPE {
|
||||
GAME_ARG_CLIENT,
|
||||
GAME_ARG_SERVER,
|
||||
GAME_ARG_LOADSCENARIO,
|
||||
GAME_ARG_PREVIEW_MAP,
|
||||
GAME_ARG_VERSION,
|
||||
GAME_ARG_OPENGL_INFO,
|
||||
GAME_ARG_SDL_INFO,
|
||||
@ -1009,6 +1011,7 @@ void printParameterHelp(const char *argv0, bool foundInvalidArgs) {
|
||||
printf("\n%s=x\t\t\tAuto connects to a network server at IP or hostname x",GAME_ARGS[GAME_ARG_CLIENT]);
|
||||
printf("\n%s\t\t\tAuto creates a network server.",GAME_ARGS[GAME_ARG_SERVER]);
|
||||
printf("\n%s=x\t\tAuto loads the specified scenario by scenario name.",GAME_ARGS[GAME_ARG_LOADSCENARIO]);
|
||||
printf("\n%s=x\t\tAuto Preview the specified map by map name.",GAME_ARGS[GAME_ARG_PREVIEW_MAP]);
|
||||
printf("\n%s\t\t\tdisplays the version string of this program.",GAME_ARGS[GAME_ARG_VERSION]);
|
||||
printf("\n%s\t\t\tdisplays your video driver's OpenGL information.",GAME_ARGS[GAME_ARG_OPENGL_INFO]);
|
||||
printf("\n%s\t\t\tdisplays your SDL version information.",GAME_ARGS[GAME_ARG_SDL_INFO]);
|
||||
@ -3116,6 +3119,8 @@ int glestMain(int argc, char** argv) {
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
GameSettings startupGameSettings;
|
||||
|
||||
//parse command line
|
||||
if(hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_SERVER]) == true) {
|
||||
program->initServer(mainWindow,false,true);
|
||||
@ -3123,6 +3128,64 @@ int glestMain(int argc, char** argv) {
|
||||
else if(hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_AUTOSTART_LASTGAME])) == true) {
|
||||
program->initServer(mainWindow,true,false);
|
||||
}
|
||||
else if(hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_PREVIEW_MAP])) == true) {
|
||||
int foundParamIndIndex = -1;
|
||||
hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_PREVIEW_MAP]) + string("="),&foundParamIndIndex);
|
||||
if(foundParamIndIndex < 0) {
|
||||
hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_PREVIEW_MAP]),&foundParamIndIndex);
|
||||
}
|
||||
string mapName = argv[foundParamIndIndex];
|
||||
vector<string> paramPartTokens;
|
||||
Tokenize(mapName,paramPartTokens,"=");
|
||||
if(paramPartTokens.size() >= 2 && paramPartTokens[1].length() > 0) {
|
||||
string autoloadMapName = paramPartTokens[1];
|
||||
|
||||
GameSettings *gameSettings = &startupGameSettings;
|
||||
int factionCount= 0;
|
||||
gameSettings->setMap(autoloadMapName);
|
||||
gameSettings->setTileset("forest");
|
||||
gameSettings->setTech("megapack");
|
||||
gameSettings->setDefaultUnits(false);
|
||||
gameSettings->setDefaultResources(false);
|
||||
gameSettings->setDefaultVictoryConditions(true);
|
||||
gameSettings->setFogOfWar(false);
|
||||
gameSettings->setAllowObservers(true);
|
||||
gameSettings->setPathFinderType(pfBasic);
|
||||
|
||||
for(int i = 0; i < GameConstants::maxPlayers; ++i) {
|
||||
ControlType ct= ctClosed;
|
||||
|
||||
gameSettings->setNetworkPlayerStatuses(i, 0);
|
||||
gameSettings->setFactionControl(i, ct);
|
||||
gameSettings->setStartLocationIndex(i, i);
|
||||
gameSettings->setResourceMultiplierIndex(i, 10);
|
||||
gameSettings->setNetworkPlayerName(i, "Closed");
|
||||
}
|
||||
|
||||
ControlType ct= ctHuman;
|
||||
|
||||
gameSettings->setNetworkPlayerStatuses(0, 0);
|
||||
gameSettings->setFactionControl(0, ct);
|
||||
gameSettings->setFactionTypeName(0, formatString(GameConstants::OBSERVER_SLOTNAME));
|
||||
gameSettings->setTeam(0, GameConstants::maxPlayers + fpt_Observer - 1);
|
||||
gameSettings->setStartLocationIndex(0, 0);
|
||||
gameSettings->setNetworkPlayerName(0, GameConstants::OBSERVER_SLOTNAME);
|
||||
|
||||
gameSettings->setFactionCount(1);
|
||||
|
||||
Config &config = Config::getInstance();
|
||||
gameSettings->setEnableServerControlledAI(config.getBool("ServerControlledAI","true"));
|
||||
gameSettings->setNetworkFramePeriod(config.getInt("NetworkSendFrameCount","20"));
|
||||
|
||||
program->initServer(mainWindow,gameSettings);
|
||||
}
|
||||
else {
|
||||
printf("\nInvalid map name specified on commandline [%s] map [%s]\n\n",argv[foundParamIndIndex],(paramPartTokens.size() >= 2 ? paramPartTokens[1].c_str() : NULL));
|
||||
printParameterHelp(argv[0],foundInvalidArgs);
|
||||
delete mainWindow;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else if(hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_CLIENT])) == true) {
|
||||
int foundParamIndIndex = -1;
|
||||
hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_CLIENT]) + string("="),&foundParamIndIndex);
|
||||
|
@ -190,6 +190,15 @@ void Program::initServer(WindowGl *window, bool autostart,bool openNetworkSlots)
|
||||
mainMenu->setState(new MenuStateCustomGame(this, mainMenu, openNetworkSlots, false, autostart));
|
||||
}
|
||||
|
||||
void Program::initServer(WindowGl *window, GameSettings *settings) {
|
||||
MainMenu* mainMenu= NULL;
|
||||
|
||||
init(window);
|
||||
mainMenu= new MainMenu(this);
|
||||
setState(mainMenu);
|
||||
mainMenu->setState(new MenuStateCustomGame(this, mainMenu, false, false, true, settings));
|
||||
}
|
||||
|
||||
void Program::initClient(WindowGl *window, const Ip &serverIp) {
|
||||
MainMenu* mainMenu= NULL;
|
||||
|
||||
|
@ -35,6 +35,7 @@ namespace Glest{ namespace Game{
|
||||
|
||||
class Program;
|
||||
class MainWindow;
|
||||
class GameSettings;
|
||||
|
||||
// =====================================================
|
||||
// class ProgramState
|
||||
@ -152,6 +153,7 @@ public:
|
||||
GraphicMessageBox * getMsgBox() { return &msgBox; }
|
||||
void initNormal(WindowGl *window);
|
||||
void initServer(WindowGl *window,bool autostart=false,bool openNetworkSlots=false);
|
||||
void initServer(WindowGl *window, GameSettings *settings);
|
||||
void initClient(WindowGl *window, const Ip &serverIp);
|
||||
void initScenario(WindowGl *window, string autoloadScenarioName);
|
||||
|
||||
|
@ -47,11 +47,13 @@ struct FormatString {
|
||||
// class MenuStateCustomGame
|
||||
// =====================================================
|
||||
|
||||
MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, bool openNetworkSlots,bool parentMenuIsMasterserver, bool autostart) :
|
||||
MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, bool openNetworkSlots,bool parentMenuIsMasterserver, bool autostart, GameSettings *settings) :
|
||||
MenuState(program, mainMenu, "new-game")
|
||||
{
|
||||
forceWaitForShutdown = true;
|
||||
this->autostart = autostart;
|
||||
this->autoStartSettings = settings;
|
||||
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] autostart = %d\n",__FILE__,__FUNCTION__,__LINE__,autostart);
|
||||
|
||||
containerName = "CustomGame";
|
||||
@ -700,7 +702,7 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){
|
||||
else if(buttonPlayNow.mouseClick(x,y) && buttonPlayNow.getEnabled()) {
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
PlayNow();
|
||||
PlayNow(true);
|
||||
return;
|
||||
}
|
||||
else if(buttonRestoreLastSettings.mouseClick(x,y) && buttonRestoreLastSettings.getEnabled()) {
|
||||
@ -1114,9 +1116,11 @@ void MenuStateCustomGame::RestoreLastGameSettings() {
|
||||
}
|
||||
}
|
||||
|
||||
void MenuStateCustomGame::PlayNow() {
|
||||
void MenuStateCustomGame::PlayNow(bool saveGame) {
|
||||
MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL),string(__FILE__) + "_" + intToStr(__LINE__));
|
||||
saveGameSettingsToFile("lastCustomGamSettings.mgg");
|
||||
if(saveGame == true) {
|
||||
saveGameSettingsToFile("lastCustomGamSettings.mgg");
|
||||
}
|
||||
|
||||
forceWaitForShutdown = false;
|
||||
closeUnusedSlots();
|
||||
@ -2041,9 +2045,18 @@ void MenuStateCustomGame::update() {
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start();
|
||||
|
||||
if(autostart == true) {
|
||||
autostart = false;
|
||||
safeMutex.ReleaseLock();
|
||||
RestoreLastGameSettings();
|
||||
PlayNow();
|
||||
if(autoStartSettings != NULL) {
|
||||
|
||||
setupUIFromGameSettings(*autoStartSettings);
|
||||
ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface();
|
||||
serverInterface->setGameSettings(autoStartSettings,false);
|
||||
}
|
||||
else {
|
||||
RestoreLastGameSettings();
|
||||
}
|
||||
PlayNow((autoStartSettings == NULL));
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -2289,9 +2302,17 @@ void MenuStateCustomGame::loadGameSettings(GameSettings *gameSettings,bool force
|
||||
gameSettings->setMap(getCurrentMapFile());
|
||||
gameSettings->setTileset(tilesetFiles[listBoxTileset.getSelectedItemIndex()]);
|
||||
gameSettings->setTech(techTreeFiles[listBoxTechTree.getSelectedItemIndex()]);
|
||||
gameSettings->setDefaultUnits(true);
|
||||
gameSettings->setDefaultResources(true);
|
||||
gameSettings->setDefaultVictoryConditions(true);
|
||||
|
||||
if(autoStartSettings != NULL) {
|
||||
gameSettings->setDefaultUnits(autoStartSettings->getDefaultUnits());
|
||||
gameSettings->setDefaultResources(autoStartSettings->getDefaultResources());
|
||||
gameSettings->setDefaultVictoryConditions(autoStartSettings->getDefaultVictoryConditions());
|
||||
}
|
||||
else {
|
||||
gameSettings->setDefaultUnits(true);
|
||||
gameSettings->setDefaultResources(true);
|
||||
gameSettings->setDefaultVictoryConditions(true);
|
||||
}
|
||||
gameSettings->setFogOfWar(listBoxFogOfWar.getSelectedItemIndex() == 0 ||
|
||||
listBoxFogOfWar.getSelectedItemIndex() == 1 );
|
||||
|
||||
@ -2653,6 +2674,8 @@ void MenuStateCustomGame::setupUIFromGameSettings(const GameSettings &gameSettin
|
||||
listBoxMapFilter.setSelectedItemIndex(gameSettings.getMapFilterIndex());
|
||||
listBoxMap.setItems(formattedPlayerSortedMaps[gameSettings.getMapFilterIndex()]);
|
||||
|
||||
printf("In [%s::%s line %d] map [%s]\n",__FILE__,__FUNCTION__,__LINE__,gameSettings.getMap().c_str());
|
||||
|
||||
string mapFile = gameSettings.getMap();
|
||||
mapFile = formatString(mapFile);
|
||||
listBoxMap.setSelectedItem(mapFile);
|
||||
@ -2683,12 +2706,15 @@ void MenuStateCustomGame::setupUIFromGameSettings(const GameSettings &gameSettin
|
||||
if(gameSettings.getFogOfWar() == false){
|
||||
listBoxFogOfWar.setSelectedItemIndex(2);
|
||||
}
|
||||
|
||||
if((gameSettings.getFlagTypes1() & ft1_show_map_resources) == ft1_show_map_resources){
|
||||
if(gameSettings.getFogOfWar() == true){
|
||||
listBoxFogOfWar.setSelectedItemIndex(1);
|
||||
}
|
||||
}
|
||||
|
||||
//printf("In [%s::%s line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
listBoxAllowObservers.setSelectedItem(gameSettings.getAllowObservers() == true ? lang.get("Yes") : lang.get("No"));
|
||||
listBoxEnableObserverMode.setSelectedItem(gameSettings.getEnableObserverModeAtEndGame() == true ? lang.get("Yes") : lang.get("No"));
|
||||
listBoxPathFinderType.setSelectedItemIndex(gameSettings.getPathFinderType());
|
||||
@ -2713,9 +2739,12 @@ void MenuStateCustomGame::setupUIFromGameSettings(const GameSettings &gameSettin
|
||||
if(gameSettings.getFactionControl(i) < listBoxControls[i].getItemCount()) {
|
||||
listBoxControls[i].setSelectedItemIndex(gameSettings.getFactionControl(i));
|
||||
}
|
||||
|
||||
updateResourceMultiplier(i);
|
||||
listBoxRMultiplier[i].setSelectedItemIndex(gameSettings.getResourceMultiplierIndex(i));
|
||||
|
||||
listBoxTeams[i].setSelectedItemIndex(gameSettings.getTeam(i));
|
||||
|
||||
lastSelectedTeamIndex[i] = listBoxTeams[i].getSelectedItemIndex();
|
||||
|
||||
string factionName = gameSettings.getFactionTypeName(i);
|
||||
|
@ -147,6 +147,8 @@ private:
|
||||
Texture2D *mapPreviewTexture;
|
||||
|
||||
bool autostart;
|
||||
GameSettings *autoStartSettings;
|
||||
|
||||
std::map<int,int> lastSelectedTeamIndex;
|
||||
float rMultiplierOffset;
|
||||
bool hasCheckedForUPNP;
|
||||
@ -162,7 +164,7 @@ private:
|
||||
bool forceWaitForShutdown;
|
||||
|
||||
public:
|
||||
MenuStateCustomGame(Program *program, MainMenu *mainMenu ,bool openNetworkSlots= false, bool parentMenuIsMasterserver=false, bool autostart=false);
|
||||
MenuStateCustomGame(Program *program, MainMenu *mainMenu ,bool openNetworkSlots= false, bool parentMenuIsMasterserver=false, bool autostart=false,GameSettings *settings=NULL);
|
||||
virtual ~MenuStateCustomGame();
|
||||
|
||||
void mouseClick(int x, int y, MouseButton mouseButton);
|
||||
@ -205,7 +207,7 @@ private:
|
||||
void loadFactionTexture(string filepath);
|
||||
|
||||
void RestoreLastGameSettings();
|
||||
void PlayNow();
|
||||
void PlayNow(bool saveGame);
|
||||
|
||||
void SetActivePlayerNameEditor();
|
||||
void cleanup();
|
||||
|
Loading…
x
Reference in New Issue
Block a user