2011-04-13 21:01:59 -07:00
|
|
|
/* Copyright (C) 2011 Wildfire Games.
|
2009-06-20 09:13:29 -07:00
|
|
|
* This file is part of 0 A.D.
|
|
|
|
|
*
|
|
|
|
|
* 0 A.D. 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 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* 0 A.D. 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 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2006-04-23 16:14:18 -07:00
|
|
|
#include "precompiled.h"
|
|
|
|
|
|
|
|
|
|
#include "MessageHandler.h"
|
|
|
|
|
#include "../GameLoop.h"
|
2011-05-29 08:02:02 -07:00
|
|
|
#include "../CommandProc.h"
|
2006-04-23 16:14:18 -07:00
|
|
|
|
2006-06-09 09:44:16 -07:00
|
|
|
#include "graphics/GameView.h"
|
2011-05-29 08:02:02 -07:00
|
|
|
#include "graphics/LOSTexture.h"
|
2006-06-09 09:44:16 -07:00
|
|
|
#include "graphics/MapWriter.h"
|
2006-04-23 16:14:18 -07:00
|
|
|
#include "graphics/Patch.h"
|
2006-06-09 09:44:16 -07:00
|
|
|
#include "graphics/Terrain.h"
|
2010-09-04 14:26:52 -07:00
|
|
|
#include "graphics/TerrainTextureEntry.h"
|
|
|
|
|
#include "graphics/TerrainTextureManager.h"
|
2006-04-23 16:14:18 -07:00
|
|
|
#include "ps/Game.h"
|
|
|
|
|
#include "ps/Loader.h"
|
2007-01-13 14:44:42 -08:00
|
|
|
#include "ps/World.h"
|
2006-06-11 00:03:59 -07:00
|
|
|
#include "renderer/Renderer.h"
|
2010-06-30 14:41:04 -07:00
|
|
|
#include "scriptinterface/ScriptInterface.h"
|
2010-01-22 12:03:14 -08:00
|
|
|
#include "simulation2/Simulation2.h"
|
|
|
|
|
#include "simulation2/components/ICmpPlayer.h"
|
|
|
|
|
#include "simulation2/components/ICmpPlayerManager.h"
|
|
|
|
|
#include "simulation2/components/ICmpPosition.h"
|
2010-09-23 05:13:13 -07:00
|
|
|
#include "simulation2/components/ICmpRangeManager.h"
|
2011-05-29 08:02:02 -07:00
|
|
|
#include "simulation2/components/ICmpTerrain.h"
|
2006-04-23 16:14:18 -07:00
|
|
|
|
2007-01-24 12:17:28 -08:00
|
|
|
namespace
|
2006-04-23 16:14:18 -07:00
|
|
|
{
|
2010-06-30 14:41:04 -07:00
|
|
|
void InitGame()
|
2007-01-24 12:17:28 -08:00
|
|
|
{
|
|
|
|
|
if (g_Game)
|
|
|
|
|
{
|
|
|
|
|
delete g_Game;
|
|
|
|
|
g_Game = NULL;
|
|
|
|
|
}
|
2006-04-23 16:14:18 -07:00
|
|
|
|
2007-01-24 12:17:28 -08:00
|
|
|
g_Game = new CGame();
|
2010-06-30 14:41:04 -07:00
|
|
|
|
|
|
|
|
// Default to player 1 for playtesting
|
|
|
|
|
g_Game->SetPlayerID(1);
|
2007-01-24 12:17:28 -08:00
|
|
|
}
|
2006-04-23 16:14:18 -07:00
|
|
|
|
2011-04-13 21:01:59 -07:00
|
|
|
void StartGame(const CScriptValRooted& attrs)
|
2010-01-22 12:03:14 -08:00
|
|
|
{
|
2010-06-30 14:41:04 -07:00
|
|
|
g_Game->StartGame(attrs);
|
2011-04-06 19:32:16 -07:00
|
|
|
|
|
|
|
|
// TODO: Non progressive load can fail - need a decent way to handle this
|
2007-01-24 12:17:28 -08:00
|
|
|
LDR_NonprogressiveLoad();
|
2011-04-06 19:32:16 -07:00
|
|
|
|
2010-06-30 14:41:04 -07:00
|
|
|
PSRETURN ret = g_Game->ReallyStartGame();
|
2011-04-30 06:01:45 -07:00
|
|
|
ENSURE(ret == PSRETURN_OK);
|
2010-09-23 05:13:13 -07:00
|
|
|
|
|
|
|
|
// Disable fog-of-war
|
|
|
|
|
CmpPtr<ICmpRangeManager> cmpRangeManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY);
|
|
|
|
|
if (!cmpRangeManager.null())
|
2011-06-28 16:24:42 -07:00
|
|
|
cmpRangeManager->SetLosRevealAll(-1, true);
|
2007-01-24 12:17:28 -08:00
|
|
|
}
|
2006-04-23 16:14:18 -07:00
|
|
|
}
|
|
|
|
|
|
2007-01-24 12:17:28 -08:00
|
|
|
namespace AtlasMessage {
|
|
|
|
|
|
2011-04-13 21:01:59 -07:00
|
|
|
QUERYHANDLER(GenerateMap)
|
2006-04-23 16:14:18 -07:00
|
|
|
{
|
2010-06-30 14:41:04 -07:00
|
|
|
InitGame();
|
2006-04-23 16:14:18 -07:00
|
|
|
|
2011-04-13 21:01:59 -07:00
|
|
|
// Random map
|
|
|
|
|
ScriptInterface& scriptInterface = g_Game->GetSimulation2()->GetScriptInterface();
|
|
|
|
|
|
2011-04-15 21:04:06 -07:00
|
|
|
CScriptValRooted settings = scriptInterface.ParseJSON(*msg->settings);
|
|
|
|
|
|
2011-04-13 21:01:59 -07:00
|
|
|
CScriptValRooted attrs;
|
|
|
|
|
scriptInterface.Eval("({})", attrs);
|
|
|
|
|
scriptInterface.SetProperty(attrs.get(), "mapType", std::string("random"));
|
2011-04-15 21:04:06 -07:00
|
|
|
scriptInterface.SetProperty(attrs.get(), "script", std::wstring(*msg->filename));
|
2011-04-13 21:01:59 -07:00
|
|
|
scriptInterface.SetProperty(attrs.get(), "settings", settings, false);
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
StartGame(attrs);
|
|
|
|
|
|
|
|
|
|
msg->status = 0;
|
|
|
|
|
}
|
|
|
|
|
catch (PSERROR_Game_World_MapLoadFailed e)
|
|
|
|
|
{
|
|
|
|
|
// Cancel loading
|
|
|
|
|
LDR_Cancel();
|
2006-04-23 16:14:18 -07:00
|
|
|
|
2011-04-13 21:01:59 -07:00
|
|
|
msg->status = -1;
|
|
|
|
|
}
|
2006-04-23 16:14:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MESSAGEHANDLER(LoadMap)
|
|
|
|
|
{
|
2010-06-30 14:41:04 -07:00
|
|
|
InitGame();
|
2011-04-13 21:01:59 -07:00
|
|
|
|
|
|
|
|
// Scenario
|
|
|
|
|
CStrW map = *msg->filename;
|
|
|
|
|
CStrW mapBase = map.BeforeLast(L".pmp"); // strip the file extension, if any
|
|
|
|
|
|
|
|
|
|
ScriptInterface& scriptInterface = g_Game->GetSimulation2()->GetScriptInterface();
|
|
|
|
|
|
|
|
|
|
CScriptValRooted attrs;
|
|
|
|
|
scriptInterface.Eval("({})", attrs);
|
|
|
|
|
scriptInterface.SetProperty(attrs.get(), "mapType", std::string("scenario"));
|
|
|
|
|
scriptInterface.SetProperty(attrs.get(), "map", std::wstring(mapBase));
|
|
|
|
|
|
|
|
|
|
StartGame(attrs);
|
2006-04-23 16:14:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MESSAGEHANDLER(SaveMap)
|
|
|
|
|
{
|
|
|
|
|
CMapWriter writer;
|
2011-03-23 06:36:20 -07:00
|
|
|
const VfsPath pathname = VfsPath("maps/scenarios") / *msg->filename;
|
2009-11-03 13:46:35 -08:00
|
|
|
writer.SaveMap(pathname,
|
2010-08-01 13:56:34 -07:00
|
|
|
g_Game->GetWorld()->GetTerrain(),
|
2006-06-21 15:37:31 -07:00
|
|
|
g_Renderer.GetWaterManager(), g_Renderer.GetSkyManager(),
|
2010-04-29 16:22:18 -07:00
|
|
|
&g_LightEnv, g_Game->GetView()->GetCamera(), g_Game->GetView()->GetCinema(),
|
|
|
|
|
g_Game->GetSimulation2());
|
2006-04-23 16:14:18 -07:00
|
|
|
}
|
|
|
|
|
|
2011-04-13 21:01:59 -07:00
|
|
|
QUERYHANDLER(GetMapSettings)
|
|
|
|
|
{
|
|
|
|
|
msg->settings = g_Game->GetSimulation2()->GetMapSettingsString();
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-09 16:47:20 -07:00
|
|
|
QUERYHANDLER(GetMapSizes)
|
2011-04-13 21:01:59 -07:00
|
|
|
{
|
2011-06-09 16:47:20 -07:00
|
|
|
msg->sizes = g_Game->GetSimulation2()->GetMapSizes();
|
2011-04-13 21:01:59 -07:00
|
|
|
}
|
|
|
|
|
|
2011-06-09 16:47:20 -07:00
|
|
|
BEGIN_COMMAND(SetMapSettings)
|
|
|
|
|
{
|
|
|
|
|
void Do()
|
|
|
|
|
{
|
|
|
|
|
Redo();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Undo()
|
|
|
|
|
{
|
|
|
|
|
// TODO
|
|
|
|
|
debug_warn(L"Can't undo SetMapSettings");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Redo()
|
|
|
|
|
{
|
|
|
|
|
g_Game->GetSimulation2()->SetMapSettings(*msg->settings);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
END_COMMAND(SetMapSettings)
|
|
|
|
|
|
2011-04-13 21:01:59 -07:00
|
|
|
QUERYHANDLER(GetRMSData)
|
|
|
|
|
{
|
|
|
|
|
msg->data = g_Game->GetSimulation2()->GetRMSData();
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-29 08:02:02 -07:00
|
|
|
BEGIN_COMMAND(ResizeMap)
|
|
|
|
|
{
|
|
|
|
|
cResizeMap()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MakeDirty()
|
|
|
|
|
{
|
|
|
|
|
CmpPtr<ICmpTerrain> cmpTerrain(*g_Game->GetSimulation2(), SYSTEM_ENTITY);
|
|
|
|
|
if (!cmpTerrain.null())
|
|
|
|
|
cmpTerrain->ReloadTerrain();
|
|
|
|
|
|
|
|
|
|
// The LOS texture won't normally get updated when running Atlas
|
|
|
|
|
// (since there's no simulation updates), so explicitly dirty it
|
|
|
|
|
g_Game->GetView()->GetLOSTexture().MakeDirty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Do()
|
|
|
|
|
{
|
|
|
|
|
Redo();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Undo()
|
|
|
|
|
{
|
|
|
|
|
// TODO
|
|
|
|
|
debug_warn(L"Can't undo ResizeMap");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Redo()
|
|
|
|
|
{
|
|
|
|
|
CTerrain* terrain = g_Game->GetWorld()->GetTerrain();
|
|
|
|
|
|
|
|
|
|
terrain->Resize(msg->tiles / PATCH_SIZE);
|
|
|
|
|
|
|
|
|
|
MakeDirty();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
END_COMMAND(ResizeMap)
|
|
|
|
|
|
2006-04-23 16:14:18 -07:00
|
|
|
}
|