- added support for random faction selection
This commit is contained in:
parent
350d658ceb
commit
52916bdc6e
|
@ -155,6 +155,7 @@ public:
|
||||||
void init(int x, int y, int w=defW, int h=defH);
|
void init(int x, int y, int w=defW, int h=defH);
|
||||||
|
|
||||||
int getItemCount() const {return items.size();}
|
int getItemCount() const {return items.size();}
|
||||||
|
string getItem(int index) const {return items[index];}
|
||||||
int getSelectedItemIndex() const {return selectedItemIndex;}
|
int getSelectedItemIndex() const {return selectedItemIndex;}
|
||||||
string getSelectedItem() const {return items[selectedItemIndex];}
|
string getSelectedItem() const {return items[selectedItemIndex];}
|
||||||
const GraphicButton *getButton1() const {return &graphButton1;}
|
const GraphicButton *getButton1() const {return &graphButton1;}
|
||||||
|
|
|
@ -80,6 +80,7 @@ public:
|
||||||
static const char *folder_path_screenshots;
|
static const char *folder_path_screenshots;
|
||||||
|
|
||||||
static const char *OBSERVER_SLOTNAME;
|
static const char *OBSERVER_SLOTNAME;
|
||||||
|
static const char *RANDOMFACTION_SLOTNAME;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum PathType {
|
enum PathType {
|
||||||
|
|
|
@ -43,6 +43,7 @@ const char *GameConstants::NETWORK_SLOT_UNCONNECTED_SLOTNAME = "???";
|
||||||
const char *GameConstants::folder_path_screenshots = "screens/";
|
const char *GameConstants::folder_path_screenshots = "screens/";
|
||||||
|
|
||||||
const char *GameConstants::OBSERVER_SLOTNAME = "*Observer*";
|
const char *GameConstants::OBSERVER_SLOTNAME = "*Observer*";
|
||||||
|
const char *GameConstants::RANDOMFACTION_SLOTNAME = "*Random*";
|
||||||
|
|
||||||
// =====================================================
|
// =====================================================
|
||||||
// class Config
|
// class Config
|
||||||
|
|
|
@ -1034,6 +1034,7 @@ bool MenuStateConnectedGame::loadFactions(const GameSettings *gameSettings, bool
|
||||||
if(gameSettings->getAllowObservers() == true) {
|
if(gameSettings->getAllowObservers() == true) {
|
||||||
results.push_back(formatString(GameConstants::OBSERVER_SLOTNAME));
|
results.push_back(formatString(GameConstants::OBSERVER_SLOTNAME));
|
||||||
}
|
}
|
||||||
|
results.push_back(formatString(GameConstants::RANDOMFACTION_SLOTNAME));
|
||||||
|
|
||||||
factionFiles= results;
|
factionFiles= results;
|
||||||
for(int i= 0; i<results.size(); ++i){
|
for(int i= 0; i<results.size(); ++i){
|
||||||
|
|
|
@ -588,6 +588,51 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
std::vector<string> randomFactionSelectionList;
|
||||||
|
int RandomCount = 0;
|
||||||
|
for(int i= 0; i < mapInfo.players; ++i) {
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
// Check for random faction selection and choose the faction now
|
||||||
|
if(listBoxFactions[i].getSelectedItem() == formatString(GameConstants::RANDOMFACTION_SLOTNAME)) {
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] i = %d\n",__FILE__,__FUNCTION__,__LINE__,i);
|
||||||
|
|
||||||
|
// Max 1000 tries to get a random, unused faction
|
||||||
|
for(int findRandomFaction = 1; findRandomFaction < 1000; ++findRandomFaction) {
|
||||||
|
srand(time(NULL) + findRandomFaction);
|
||||||
|
int selectedFactionIndex = rand() % listBoxFactions[i].getItemCount();
|
||||||
|
string selectedFactionName = listBoxFactions[i].getItem(selectedFactionIndex);
|
||||||
|
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] selectedFactionName [%s] selectedFactionIndex = %d, findRandomFaction = %d\n",__FILE__,__FUNCTION__,__LINE__,selectedFactionName.c_str(),selectedFactionIndex,findRandomFaction);
|
||||||
|
|
||||||
|
if( selectedFactionName != formatString(GameConstants::RANDOMFACTION_SLOTNAME) &&
|
||||||
|
selectedFactionName != formatString(GameConstants::OBSERVER_SLOTNAME) &&
|
||||||
|
std::find(randomFactionSelectionList.begin(),randomFactionSelectionList.end(),selectedFactionName) == randomFactionSelectionList.end()) {
|
||||||
|
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
listBoxFactions[i].setSelectedItem(selectedFactionName);
|
||||||
|
randomFactionSelectionList.push_back(selectedFactionName);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(listBoxFactions[i].getSelectedItem() == formatString(GameConstants::RANDOMFACTION_SLOTNAME)) {
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] RandomCount = %d\n",__FILE__,__FUNCTION__,__LINE__,RandomCount);
|
||||||
|
|
||||||
|
listBoxFactions[i].setSelectedItemIndex(RandomCount);
|
||||||
|
randomFactionSelectionList.push_back(listBoxFactions[i].getItem(RandomCount));
|
||||||
|
}
|
||||||
|
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] i = %d, listBoxFactions[i].getSelectedItem() [%s]\n",__FILE__,__FUNCTION__,__LINE__,i,listBoxFactions[i].getSelectedItem().c_str());
|
||||||
|
|
||||||
|
RandomCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(RandomCount > 0) {
|
||||||
|
needToSetChangedGameSettings = true;
|
||||||
|
}
|
||||||
|
|
||||||
safeMutex.ReleaseLock(true);
|
safeMutex.ReleaseLock(true);
|
||||||
GameSettings gameSettings;
|
GameSettings gameSettings;
|
||||||
loadGameSettings(&gameSettings);
|
loadGameSettings(&gameSettings);
|
||||||
|
@ -599,7 +644,7 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){
|
||||||
safeMutex.Lock();
|
safeMutex.Lock();
|
||||||
|
|
||||||
bool dataSynchCheckOk = true;
|
bool dataSynchCheckOk = true;
|
||||||
for(int i= 0; i<mapInfo.players; ++i) {
|
for(int i= 0; i < mapInfo.players; ++i) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
if(listBoxControls[i].getSelectedItemIndex() == ctNetwork) {
|
if(listBoxControls[i].getSelectedItemIndex() == ctNetwork) {
|
||||||
|
@ -626,8 +671,8 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
if( hasNetworkGameSettings() == true &&
|
if( (hasNetworkGameSettings() == true &&
|
||||||
needToSetChangedGameSettings == true) {
|
needToSetChangedGameSettings == true) || (RandomCount > 0)) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
serverInterface->setGameSettings(&gameSettings,true);
|
serverInterface->setGameSettings(&gameSettings,true);
|
||||||
|
|
||||||
|
@ -1669,6 +1714,9 @@ void MenuStateCustomGame::loadGameSettings(GameSettings *gameSettings) {
|
||||||
labelPlayerNames[i].setText(getHumanPlayerName(i));
|
labelPlayerNames[i].setText(getHumanPlayerName(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] i = %d, factionFiles[listBoxFactions[i].getSelectedItemIndex()] [%s]\n",__FILE__,__FUNCTION__,__LINE__,i,factionFiles[listBoxFactions[i].getSelectedItemIndex()].c_str());
|
||||||
gameSettings->setFactionTypeName(slotIndex, factionFiles[listBoxFactions[i].getSelectedItemIndex()]);
|
gameSettings->setFactionTypeName(slotIndex, factionFiles[listBoxFactions[i].getSelectedItemIndex()]);
|
||||||
if(factionFiles[listBoxFactions[i].getSelectedItemIndex()] == formatString(GameConstants::OBSERVER_SLOTNAME)) {
|
if(factionFiles[listBoxFactions[i].getSelectedItemIndex()] == formatString(GameConstants::OBSERVER_SLOTNAME)) {
|
||||||
listBoxTeams[i].setSelectedItem(intToStr(GameConstants::maxPlayers + fpt_Observer));
|
listBoxTeams[i].setSelectedItem(intToStr(GameConstants::maxPlayers + fpt_Observer));
|
||||||
|
@ -1721,6 +1769,8 @@ void MenuStateCustomGame::loadGameSettings(GameSettings *gameSettings) {
|
||||||
gameSettings->setFactionControl(slotIndex, ct);
|
gameSettings->setFactionControl(slotIndex, ct);
|
||||||
gameSettings->setTeam(slotIndex, listBoxTeams[i].getSelectedItemIndex());
|
gameSettings->setTeam(slotIndex, listBoxTeams[i].getSelectedItemIndex());
|
||||||
gameSettings->setStartLocationIndex(slotIndex, i);
|
gameSettings->setStartLocationIndex(slotIndex, i);
|
||||||
|
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] i = %d, factionFiles[listBoxFactions[i].getSelectedItemIndex()] [%s]\n",__FILE__,__FUNCTION__,__LINE__,i,factionFiles[listBoxFactions[i].getSelectedItemIndex()].c_str());
|
||||||
gameSettings->setFactionTypeName(slotIndex, factionFiles[listBoxFactions[i].getSelectedItemIndex()]);
|
gameSettings->setFactionTypeName(slotIndex, factionFiles[listBoxFactions[i].getSelectedItemIndex()]);
|
||||||
gameSettings->setNetworkPlayerName(slotIndex, "Closed");
|
gameSettings->setNetworkPlayerName(slotIndex, "Closed");
|
||||||
|
|
||||||
|
@ -1842,6 +1892,9 @@ GameSettings MenuStateCustomGame::loadGameSettingsFromFile(std::string fileName)
|
||||||
gameSettings.setTeam(i,properties.getInt(string("FactionTeamForIndex") + intToStr(i),"0") );
|
gameSettings.setTeam(i,properties.getInt(string("FactionTeamForIndex") + intToStr(i),"0") );
|
||||||
gameSettings.setStartLocationIndex(i,properties.getInt(string("FactionStartLocationForIndex") + intToStr(i),intToStr(i).c_str()) );
|
gameSettings.setStartLocationIndex(i,properties.getInt(string("FactionStartLocationForIndex") + intToStr(i),intToStr(i).c_str()) );
|
||||||
gameSettings.setFactionTypeName(i,properties.getString(string("FactionTypeNameForIndex") + intToStr(i),"?") );
|
gameSettings.setFactionTypeName(i,properties.getString(string("FactionTypeNameForIndex") + intToStr(i),"?") );
|
||||||
|
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] i = %d, factionTypeName [%s]\n",__FILE__,__FUNCTION__,__LINE__,i,gameSettings.getFactionTypeName(i).c_str());
|
||||||
|
|
||||||
gameSettings.setNetworkPlayerName(i,properties.getString(string("FactionPlayerNameForIndex") + intToStr(i),"") );
|
gameSettings.setNetworkPlayerName(i,properties.getString(string("FactionPlayerNameForIndex") + intToStr(i),"") );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2041,6 +2094,8 @@ void MenuStateCustomGame::reloadFactions() {
|
||||||
results.push_back(formatString(GameConstants::OBSERVER_SLOTNAME));
|
results.push_back(formatString(GameConstants::OBSERVER_SLOTNAME));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
results.push_back(formatString(GameConstants::RANDOMFACTION_SLOTNAME));
|
||||||
|
|
||||||
factionFiles= results;
|
factionFiles= results;
|
||||||
for(int i= 0; i<results.size(); ++i){
|
for(int i= 0; i<results.size(); ++i){
|
||||||
results[i]= formatString(results[i]);
|
results[i]= formatString(results[i]);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user