- added support for team unit sharing

This commit is contained in:
SoftCoder 2014-01-27 14:15:05 -08:00
parent 338f156a95
commit e63b3d7499
13 changed files with 385 additions and 328 deletions

View File

@ -10,6 +10,6 @@ CPUS=`lscpu -p | grep -cv '^#'`
if [ "$CPUS" = '' ]; then CPUS=1; fi
#~/cppcheck-1.62/cppcheck ../../source/ -i ../../source/win32_deps -i ../../source/configurator -i ../../source/shared_lib/sources/libircclient -i ../../source/shared_lib/sources/platform/miniupnpc -j $CPUS --enable=all --force --verbose 2> $OUTFILE
cppcheck ../../source/ -i ../../source/win32_deps -i ../../source/configurator -i ../../source/shared_lib/sources/libircclient -i ../../source/shared_lib/sources/platform/miniupnpc -j $CPUS --enable=all --force --verbose 2> $OUTFILE
cppcheck ../../source/ -i ../../source/win32_deps -i ../../source/configurator -i ../../source/shared_lib/sources/libircclient -i ../../source/shared_lib/sources/platform/miniupnpc -i ../../source/shared_lib/sources/streflop -j $CPUS --enable=all --force --verbose 2> $OUTFILE
echo "Results from cppcheck were written to $OUTFILE"

View File

@ -620,6 +620,7 @@ void Commander::giveNetworkCommand(NetworkCommand* networkCommand) const {
gameNetworkInterface->sendTextMessage(szMsg,-1, localEcho,languageList[i]);
}
}
world->getGame()->reInitGUI();
}
}
else {
@ -713,6 +714,7 @@ void Commander::giveNetworkCommand(NetworkCommand* networkCommand) const {
gameNetworkInterface->sendTextMessage(szMsg,-1, localEcho,languageList[i]);
}
}
world->getGame()->reInitGUI();
}
}
else if(newTeamTotalMemberCount == (newTeamVotedYes + newTeamVotedNo)) {

View File

@ -1622,6 +1622,10 @@ void Game::init(bool initForPreviewOnly) {
// ==================== update ====================
void Game::reInitGUI() {
gui.init(this);
}
void Game::setupPopupMenus(bool checkClientAdminOverrideOnly) {
Lang &lang= Lang::getInstance();
NetworkManager &networkManager= NetworkManager::getInstance();

View File

@ -223,6 +223,8 @@ public:
Game(Program *program, const GameSettings *gameSettings, bool masterserverMode);
~Game();
void reInitGUI();
bool isMarkCellMode() const { return isMarkCellEnabled; }
const Texture2D * getMarkCellTexture() const { return markCellTexture; }
bool isUnMarkCellMode() const { return isUnMarkCellEnabled; }

View File

@ -1,14 +1,3 @@
#ifndef _GLEST_GAME_GAMECONSTANTS_H_
#define _GLEST_GAME_GAMECONSTANTS_H_
#include <cassert>
#include <stdio.h>
#include "vec.h"
#include <map>
#include <string>
#include "conversion.h"
#include <stdexcept>
// ==============================================================
// This file is part of Glest (www.glest.org)
//
@ -20,6 +9,17 @@
// License, or (at your option) any later version
// ==============================================================
#ifndef _GLEST_GAME_GAMECONSTANTS_H_
#define _GLEST_GAME_GAMECONSTANTS_H_
#include <cassert>
#include <stdio.h>
#include "vec.h"
#include <map>
#include <string>
#include "conversion.h"
#include <stdexcept>
using namespace Shared::Graphics;
using namespace std;
using namespace Shared::Util;
@ -115,30 +115,27 @@ enum FactionPersonalityType {
enum MasterServerGameStatusType {
game_status_waiting_for_players = 0,
game_status_waiting_for_start = 1,
game_status_in_progress = 2,
game_status_finished = 3
game_status_waiting_for_start = 1,
game_status_in_progress = 2,
game_status_finished = 3
};
class GameConstants {
public:
static const int specialFactions = fpt_EndCount - 1;
static const int maxPlayers= 8;
static const int serverPort= 61357;
static const int serverAdminPort= 61355;
//static const int updateFps= 40;
//static const int cameraFps= 100;
static const int specialFactions = fpt_EndCount - 1;
static const int maxPlayers = 8;
static const int serverPort = 61357;
static const int serverAdminPort = 61355;
static int updateFps;
static int cameraFps;
static int networkFramePeriod;
static const int networkPingInterval = 5;
static const int networkSmoothInterval= 30;
//static const int networkExtraLatency= 200;
static const int maxClientConnectHandshakeSecs= 10;
static const int networkPingInterval = 5;
static const int networkSmoothInterval = 30;
static const int maxClientConnectHandshakeSecs = 10;
static const int cellScale = 2;
static const int clusterSize = 16;
static const int cellScale = 2;
static const int clusterSize = 16;
static const char *folder_path_maps;
static const char *folder_path_scenarios;
@ -212,9 +209,7 @@ public:
static void assertDirValid(int v) { assert(v >= 0 && v < 4); }
void operator++() {
//printf("In [%s::%s] Line: %d BEFORE +: value = %d\n",__FILE__,__FUNCTION__,__LINE__,asInt());
value = static_cast<Enum>((value + 1) % 4);
//printf("In [%s::%s] Line: %d AFTER +: value = %d\n",__FILE__,__FUNCTION__,__LINE__,asInt());
}
void operator--() { // mod with negative numbers is a 'grey area', hence the +3 rather than -1
value = static_cast<Enum>((value + 3) % 4);

View File

@ -17,7 +17,6 @@
#include <algorithm>
#include "xml_parser.h"
#include "config.h"
//#include "util.h"
#include "platform_common.h"
#include "conversion.h"
#include "platform_util.h"
@ -66,9 +65,10 @@ enum FlagTypes1 {
ft1_allow_team_switching = 0x02,
ft1_allow_in_game_joining = 0x04,
ft1_network_synch_checks_verbose = 0x08,
ft1_network_synch_checks = 0x10
//ft1_xx = 0x20,
//ft1_xx = 0x40,
ft1_network_synch_checks = 0x10,
ft1_allow_shared_team_units = 0x20,
ft1_allow_shared_team_resources = 0x40
//ft1_xxx = 0x80
};
inline static bool isFlagType1BitEnabled(uint32 flagValue,FlagTypes1 type) {
@ -590,7 +590,7 @@ public:
result += "networkFramePeriod = " + intToStr(networkFramePeriod) + "\n";
result += "networkPauseGameForLaggedClients = " + intToStr(networkPauseGameForLaggedClients) + "\n";
result += "pathFinderType = " + intToStr(pathFinderType) + "\n";
result += "flagTypes1 = " + intToStr(flagTypes1) + "\n";
result += "flagTypes1 = " + uIntToStr(flagTypes1) + "\n";
result += "mapCRC = " + uIntToStr(mapCRC) + "\n";
result += "tilesetCRC = " + uIntToStr(tilesetCRC) + "\n";
result += "techCRC = " + uIntToStr(techCRC) + "\n";
@ -718,7 +718,7 @@ public:
// PathFinderType pathFinderType;
gameSettingsNode->addAttribute("pathFinderType",intToStr(pathFinderType), mapTagReplacements);
// uint32 flagTypes1;
gameSettingsNode->addAttribute("flagTypes1",intToStr(flagTypes1), mapTagReplacements);
gameSettingsNode->addAttribute("flagTypes1",uIntToStr(flagTypes1), mapTagReplacements);
// int32 mapCRC;
gameSettingsNode->addAttribute("mapCRC",uIntToStr(mapCRC), mapTagReplacements);
// int32 tilesetCRC;
@ -858,7 +858,7 @@ public:
// PathFinderType pathFinderType;
pathFinderType = static_cast<PathFinderType>(gameSettingsNode->getAttribute("pathFinderType")->getIntValue());
// uint32 flagTypes1;
flagTypes1 = gameSettingsNode->getAttribute("flagTypes1")->getIntValue();
flagTypes1 = gameSettingsNode->getAttribute("flagTypes1")->getUIntValue();
// int32 mapCRC;
mapCRC = gameSettingsNode->getAttribute("mapCRC")->getUIntValue();
// int32 tilesetCRC;

View File

@ -124,13 +124,18 @@ Gui::Gui(){
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] END\n",__FILE__,__FUNCTION__);
}
void Gui::init(Game *game){
this->commander= game->getCommander();
this->gameCamera= game->getGameCameraPtr();
this->console= game->getConsole();
this->world= game->getWorld();
this->game=game;
selection.init(this, world->getThisFactionIndex(), world->getThisTeamIndex());
void Gui::init(Game *game) {
this->commander = game->getCommander();
this->gameCamera = game->getGameCameraPtr();
this->console = game->getConsole();
this->world = game->getWorld();
this->game = game;
selection.init(this,
world->getThisFactionIndex(),
world->getThisTeamIndex(),
isFlagType1BitEnabled(game->getGameSettings()->getFlagTypes1(),ft1_allow_shared_team_units));
}
void Gui::end(){
@ -217,10 +222,14 @@ bool Gui::mouseValid(int x, int y) {
}
void Gui::mouseDownLeftDisplay(int x, int y) {
if(!selectingPos && !selectingMeetingPoint) {
int posDisplay= computePosDisplay(x, y);
if(posDisplay!= invalidPos) {
if(selectingPos == false &&
selectingMeetingPoint == false) {
int posDisplay = computePosDisplay(x, y);
if(posDisplay != invalidPos) {
if(selection.isCommandable()) {
if(selectingBuilding) {
mouseDownDisplayUnitBuild(posDisplay);
}
@ -548,15 +557,15 @@ void Gui::centerCameraOnSelection() {
}
void Gui::selectInterestingUnit(InterestingUnitType iut) {
const Faction* thisFaction= world->getThisFaction();
const Unit* previousUnit= NULL;
bool previousFound= true;
const Faction *thisFaction = world->getThisFaction();
const Unit* previousUnit = NULL;
bool previousFound = true;
//start at the next harvester
if(selection.getCount()==1){
if(selection.getCount() == 1) {
const Unit* refUnit= selection.getFrontUnit();
if(refUnit->isInteresting(iut)){
if(refUnit->isInteresting(iut)) {
previousUnit= refUnit;
previousFound= false;
}
@ -566,28 +575,28 @@ void Gui::selectInterestingUnit(InterestingUnitType iut) {
selection.clear();
//search
for(int i= 0; i<thisFaction->getUnitCount(); ++i){
Unit* unit= thisFaction->getUnit(i);
for(int index = 0; index < thisFaction->getUnitCount(); ++index){
Unit* unit = thisFaction->getUnit(index);
if(previousFound){
if(unit->isInteresting(iut)){
if(previousFound == true) {
if(unit->isInteresting(iut)) {
selection.select(unit);
break;
}
}
else{
if(unit==previousUnit){
previousFound= true;
if(unit == previousUnit) {
previousFound = true;
}
}
}
//search again if we have a previous
if(selection.isEmpty() && previousUnit!=NULL && previousFound==true){
for(int i= 0; i<thisFaction->getUnitCount(); ++i){
Unit* unit= thisFaction->getUnit(i);
if(selection.isEmpty() && previousUnit != NULL && previousFound == true) {
for(int index = 0; index < thisFaction->getUnitCount(); ++index) {
Unit* unit = thisFaction->getUnit(index);
if(unit->isInteresting(iut)){
if(unit->isInteresting(iut)) {
selection.select(unit);
break;
}
@ -595,11 +604,14 @@ void Gui::selectInterestingUnit(InterestingUnitType iut) {
}
}
void Gui::clickCommonCommand(CommandClass commandClass){
for(int i= 0; i<Display::downCellCount; ++i){
const CommandType* ct= display.getCommandType(i);
if((ct!=NULL && ct->getClass()==commandClass) || display.getCommandClass(i)==commandClass){
mouseDownDisplayUnitSkills(i);
void Gui::clickCommonCommand(CommandClass commandClass) {
for(int index = 0; index < Display::downCellCount; ++index) {
const CommandType *ct = display.getCommandType(index);
if((ct != NULL && ct->getClass() == commandClass) ||
display.getCommandClass(index) == commandClass) {
mouseDownDisplayUnitSkills(index);
break;
}
}
@ -607,34 +619,34 @@ void Gui::clickCommonCommand(CommandClass commandClass){
}
void Gui::mouseDownDisplayUnitSkills(int posDisplay) {
if(!selection.isEmpty()) {
if(selection.isEmpty() == false) {
if(posDisplay != cancelPos) {
if(posDisplay!=meetingPointPos) {
if(posDisplay != meetingPointPos) {
const Unit *unit= selection.getFrontUnit();
//uniform selection
if(selection.isUniform()) {
const CommandType *ct = display.getCommandType(posDisplay);
if(activeCommandClass == ccAttack)
{// try to switch to next attack type
int maxI=unit->getType()->getCommandTypeCount();
int i=activeCommandType->getId();
int k=i+1;
while(k!=i)
{
if(k>=maxI)
{
k=0;
// try to switch to next attack type
if(activeCommandClass == ccAttack) {
int maxI = unit->getType()->getCommandTypeCount();
int cmdTypeId = activeCommandType->getId();
int cmdTypeIdNext = cmdTypeId+1;
while(cmdTypeIdNext != cmdTypeId) {
if(cmdTypeIdNext >= maxI) {
cmdTypeIdNext = 0;
}
const CommandType *ctype=display.getCommandType(k);
if(ctype != NULL && ctype->getClass() == ccAttack)
{
const CommandType *ctype = display.getCommandType(cmdTypeIdNext);
if(ctype != NULL && ctype->getClass() == ccAttack) {
if(ctype != NULL && unit->getFaction()->reqsOk(ctype)) {
posDisplay=k;
posDisplay=cmdTypeIdNext;
break;
}
}
k++;
cmdTypeIdNext++;
}
}
@ -684,22 +696,32 @@ void Gui::mouseDownDisplayUnitSkills(int posDisplay) {
}
}
void Gui::mouseDownDisplayUnitBuild(int posDisplay){
int factionIndex= world->getThisFactionIndex();
void Gui::mouseDownDisplayUnitBuild(int posDisplay) {
//int factionIndex = world->getThisFactionIndex();
if(posDisplay==cancelPos){
if(posDisplay == cancelPos) {
resetState();
}
else{
if(activeCommandType!=NULL && activeCommandType->getClass()==ccBuild){
const BuildCommandType *bct= static_cast<const BuildCommandType*>(activeCommandType);
const UnitType *ut= bct->getBuilding(posDisplay);
if(world->getFaction(factionIndex)->reqsOk(ut)){
choosenBuildingType= ut;
assert(choosenBuildingType!=NULL);
selectingPos= true;
selectedBuildingFacing = CardinalDir::NORTH;
activePos= posDisplay;
else {
if(activeCommandType != NULL &&
activeCommandType->getClass() == ccBuild) {
const BuildCommandType *bct = dynamic_cast<const BuildCommandType*>(activeCommandType);
if(bct != NULL) {
const UnitType *ut = bct->getBuilding(posDisplay);
const Unit *unit = selection.getFrontUnit();
if(unit != NULL && unit->getFaction() != NULL) {
if(selection.canSelectUnitFactionCheck(unit) == true &&
unit->getFaction()->reqsOk(ut)) {
choosenBuildingType = ut;
selectingPos = true;
selectedBuildingFacing = CardinalDir::NORTH;
activePos = posDisplay;
}
}
}
}
}
@ -707,10 +729,7 @@ void Gui::mouseDownDisplayUnitBuild(int posDisplay){
string Gui::computeDefaultInfoString() {
//Lang &lang= Lang::getInstance();
string result="";
//printf("\n\n\n\n********* selection.isCommandable() [%d] selection.isUniform() [%d]\n\n",selection.isCommandable(),selection.isUniform());
if(selection.isUniform()) {
if(selection.isObserver() || selection.isCommandable()) {
@ -1251,138 +1270,53 @@ void Gui::saveGame(XmlNode *rootNode) const {
std::map<string,string> mapTagReplacements;
XmlNode *guiNode = rootNode->addChild("Gui");
//External objects
// RandomGen random;
guiNode->addAttribute("random",intToStr(random.getLastNumber()), mapTagReplacements);
// const Commander *commander;
// const World *world;
// const Game *game;
// GameCamera *gameCamera;
// Console *console;
//
// //Positions
// Vec2i posObjWorld; //world coords
guiNode->addAttribute("posObjWorld",posObjWorld.getString(), mapTagReplacements);
// bool validPosObjWorld;
guiNode->addAttribute("validPosObjWorld",intToStr(validPosObjWorld), mapTagReplacements);
// //display
// const UnitType *choosenBuildingType;
if(choosenBuildingType != NULL) {
const Faction* thisFaction= world->getThisFaction();
guiNode->addAttribute("choosenBuildingType",choosenBuildingType->getName(false), mapTagReplacements);
guiNode->addAttribute("choosenBuildingTypeFactionIndex",intToStr(thisFaction->getIndex()), mapTagReplacements);
}
// const CommandType *activeCommandType;
if(activeCommandType != NULL) {
guiNode->addAttribute("activeCommandType",activeCommandType->getName(false), mapTagReplacements);
}
// CommandClass activeCommandClass;
guiNode->addAttribute("activeCommandClass",intToStr(activeCommandClass), mapTagReplacements);
// int activePos;
guiNode->addAttribute("activePos",intToStr(activePos), mapTagReplacements);
// int lastPosDisplay;
guiNode->addAttribute("lastPosDisplay",intToStr(lastPosDisplay), mapTagReplacements);
// //composite
// Display display;
display.saveGame(guiNode);
// Mouse3d mouse3d;
// Selection selection;
selection.saveGame(guiNode);
// SelectionQuad selectionQuad;
// int lastQuadCalcFrame;
guiNode->addAttribute("lastQuadCalcFrame",intToStr(lastQuadCalcFrame), mapTagReplacements);
// int selectionCalculationFrameSkip;
guiNode->addAttribute("selectionCalculationFrameSkip",intToStr(selectionCalculationFrameSkip), mapTagReplacements);
// int minQuadSize;
guiNode->addAttribute("minQuadSize",intToStr(minQuadSize), mapTagReplacements);
// Chrono lastGroupRecallTime;
//guiNode->addAttribute("lastGroupRecallTime",intToStr(lastGroupRecallTime.getMillis()), mapTagReplacements);
// int lastGroupRecall;
guiNode->addAttribute("lastGroupRecall",intToStr(lastGroupRecall), mapTagReplacements);
// //states
// bool selectingBuilding;
guiNode->addAttribute("selectingBuilding",intToStr(selectingBuilding), mapTagReplacements);
// bool selectingPos;
guiNode->addAttribute("selectingPos",intToStr(selectingPos), mapTagReplacements);
// bool selectingMeetingPoint;
guiNode->addAttribute("selectingMeetingPoint",intToStr(selectingMeetingPoint), mapTagReplacements);
// CardinalDir selectedBuildingFacing;
guiNode->addAttribute("selectedBuildingFacing",intToStr(selectedBuildingFacing), mapTagReplacements);
// const Object *selectedResourceObject;
//
// Texture2D* hudTexture;
}
void Gui::loadGame(const XmlNode *rootNode, World *world) {
const XmlNode *guiNode = rootNode->getChild("Gui");
//External objects
// RandomGen random;
random.setLastNumber(guiNode->getAttribute("random")->getIntValue());
// const Commander *commander;
// const World *world;
// const Game *game;
// GameCamera *gameCamera;
// Console *console;
//
// //Positions
// Vec2i posObjWorld; //world coords
//guiNode->addAttribute("posObjWorld",posObjWorld.getString(), mapTagReplacements);
posObjWorld = Vec2i::strToVec2(guiNode->getAttribute("posObjWorld")->getValue());
// bool validPosObjWorld;
validPosObjWorld = guiNode->getAttribute("validPosObjWorld")->getIntValue() != 0;
// //display
// const UnitType *choosenBuildingType;
// if(choosenBuildingType != NULL) {
// guiNode->addAttribute("choosenBuildingType",choosenBuildingType->getName(), mapTagReplacements);
// }
if(guiNode->hasAttribute("choosenBuildingType") == true) {
string unitType = guiNode->getAttribute("choosenBuildingType")->getValue();
int factionIndex = guiNode->getAttribute("choosenBuildingTypeFactionIndex")->getIntValue();
choosenBuildingType = world->getFaction(factionIndex)->getType()->getUnitType(unitType);
}
// const CommandType *activeCommandType;
//if(activeCommandType != NULL) {
// guiNode->addAttribute("activeCommandType",activeCommandType->getName(), mapTagReplacements);
//}
// CommandClass activeCommandClass;
//guiNode->addAttribute("activeCommandClass",intToStr(activeCommandClass), mapTagReplacements);
// int activePos;
activePos = guiNode->getAttribute("activePos")->getIntValue();
// int lastPosDisplay;
lastPosDisplay = guiNode->getAttribute("lastPosDisplay")->getIntValue();
// //composite
// Display display;
display.loadGame(guiNode);
// Mouse3d mouse3d;
// Selection selection;
selection.loadGame(guiNode,world);
// SelectionQuad selectionQuad;
// int lastQuadCalcFrame;
// don't load this! lastQuadCalcFrame = guiNode->getAttribute("lastQuadCalcFrame")->getIntValue();
lastQuadCalcFrame = game->getTotalRenderFps();
// int selectionCalculationFrameSkip;
selectionCalculationFrameSkip = guiNode->getAttribute("selectionCalculationFrameSkip")->getIntValue();
// int minQuadSize;
minQuadSize = guiNode->getAttribute("minQuadSize")->getIntValue();
// Chrono lastGroupRecallTime;
//guiNode->addAttribute("lastGroupRecallTime",intToStr(lastGroupRecallTime.getMillis()), mapTagReplacements);
// int lastGroupRecall;
lastGroupRecall = guiNode->getAttribute("lastGroupRecall")->getIntValue();
// //states
// bool selectingBuilding;
//selectingBuilding = guiNode->getAttribute("selectingBuilding")->getIntValue();
// bool selectingPos;
//guiNode->addAttribute("selectingPos",intToStr(selectingPos), mapTagReplacements);
// bool selectingMeetingPoint;
//guiNode->addAttribute("selectingMeetingPoint",intToStr(selectingMeetingPoint), mapTagReplacements);
// CardinalDir selectedBuildingFacing;
//guiNode->addAttribute("selectedBuildingFacing",intToStr(selectedBuildingFacing), mapTagReplacements);
// const Object *selectedResourceObject;
//
// Texture2D* hudTexture;
}
}}//end namespace

View File

@ -27,20 +27,32 @@ namespace Glest{ namespace Game{
// class Selection
// =====================================================
void Selection::init(Gui *gui, int factionIndex, int teamIndex) {
this->factionIndex= factionIndex;
this->teamIndex = teamIndex;
this->gui= gui;
void Selection::init(Gui *gui, int factionIndex, int teamIndex, bool allowSharedTeamUnits) {
this->factionIndex = factionIndex;
this->teamIndex = teamIndex;
this->allowSharedTeamUnits = allowSharedTeamUnits;
this->gui = gui;
clear();
}
Selection::~Selection(){
clear();
}
bool Selection::canSelectUnitFactionCheck(const Unit *unit) const {
//check if enemy
if(unit->getFactionIndex() != factionIndex) {
if(this->allowSharedTeamUnits == false ||
unit->getFaction()->getTeam() != teamIndex) {
return false;
}
}
return true;
}
bool Selection::select(Unit *unit) {
bool result = false;
//check size
//if(selectedUnits.size() >= maxUnits){
if((int)selectedUnits.size() >= Config::getInstance().getInt("MaxUnitSelectCount",intToStr(maxUnits).c_str())) {
return result;
}
@ -48,34 +60,36 @@ bool Selection::select(Unit *unit) {
// Fix Bug reported on sourceforge.net: Glest::Game::Selection::select crash with NULL pointer - ID: 3608835
if(unit != NULL) {
//check if already selected
for(int i=0; i < (int)selectedUnits.size(); ++i) {
if(selectedUnits[i ]== unit) {
for(int index = 0; index < (int)selectedUnits.size(); ++index) {
if(selectedUnits[index] == unit) {
return true;
}
}
//check if dead
if(unit->isDead()) {
if(unit->isDead() == true) {
return false;
}
//check if multisel
if(!unit->getType()->getMultiSelect() && !isEmpty()) {
if(unit->getType()->getMultiSelect() == false && isEmpty() == false) {
return false;
}
//check if enemy
if(unit->getFactionIndex() != factionIndex && !isEmpty()) {
if(canSelectUnitFactionCheck(unit) == false && isEmpty() == false) {
return false;
}
//check existing enemy
if(selectedUnits.size()==1 && selectedUnits.front()->getFactionIndex() != factionIndex) {
//if(selectedUnits.size() == 1 && selectedUnits.front()->getFactionIndex() != factionIndex) {
if(selectedUnits.size() == 1 && canSelectUnitFactionCheck(selectedUnits.front()) == false) {
clear();
}
//check existing multisel
if(selectedUnits.size()==1 && !selectedUnits.front()->getType()->getMultiSelect()){
if(selectedUnits.size() == 1 &&
selectedUnits.front()->getType()->getMultiSelect() == false) {
clear();
}
@ -83,22 +97,20 @@ bool Selection::select(Unit *unit) {
unit->addObserver(this);
int unitTypeId=unit->getType()->getId();
bool inserted=false;
for(int i=0; i < (int)selectedUnits.size(); ++i) {
int currentTypeId=selectedUnits[i]->getType()->getId();
int unitTypeId = unit->getType()->getId();
bool inserted = false;
for(int index = 0; index < (int)selectedUnits.size(); ++index) {
int currentTypeId = selectedUnits[index]->getType()->getId();
if(unitTypeId <= currentTypeId) {
if(unitTypeId<=currentTypeId) {
//place unit here
selectedUnits.insert(selectedUnits.begin()+i,unit);
inserted=true;
selectedUnits.insert(selectedUnits.begin() + index,unit);
inserted = true;
break;
}
else if(unitTypeId>currentTypeId) {
//do nothing
}
}
if( !inserted ){
if(inserted == false) {
selectedUnits.push_back(unit);
}
result = true;
@ -111,15 +123,15 @@ bool Selection::select(Unit *unit) {
void Selection::select(const UnitContainer &units){
//add units to gui
for(UnitIterator it= units.begin(); it!=units.end(); ++it){
for(UnitIterator it = units.begin(); it != units.end(); ++it) {
select(*it);
}
}
void Selection::unSelect(const UnitContainer &units){
void Selection::unSelect(const UnitContainer &units) {
//add units to gui
for(UnitIterator it= units.begin(); it!=units.end(); ++it){
for(UnitIterator it = units.begin(); it != units.end(); ++it) {
for(int i = 0; i < (int)selectedUnits.size(); ++i) {
if(selectedUnits[i] == *it) {
unSelect(i);
@ -128,26 +140,24 @@ void Selection::unSelect(const UnitContainer &units){
}
}
void Selection::unSelect(int i){
//remove unit from list
selectedUnits.erase(selectedUnits.begin()+i);
void Selection::unSelect(int i) {
selectedUnits.erase(selectedUnits.begin() + i);
gui->onSelectionChanged();
}
void Selection::clear(){
//clear list
selectedUnits.clear();
}
bool Selection::isUniform() const{
if(selectedUnits.empty()){
if(selectedUnits.empty() == true) {
return true;
}
const UnitType *ut= selectedUnits.front()->getType();
for(int i = 0; i < (int)selectedUnits.size(); ++i) {
if(selectedUnits[i]->getType()!=ut){
if(selectedUnits[i]->getType() != ut) {
return false;
}
}
@ -156,7 +166,8 @@ bool Selection::isUniform() const{
bool Selection::isEnemy() const {
return selectedUnits.size() == 1 &&
selectedUnits.front()->getFactionIndex() != factionIndex;
//selectedUnits.front()->getFactionIndex() != factionIndex;
canSelectUnitFactionCheck(selectedUnits.front()) == false;
}
bool Selection::isObserver() const {
@ -168,12 +179,12 @@ bool Selection::isCommandable() const {
//printf("\n\n\n\n********* selection.isCommandable() ---> isEmpty() [%d] isEnemy() [%d] selectedUnits.size() [%d]\n\n",isEmpty(),isEnemy(),(int)selectedUnits.size());
return
!isEmpty() &&
!isEnemy() &&
!(selectedUnits.size()==1 && !selectedUnits.front()->isAlive());
isEmpty() == false &&
isEnemy() == false &&
(selectedUnits.size() == 1 && selectedUnits.front()->isAlive() == false) == false;
}
bool Selection::isCancelable() const{
bool Selection::isCancelable() const {
return
selectedUnits.size() > 1 ||
(selectedUnits.size() == 1 && selectedUnits[0]->anyCommand(true));
@ -190,8 +201,8 @@ Vec3f Selection::getRefPos() const{
return getFrontUnit()->getCurrVector();
}
bool Selection::hasUnit(const Unit* unit) const{
return find(selectedUnits.begin(), selectedUnits.end(), unit)!=selectedUnits.end();
bool Selection::hasUnit(const Unit* unit) const {
return find(selectedUnits.begin(), selectedUnits.end(), unit) != selectedUnits.end();
}
void Selection::assignGroup(int groupIndex,const UnitContainer *pUnits) {
@ -256,21 +267,21 @@ void Selection::recallGroup(int groupIndex){
void Selection::unitEvent(UnitObserver::Event event, const Unit *unit) {
if(event==UnitObserver::eKill){
if(event == UnitObserver::eKill) {
//remove from selection
for(int i = 0; i < (int)selectedUnits.size(); ++i) {
if(selectedUnits[i]==unit){
selectedUnits.erase(selectedUnits.begin()+i);
for(int index = 0; index < (int)selectedUnits.size(); ++index) {
if(selectedUnits[index] == unit){
selectedUnits.erase(selectedUnits.begin() + index);
break;
}
}
//remove from groups
for(int i=0; i<maxGroups; ++i){
for(int j = 0; j < (int)groups[i].size(); ++j) {
if(groups[i][j]==unit){
groups[i].erase(groups[i].begin()+j);
for(int index = 0; index < maxGroups; ++index) {
for(int index2 = 0; index2 < (int)groups[index].size(); ++index2) {
if(groups[index][index2] == unit) {
groups[index].erase(groups[index].begin() + index2);
break;
}
}
@ -278,29 +289,28 @@ void Selection::unitEvent(UnitObserver::Event event, const Unit *unit) {
//notify gui only if no more units to execute the command
//of course the selection changed, but this doesn't matter in this case.
if( selectedUnits.empty() == true ){
if( selectedUnits.empty() == true) {
gui->onSelectionChanged();
}
}
}
void Selection::saveGame(XmlNode *rootNode) const {
std::map<string,string> mapTagReplacements;
XmlNode *selectionNode = rootNode->addChild("Selection");
// int factionIndex;
selectionNode->addAttribute("factionIndex",intToStr(factionIndex), mapTagReplacements);
// int teamIndex;
selectionNode->addAttribute("teamIndex",intToStr(teamIndex), mapTagReplacements);
// UnitContainer selectedUnits;
selectionNode->addAttribute("allowSharedTeamUnits",intToStr(allowSharedTeamUnits), mapTagReplacements);
for(unsigned int i = 0; i < selectedUnits.size(); i++) {
Unit *unit = selectedUnits[i];
XmlNode *selectedUnitsNode = selectionNode->addChild("selectedUnits");
selectedUnitsNode->addAttribute("unitId",intToStr(unit->getId()), mapTagReplacements);
}
// UnitContainer groups[maxGroups];
for(unsigned int x = 0; x < (unsigned int)maxGroups; ++x) {
XmlNode *groupsNode = selectionNode->addChild("groups");
for(unsigned int i = 0; i < (unsigned int)groups[x].size(); ++i) {
@ -310,32 +320,18 @@ void Selection::saveGame(XmlNode *rootNode) const {
selectedUnitsNode->addAttribute("unitId",intToStr(unit->getId()), mapTagReplacements);
}
}
// Gui *gui;
}
void Selection::loadGame(const XmlNode *rootNode, World *world) {
const XmlNode *selectionNode = rootNode->getChild("Selection");
// vector<XmlNode *> fowPixmap1NodeList = minimapNode->getChildList("fowPixmap1");
// for(unsigned int i = 0; i < fowPixmap1NodeList.size(); ++i) {
// XmlNode *fowPixmap1Node = fowPixmap1NodeList[i];
//
// int pixelIndex = fowPixmap1Node->getAttribute("index")->getIntValue();
// fowPixmap1->getPixels()[pixelIndex] = fowPixmap1Node->getAttribute("pixel")->getIntValue();
// }
// int factionIndex;
factionIndex = selectionNode->getAttribute("factionIndex")->getIntValue();
// int teamIndex;
teamIndex = selectionNode->getAttribute("teamIndex")->getIntValue();
// UnitContainer selectedUnits;
// for(unsigned int i = 0; i < selectedUnits.size(); i++) {
// Unit *unit = selectedUnits[i];
//
// XmlNode *selectedUnitsNode = selectionNode->addChild("selectedUnits");
// selectedUnitsNode->addAttribute("id",intToStr(unit->getId()), mapTagReplacements);
// }
if(selectionNode->hasAttribute("allowSharedTeamUnits") == true) {
allowSharedTeamUnits = selectionNode->getAttribute("allowSharedTeamUnits")->getIntValue();
}
vector<XmlNode *> selectedUnitsNodeList = selectionNode->getChildList("selectedUnits");
for(unsigned int i = 0; i < selectedUnitsNodeList.size(); ++i) {
XmlNode *selectedUnitsNode = selectedUnitsNodeList[i];
@ -347,16 +343,6 @@ void Selection::loadGame(const XmlNode *rootNode, World *world) {
selectedUnits.push_back(unit);
}
// UnitContainer groups[maxGroups];
// for(unsigned int x = 0; x < maxGroups; ++x) {
// XmlNode *groupsNode = selectionNode->addChild("groups");
// for(unsigned int i = 0; i < groups[x].size(); ++i) {
// Unit *unit = groups[x][i];
//
// XmlNode *selectedUnitsNode = groupsNode->addChild("selectedUnits");
// selectedUnitsNode->addAttribute("unitId",intToStr(unit->getId()), mapTagReplacements);
// }
// }
vector<XmlNode *> groupsNodeList = selectionNode->getChildList("groups");
for(unsigned int i = 0; i < groupsNodeList.size(); ++i) {
XmlNode *groupsNode = groupsNodeList[i];
@ -372,9 +358,6 @@ void Selection::loadGame(const XmlNode *rootNode, World *world) {
groups[i].push_back(unit);
}
}
// Gui *gui;
}

View File

@ -47,23 +47,25 @@ public:
typedef UnitContainer::const_iterator UnitIterator;
public:
static const int maxGroups= 10;
static const int maxUnits= 36;
static const int maxGroups = 10;
static const int maxUnits = 36;
private:
int factionIndex;
int teamIndex;
bool allowSharedTeamUnits;
UnitContainer selectedUnits;
UnitContainer groups[maxGroups];
Gui *gui;
public:
Selection() : UnitObserver() {
factionIndex = 0;
teamIndex = 0;
gui = NULL;
factionIndex = 0;
teamIndex = 0;
allowSharedTeamUnits = false;
gui = NULL;
}
void init(Gui *gui, int factionIndex, int teamIndex);
void init(Gui *gui, int factionIndex, int teamIndex, bool allowSharedTeamUnits);
virtual ~Selection();
bool select(Unit *unit);
@ -77,7 +79,6 @@ public:
bool isEnemy() const;
bool isObserver() const;
//bool isComandable() const;
bool isCommandable() const;
bool isCancelable() const;
bool isMeetable() const;
@ -96,9 +97,11 @@ public:
vector<Unit*> getUnitsForGroup(int groupIndex);
virtual void unitEvent(UnitObserver::Event event, const Unit *unit);
bool canSelectUnitFactionCheck(const Unit *unit) const;
virtual void saveGame(XmlNode *rootNode) const;
void loadGame(const XmlNode *rootNode, World *world);
};
}}//end namespace

View File

@ -210,6 +210,28 @@ MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainM
checkBoxAllowObservers.setValue(false);
checkBoxAllowObservers.setEditable(false);
labelAllowTeamUnitSharing.registerGraphicComponent(containerName,"labelAllowTeamUnitSharing");
labelAllowTeamUnitSharing.init(xoffset+410, 670, 80);
labelAllowTeamUnitSharing.setText(lang.getString("AllowTeamUnitSharing"));
labelAllowTeamUnitSharing.setVisible(true);
checkBoxAllowTeamUnitSharing.registerGraphicComponent(containerName,"checkBoxAllowTeamUnitSharing");
checkBoxAllowTeamUnitSharing.init(xoffset+600, 670);
checkBoxAllowTeamUnitSharing.setValue(false);
checkBoxAllowTeamUnitSharing.setVisible(true);
checkBoxAllowTeamUnitSharing.setEditable(false);
labelAllowTeamResourceSharing.registerGraphicComponent(containerName,"labelAllowTeamResourceSharing");
labelAllowTeamResourceSharing.init(xoffset+410, 640, 80);
labelAllowTeamResourceSharing.setText(lang.getString("AllowTeamResourceSharing"));
labelAllowTeamResourceSharing.setVisible(true);
checkBoxAllowTeamResourceSharing.registerGraphicComponent(containerName,"checkBoxAllowTeamResourceSharing");
checkBoxAllowTeamResourceSharing.init(xoffset+600, 640);
checkBoxAllowTeamResourceSharing.setValue(false);
checkBoxAllowTeamResourceSharing.setVisible(true);
checkBoxAllowTeamResourceSharing.setEditable(false);
for(int i=0; i<45; ++i){
rMultiplier.push_back(floatToStr(0.5f+0.1f*i,1));
}
@ -637,6 +659,9 @@ void MenuStateConnectedGame::reloadUI() {
labelEnableSwitchTeamMode.setText(lang.getString("EnableSwitchTeamMode"));
labelAllowTeamUnitSharing.setText(lang.getString("AllowTeamUnitSharing"));
labelAllowTeamResourceSharing.setText(lang.getString("AllowTeamResourceSharing"));
labelAISwitchTeamAcceptPercent.setText(lang.getString("AISwitchTeamAcceptPercent"));
vector<string> aiswitchteamModeItems;
@ -1814,6 +1839,15 @@ void MenuStateConnectedGame::mouseClickAdmin(int x, int y, MouseButton mouseButt
needToBroadcastServerSettings=true;
broadcastServerSettingsDelayTimer=time(NULL);
}
else if (checkBoxAllowTeamUnitSharing.mouseClick(x, y)) {
needToBroadcastServerSettings=true;
broadcastServerSettingsDelayTimer=time(NULL);
}
else if (checkBoxAllowTeamResourceSharing.mouseClick(x, y)) {
needToBroadcastServerSettings=true;
broadcastServerSettingsDelayTimer=time(NULL);
}
else {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
@ -2156,6 +2190,26 @@ void MenuStateConnectedGame::loadGameSettings(GameSettings *gameSettings) {
gameSettings->setAiAcceptSwitchTeamPercentChance(strToInt(listBoxAISwitchTeamAcceptPercent.getSelectedItem()));
gameSettings->setFallbackCpuMultiplier(listBoxFallbackCpuMultiplier.getSelectedItemIndex());
valueFlags1 = gameSettings->getFlagTypes1();
if(checkBoxAllowTeamUnitSharing.getValue() == true) {
valueFlags1 |= ft1_allow_shared_team_units;
gameSettings->setFlagTypes1(valueFlags1);
}
else {
valueFlags1 &= ~ft1_allow_shared_team_units;
gameSettings->setFlagTypes1(valueFlags1);
}
valueFlags1 = gameSettings->getFlagTypes1();
if(checkBoxAllowTeamResourceSharing.getValue() == true) {
valueFlags1 |= ft1_allow_shared_team_resources;
gameSettings->setFlagTypes1(valueFlags1);
}
else {
valueFlags1 &= ~ft1_allow_shared_team_resources;
gameSettings->setFlagTypes1(valueFlags1);
}
// First save Used slots
//for(int i=0; i<mapInfo.players; ++i)
int AIPlayerCount = 0;
@ -2398,6 +2452,11 @@ void MenuStateConnectedGame::mouseMove(int x, int y, const MouseState *ms) {
checkBoxScenario.mouseMove(x, y);
listBoxScenario.mouseMove(x, y);
labelAllowTeamUnitSharing.mouseMove(x,y);
checkBoxAllowTeamUnitSharing.mouseMove(x,y);
labelAllowTeamResourceSharing.mouseMove(x,y);
checkBoxAllowTeamResourceSharing.mouseMove(x,y);
checkBoxAllowNativeLanguageTechtree.mouseMove(x, y);
buttonPlayNow.mouseMove(x, y);
@ -2642,6 +2701,12 @@ void MenuStateConnectedGame::render() {
renderer.renderListBox(&listBoxAISwitchTeamAcceptPercent);
renderer.renderListBox(&listBoxFallbackCpuMultiplier);
renderer.renderLabel(&labelAllowTeamUnitSharing);
renderer.renderCheckBox(&checkBoxAllowTeamUnitSharing);
renderer.renderLabel(&labelAllowTeamResourceSharing);
renderer.renderCheckBox(&checkBoxAllowTeamResourceSharing);
renderer.renderButton(&buttonPlayNow);
renderer.renderButton(&buttonRestoreLastSettings);
@ -2777,6 +2842,9 @@ void MenuStateConnectedGame::update() {
listBoxFogOfWar.setEditable(isHeadlessAdmin());
checkBoxAllowObservers.setEditable(isHeadlessAdmin());
checkBoxAllowTeamUnitSharing.setEditable(isHeadlessAdmin());
checkBoxAllowTeamResourceSharing.setEditable(isHeadlessAdmin());
if(isHeadlessAdmin() == true) {
for(unsigned int i = 0; i < (unsigned int)GameConstants::maxPlayers; ++i) {
listBoxControls[i].setEditable(isHeadlessAdmin());
@ -4625,6 +4693,20 @@ void MenuStateConnectedGame::setupUIFromGameSettings(GameSettings *gameSettings,
listBoxAISwitchTeamAcceptPercent.setSelectedItem(intToStr(gameSettings->getAiAcceptSwitchTeamPercentChance()));
listBoxFallbackCpuMultiplier.setSelectedItemIndex(gameSettings->getFallbackCpuMultiplier());
if((gameSettings->getFlagTypes1() & ft1_allow_shared_team_units) == ft1_allow_shared_team_units) {
checkBoxAllowTeamUnitSharing.setValue(true);
}
else {
checkBoxAllowTeamUnitSharing.setValue(false);
}
if((gameSettings->getFlagTypes1() & ft1_allow_shared_team_resources) == ft1_allow_shared_team_resources) {
checkBoxAllowTeamResourceSharing.setValue(true);
}
else {
checkBoxAllowTeamResourceSharing.setValue(false);
}
// Control
for(int i=0; i<GameConstants::maxPlayers; ++i) {
listBoxControls[i].setSelectedItemIndex(ctClosed);

View File

@ -206,9 +206,14 @@ private:
GraphicButton buttonCancelDownloads;
GraphicLabel labelEnableSwitchTeamMode;
//GraphicListBox listBoxEnableSwitchTeamMode;
GraphicCheckBox checkBoxEnableSwitchTeamMode;
GraphicLabel labelAllowTeamUnitSharing;
GraphicCheckBox checkBoxAllowTeamUnitSharing;
GraphicLabel labelAllowTeamResourceSharing;
GraphicCheckBox checkBoxAllowTeamResourceSharing;
GraphicLabel labelAISwitchTeamAcceptPercent;
GraphicListBox listBoxAISwitchTeamAcceptPercent;
GraphicLabel labelFallbackCpuMultiplier;

View File

@ -30,8 +30,6 @@
#include "cache_manager.h"
#include <iterator>
#include "map_preview.h"
#include "string_utils.h"
#include "network_message.h"
#include "gen_uuid.h"
#include "leak_dumper.h"
@ -39,10 +37,10 @@ namespace Glest{ namespace Game{
using namespace ::Shared::Util;
const int MASTERSERVER_BROADCAST_MAX_WAIT_RESPONSE_SECONDS = 15;
const int MASTERSERVER_BROADCAST_MAX_WAIT_RESPONSE_SECONDS = 15;
const int MASTERSERVER_BROADCAST_PUBLISH_SECONDS = 6;
const int BROADCAST_MAP_DELAY_SECONDS = 5;
const int BROADCAST_SETTINGS_SECONDS = 4;
const int BROADCAST_MAP_DELAY_SECONDS = 5;
const int BROADCAST_SETTINGS_SECONDS = 4;
static const char *SAVED_GAME_FILENAME = "lastCustomGameSettings.mgg";
static const char *DEFAULT_GAME_FILENAME = "data/defaultGameSetup.mgg";
static const char *DEFAULT_NETWORKGAME_FILENAME = "data/defaultNetworkGameSetup.mgg";
@ -480,6 +478,26 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu,
checkBoxAllowInGameJoinPlayer.setVisible(allowInProgressJoin);
labelAllowTeamUnitSharing.registerGraphicComponent(containerName,"labelAllowTeamUnitSharing");
labelAllowTeamUnitSharing.init(xoffset+410, 670, 80);
labelAllowTeamUnitSharing.setText(lang.getString("AllowTeamUnitSharing"));
labelAllowTeamUnitSharing.setVisible(true);
checkBoxAllowTeamUnitSharing.registerGraphicComponent(containerName,"checkBoxAllowTeamUnitSharing");
checkBoxAllowTeamUnitSharing.init(xoffset+600, 670);
checkBoxAllowTeamUnitSharing.setValue(false);
checkBoxAllowTeamUnitSharing.setVisible(true);
labelAllowTeamResourceSharing.registerGraphicComponent(containerName,"labelAllowTeamResourceSharing");
labelAllowTeamResourceSharing.init(xoffset+410, 640, 80);
labelAllowTeamResourceSharing.setText(lang.getString("AllowTeamResourceSharing"));
labelAllowTeamResourceSharing.setVisible(true);
checkBoxAllowTeamResourceSharing.registerGraphicComponent(containerName,"checkBoxAllowTeamResourceSharing");
checkBoxAllowTeamResourceSharing.init(xoffset+600, 640);
checkBoxAllowTeamResourceSharing.setValue(false);
checkBoxAllowTeamResourceSharing.setVisible(true);
// Network Pause for lagged clients
labelNetworkPauseGameForLaggedClients.registerGraphicComponent(containerName,"labelNetworkPauseGameForLaggedClients");
@ -766,6 +784,9 @@ void MenuStateCustomGame::reloadUI() {
labelAllowInGameJoinPlayer.setText(lang.getString("AllowInGameJoinPlayer"));
labelAllowTeamUnitSharing.setText(lang.getString("AllowTeamUnitSharing"));
labelAllowTeamResourceSharing.setText(lang.getString("AllowTeamResourceSharing"));
labelAISwitchTeamAcceptPercent.setText(lang.getString("AISwitchTeamAcceptPercent"));
listBoxData.clear();
@ -1147,7 +1168,6 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton) {
mapPublishingDelayTimer=time(NULL);
}
}
//else if (listBoxAdvanced.getSelectedItemIndex() == 1 && listBoxFogOfWar.mouseClick(x, y)) {
else if (checkBoxAdvanced.getValue() == 1 && listBoxFogOfWar.mouseClick(x, y)) {
MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL),string(__FILE__) + "_" + intToStr(__LINE__));
MutexSafeWrapper safeMutexCLI((publishToClientsThread != NULL ? publishToClientsThread->getMutexThreadObjectAccessor() : NULL),string(__FILE__) + "_" + intToStr(__LINE__));
@ -1185,8 +1205,7 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton) {
needToRepublishToMasterserver = true;
}
if(hasNetworkGameSettings() == true)
{
if(hasNetworkGameSettings() == true) {
needToSetChangedGameSettings = true;
lastSetChangedGameSettings = time(NULL);
}
@ -1194,6 +1213,34 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton) {
ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface();
serverInterface->setAllowInGameConnections(checkBoxAllowInGameJoinPlayer.getValue() == true);
}
else if (checkBoxAdvanced.getValue() == 1 && checkBoxAllowTeamUnitSharing.mouseClick(x, y)) {
MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL),string(__FILE__) + "_" + intToStr(__LINE__));
MutexSafeWrapper safeMutexCLI((publishToClientsThread != NULL ? publishToClientsThread->getMutexThreadObjectAccessor() : NULL),string(__FILE__) + "_" + intToStr(__LINE__));
if(checkBoxPublishServer.getValue() == true) {
needToRepublishToMasterserver = true;
}
if(hasNetworkGameSettings() == true) {
needToSetChangedGameSettings = true;
lastSetChangedGameSettings = time(NULL);
}
}
else if (checkBoxAdvanced.getValue() == 1 && checkBoxAllowTeamResourceSharing.mouseClick(x, y)) {
MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL),string(__FILE__) + "_" + intToStr(__LINE__));
MutexSafeWrapper safeMutexCLI((publishToClientsThread != NULL ? publishToClientsThread->getMutexThreadObjectAccessor() : NULL),string(__FILE__) + "_" + intToStr(__LINE__));
if(checkBoxPublishServer.getValue() == true) {
needToRepublishToMasterserver = true;
}
if(hasNetworkGameSettings() == true) {
needToSetChangedGameSettings = true;
lastSetChangedGameSettings = time(NULL);
}
}
else if (checkBoxAllowNativeLanguageTechtree.mouseClick(x, y)) {
MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL),string(__FILE__) + "_" + intToStr(__LINE__));
MutexSafeWrapper safeMutexCLI((publishToClientsThread != NULL ? publishToClientsThread->getMutexThreadObjectAccessor() : NULL),string(__FILE__) + "_" + intToStr(__LINE__));
@ -1949,13 +1996,10 @@ void MenuStateCustomGame::mouseMove(int x, int y, const MouseState *ms) {
}
listBoxMap.mouseMove(x, y);
if(checkBoxAdvanced.getValue() == 1) {
listBoxFogOfWar.mouseMove(x, y);
checkBoxAllowObservers.mouseMove(x, y);
//listBoxEnableObserverMode.mouseMove(x, y);
//listBoxEnableServerControlledAI.mouseMove(x, y);
//labelNetworkFramePeriod.mouseMove(x, y);
//listBoxNetworkFramePeriod.mouseMove(x, y);
checkBoxEnableSwitchTeamMode.mouseMove(x, y);
listBoxAISwitchTeamAcceptPercent.mouseMove(x, y);
@ -1964,8 +2008,10 @@ void MenuStateCustomGame::mouseMove(int x, int y, const MouseState *ms) {
labelNetworkPauseGameForLaggedClients.mouseMove(x, y);
checkBoxNetworkPauseGameForLaggedClients.mouseMove(x, y);
//labelPathFinderType.mouseMove(x, y);
//listBoxPathFinderType.mouseMove(x, y);
labelAllowTeamUnitSharing.mouseMove(x,y);
checkBoxAllowTeamUnitSharing.mouseMove(x,y);
labelAllowTeamResourceSharing.mouseMove(x,y);
checkBoxAllowTeamResourceSharing.mouseMove(x,y);
}
checkBoxAllowInGameJoinPlayer.mouseMove(x, y);
@ -2060,7 +2106,6 @@ void MenuStateCustomGame::render() {
// START - this code ensure player title and player names don't overlap
int offsetPosition=0;
for(int i=0; i < GameConstants::maxPlayers; ++i) {
//const Metrics &metrics= Metrics::getInstance();
FontMetrics *fontMetrics= NULL;
if(Renderer::renderText3DEnabled == false) {
fontMetrics = labelPlayers[i].getFont()->getMetrics();
@ -2071,7 +2116,6 @@ void MenuStateCustomGame::render() {
if(fontMetrics == NULL) {
throw megaglest_runtime_error("fontMetrics == NULL");
}
//int curWidth = (metrics.toVirtualX(fontMetrics->getTextWidth(labelPlayers[i].getText())));
int curWidth = (fontMetrics->getTextWidth(labelPlayers[i].getText()));
int newOffsetPosition = labelPlayers[i].getX() + curWidth + 2;
@ -2115,13 +2159,6 @@ void MenuStateCustomGame::render() {
// Render the player # label the player's color
Vec3f playerColor = crcPlayerTextureCache[i]->getPixmap()->getPixel3f(0, 0);
renderer.renderLabel(&labelPlayers[i],&playerColor);
// Blend the color with white so make it more readable
//Vec4f newColor(1.f, 1.f, 1.f, 0.57f);
//renderer.renderLabel(&labelPlayers[i],&newColor);
//int quadWidth = labelPlayerNames[i].getX() - labelPlayers[i].getX() - 5;
//renderer.renderTextureQuad(labelPlayers[i].getX(), labelPlayers[i].getY(), quadWidth, labelPlayers[i].getH(), crcPlayerTextureCache[i],1.0f,&playerColor);
}
else {
renderer.renderLabel(&labelPlayers[i]);
@ -2166,19 +2203,22 @@ void MenuStateCustomGame::render() {
renderer.renderLabel(&labelFogOfWar);
renderer.renderLabel(&labelAllowObservers);
renderer.renderLabel(&labelFallbackCpuMultiplier);
//renderer.renderLabel(&labelPathFinderType);
renderer.renderLabel(&labelEnableSwitchTeamMode);
renderer.renderLabel(&labelAISwitchTeamAcceptPercent);
renderer.renderListBox(&listBoxFogOfWar);
renderer.renderCheckBox(&checkBoxAllowObservers);
//renderer.renderListBox(&listBoxEnableObserverMode);
//renderer.renderListBox(&listBoxPathFinderType);
renderer.renderCheckBox(&checkBoxEnableSwitchTeamMode);
renderer.renderListBox(&listBoxAISwitchTeamAcceptPercent);
renderer.renderListBox(&listBoxFallbackCpuMultiplier);
renderer.renderLabel(&labelAllowTeamUnitSharing);
renderer.renderCheckBox(&checkBoxAllowTeamUnitSharing);
renderer.renderLabel(&labelAllowTeamResourceSharing);
renderer.renderCheckBox(&checkBoxAllowTeamResourceSharing);
}
renderer.renderLabel(&labelAllowInGameJoinPlayer);
renderer.renderCheckBox(&checkBoxAllowInGameJoinPlayer);
@ -2187,7 +2227,6 @@ void MenuStateCustomGame::render() {
renderer.renderLabel(&labelMapFilter);
renderer.renderLabel(&labelTechTree);
renderer.renderLabel(&labelControl);
//renderer.renderLabel(&labelRMultiplier);
renderer.renderLabel(&labelFaction);
renderer.renderLabel(&labelTeam);
renderer.renderLabel(&labelMapInfo);
@ -2197,7 +2236,6 @@ void MenuStateCustomGame::render() {
renderer.renderListBox(&listBoxTileset);
renderer.renderListBox(&listBoxMapFilter);
renderer.renderListBox(&listBoxTechTree);
//renderer.renderListBox(&listBoxAdvanced);
renderer.renderCheckBox(&checkBoxAdvanced);
if(checkBoxPublishServer.getEditable())
@ -2206,16 +2244,11 @@ void MenuStateCustomGame::render() {
renderer.renderLabel(&labelPublishServer);
renderer.renderLabel(&labelGameName);
if(checkBoxAdvanced.getValue() == 1) {
//renderer.renderListBox(&listBoxEnableServerControlledAI);
//renderer.renderLabel(&labelEnableServerControlledAI);
//renderer.renderLabel(&labelNetworkFramePeriod);
//renderer.renderListBox(&listBoxNetworkFramePeriod);
renderer.renderLabel(&labelNetworkPauseGameForLaggedClients);
renderer.renderCheckBox(&checkBoxNetworkPauseGameForLaggedClients);
}
}
//renderer.renderLabel(&labelInfo);
renderer.renderCheckBox(&checkBoxScenario);
renderer.renderLabel(&labelScenario);
if(checkBoxScenario.getValue() == true) {
@ -2740,7 +2773,6 @@ void MenuStateCustomGame::update() {
}
listBoxFallbackCpuMultiplier.setEditable(true);
checkBoxPublishServer.setEditable(true);
//listBoxEnableServerControlledAI.setEditable(true);
// Masterserver always needs one network slot
if(this->headlessServerMode == true && hasOneNetworkSlotOpen == false) {
@ -2773,7 +2805,6 @@ void MenuStateCustomGame::update() {
ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface();
serverInterface->setPublishEnabled(checkBoxPublishServer.getValue() == true);
//listBoxEnableServerControlledAI.setEditable(false);
}
bool republishToMaster = (difftime((long int)time(NULL),lastMasterserverPublishing) >= MASTERSERVER_BROADCAST_PUBLISH_SECONDS);
@ -3470,6 +3501,24 @@ void MenuStateCustomGame::loadGameSettings(GameSettings *gameSettings,bool force
gameSettings->setFlagTypes1(valueFlags1);
}
if(checkBoxAllowTeamUnitSharing.getValue() == true) {
valueFlags1 |= ft1_allow_shared_team_units;
gameSettings->setFlagTypes1(valueFlags1);
}
else {
valueFlags1 &= ~ft1_allow_shared_team_units;
gameSettings->setFlagTypes1(valueFlags1);
}
if(checkBoxAllowTeamResourceSharing.getValue() == true) {
valueFlags1 |= ft1_allow_shared_team_resources;
gameSettings->setFlagTypes1(valueFlags1);
}
else {
valueFlags1 &= ~ft1_allow_shared_team_resources;
gameSettings->setFlagTypes1(valueFlags1);
}
if(Config::getInstance().getBool("EnableNetworkGameSynchChecks","false") == true) {
//printf("*WARNING* - EnableNetworkGameSynchChecks is enabled\n");
@ -3991,6 +4040,10 @@ void MenuStateCustomGame::setupUIFromGameSettings(const GameSettings &gameSettin
listBoxFallbackCpuMultiplier.setSelectedItemIndex(gameSettings.getFallbackCpuMultiplier());
checkBoxAllowInGameJoinPlayer.setValue((gameSettings.getFlagTypes1() & ft1_allow_in_game_joining) == ft1_allow_in_game_joining ? true : false);
checkBoxAllowTeamUnitSharing.setValue((gameSettings.getFlagTypes1() & ft1_allow_shared_team_units) == ft1_allow_shared_team_units ? true : false);
checkBoxAllowTeamResourceSharing.setValue((gameSettings.getFlagTypes1() & ft1_allow_shared_team_resources) == ft1_allow_shared_team_resources ? true : false);
ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface();
if(serverInterface != NULL) {
serverInterface->setAllowInGameConnections(checkBoxAllowInGameJoinPlayer.getValue() == true);

View File

@ -54,8 +54,6 @@ private:
GraphicLabel labelTechTree;
GraphicLabel labelTileset;
GraphicLabel labelMapInfo;
//GraphicLabel labelEnableObserverMode;
//GraphicLabel labelEnableServerControlledAI;
GraphicLabel labelLocalGameVersion;
GraphicLabel labelLocalIP;
GraphicLabel labelGameName;
@ -64,8 +62,6 @@ private:
GraphicListBox listBoxFogOfWar;
GraphicListBox listBoxTechTree;
GraphicListBox listBoxTileset;
//GraphicListBox listBoxEnableObserverMode;
//GraphicListBox listBoxEnableServerControlledAI;
vector<string> mapFiles;
vector<string> playerSortedMaps[GameConstants::maxPlayers+1];
@ -86,31 +82,21 @@ private:
GraphicButton buttonClearBlockedPlayers;
GraphicLabel labelPublishServer;
//GraphicListBox listBoxPublishServer;
GraphicCheckBox checkBoxPublishServer;
GraphicMessageBox mainMessageBox;
int mainMessageBoxState;
//GraphicListBox listBoxNetworkFramePeriod;
//GraphicLabel labelNetworkFramePeriod;
GraphicLabel labelNetworkPauseGameForLaggedClients;
//GraphicListBox listBoxNetworkPauseGameForLaggedClients;
GraphicCheckBox checkBoxNetworkPauseGameForLaggedClients;
//GraphicLabel labelPathFinderType;
//GraphicListBox listBoxPathFinderType;
GraphicLabel labelMapFilter;
GraphicListBox listBoxMapFilter;
GraphicLabel labelAdvanced;
//GraphicListBox listBoxAdvanced;
GraphicCheckBox checkBoxAdvanced;
GraphicLabel labelAllowObservers;
//GraphicListBox listBoxAllowObservers;
GraphicCheckBox checkBoxAllowObservers;
GraphicLabel *activeInputLabel;
@ -119,7 +105,6 @@ private:
GraphicListBox listBoxPlayerStatus;
GraphicLabel labelEnableSwitchTeamMode;
//GraphicListBox listBoxEnableSwitchTeamMode;
GraphicCheckBox checkBoxEnableSwitchTeamMode;
GraphicLabel labelAISwitchTeamAcceptPercent;
@ -130,12 +115,20 @@ private:
GraphicLabel labelAllowInGameJoinPlayer;
GraphicCheckBox checkBoxAllowInGameJoinPlayer;
GraphicLabel labelAllowTeamUnitSharing;
GraphicCheckBox checkBoxAllowTeamUnitSharing;
GraphicLabel labelAllowTeamResourceSharing;
GraphicCheckBox checkBoxAllowTeamResourceSharing;
GraphicLabel labelAllowNativeLanguageTechtree;
GraphicCheckBox checkBoxAllowNativeLanguageTechtree;
GraphicCheckBox checkBoxScenario;
GraphicLabel labelScenario;
GraphicListBox listBoxScenario;
vector<string> scenarioFiles;
ScenarioInfo scenarioInfo;
vector<string> dirList;
@ -226,6 +219,7 @@ private:
std::auto_ptr<TechTree> techTree;
string gameUUID;
public:
MenuStateCustomGame(Program *program, MainMenu *mainMenu ,
bool openNetworkSlots= false, ParentMenuState parentMenuState=pNewGame,