From 2440d475b346b3237e26e08646942e9a601dfe86 Mon Sep 17 00:00:00 2001 From: Titus Tscharntke Date: Mon, 8 Nov 2010 23:15:50 +0000 Subject: [PATCH] beginning of new resource multiplier. Still work in progress but hopefully ready to test some things. --- source/glest_game/game/game_settings.h | 6 ++ .../menu/menu_state_connected_game.cpp | 44 +++++++++---- .../menu/menu_state_connected_game.h | 3 + .../menu/menu_state_custom_game.cpp | 61 ++++++++++++++----- .../glest_game/menu/menu_state_custom_game.h | 3 + source/glest_game/network/network_message.cpp | 2 + source/glest_game/network/network_message.h | 1 + source/glest_game/world/unit_updater.cpp | 1 + 8 files changed, 93 insertions(+), 28 deletions(-) diff --git a/source/glest_game/game/game_settings.h b/source/glest_game/game/game_settings.h index 27c3838f..60daec4a 100644 --- a/source/glest_game/game/game_settings.h +++ b/source/glest_game/game/game_settings.h @@ -36,6 +36,7 @@ private: string networkPlayerNames[GameConstants::maxPlayers]; ControlType factionControls[GameConstants::maxPlayers]; + float resourceMultiplier[GameConstants::maxPlayers]; int thisFactionIndex; int factionCount; @@ -73,6 +74,7 @@ public: factionTypeNames[i] = ""; networkPlayerNames[i] = ""; factionControls[i] = ctClosed; + resourceMultiplier[i] = 1.0f; teams[i] = 0; startLocationIndex[i] = i; } @@ -100,6 +102,7 @@ public: return result; } ControlType getFactionControl(int factionIndex) const {return factionControls[factionIndex];} + float getResourceMultiplier(int factionIndex) const {return resourceMultiplier[factionIndex];} bool isNetworkGame() const { bool result = false; @@ -140,6 +143,8 @@ public: void setFactionTypeName(int factionIndex, const string& factionTypeName) {this->factionTypeNames[factionIndex]= factionTypeName;} void setNetworkPlayerName(int factionIndex,const string& playername) {this->networkPlayerNames[factionIndex]= playername;} void setFactionControl(int factionIndex, ControlType controller) {this->factionControls[factionIndex]= controller;} + void setResourceMultiplier(int factionIndex, float multiplier) {this->resourceMultiplier[factionIndex]= multiplier;} + void setThisFactionIndex(int thisFactionIndex) {this->thisFactionIndex= thisFactionIndex;} void setFactionCount(int factionCount) {this->factionCount= factionCount;} void setTeam(int factionIndex, int team) {this->teams[factionIndex]= team;} @@ -175,6 +180,7 @@ public: result += "networkPlayerName = " + networkPlayerNames[idx] + "\n"; result += "factionControl = " + intToStr(factionControls[idx]) + "\n"; + result += "resourceMultiplier = " + intToStr(resourceMultiplier[idx]) + "\n"; result += "team = " + intToStr(teams[idx]) + "\n"; result += "startLocationIndex = " + intToStr(startLocationIndex[idx]) + "\n"; } diff --git a/source/glest_game/menu/menu_state_connected_game.cpp b/source/glest_game/menu/menu_state_connected_game.cpp index d81b8697..a6d47ef5 100644 --- a/source/glest_game/menu/menu_state_connected_game.cpp +++ b/source/glest_game/menu/menu_state_connected_game.cpp @@ -68,6 +68,8 @@ MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainM lastSetChangedGameSettings = time(NULL); showFullConsole=false; + rMultiplierOffset=0.5f; + currentFactionName=""; currentMap=""; settingsReceivedFromServer=false; @@ -87,7 +89,7 @@ MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainM enableFactionTexturePreview = config.getBool("FactionPreview","true"); enableMapPreview = config.getBool("MapPreview","true"); - vector teamItems, controlItems, results; + vector teamItems, controlItems, results, rMultiplier; int setupPos=590; int mapHeadPos=330; int mapPos=mapHeadPos-30; @@ -252,46 +254,54 @@ MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainM SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); //list boxes - xoffset=120; + xoffset=100; int rowHeight=27; for(int i=0; i"); } labelControl.registerGraphicComponent(containerName,"labelControl"); - labelControl.init(xoffset+200, setupPos, GraphicListBox::defW, GraphicListBox::defH, true); + labelControl.init(xoffset+210, setupPos, GraphicListBox::defW, GraphicListBox::defH, true); labelControl.setText(lang.get("Control")); + labelRMultiplier.registerGraphicComponent(containerName,"labelRMultiplier"); + labelRMultiplier.init(xoffset+350, setupPos, GraphicListBox::defW, GraphicListBox::defH, true); + //labelRMultiplier.setText(lang.get("RMultiplier")); + labelFaction.registerGraphicComponent(containerName,"labelFaction"); - labelFaction.init(xoffset+350, setupPos, GraphicListBox::defW, GraphicListBox::defH, true); + labelFaction.init(xoffset+430, setupPos, GraphicListBox::defW, GraphicListBox::defH, true); labelFaction.setText(lang.get("Faction")); labelTeam.registerGraphicComponent(containerName,"labelTeam"); - labelTeam.init(xoffset+520, setupPos, 60, GraphicListBox::defH, true); + labelTeam.init(xoffset+590, setupPos, 60, GraphicListBox::defH, true); labelTeam.setText(lang.get("Team")); labelControl.setFont(CoreData::getInstance().getMenuFontBig()); @@ -310,6 +320,10 @@ MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainM controlItems.push_back(lang.get("Network")); controlItems.push_back(lang.get("Human")); + for(int i=0; i<45; ++i){ + rMultiplier.push_back(floatToStr(rMultiplierOffset+0.1f*i)); + } + if(config.getBool("EnableNetworkCpu","false") == true) { controlItems.push_back(lang.get("NetworkCpuEasy")); controlItems.push_back(lang.get("NetworkCpu")); @@ -331,6 +345,9 @@ MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainM listBoxTeams[i].setItems(teamItems); listBoxTeams[i].setSelectedItemIndex(i); listBoxControls[i].setItems(controlItems); + listBoxRMultiplier[i].setItems(rMultiplier); + listBoxRMultiplier[i].setSelectedItemIndex(5); + labelNetStatus[i].setText("V"); } SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); @@ -588,6 +605,7 @@ void MenuStateConnectedGame::render() { renderer.renderListBox(&listBoxControls[i]); if(listBoxControls[i].getSelectedItemIndex()!=ctClosed){ + renderer.renderListBox(&listBoxRMultiplier[i]); renderer.renderListBox(&listBoxFactions[i]); renderer.renderListBox(&listBoxTeams[i]); //renderer.renderLabel(&labelNetStatus[i]); @@ -619,6 +637,7 @@ void MenuStateConnectedGame::render() { renderer.renderLabel(&labelTileset); renderer.renderLabel(&labelTechTree); renderer.renderLabel(&labelControl); + //renderer.renderLabel(&labelRMultiplier); renderer.renderLabel(&labelFaction); renderer.renderLabel(&labelTeam); renderer.renderLabel(&labelMapInfo); @@ -987,6 +1006,7 @@ void MenuStateConnectedGame::update() { for(int i=0; igetFactionCount(); ++i){ int slot=gameSettings->getStartLocationIndex(i); listBoxControls[slot].setSelectedItemIndex(gameSettings->getFactionControl(i),errorOnMissingData); + listBoxRMultiplier[slot].setSelectedItemIndex((gameSettings->getResourceMultiplier(i)-rMultiplierOffset)*10); listBoxTeams[slot].setSelectedItemIndex(gameSettings->getTeam(i),errorOnMissingData); //listBoxFactions[slot].setSelectedItem(formatString(gameSettings->getFactionTypeName(i)),errorOnMissingData); listBoxFactions[slot].setSelectedItem(formatString(gameSettings->getFactionTypeName(i)),false); diff --git a/source/glest_game/menu/menu_state_connected_game.h b/source/glest_game/menu/menu_state_connected_game.h index 6daa3510..8a9de50b 100644 --- a/source/glest_game/menu/menu_state_connected_game.h +++ b/source/glest_game/menu/menu_state_connected_game.h @@ -36,6 +36,7 @@ private: GraphicButton buttonDisconnect; GraphicButton buttonPlayNow; GraphicLabel labelControl; + GraphicLabel labelRMultiplier; GraphicLabel labelFaction; GraphicLabel labelTeam; GraphicLabel labelMap; @@ -79,6 +80,7 @@ private: GraphicLabel labelPlayers[GameConstants::maxPlayers]; GraphicLabel labelPlayerNames[GameConstants::maxPlayers]; GraphicListBox listBoxControls[GameConstants::maxPlayers]; + GraphicListBox listBoxRMultiplier[GameConstants::maxPlayers]; GraphicListBox listBoxFactions[GameConstants::maxPlayers]; GraphicListBox listBoxTeams[GameConstants::maxPlayers]; GraphicLabel labelNetStatus[GameConstants::maxPlayers]; @@ -133,6 +135,7 @@ private: std::vector tileSets; + float rMultiplierOffset; public: MenuStateConnectedGame(Program *program, MainMenu *mainMenu, JoinMenu joinMenuInfo=jmSimple, bool openNetworkSlots= false); diff --git a/source/glest_game/menu/menu_state_custom_game.cpp b/source/glest_game/menu/menu_state_custom_game.cpp index 7b7c780c..ec676628 100644 --- a/source/glest_game/menu/menu_state_custom_game.cpp +++ b/source/glest_game/menu/menu_state_custom_game.cpp @@ -60,6 +60,8 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, b currentTechName_factionPreview=""; currentFactionName_factionPreview=""; mapPreviewTexture=NULL; + + rMultiplierOffset=0.5f; publishToMasterserverThread = NULL; Lang &lang= Lang::getInstance(); @@ -111,7 +113,7 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, b lastNetworkPing = 0; soundConnectionCount=0; - vector teamItems, controlItems, results; + vector teamItems, controlItems, results , rMultiplier; //create buttonReturn.registerGraphicComponent(containerName,"buttonReturn"); @@ -349,41 +351,49 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, b //list boxes - xoffset=120; + xoffset=100; int rowHeight=27; for(int i=0; isetResourceMultiplier(slotIndex, rMultiplierOffset+listBoxRMultiplier[i].getSelectedItemIndex()*0.1f); 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()]); if(factionFiles[listBoxFactions[i].getSelectedItemIndex()] == formatString(GameConstants::OBSERVER_SLOTNAME)) { @@ -1973,6 +1998,7 @@ void MenuStateCustomGame::loadGameSettings(GameSettings *gameSettings) { gameSettings->setFactionControl(slotIndex, ct); gameSettings->setTeam(slotIndex, listBoxTeams[i].getSelectedItemIndex()); gameSettings->setStartLocationIndex(slotIndex, i); + gameSettings->setResourceMultiplier(slotIndex, 1.0f); 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()]); @@ -2044,6 +2070,7 @@ void MenuStateCustomGame::saveGameSettingsToFile(std::string fileName) { int slotIndex = gameSettings.getStartLocationIndex(i); saveGameFile << "FactionControlForIndex" << slotIndex << "=" << gameSettings.getFactionControl(i) << std::endl; + saveGameFile << "ResourceMultiplier" << slotIndex << "=" << gameSettings.getResourceMultiplier(i) << std::endl; saveGameFile << "FactionTeamForIndex" << slotIndex << "=" << gameSettings.getTeam(i) << std::endl; saveGameFile << "FactionStartLocationForIndex" << slotIndex << "=" << gameSettings.getStartLocationIndex(i) << std::endl; saveGameFile << "FactionTypeNameForIndex" << slotIndex << "=" << gameSettings.getFactionTypeName(i) << std::endl; @@ -2098,6 +2125,7 @@ GameSettings MenuStateCustomGame::loadGameSettingsFromFile(std::string fileName) //for(int i = 0; i < gameSettings.getFactionCount(); ++i) { for(int i = 0; i < GameConstants::maxPlayers; ++i) { gameSettings.setFactionControl(i,(ControlType)properties.getInt(string("FactionControlForIndex") + intToStr(i),intToStr(ctClosed).c_str()) ); + gameSettings.setResourceMultiplier(i,properties.getFloat(string("ResourceMultiplier") + intToStr(i))); gameSettings.setTeam(i,properties.getInt(string("FactionTeamForIndex") + intToStr(i),"0") ); gameSettings.setStartLocationIndex(i,properties.getInt(string("FactionStartLocationForIndex") + intToStr(i),intToStr(i).c_str()) ); gameSettings.setFactionTypeName(i,properties.getString(string("FactionTypeNameForIndex") + intToStr(i),"?") ); @@ -2166,6 +2194,7 @@ GameSettings MenuStateCustomGame::loadGameSettingsFromFile(std::string fileName) //for(int i = 0; i < gameSettings.getFactionCount(); ++i) { for(int i = 0; i < GameConstants::maxPlayers; ++i) { listBoxControls[i].setSelectedItemIndex(gameSettings.getFactionControl(i)); + listBoxRMultiplier[i].setSelectedItemIndex((gameSettings.getResourceMultiplier(i)-rMultiplierOffset)*10); listBoxTeams[i].setSelectedItemIndex(gameSettings.getTeam(i)); lastSelectedTeamIndex[i] = listBoxTeams[i].getSelectedItemIndex(); diff --git a/source/glest_game/menu/menu_state_custom_game.h b/source/glest_game/menu/menu_state_custom_game.h index a1c9f74e..4859cafc 100644 --- a/source/glest_game/menu/menu_state_custom_game.h +++ b/source/glest_game/menu/menu_state_custom_game.h @@ -32,6 +32,7 @@ private: GraphicButton buttonPlayNow; GraphicButton buttonRestoreLastSettings; GraphicLabel labelControl; + GraphicLabel labelRMultiplier; GraphicLabel labelFaction; GraphicLabel labelTeam; GraphicLabel labelMap; @@ -60,6 +61,7 @@ private: GraphicLabel labelPlayers[GameConstants::maxPlayers]; GraphicLabel labelPlayerNames[GameConstants::maxPlayers]; GraphicListBox listBoxControls[GameConstants::maxPlayers]; + GraphicListBox listBoxRMultiplier[GameConstants::maxPlayers]; GraphicListBox listBoxFactions[GameConstants::maxPlayers]; GraphicListBox listBoxTeams[GameConstants::maxPlayers]; GraphicLabel labelNetStatus[GameConstants::maxPlayers]; @@ -138,6 +140,7 @@ private: bool autostart; std::map lastSelectedTeamIndex; + float rMultiplierOffset; public: MenuStateCustomGame(Program *program, MainMenu *mainMenu ,bool openNetworkSlots= false, bool parentMenuIsMasterserver=false, bool autostart=false); diff --git a/source/glest_game/network/network_message.cpp b/source/glest_game/network/network_message.cpp index 9b744425..9def4818 100644 --- a/source/glest_game/network/network_message.cpp +++ b/source/glest_game/network/network_message.cpp @@ -237,6 +237,7 @@ NetworkMessageLaunch::NetworkMessageLaunch(const GameSettings *gameSettings,int8 data.factionTypeNames[i]= gameSettings->getFactionTypeName(i); data.networkPlayerNames[i]= gameSettings->getNetworkPlayerName(i); data.factionControls[i]= gameSettings->getFactionControl(i); + data.resourceMultiplier[i]= 10*(gameSettings->getResourceMultiplier(i)); data.teams[i]= gameSettings->getTeam(i); data.startLocationIndex[i]= gameSettings->getStartLocationIndex(i); } @@ -265,6 +266,7 @@ void NetworkMessageLaunch::buildGameSettings(GameSettings *gameSettings) const{ gameSettings->setFactionTypeName(i, data.factionTypeNames[i].getString()); gameSettings->setNetworkPlayerName(i,data.networkPlayerNames[i].getString()); gameSettings->setFactionControl(i, static_cast(data.factionControls[i])); + gameSettings->setResourceMultiplier(i,data.resourceMultiplier[i]*0.1f); gameSettings->setTeam(i, data.teams[i]); gameSettings->setStartLocationIndex(i, data.startLocationIndex[i]); } diff --git a/source/glest_game/network/network_message.h b/source/glest_game/network/network_message.h index 93025603..b7804cd5 100644 --- a/source/glest_game/network/network_message.h +++ b/source/glest_game/network/network_message.h @@ -195,6 +195,7 @@ private: NetworkString networkPlayerNames[GameConstants::maxPlayers]; //networkPlayerNames int8 factionControls[GameConstants::maxPlayers]; + int8 resourceMultiplier[GameConstants::maxPlayers]; int8 thisFactionIndex; int8 factionCount; diff --git a/source/glest_game/world/unit_updater.cpp b/source/glest_game/world/unit_updater.cpp index f3bf4784..65b6895b 100644 --- a/source/glest_game/world/unit_updater.cpp +++ b/source/glest_game/world/unit_updater.cpp @@ -839,6 +839,7 @@ void UnitUpdater::updateHarvest(Unit *unit) { if(unit->getFaction()->getCpuMegaControl()){ resourceAmount*= megaResourceFactor; } + resourceAmount*=game->getGameSettings()->getResourceMultiplier(unit->getFaction()->getIndex()); unit->getFaction()->incResourceAmount(unit->getLoadType(), resourceAmount); world->getStats()->harvest(unit->getFactionIndex(), resourceAmount); scriptManager->onResourceHarvested();