Added a new lua script function called: unfogMap to allow scenarios and tutorials to turn off fog of war.

This commit is contained in:
Mark Vejvoda 2010-04-23 02:48:56 +00:00
parent dd704fe372
commit a01c0adb78
4 changed files with 36 additions and 6 deletions

View File

@ -1,7 +1,7 @@
// ==============================================================
// This file is part of Glest (www.glest.org)
//
// Copyright (C) 2001-2005 Martiño Figueroa
// Copyright (C) 2001-2005 Martio Figueroa
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
@ -71,6 +71,7 @@ void ScriptManager::init(World* world, GameCamera *gameCamera){
luaScript.registerFunction(getLastDeadUnitId, "lastDeadUnit");
luaScript.registerFunction(getUnitCount, "unitCount");
luaScript.registerFunction(getUnitCountOfType, "unitCountOfType");
luaScript.registerFunction(unfogMap, "unfogMap");
//load code
@ -396,4 +397,14 @@ int ScriptManager::getUnitCountOfType(LuaHandle* luaHandle){
return luaArguments.getReturnCount();
}
void ScriptManager::unfogMap() {
world->setFogOfWar(false);
}
int ScriptManager::unfogMap(LuaHandle* luaHandle){
LuaArguments luaArguments(luaHandle);
thisScriptManager->unfogMap();
return luaArguments.getReturnCount();
}
}}//end namespace

View File

@ -1,7 +1,7 @@
// ==============================================================
// This file is part of Glest (www.glest.org)
//
// Copyright (C) 2001-2005 Martiño Figueroa
// Copyright (C) 2001-2005 Martio Figueroa
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
@ -16,7 +16,6 @@
#include <queue>
#include "lua_script.h"
#include "vec.h"
#include "components.h"
#include "game_constants.h"
@ -122,7 +121,6 @@ public:
void onUnitDied(const Unit* unit);
private:
string wrapString(const string &str, int wrapCount);
//wrappers, commands
@ -138,6 +136,7 @@ private:
void disableAi(int factionIndex);
void setPlayerAsWinner(int factionIndex);
void endGame();
void unfogMap();
//wrappers, queries
Vec2i getStartLocation(int factionIndex);
@ -164,6 +163,7 @@ private:
static int disableAi(LuaHandle* luaHandle);
static int setPlayerAsWinner(LuaHandle* luaHandle);
static int endGame(LuaHandle* luaHandle);
static int unfogMap(LuaHandle* luaHandle);
//callbacks, queries
static int getStartLocation(LuaHandle* luaHandle);

View File

@ -39,6 +39,8 @@ const float World::airHeight= 5.f;
World::World(){
Config &config= Config::getInstance();
fogOfWarOverride = false;
fogOfWarSmoothing= config.getBool("FogOfWarSmoothing");
fogOfWarSmoothingFrameSkip= config.getInt("FogOfWarSmoothingFrameSkip");
@ -57,11 +59,23 @@ void World::end(){
for(int i= 0; i<factions.size(); ++i){
factions[i].end();
}
fogOfWarOverride = false;
//stats will be deleted by BattleEnd
}
// ========================== init ===============================================
void World::setFogOfWar(bool value) {
fogOfWar = value;
fogOfWarOverride = true;
if(game != NULL && game->getGameSettings() != NULL) {
game->getGameSettings()->setFogOfWar(fogOfWar);
initCells(fogOfWar); //must be done after knowing faction number and dimensions
initMinimap();
}
}
void World::init(Game *game, bool createUnits){
this->game = game;
@ -70,7 +84,9 @@ void World::init(Game *game, bool createUnits){
unitUpdater.init(game);
GameSettings *gs = game->getGameSettings();
if(fogOfWarOverride == false) {
fogOfWar = gs->getFogOfWar();
}
initFactionTypes(gs);
initCells(fogOfWar); //must be done after knowing faction number and dimensions

View File

@ -1,7 +1,7 @@
// ==============================================================
// This file is part of Glest (www.glest.org)
//
// Copyright (C) 2001-2008 Martiño Figueroa
// Copyright (C) 2001-2008 Martio Figueroa
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
@ -84,6 +84,7 @@ private:
int nextUnitId;
//config
bool fogOfWarOverride;
bool fogOfWar;
int fogOfWarSmoothingFrameSkip;
bool fogOfWarSmoothing;
@ -149,6 +150,8 @@ public:
Game * getGame() { return game; }
void setFogOfWar(bool value);
private:
void initCells(bool fogOfWar);