Skip to content
This repository has been archived by the owner on Jul 19, 2022. It is now read-only.

Commit

Permalink
[wip] change how observer mode works (#13) (#14)
Browse files Browse the repository at this point in the history
The positioning of the labels and text will need changing. I'm going to
ask @Jammyjamjamman if he'll fix it up all nice and pretty.

* [wip] change how observer mode works (#13)

* [wip] opens 10 slots on any map [observer mode]

* [wip]set start location for observers [skip ci]

* [wip] new observer mode works with no crashing

I need to clean up the code more though. I only did the bare minimum to
change the way observer mode works.
  • Loading branch information
andy5995 committed Jan 24, 2018
1 parent ce3f792 commit 42541ca
Show file tree
Hide file tree
Showing 16 changed files with 365 additions and 139 deletions.
35 changes: 26 additions & 9 deletions source/glest_game/ai/ai_interface.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
// ==============================================================
// This file is part of Glest (www.glest.org)
//
// Copyright (C) 2001-2008 Martiño Figueroa
// ai_interface.cpp:
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version
// ==============================================================
// This file is part of ZetaGlest <https://github.com/ZetaGlest>
//
// Copyright (C) 2018 The ZetaGlest team
//
// ZetaGlest is a fork of MegaGlest <https://megaglest.org>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>

#include "ai_interface.h"

Expand Down Expand Up @@ -576,7 +587,13 @@ std::pair<CommandResult,string> AiInterface::giveCommand(int unitIndex, const Co
// ==================== get data ====================

int AiInterface::getMapMaxPlayers(){
return world->getMaxPlayers();
// return world->getMaxPlayers();

// If a player is connected to slot 5 on a 4 player map,
// there would be problems. Let's tell the game the max players
// for any map is 12 (issue 13 - observer mode)
return GameConstants::maxPlayers;

}

Vec2i AiInterface::getHomeLocation(){
Expand Down
27 changes: 19 additions & 8 deletions source/glest_game/ai/ai_interface.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
// ==============================================================
// This file is part of Glest (www.glest.org)
//
// Copyright (C) 2001-2008 Martiño Figueroa
// ai_interface.cpp:
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version
// ==============================================================
// This file is part of ZetaGlest <https://github.com/ZetaGlest>
//
// Copyright (C) 2018 The ZetaGlest team
//
// ZetaGlest is a fork of MegaGlest <https://megaglest.org>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>

#ifndef _GLEST_GAME_AIINTERFACE_H_
#define _GLEST_GAME_AIINTERFACE_H_
Expand Down
34 changes: 27 additions & 7 deletions source/glest_game/game/game.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
// This file is part of Glest (www.glest.org)
//
// Copyright (C) 2001-2008 Martiño Figueroa
// game.cpp:
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version
// ==============================================================
// This file is part of ZetaGlest <https://github.com/ZetaGlest>
//
// Copyright (C) 2018 The ZetaGlest team
//
// ZetaGlest is a fork of MegaGlest <https://megaglest.org>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>

#include "game.h"

Expand Down Expand Up @@ -1623,7 +1635,15 @@ void Game::initCamera(Map *map){

if(world.getThisFaction() != NULL) {
const Vec2i &v= map->getStartLocation(world.getThisFaction()->getStartLocationIndex());
// This args are set in map.cpp - Map::getStartLocation()
gameCamera.setPos(Vec2f(v.x, v.y+gameCamera.getCalculatedDefault()/2));
//
// for issue 13: observer mode (wip)
// This sets the camera position the same for each player.
// The goal is to set the camera position to this for observers only
// since they don't have a StartLocationIndex
// gameCamera.setPos(Vec2f(10, 10));

}
}

Expand Down
31 changes: 23 additions & 8 deletions source/glest_game/game/game.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
// ==============================================================
// This file is part of Glest (www.glest.org)
//
// Copyright (C) 2001-2008 Martiño Figueroa
// game.h:
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version
// ==============================================================
// This file is part of ZetaGlest <https://github.com/ZetaGlest>
//
// Copyright (C) 2018 The ZetaGlest team
//
// ZetaGlest is a fork of MegaGlest <https://megaglest.org>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>

#ifndef _GLEST_GAME_GAME_H_
#define _GLEST_GAME_GAME_H_
Expand All @@ -17,6 +28,10 @@
#include <winsock.h>
#endif

#ifdef DEBUG
# define PRINT_DEBUG printf("[DEBUG] "); printf
#endif

#include <vector>
#include "gui.h"
#include "game_camera.h"
Expand Down
6 changes: 3 additions & 3 deletions source/glest_game/game/game_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ enum MasterServerGameStatusType {
class GameConstants {
public:
static const int specialFactions = fpt_EndCount - 1;
static const int maxPlayers = 8;
static const int maxPlayers = 10;
static const int serverPort = 61357;
static const int serverAdminPort = 61355;
static int updateFps;
Expand Down Expand Up @@ -167,7 +167,7 @@ class GameConstants {
static const char *path_logs_CacheLookupKey;

static const char *application_name;

static const char *saveNetworkGameFileServerCompressed;
static const char *saveNetworkGameFileServer;
static const char *saveNetworkGameFileClientCompressed;
Expand All @@ -182,7 +182,7 @@ class GameConstants {
static const float ultraMultiplier;
static const float megaMultiplier;
//

static const char * LOADING_SCREEN_FILE;
static const char * LOADING_SCREEN_FILE_FILTER;
static const char * PREVIEW_SCREEN_FILE;
Expand Down
36 changes: 25 additions & 11 deletions source/glest_game/menu/menu_state_connected_game.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
// ==============================================================
// This file is part of Glest (www.glest.org)
// menu_state_connected_game.cpp: game setup menu as it appears to
// connected clients (not the host or user setting up the game)
//
// Copyright (C) 2001-2005 Martiño Figueroa
// Copyright (C) 2018 The ZetaGlest team <https://github.com/ZetaGlest>
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version
// ==============================================================
// ZetaGlest is a fork of MegaGlest <https://megaglest.org>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

#include "menu_state_connected_game.h"

Expand Down Expand Up @@ -167,7 +176,7 @@ MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainM
vector<string> teamItems, controlItems, results, rMultiplier, playerStatuses;
int labelOffset=23;
int setupPos=590;
int mapHeadPos=330;
int mapHeadPos=300;//330;
int mapPos=mapHeadPos-labelOffset;
int aHeadPos=240;
int aPos=aHeadPos-labelOffset;
Expand Down Expand Up @@ -1860,7 +1869,9 @@ void MenuStateConnectedGame::mouseClickAdmin(int x, int y, MouseButton mouseButt
broadcastServerSettingsDelayTimer=time(NULL);
}
else if(checkBoxAllowObservers.mouseClick(x, y)) {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
#ifdef DEBUG
PRINT_DEBUG("In [%s::%s Line %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
#endif
needToBroadcastServerSettings=true;
broadcastServerSettingsDelayTimer=time(NULL);
}
Expand Down Expand Up @@ -1967,7 +1978,9 @@ void MenuStateConnectedGame::mouseClickAdmin(int x, int y, MouseButton mouseButt
}
else if(clientInterface != NULL && clientInterface->getGameSettings()->getStartLocationIndex(clientInterface->getGameSettings()->getThisFactionIndex()) != i &&
listBoxTeams[i].mouseClick(x, y)) {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
#ifdef DEBUG
PRINT_DEBUG("In [%s::%s Line %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
#endif
if(factionFiles[listBoxFactions[i].getSelectedItemIndex()] != formatString(GameConstants::OBSERVER_SLOTNAME)) {
if(listBoxTeams[i].getSelectedItemIndex() + 1 != (GameConstants::maxPlayers + fpt_Observer)) {
//lastSelectedTeamIndex[i] = listBoxTeams[i].getSelectedItemIndex();
Expand Down Expand Up @@ -4151,6 +4164,7 @@ bool MenuStateConnectedGame::loadMapInfo(string file, MapInfo *mapInfo, bool loa
Lang &lang= Lang::getInstance();
if(MapPreview::loadMapInfo(file, mapInfo, lang.getString("MaxPlayers"),lang.getString("Size"),true) == true) {
for(int i = 0; i < GameConstants::maxPlayers; ++i) {
mapInfo->players = GameConstants::maxPlayers;
bool visible=i+1 <= mapInfo->players;
labelPlayers[i].setVisible(visible);
labelPlayerNames[i].setVisible(visible);
Expand Down
9 changes: 6 additions & 3 deletions source/glest_game/menu/menu_state_custom_game.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
//
// menu_state_custom_game.cpp: game setup menu as it appears to
// to the host
//
// Copyright (C) 2018 The ZetaGlest team <https://github.com/ZetaGlest>
// This file is part of ZetaGlest <https://github.com/ZetaGlest>
//
// Copyright (C) 2018 The ZetaGlest team
//
// ZetaGlest is a fork of MegaGlest <https://megaglest.org>
//
Expand Down Expand Up @@ -196,7 +199,7 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu,

int labelOffset=23;
int setupPos=605;
int mapHeadPos=330;
int mapHeadPos=300; //330;
int mapPos=mapHeadPos-labelOffset;
int aHeadPos=240;
int aPos=aHeadPos-labelOffset;
Expand Down Expand Up @@ -4287,7 +4290,7 @@ void MenuStateCustomGame::loadMapInfo(string file, MapInfo *mapInfo, bool loadMa
}
}
}

mapInfo->players = GameConstants::maxPlayers;
labelPlayers[i].setVisible(i+1 <= mapInfo->players);
labelPlayerNames[i].setVisible(i+1 <= mapInfo->players);
listBoxControls[i].setVisible(i+1 <= mapInfo->players);
Expand Down
32 changes: 22 additions & 10 deletions source/glest_game/menu/menu_state_join_game.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
// ==============================================================
// This file is part of Glest (www.glest.org)
// menu_state_join_game.cpp
// Copyright (C) 2018 The ZetaGlest team <https://github.com/ZetaGlest>
//
// Copyright (C) 2001-2008 Martiño Figueroa
// ZetaGlest is a fork of MegaGlest <https://megaglest.org>
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version
// ==============================================================
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

#include "menu_state_join_game.h"

Expand Down Expand Up @@ -270,7 +277,10 @@ void MenuStateJoinGame::reloadUI() {

MenuStateJoinGame::~MenuStateJoinGame() {
abortAutoFind = true;
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);

#ifdef DEBUG
PRINT_DEBUG ("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
#endif
}

void MenuStateJoinGame::DiscoveredServers(std::vector<string> serverList) {
Expand All @@ -285,7 +295,9 @@ void MenuStateJoinGame::DiscoveredServers(std::vector<string> serverList) {
//serverList.push_back("test2");
//

if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] serverList.size() = %d\n",__FILE__,__FUNCTION__,__LINE__,(int)serverList.size());
#ifdef DEBUG
PRINT_DEBUG ("In [%s::%s Line: %d] serverList.size() = %d\n",__FILE__,__FUNCTION__,__LINE__,(int)serverList.size());
#endif

autoConnectToServer = false;
buttonAutoFindServers.setEnabled(true);
Expand Down

0 comments on commit 42541ca

Please sign in to comment.