Implements skirmish maps, based on patch by sanderd17, fixes #1198. Skirmish maps are like scenarios, except the player can choose their civ during match setup. To create a skirmish map: place some skirmish entities for each player in Atlas (see templates/skirmish/* for examples), uncheck the player's civ in Atlas' player panel if desired, and save in the maps/skirmishes directory. The map will appear in match setup under the "Skirmish" match type.
Implements custom, VFS-based map load/save dialogs for Atlas (replaces
broken native file dialogs), fixes #631, #889.
Fixes map loading/saving to handle arbitrary subdirectories for better
organization.
Adds default settings to Atlas player panel, fixes #1872. Each setting
now has a checkbox to choose whether it should be saved with the map
(avoids writing lots of useless default data for each map).
Adds map preview setting to Atlas, refs #1745.
Cleans up and simplifies some duplicate code.
Fixes optional serialization performance test.
This was SVN commit r13938.
2013-10-04 04:29:16 +02:00
|
|
|
/* Copyright (C) 2013 Wildfire Games.
|
2009-04-18 19:00:33 +02: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/>.
|
|
|
|
*/
|
|
|
|
|
2007-05-07 18:33:24 +02:00
|
|
|
#ifndef INCLUDED_MAPREADER
|
|
|
|
#define INCLUDED_MAPREADER
|
2004-05-29 22:56:24 +02:00
|
|
|
|
|
|
|
#include "MapIO.h"
|
2005-08-12 19:06:53 +02:00
|
|
|
#include "lib/res/handle.h"
|
2006-06-02 04:10:27 +02:00
|
|
|
#include "ps/CStr.h"
|
2004-05-29 22:56:24 +02:00
|
|
|
#include "LightEnv.h"
|
2008-02-04 12:40:42 +01:00
|
|
|
#include "ps/FileIo.h"
|
2010-10-30 06:02:42 +02:00
|
|
|
#include "scriptinterface/ScriptInterface.h"
|
2010-07-03 15:15:57 +02:00
|
|
|
#include "simulation2/system/Entity.h"
|
2004-05-29 22:56:24 +02:00
|
|
|
|
|
|
|
class CObjectEntry;
|
2004-07-31 17:57:18 +02:00
|
|
|
class CTerrain;
|
2006-06-11 09:03:59 +02:00
|
|
|
class WaterManager;
|
2006-06-22 00:37:31 +02:00
|
|
|
class SkyManager;
|
2004-07-31 17:57:18 +02:00
|
|
|
class CLightEnv;
|
2006-08-22 04:24:44 +02:00
|
|
|
class CCinemaManager;
|
2012-10-15 12:34:23 +02:00
|
|
|
class CPostprocManager;
|
2006-11-24 20:45:04 +01:00
|
|
|
class CTriggerManager;
|
2010-02-08 23:05:05 +01:00
|
|
|
class CSimulation2;
|
2011-10-24 16:31:05 +02:00
|
|
|
class CSimContext;
|
2010-09-04 23:26:52 +02:00
|
|
|
class CTerrainTextureEntry;
|
2010-08-04 23:15:41 +02:00
|
|
|
class CScriptValRooted;
|
|
|
|
class ScriptInterface;
|
2010-08-13 15:26:29 +02:00
|
|
|
class CGameView;
|
2005-05-03 23:42:09 +02:00
|
|
|
class CXMLReader;
|
2011-04-10 07:31:18 +02:00
|
|
|
class CMapGenerator;
|
2005-05-03 23:42:09 +02:00
|
|
|
|
2004-05-29 22:56:24 +02:00
|
|
|
class CMapReader : public CMapIO
|
|
|
|
{
|
2005-05-11 05:07:08 +02:00
|
|
|
friend class CXMLReader;
|
|
|
|
|
2004-05-29 22:56:24 +02:00
|
|
|
public:
|
|
|
|
// constructor
|
|
|
|
CMapReader();
|
2011-04-10 07:31:18 +02:00
|
|
|
~CMapReader();
|
|
|
|
|
2004-05-29 22:56:24 +02:00
|
|
|
// LoadMap: try to load the map from given file; reinitialise the scene to new data if successful
|
Implements skirmish maps, based on patch by sanderd17, fixes #1198. Skirmish maps are like scenarios, except the player can choose their civ during match setup. To create a skirmish map: place some skirmish entities for each player in Atlas (see templates/skirmish/* for examples), uncheck the player's civ in Atlas' player panel if desired, and save in the maps/skirmishes directory. The map will appear in match setup under the "Skirmish" match type.
Implements custom, VFS-based map load/save dialogs for Atlas (replaces
broken native file dialogs), fixes #631, #889.
Fixes map loading/saving to handle arbitrary subdirectories for better
organization.
Adds default settings to Atlas player panel, fixes #1872. Each setting
now has a checkbox to choose whether it should be saved with the map
(avoids writing lots of useless default data for each map).
Adds map preview setting to Atlas, refs #1745.
Cleans up and simplifies some duplicate code.
Fixes optional serialization performance test.
This was SVN commit r13938.
2013-10-04 04:29:16 +02:00
|
|
|
void LoadMap(const VfsPath& pathname, const CScriptValRooted& settings, CTerrain*, WaterManager*, SkyManager*, CLightEnv*, CGameView*,
|
2012-10-15 12:34:23 +02:00
|
|
|
CCinemaManager*, CTriggerManager*, CPostprocManager* pPostproc, CSimulation2*, const CSimContext*,
|
|
|
|
int playerID, bool skipEntities);
|
2010-10-30 06:02:42 +02:00
|
|
|
|
2012-10-15 12:34:23 +02:00
|
|
|
void LoadRandomMap(const CStrW& scriptFile, const CScriptValRooted& settings, CTerrain*, WaterManager*, SkyManager*, CLightEnv*, CGameView*, CCinemaManager*, CTriggerManager*, CPostprocManager* pPostproc_, CSimulation2*, int playerID);
|
2004-05-29 22:56:24 +02:00
|
|
|
|
|
|
|
private:
|
2010-10-30 06:02:42 +02:00
|
|
|
// Load script settings for use by scripts
|
|
|
|
int LoadScriptSettings();
|
|
|
|
|
|
|
|
// load player settings only
|
|
|
|
int LoadPlayerSettings();
|
|
|
|
|
|
|
|
// load map settings only
|
|
|
|
int LoadMapSettings();
|
|
|
|
|
2004-05-29 22:56:24 +02:00
|
|
|
// UnpackTerrain: unpack the terrain from the input stream
|
2005-05-05 01:12:46 +02:00
|
|
|
int UnpackTerrain();
|
2006-08-22 04:24:44 +02:00
|
|
|
//UnpackCinema: unpack the cinematic tracks from the input stream
|
|
|
|
int UnpackCinema();
|
2004-05-29 22:56:24 +02:00
|
|
|
|
2005-05-03 23:42:09 +02:00
|
|
|
// UnpackMap: unpack the given data from the raw data stream into local variables
|
|
|
|
int UnpackMap();
|
|
|
|
|
2004-05-29 22:56:24 +02:00
|
|
|
// ApplyData: take all the input data, and rebuild the scene from it
|
2005-05-03 23:42:09 +02:00
|
|
|
int ApplyData();
|
2004-05-29 22:56:24 +02:00
|
|
|
|
2005-01-12 15:31:47 +01:00
|
|
|
// ReadXML: read some other data (entities, etc) in XML format
|
2005-05-03 23:42:09 +02:00
|
|
|
int ReadXML();
|
2005-03-22 22:00:56 +01:00
|
|
|
|
|
|
|
// clean up everything used during delayed load
|
2005-05-03 23:42:09 +02:00
|
|
|
int DelayLoadFinished();
|
2011-03-22 02:34:45 +01:00
|
|
|
|
|
|
|
// Copy random map settings over to sim
|
|
|
|
int LoadRMSettings();
|
|
|
|
|
|
|
|
// Generate random map
|
|
|
|
int GenerateMap();
|
|
|
|
|
|
|
|
// Parse script data into terrain
|
|
|
|
int ParseTerrain();
|
|
|
|
|
|
|
|
// Parse script data into entities
|
|
|
|
int ParseEntities();
|
|
|
|
|
|
|
|
// Parse script data into environment
|
|
|
|
int ParseEnvironment();
|
|
|
|
|
|
|
|
// Parse script data into camera
|
|
|
|
int ParseCamera();
|
|
|
|
|
2005-01-12 15:31:47 +01:00
|
|
|
|
2004-05-29 22:56:24 +02:00
|
|
|
// size of map
|
2009-11-08 17:49:52 +01:00
|
|
|
ssize_t m_PatchesPerSide;
|
2004-05-29 22:56:24 +02:00
|
|
|
// heightmap for map
|
|
|
|
std::vector<u16> m_Heightmap;
|
|
|
|
// list of terrain textures used by map
|
2010-09-04 23:26:52 +02:00
|
|
|
std::vector<CTerrainTextureEntry*> m_TerrainTextures;
|
2004-05-29 22:56:24 +02:00
|
|
|
// tile descriptions for each tile
|
|
|
|
std::vector<STileDesc> m_Tiles;
|
|
|
|
// lightenv stored in file
|
|
|
|
CLightEnv m_LightEnv;
|
2010-04-30 01:22:18 +02:00
|
|
|
// startup script
|
|
|
|
CStrW m_Script;
|
2005-03-22 22:00:56 +01:00
|
|
|
|
2011-03-22 02:34:45 +01:00
|
|
|
// random map data
|
|
|
|
CStrW m_ScriptFile;
|
|
|
|
CScriptValRooted m_ScriptSettings;
|
|
|
|
CScriptValRooted m_MapData;
|
|
|
|
|
2011-04-10 07:31:18 +02:00
|
|
|
CMapGenerator* m_MapGen;
|
|
|
|
|
2005-03-22 22:00:56 +01:00
|
|
|
// state latched by LoadMap and held until DelayedLoadFinished
|
|
|
|
CFileUnpacker unpacker;
|
2005-05-03 23:42:09 +02:00
|
|
|
CTerrain* pTerrain;
|
2006-06-11 09:03:59 +02:00
|
|
|
WaterManager* pWaterMan;
|
2006-06-22 00:37:31 +02:00
|
|
|
SkyManager* pSkyMan;
|
2012-10-15 12:34:23 +02:00
|
|
|
CPostprocManager* pPostproc;
|
2005-05-03 23:42:09 +02:00
|
|
|
CLightEnv* pLightEnv;
|
2010-08-13 15:26:29 +02:00
|
|
|
CGameView* pGameView;
|
2006-08-22 04:24:44 +02:00
|
|
|
CCinemaManager* pCinema;
|
2006-11-24 20:45:04 +01:00
|
|
|
CTriggerManager* pTrigMan;
|
2010-02-08 23:05:05 +01:00
|
|
|
CSimulation2* pSimulation2;
|
2011-10-24 16:31:05 +02:00
|
|
|
const CSimContext* pSimContext;
|
2010-07-03 15:15:57 +02:00
|
|
|
int m_PlayerID;
|
2011-10-24 16:31:05 +02:00
|
|
|
bool m_SkipEntities;
|
2009-11-03 22:46:35 +01:00
|
|
|
VfsPath filename_xml;
|
2010-05-03 21:13:58 +02:00
|
|
|
bool only_xml;
|
|
|
|
u32 file_format_version;
|
2011-06-14 01:32:41 +02:00
|
|
|
entity_id_t m_StartingCameraTarget;
|
|
|
|
CVector3D m_StartingCamera;
|
2005-05-03 23:42:09 +02:00
|
|
|
|
2005-05-05 01:12:46 +02:00
|
|
|
// UnpackTerrain generator state
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 20:48:32 +02:00
|
|
|
size_t cur_terrain_tex;
|
|
|
|
size_t num_terrain_tex;
|
2005-05-05 01:12:46 +02:00
|
|
|
|
2005-05-03 23:42:09 +02:00
|
|
|
CXMLReader* xml_reader;
|
2004-05-29 22:56:24 +02:00
|
|
|
};
|
|
|
|
|
2010-08-04 23:15:41 +02:00
|
|
|
/**
|
|
|
|
* A restricted map reader that returns various summary information
|
|
|
|
* for use by scripts (particularly the GUI).
|
|
|
|
*/
|
|
|
|
class CMapSummaryReader
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Try to load a map file.
|
|
|
|
* @param pathname Path to .pmp or .xml file
|
|
|
|
*/
|
|
|
|
PSRETURN LoadMap(const VfsPath& pathname);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a value of the form:
|
|
|
|
* @code
|
|
|
|
* {
|
|
|
|
* "settings": { ... contents of the map's <ScriptSettings> ... }
|
|
|
|
* }
|
|
|
|
* @endcode
|
|
|
|
*/
|
2010-10-30 06:02:42 +02:00
|
|
|
CScriptValRooted GetMapSettings(ScriptInterface& scriptInterface);
|
2010-08-04 23:15:41 +02:00
|
|
|
|
|
|
|
private:
|
2011-02-17 21:08:20 +01:00
|
|
|
CStr m_ScriptSettings;
|
2010-08-04 23:15:41 +02:00
|
|
|
};
|
|
|
|
|
2004-06-02 17:03:17 +02:00
|
|
|
#endif
|