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

Commit

Permalink
observers don't use a slot on maps [wip #13]
Browse files Browse the repository at this point in the history
* This reverts part of 42541ca
* This fixes the bug from 42541ca
where if there 4 slots being used on a 4 player map, the game will crash
if an observer is in the 5th slot.
* The menu needs to be altered to accomodate the extra lines of text.
* There needs to be checks put in place so people in the extra slots can
only choose "observer" mode. If they choose a different faction, the
game will crash.
  • Loading branch information
andy5995 committed Jan 24, 2018
1 parent 42541ca commit 31d91e8
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 35 deletions.
8 changes: 1 addition & 7 deletions source/glest_game/ai/ai_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -587,13 +587,7 @@ std::pair<CommandResult,string> AiInterface::giveCommand(int unitIndex, const Co
// ==================== get data ====================

int AiInterface::getMapMaxPlayers(){
// 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;

return world->getMaxPlayers();
}

Vec2i AiInterface::getHomeLocation(){
Expand Down
2 changes: 1 addition & 1 deletion source/glest_game/ai/ai_interface.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// ai_interface.cpp:
// ai_interface.h:
//
// This file is part of ZetaGlest <https://github.com/ZetaGlest>
//
Expand Down
9 changes: 6 additions & 3 deletions source/glest_game/graphics/renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,10 @@ Renderer::~Renderer() {
SystemFlags::OutputDebug(SystemFlags::debugError,szBuf);
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,szBuf);

throw megaglest_runtime_error(szBuf);
// FIXME: this always gives a warning that "throw will always call terminate".
// Is it needed? -andy5995

// throw megaglest_runtime_error(szBuf);
}
}

Expand Down Expand Up @@ -4072,7 +4075,7 @@ Renderer::MapRenderer::Layer::~Layer() {
if(vbo_fowTexCoords) glDeleteBuffersARB(1,&vbo_fowTexCoords);
if(vbo_surfTexCoords) glDeleteBuffersARB(1,&vbo_surfTexCoords);
if(vbo_indices) glDeleteBuffersARB(1,&vbo_indices);

}

template<typename T> void _loadVBO(GLuint &vbo,std::vector<T> buf,int target=GL_ARRAY_BUFFER_ARB) {
Expand Down Expand Up @@ -4519,7 +4522,7 @@ void Renderer::renderSurface(const int renderFps) {
glActiveTexture(baseTexUnit);

VisibleQuadContainerCache &qCache = getQuadCache();

bool useVBORendering = getVBOSupported();
if(useVBORendering == true) {
VisibleQuadContainerCache &qCache = getQuadCache();
Expand Down
14 changes: 9 additions & 5 deletions source/glest_game/world/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,10 +402,11 @@ Vec2i Map::getStartLocation(int locationIndex) const {
// throw megaglest_runtime_error("startLocations == NULL");
// }

if(locationIndex < maxPlayers + GameConstants::specialFactions) // maxPlayers for a map, not the Game
if(locationIndex < hardMaxPlayers) // maxPlayers for a map, not the Game
return startLocations[locationIndex];
else if (locationIndex < GameConstants::maxPlayers + GameConstants::specialFactions)
return startLocations[0];
else if (locationIndex < maxPlayers) {
return startLocations[1];
}
else {
char szBuf[8096]="";
snprintf(szBuf,8096,"locationIndex >= maxPlayers [%d] [%d]",locationIndex, maxPlayers);
Expand Down Expand Up @@ -452,7 +453,10 @@ Checksum Map::load(const string &path, TechTree *techTree, Tileset *tileset) {
waterLevel= static_cast<float>((header.waterLevel-0.01f)/heightFactor);
waterLevel = truncateDecimal<float>(waterLevel,6);
title= header.title;
maxPlayers= header.maxFactions;

//maxPlayers= header.maxFactions;
hardMaxPlayers = header.maxFactions;
maxPlayers = GameConstants::maxPlayers;

surfaceW= header.width;
surfaceH= header.height;
Expand All @@ -478,7 +482,7 @@ Checksum Map::load(const string &path, TechTree *techTree, Tileset *tileset) {

//start locations
startLocations= new Vec2i[maxPlayers];
for(int i=0; i < maxPlayers; ++i) {
for(int i=0; i < hardMaxPlayers; ++i) {
int x=0, y=0;
readBytes = fread(&x, sizeof(int32), 1, f);
if(readBytes != 1) {
Expand Down
1 change: 1 addition & 0 deletions source/glest_game/world/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ class Map {
int surfaceH;
int surfaceSize;

int hardMaxPlayers; // the max players hard-coded into a map
int maxPlayers;
Cell *cells;
SurfaceCell *surfaceCells;
Expand Down
38 changes: 27 additions & 11 deletions source/glest_game/world/world.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
// world.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 "world.h"

Expand Down Expand Up @@ -2032,9 +2043,14 @@ void World::initFactionTypes(GameSettings *gs) {
throw megaglest_runtime_error("gs == NULL");
}

if(gs->getFactionCount() > map.getMaxPlayers()) {
throw megaglest_runtime_error("This map only supports "+intToStr(map.getMaxPlayers())+" players, factionCount is " + intToStr(gs->getFactionCount()));
}
// FIXME: This was commented out while working on issue 13
// <https://github.com/ZetaGlest/zetaglest-source/issues/13>
//
// The check may not be needed or it may need to be re-written

// if(gs->getFactionCount() > map.getMaxPlayers()) {
// throw megaglest_runtime_error("This map only supports "+intToStr(map.getMaxPlayers())+" players, factionCount is " + intToStr(gs->getFactionCount()));
// }

//create stats
//printf("World gs->getThisFactionIndex() = %d\n",gs->getThisFactionIndex());
Expand Down
27 changes: 19 additions & 8 deletions source/glest_game/world/world.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
// world.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_WORLD_H_
#define _GLEST_GAME_WORLD_H_
Expand Down

0 comments on commit 31d91e8

Please sign in to comment.