2010-11-20 10:37:14 +00:00
|
|
|
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
|
|
|
|
/* If you are missing that file, acquire a complete release at teeworlds.com. */
|
2011-08-31 11:56:04 +00:00
|
|
|
|
|
|
|
#include <base/tl/array.h>
|
|
|
|
|
2010-10-30 12:06:28 +00:00
|
|
|
#include <engine/client.h>
|
2010-08-17 22:06:00 +00:00
|
|
|
#include <engine/console.h>
|
2010-05-29 07:25:38 +00:00
|
|
|
#include <engine/graphics.h>
|
2010-11-17 12:08:29 +00:00
|
|
|
#include <engine/serverbrowser.h>
|
2010-05-29 07:25:38 +00:00
|
|
|
#include <engine/storage.h>
|
2010-08-06 18:18:53 +00:00
|
|
|
#include <game/gamecore.h>
|
2011-04-19 08:34:51 +00:00
|
|
|
#include "editor.h"
|
2008-01-17 23:09:49 +00:00
|
|
|
|
|
|
|
template<typename T>
|
2010-05-29 07:25:38 +00:00
|
|
|
static int MakeVersion(int i, const T &v)
|
2008-01-17 23:09:49 +00:00
|
|
|
{ return (i<<16)+sizeof(T); }
|
|
|
|
|
|
|
|
// backwards compatiblity
|
2009-10-27 14:38:53 +00:00
|
|
|
/*
|
2008-03-05 19:38:47 +00:00
|
|
|
void editor_load_old(DATAFILE *df, MAP *map)
|
2008-01-17 23:09:49 +00:00
|
|
|
{
|
|
|
|
class mapres_image
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
int image_data;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct mapres_tilemap
|
|
|
|
{
|
|
|
|
int image;
|
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
int x, y;
|
|
|
|
int scale;
|
|
|
|
int data;
|
|
|
|
int main;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct mapres_entity
|
|
|
|
{
|
|
|
|
int x, y;
|
|
|
|
int data[1];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct mapres_spawnpoint
|
|
|
|
{
|
|
|
|
int x, y;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct mapres_item
|
|
|
|
{
|
|
|
|
int x, y;
|
|
|
|
int type;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct mapres_flagstand
|
|
|
|
{
|
|
|
|
int x, y;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
MAPRES_ENTS_START=1,
|
|
|
|
MAPRES_SPAWNPOINT=1,
|
|
|
|
MAPRES_ITEM=2,
|
|
|
|
MAPRES_SPAWNPOINT_RED=3,
|
|
|
|
MAPRES_SPAWNPOINT_BLUE=4,
|
|
|
|
MAPRES_FLAGSTAND_RED=5,
|
|
|
|
MAPRES_FLAGSTAND_BLUE=6,
|
|
|
|
MAPRES_ENTS_END,
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-01-17 23:09:49 +00:00
|
|
|
ITEM_NULL=0,
|
|
|
|
ITEM_WEAPON_GUN=0x00010001,
|
|
|
|
ITEM_WEAPON_SHOTGUN=0x00010002,
|
|
|
|
ITEM_WEAPON_ROCKET=0x00010003,
|
|
|
|
ITEM_WEAPON_SNIPER=0x00010004,
|
|
|
|
ITEM_WEAPON_HAMMER=0x00010005,
|
|
|
|
ITEM_HEALTH =0x00020001,
|
|
|
|
ITEM_ARMOR=0x00030001,
|
|
|
|
ITEM_NINJA=0x00040001,
|
|
|
|
};
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-01-17 23:09:49 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
MAPRES_REGISTERED=0x8000,
|
|
|
|
MAPRES_IMAGE=0x8001,
|
|
|
|
MAPRES_TILEMAP=0x8002,
|
|
|
|
MAPRES_COLLISIONMAP=0x8003,
|
|
|
|
MAPRES_TEMP_THEME=0x8fff,
|
|
|
|
};
|
|
|
|
|
|
|
|
// load tilemaps
|
|
|
|
int game_width = 0;
|
|
|
|
int game_height = 0;
|
|
|
|
{
|
|
|
|
int start, num;
|
|
|
|
datafile_get_type(df, MAPRES_TILEMAP, &start, &num);
|
|
|
|
for(int t = 0; t < num; t++)
|
|
|
|
{
|
|
|
|
mapres_tilemap *tmap = (mapres_tilemap *)datafile_get_item(df, start+t,0,0);
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
CLayerTiles *l = new CLayerTiles(tmap->width, tmap->height);
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-01-17 23:09:49 +00:00
|
|
|
if(tmap->main)
|
|
|
|
{
|
|
|
|
// move game layer to correct position
|
2008-03-05 19:38:47 +00:00
|
|
|
for(int i = 0; i < map->groups[0]->layers.len()-1; i++)
|
2008-01-17 23:09:49 +00:00
|
|
|
{
|
2009-10-27 14:38:53 +00:00
|
|
|
if(map->groups[0]->layers[i] == pEditor->map.game_layer)
|
2008-03-05 19:38:47 +00:00
|
|
|
map->groups[0]->swap_layers(i, i+1);
|
2008-01-17 23:09:49 +00:00
|
|
|
}
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-01-17 23:09:49 +00:00
|
|
|
game_width = tmap->width;
|
|
|
|
game_height = tmap->height;
|
|
|
|
}
|
|
|
|
|
|
|
|
// add new layer
|
2008-03-05 19:38:47 +00:00
|
|
|
map->groups[0]->add_layer(l);
|
2008-01-17 23:09:49 +00:00
|
|
|
|
|
|
|
// process the data
|
|
|
|
unsigned char *src_data = (unsigned char *)datafile_get_data(df, tmap->data);
|
2010-05-29 07:25:38 +00:00
|
|
|
CTile *dst_data = l->tiles;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-01-17 23:09:49 +00:00
|
|
|
for(int y = 0; y < tmap->height; y++)
|
|
|
|
for(int x = 0; x < tmap->width; x++, dst_data++, src_data+=2)
|
|
|
|
{
|
|
|
|
dst_data->index = src_data[0];
|
|
|
|
dst_data->flags = src_data[1];
|
|
|
|
}
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-01-17 23:09:49 +00:00
|
|
|
l->image = tmap->image;
|
|
|
|
}
|
|
|
|
}
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-01-17 23:09:49 +00:00
|
|
|
// load images
|
|
|
|
{
|
|
|
|
int start, count;
|
|
|
|
datafile_get_type(df, MAPRES_IMAGE, &start, &count);
|
|
|
|
for(int i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
mapres_image *imgres = (mapres_image *)datafile_get_item(df, start+i, 0, 0);
|
|
|
|
void *data = datafile_get_data(df, imgres->image_data);
|
|
|
|
|
2008-06-12 10:51:48 +00:00
|
|
|
EDITOR_IMAGE *img = new EDITOR_IMAGE;
|
2008-01-17 23:09:49 +00:00
|
|
|
img->width = imgres->width;
|
|
|
|
img->height = imgres->height;
|
2010-05-29 07:25:38 +00:00
|
|
|
img->format = CImageInfo::FORMAT_RGBA;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-01-17 23:09:49 +00:00
|
|
|
// copy image data
|
|
|
|
img->data = mem_alloc(img->width*img->height*4, 1);
|
|
|
|
mem_copy(img->data, data, img->width*img->height*4);
|
2010-05-29 07:25:38 +00:00
|
|
|
img->tex_id = Graphics()->LoadTextureRaw(img->width, img->height, img->format, img->data, CImageInfo::FORMAT_AUTO, 0);
|
2008-03-09 23:29:14 +00:00
|
|
|
map->images.add(img);
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-01-17 23:09:49 +00:00
|
|
|
// unload image
|
|
|
|
datafile_unload_data(df, imgres->image_data);
|
|
|
|
}
|
|
|
|
}
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-01-17 23:09:49 +00:00
|
|
|
// load entities
|
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
CLayerGame *g = map->game_layer;
|
2008-01-17 23:09:49 +00:00
|
|
|
g->resize(game_width, game_height);
|
|
|
|
for(int t = MAPRES_ENTS_START; t < MAPRES_ENTS_END; t++)
|
|
|
|
{
|
|
|
|
// fetch entities of this class
|
|
|
|
int start, num;
|
|
|
|
datafile_get_type(df, t, &start, &num);
|
|
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i < num; i++)
|
|
|
|
{
|
|
|
|
mapres_entity *e = (mapres_entity *)datafile_get_item(df, start+i,0,0);
|
|
|
|
int x = e->x/32;
|
|
|
|
int y = e->y/32;
|
|
|
|
int id = -1;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-01-17 23:09:49 +00:00
|
|
|
if(t == MAPRES_SPAWNPOINT) id = ENTITY_SPAWN;
|
|
|
|
else if(t == MAPRES_SPAWNPOINT_RED) id = ENTITY_SPAWN_RED;
|
|
|
|
else if(t == MAPRES_SPAWNPOINT_BLUE) id = ENTITY_SPAWN_BLUE;
|
|
|
|
else if(t == MAPRES_FLAGSTAND_RED) id = ENTITY_FLAGSTAND_RED;
|
|
|
|
else if(t == MAPRES_FLAGSTAND_BLUE) id = ENTITY_FLAGSTAND_BLUE;
|
|
|
|
else if(t == MAPRES_ITEM)
|
|
|
|
{
|
|
|
|
if(e->data[0] == ITEM_WEAPON_SHOTGUN) id = ENTITY_WEAPON_SHOTGUN;
|
2008-02-02 18:05:16 +00:00
|
|
|
else if(e->data[0] == ITEM_WEAPON_ROCKET) id = ENTITY_WEAPON_GRENADE;
|
2008-01-17 23:09:49 +00:00
|
|
|
else if(e->data[0] == ITEM_NINJA) id = ENTITY_POWERUP_NINJA;
|
|
|
|
else if(e->data[0] == ITEM_ARMOR) id = ENTITY_ARMOR_1;
|
|
|
|
else if(e->data[0] == ITEM_HEALTH) id = ENTITY_HEALTH_1;
|
|
|
|
}
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-01-17 23:09:49 +00:00
|
|
|
if(id > 0 && x >= 0 && x < g->width && y >= 0 && y < g->height)
|
|
|
|
g->tiles[y*g->width+x].index = id+ENTITY_OFFSET;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-10-27 14:38:53 +00:00
|
|
|
}*/
|
2008-01-17 23:09:49 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
int CEditor::Save(const char *pFilename)
|
2008-03-09 23:29:14 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
return m_Map.Save(Kernel()->RequestInterface<IStorage>(), pFilename);
|
2008-03-09 23:29:14 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
int CEditorMap::Save(class IStorage *pStorage, const char *pFileName)
|
2008-01-17 23:09:49 +00:00
|
|
|
{
|
2010-08-17 22:06:00 +00:00
|
|
|
char aBuf[256];
|
|
|
|
str_format(aBuf, sizeof(aBuf), "saving to '%s'...", pFileName);
|
|
|
|
m_pEditor->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "editor", aBuf);
|
2010-05-29 07:25:38 +00:00
|
|
|
CDataFileWriter df;
|
|
|
|
if(!df.Open(pStorage, pFileName))
|
2008-01-17 23:09:49 +00:00
|
|
|
{
|
2010-08-17 22:06:00 +00:00
|
|
|
str_format(aBuf, sizeof(aBuf), "failed to open file '%s'...", pFileName);
|
|
|
|
m_pEditor->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "editor", aBuf);
|
2008-01-17 23:09:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-01-17 23:09:49 +00:00
|
|
|
// save version
|
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
CMapItemVersion Item;
|
|
|
|
Item.m_Version = 1;
|
|
|
|
df.AddItem(MAPITEMTYPE_VERSION, 0, sizeof(Item), &Item);
|
2008-01-17 23:09:49 +00:00
|
|
|
}
|
|
|
|
|
2011-07-12 21:31:39 +00:00
|
|
|
// save map info
|
|
|
|
{
|
|
|
|
CMapItemInfo Item;
|
|
|
|
Item.m_Version = 1;
|
|
|
|
|
|
|
|
if(m_MapInfo.m_aAuthor[0])
|
|
|
|
Item.m_Author = df.AddData(str_length(m_MapInfo.m_aAuthor)+1, m_MapInfo.m_aAuthor);
|
|
|
|
else
|
|
|
|
Item.m_Author = -1;
|
|
|
|
if(m_MapInfo.m_aVersion[0])
|
|
|
|
Item.m_MapVersion = df.AddData(str_length(m_MapInfo.m_aVersion)+1, m_MapInfo.m_aVersion);
|
|
|
|
else
|
|
|
|
Item.m_MapVersion = -1;
|
|
|
|
if(m_MapInfo.m_aCredits[0])
|
|
|
|
Item.m_Credits = df.AddData(str_length(m_MapInfo.m_aCredits)+1, m_MapInfo.m_aCredits);
|
|
|
|
else
|
|
|
|
Item.m_Credits = -1;
|
|
|
|
if(m_MapInfo.m_aLicense[0])
|
|
|
|
Item.m_License = df.AddData(str_length(m_MapInfo.m_aLicense)+1, m_MapInfo.m_aLicense);
|
|
|
|
else
|
|
|
|
Item.m_License = -1;
|
|
|
|
|
|
|
|
df.AddItem(MAPITEMTYPE_INFO, 0, sizeof(Item), &Item);
|
|
|
|
}
|
|
|
|
|
2008-01-17 23:09:49 +00:00
|
|
|
// save images
|
2010-05-29 07:25:38 +00:00
|
|
|
for(int i = 0; i < m_lImages.size(); i++)
|
2008-01-17 23:09:49 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
CEditorImage *pImg = m_lImages[i];
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-03-29 11:44:03 +00:00
|
|
|
// analyse the image for when saving (should be done when we load the image)
|
|
|
|
// TODO!
|
2010-05-29 07:25:38 +00:00
|
|
|
pImg->AnalyseTileFlags();
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
CMapItemImage Item;
|
|
|
|
Item.m_Version = 1;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
Item.m_Width = pImg->m_Width;
|
|
|
|
Item.m_Height = pImg->m_Height;
|
|
|
|
Item.m_External = pImg->m_External;
|
|
|
|
Item.m_ImageName = df.AddData(str_length(pImg->m_aName)+1, pImg->m_aName);
|
|
|
|
if(pImg->m_External)
|
|
|
|
Item.m_ImageData = -1;
|
2008-01-19 14:23:53 +00:00
|
|
|
else
|
2010-05-29 07:25:38 +00:00
|
|
|
Item.m_ImageData = df.AddData(Item.m_Width*Item.m_Height*4, pImg->m_pData);
|
|
|
|
df.AddItem(MAPITEMTYPE_IMAGE, i, sizeof(Item), &Item);
|
2008-01-17 23:09:49 +00:00
|
|
|
}
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-01-17 23:09:49 +00:00
|
|
|
// save layers
|
2010-10-16 16:50:05 +00:00
|
|
|
int LayerCount = 0, GroupCount = 0;
|
2010-05-29 07:25:38 +00:00
|
|
|
for(int g = 0; g < m_lGroups.size(); g++)
|
2008-01-17 23:09:49 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
CLayerGroup *pGroup = m_lGroups[g];
|
2010-10-16 16:50:05 +00:00
|
|
|
if(!pGroup->m_SaveToMap)
|
|
|
|
continue;
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
CMapItemGroup GItem;
|
|
|
|
GItem.m_Version = CMapItemGroup::CURRENT_VERSION;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
GItem.m_ParallaxX = pGroup->m_ParallaxX;
|
|
|
|
GItem.m_ParallaxY = pGroup->m_ParallaxY;
|
|
|
|
GItem.m_OffsetX = pGroup->m_OffsetX;
|
|
|
|
GItem.m_OffsetY = pGroup->m_OffsetY;
|
|
|
|
GItem.m_UseClipping = pGroup->m_UseClipping;
|
|
|
|
GItem.m_ClipX = pGroup->m_ClipX;
|
|
|
|
GItem.m_ClipY = pGroup->m_ClipY;
|
|
|
|
GItem.m_ClipW = pGroup->m_ClipW;
|
|
|
|
GItem.m_ClipH = pGroup->m_ClipH;
|
|
|
|
GItem.m_StartLayer = LayerCount;
|
|
|
|
GItem.m_NumLayers = 0;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2011-07-12 01:14:46 +00:00
|
|
|
// save group name
|
|
|
|
StrToInts(GItem.m_aName, sizeof(GItem.m_aName)/sizeof(int), pGroup->m_aName);
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
for(int l = 0; l < pGroup->m_lLayers.size(); l++)
|
2008-01-17 23:09:49 +00:00
|
|
|
{
|
2010-10-16 16:50:05 +00:00
|
|
|
if(!pGroup->m_lLayers[l]->m_SaveToMap)
|
|
|
|
continue;
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
if(pGroup->m_lLayers[l]->m_Type == LAYERTYPE_TILES)
|
2008-01-17 23:09:49 +00:00
|
|
|
{
|
2010-08-17 22:06:00 +00:00
|
|
|
m_pEditor->Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "editor", "saving tiles layer");
|
2010-05-29 07:25:38 +00:00
|
|
|
CLayerTiles *pLayer = (CLayerTiles *)pGroup->m_lLayers[l];
|
|
|
|
pLayer->PrepareForSave();
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
CMapItemLayerTilemap Item;
|
2011-07-12 01:14:46 +00:00
|
|
|
Item.m_Version = 3;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
Item.m_Layer.m_Flags = pLayer->m_Flags;
|
|
|
|
Item.m_Layer.m_Type = pLayer->m_Type;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2011-07-18 10:05:12 +00:00
|
|
|
Item.m_Color = pLayer->m_Color;
|
|
|
|
Item.m_ColorEnv = pLayer->m_ColorEnv;
|
|
|
|
Item.m_ColorEnvOffset = pLayer->m_ColorEnvOffset;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
Item.m_Width = pLayer->m_Width;
|
|
|
|
Item.m_Height = pLayer->m_Height;
|
2011-08-13 00:12:40 +00:00
|
|
|
// Item.m_Flags = pLayer->m_Game ? TILESLAYERFLAG_GAME : 0;
|
2011-04-09 06:41:31 +00:00
|
|
|
|
2010-09-30 21:31:19 +00:00
|
|
|
if(pLayer->m_Tele)
|
2011-08-13 00:12:40 +00:00
|
|
|
Item.m_Flags = TILESLAYERFLAG_TELE;
|
2010-09-30 21:31:19 +00:00
|
|
|
else if(pLayer->m_Speedup)
|
2011-08-13 00:12:40 +00:00
|
|
|
Item.m_Flags = TILESLAYERFLAG_SPEEDUP;
|
2010-09-30 21:31:19 +00:00
|
|
|
else if(pLayer->m_Front)
|
2011-08-13 00:12:40 +00:00
|
|
|
Item.m_Flags = TILESLAYERFLAG_FRONT;
|
2010-09-30 21:31:19 +00:00
|
|
|
else if(pLayer->m_Switch)
|
2011-08-13 00:12:40 +00:00
|
|
|
Item.m_Flags = TILESLAYERFLAG_SWITCH;
|
2010-09-30 21:31:19 +00:00
|
|
|
else
|
2011-08-13 00:12:40 +00:00
|
|
|
Item.m_Flags = pLayer->m_Game ? TILESLAYERFLAG_GAME : 0;
|
2011-04-09 06:41:31 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
Item.m_Image = pLayer->m_Image;
|
2010-09-30 21:31:19 +00:00
|
|
|
if(pLayer->m_Tele)
|
|
|
|
{
|
|
|
|
CTile *Tiles = new CTile[pLayer->m_Width*pLayer->m_Height];
|
|
|
|
mem_zero(Tiles, pLayer->m_Width*pLayer->m_Height*sizeof(CTile));
|
|
|
|
Item.m_Data = df.AddData(pLayer->m_Width*pLayer->m_Height*sizeof(CTile), Tiles);
|
|
|
|
Item.m_Tele = df.AddData(pLayer->m_Width*pLayer->m_Height*sizeof(CTeleTile), ((CLayerTele *)pLayer)->m_pTeleTile);
|
|
|
|
delete[] Tiles;
|
|
|
|
}
|
|
|
|
else if(pLayer->m_Speedup)
|
|
|
|
{
|
|
|
|
CTile *Tiles = new CTile[pLayer->m_Width*pLayer->m_Height];
|
|
|
|
mem_zero(Tiles, pLayer->m_Width*pLayer->m_Height*sizeof(CTile));
|
|
|
|
Item.m_Data = df.AddData(pLayer->m_Width*pLayer->m_Height*sizeof(CTile), Tiles);
|
|
|
|
Item.m_Speedup = df.AddData(pLayer->m_Width*pLayer->m_Height*sizeof(CSpeedupTile), ((CLayerSpeedup *)pLayer)->m_pSpeedupTile);
|
|
|
|
delete[] Tiles;
|
|
|
|
}
|
|
|
|
else if(pLayer->m_Front)
|
|
|
|
{
|
|
|
|
CTile *Tiles = new CTile[pLayer->m_Width*pLayer->m_Height];
|
|
|
|
mem_zero(Tiles, pLayer->m_Width*pLayer->m_Height*sizeof(CTile));
|
|
|
|
Item.m_Data = df.AddData(pLayer->m_Width*pLayer->m_Height*sizeof(CTile), Tiles);
|
|
|
|
Item.m_Front = df.AddData(pLayer->m_Width*pLayer->m_Height*sizeof(CTile), pLayer->m_pTiles);
|
|
|
|
delete[] Tiles;
|
|
|
|
}
|
|
|
|
else if(pLayer->m_Switch)
|
|
|
|
{
|
|
|
|
CTile *Tiles = new CTile[pLayer->m_Width*pLayer->m_Height];
|
|
|
|
mem_zero(Tiles, pLayer->m_Width*pLayer->m_Height*sizeof(CTile));
|
|
|
|
Item.m_Data = df.AddData(pLayer->m_Width*pLayer->m_Height*sizeof(CTile), Tiles);
|
2010-11-13 13:22:19 +00:00
|
|
|
Item.m_Switch = df.AddData(pLayer->m_Width*pLayer->m_Height*sizeof(CSwitchTile), ((CLayerSwitch *)pLayer)->m_pSwitchTile);
|
2010-09-30 21:31:19 +00:00
|
|
|
delete[] Tiles;
|
|
|
|
}
|
|
|
|
else
|
2010-05-29 07:25:38 +00:00
|
|
|
Item.m_Data = df.AddData(pLayer->m_Width*pLayer->m_Height*sizeof(CTile), pLayer->m_pTiles);
|
2011-07-12 01:14:46 +00:00
|
|
|
|
|
|
|
// save layer name
|
|
|
|
StrToInts(Item.m_aName, sizeof(Item.m_aName)/sizeof(int), pLayer->m_aName);
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
df.AddItem(MAPITEMTYPE_LAYER, LayerCount, sizeof(Item), &Item);
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
GItem.m_NumLayers++;
|
|
|
|
LayerCount++;
|
2008-01-17 23:09:49 +00:00
|
|
|
}
|
2010-05-29 07:25:38 +00:00
|
|
|
else if(pGroup->m_lLayers[l]->m_Type == LAYERTYPE_QUADS)
|
2008-01-17 23:09:49 +00:00
|
|
|
{
|
2010-08-17 22:06:00 +00:00
|
|
|
m_pEditor->Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "editor", "saving quads layer");
|
2010-05-29 07:25:38 +00:00
|
|
|
CLayerQuads *pLayer = (CLayerQuads *)pGroup->m_lLayers[l];
|
|
|
|
if(pLayer->m_lQuads.size())
|
2008-01-17 23:09:49 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
CMapItemLayerQuads Item;
|
2011-07-12 01:14:46 +00:00
|
|
|
Item.m_Version = 2;
|
2011-04-13 18:37:12 +00:00
|
|
|
Item.m_Layer.m_Flags = pLayer->m_Flags;
|
2010-05-29 07:25:38 +00:00
|
|
|
Item.m_Layer.m_Type = pLayer->m_Type;
|
|
|
|
Item.m_Image = pLayer->m_Image;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-01-17 23:09:49 +00:00
|
|
|
// add the data
|
2010-05-29 07:25:38 +00:00
|
|
|
Item.m_NumQuads = pLayer->m_lQuads.size();
|
|
|
|
Item.m_Data = df.AddDataSwapped(pLayer->m_lQuads.size()*sizeof(CQuad), pLayer->m_lQuads.base_ptr());
|
2011-07-12 01:14:46 +00:00
|
|
|
|
|
|
|
// save layer name
|
|
|
|
StrToInts(Item.m_aName, sizeof(Item.m_aName)/sizeof(int), pLayer->m_aName);
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
df.AddItem(MAPITEMTYPE_LAYER, LayerCount, sizeof(Item), &Item);
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-01-17 23:09:49 +00:00
|
|
|
// clean up
|
|
|
|
//mem_free(quads);
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
GItem.m_NumLayers++;
|
|
|
|
LayerCount++;
|
2008-01-17 23:09:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-10-16 16:50:05 +00:00
|
|
|
df.AddItem(MAPITEMTYPE_GROUP, GroupCount++, sizeof(GItem), &GItem);
|
2008-01-17 23:09:49 +00:00
|
|
|
}
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-01-17 23:09:49 +00:00
|
|
|
// save envelopes
|
2010-05-29 07:25:38 +00:00
|
|
|
int PointCount = 0;
|
|
|
|
for(int e = 0; e < m_lEnvelopes.size(); e++)
|
2008-01-17 23:09:49 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
CMapItemEnvelope Item;
|
2011-12-04 13:34:27 +00:00
|
|
|
Item.m_Version = CMapItemEnvelope::CURRENT_VERSION;
|
2010-05-29 07:25:38 +00:00
|
|
|
Item.m_Channels = m_lEnvelopes[e]->m_Channels;
|
|
|
|
Item.m_StartPoint = PointCount;
|
|
|
|
Item.m_NumPoints = m_lEnvelopes[e]->m_lPoints.size();
|
2011-12-04 13:34:27 +00:00
|
|
|
Item.m_Synchronized = m_lEnvelopes[e]->m_Synchronized;
|
2010-08-06 18:18:53 +00:00
|
|
|
StrToInts(Item.m_aName, sizeof(Item.m_aName)/sizeof(int), m_lEnvelopes[e]->m_aName);
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
df.AddItem(MAPITEMTYPE_ENVELOPE, e, sizeof(Item), &Item);
|
|
|
|
PointCount += Item.m_NumPoints;
|
2008-01-17 23:09:49 +00:00
|
|
|
}
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-01-17 23:09:49 +00:00
|
|
|
// save points
|
2010-05-29 07:25:38 +00:00
|
|
|
int TotalSize = sizeof(CEnvPoint) * PointCount;
|
|
|
|
CEnvPoint *pPoints = (CEnvPoint *)mem_alloc(TotalSize, 1);
|
|
|
|
PointCount = 0;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
for(int e = 0; e < m_lEnvelopes.size(); e++)
|
2008-01-17 23:09:49 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
int Count = m_lEnvelopes[e]->m_lPoints.size();
|
|
|
|
mem_copy(&pPoints[PointCount], m_lEnvelopes[e]->m_lPoints.base_ptr(), sizeof(CEnvPoint)*Count);
|
|
|
|
PointCount += Count;
|
2008-01-17 23:09:49 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
df.AddItem(MAPITEMTYPE_ENVPOINTS, 0, TotalSize, pPoints);
|
2012-07-08 11:13:21 +00:00
|
|
|
mem_free(pPoints);
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-01-17 23:09:49 +00:00
|
|
|
// finish the data file
|
2010-05-29 07:25:38 +00:00
|
|
|
df.Finish();
|
2010-08-17 22:06:00 +00:00
|
|
|
m_pEditor->Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "editor", "saving done");
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-03-21 00:13:55 +00:00
|
|
|
// send rcon.. if we can
|
2010-10-30 12:06:28 +00:00
|
|
|
if(m_pEditor->Client()->RconAuthed())
|
2008-03-21 00:13:55 +00:00
|
|
|
{
|
2010-11-17 12:08:29 +00:00
|
|
|
CServerInfo CurrentServerInfo;
|
|
|
|
m_pEditor->Client()->GetServerInfo(&CurrentServerInfo);
|
2014-01-24 02:41:30 +00:00
|
|
|
const unsigned char ipv4Localhost[16] = {127,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0};
|
|
|
|
const unsigned char ipv6Localhost[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1};
|
|
|
|
|
|
|
|
// and if we're on localhost
|
|
|
|
if(!mem_comp(CurrentServerInfo.m_NetAddr.ip, ipv4Localhost, sizeof(ipv4Localhost))
|
|
|
|
|| !mem_comp(CurrentServerInfo.m_NetAddr.ip, ipv6Localhost, sizeof(ipv6Localhost)))
|
|
|
|
{
|
|
|
|
char aMapName[128];
|
|
|
|
m_pEditor->ExtractName(pFileName, aMapName, sizeof(aMapName));
|
|
|
|
if(!str_comp(aMapName, CurrentServerInfo.m_aMap))
|
|
|
|
m_pEditor->Client()->Rcon("reload");
|
|
|
|
}
|
2010-11-17 12:08:29 +00:00
|
|
|
}
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-01-17 23:09:49 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2010-10-07 21:51:07 +00:00
|
|
|
int CEditor::Load(const char *pFileName, int StorageType)
|
2008-03-05 19:38:47 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
Reset();
|
2010-10-07 21:51:07 +00:00
|
|
|
return m_Map.Load(Kernel()->RequestInterface<IStorage>(), pFileName, StorageType);
|
2008-03-05 19:38:47 +00:00
|
|
|
}
|
|
|
|
|
2010-10-07 21:51:07 +00:00
|
|
|
int CEditorMap::Load(class IStorage *pStorage, const char *pFileName, int StorageType)
|
2008-01-17 23:09:49 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
CDataFileReader DataFile;
|
|
|
|
//DATAFILE *df = datafile_load(filename);
|
2010-10-07 21:51:07 +00:00
|
|
|
if(!DataFile.Open(pStorage, pFileName, StorageType))
|
2008-01-17 23:09:49 +00:00
|
|
|
return 0;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
Clean();
|
2008-01-17 23:09:49 +00:00
|
|
|
|
|
|
|
// check version
|
2010-05-29 07:25:38 +00:00
|
|
|
CMapItemVersion *pItem = (CMapItemVersion *)DataFile.FindItem(MAPITEMTYPE_VERSION, 0);
|
|
|
|
if(!pItem)
|
2008-01-17 23:09:49 +00:00
|
|
|
{
|
|
|
|
// import old map
|
2009-10-27 14:38:53 +00:00
|
|
|
/*MAP old_mapstuff;
|
|
|
|
editor->reset();
|
2008-03-21 00:13:55 +00:00
|
|
|
editor_load_old(df, this);
|
2009-10-27 14:38:53 +00:00
|
|
|
*/
|
2013-05-26 08:58:03 +00:00
|
|
|
return 0;
|
2008-01-17 23:09:49 +00:00
|
|
|
}
|
2010-05-29 07:25:38 +00:00
|
|
|
else if(pItem->m_Version == 1)
|
2008-01-17 23:09:49 +00:00
|
|
|
{
|
2008-03-09 23:29:14 +00:00
|
|
|
//editor.reset(false);
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2011-07-12 21:31:39 +00:00
|
|
|
// load map info
|
|
|
|
{
|
|
|
|
CMapItemInfo *pItem = (CMapItemInfo *)DataFile.FindItem(MAPITEMTYPE_INFO, 0);
|
|
|
|
if(pItem && pItem->m_Version == 1)
|
|
|
|
{
|
|
|
|
if(pItem->m_Author > -1)
|
|
|
|
str_copy(m_MapInfo.m_aAuthor, (char *)DataFile.GetData(pItem->m_Author), sizeof(m_MapInfo.m_aAuthor));
|
|
|
|
if(pItem->m_MapVersion > -1)
|
|
|
|
str_copy(m_MapInfo.m_aVersion, (char *)DataFile.GetData(pItem->m_MapVersion), sizeof(m_MapInfo.m_aVersion));
|
|
|
|
if(pItem->m_Credits > -1)
|
|
|
|
str_copy(m_MapInfo.m_aCredits, (char *)DataFile.GetData(pItem->m_Credits), sizeof(m_MapInfo.m_aCredits));
|
|
|
|
if(pItem->m_License > -1)
|
|
|
|
str_copy(m_MapInfo.m_aLicense, (char *)DataFile.GetData(pItem->m_License), sizeof(m_MapInfo.m_aLicense));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-17 23:09:49 +00:00
|
|
|
// load images
|
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
int Start, Num;
|
|
|
|
DataFile.GetType( MAPITEMTYPE_IMAGE, &Start, &Num);
|
|
|
|
for(int i = 0; i < Num; i++)
|
2008-01-17 23:09:49 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
CMapItemImage *pItem = (CMapItemImage *)DataFile.GetItem(Start+i, 0, 0);
|
|
|
|
char *pName = (char *)DataFile.GetData(pItem->m_ImageName);
|
2008-01-19 14:23:53 +00:00
|
|
|
|
2011-04-13 18:37:12 +00:00
|
|
|
// copy base info
|
2010-05-29 07:25:38 +00:00
|
|
|
CEditorImage *pImg = new CEditorImage(m_pEditor);
|
|
|
|
pImg->m_External = pItem->m_External;
|
2008-01-19 14:23:53 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
if(pItem->m_External)
|
2008-01-19 14:23:53 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
char aBuf[256];
|
|
|
|
str_format(aBuf, sizeof(aBuf),"mapres/%s.png", pName);
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-01-19 14:23:53 +00:00
|
|
|
// load external
|
2010-05-29 07:25:38 +00:00
|
|
|
CEditorImage ImgInfo(m_pEditor);
|
2010-10-06 21:07:35 +00:00
|
|
|
if(m_pEditor->Graphics()->LoadPNG(&ImgInfo, aBuf, IStorage::TYPE_ALL))
|
2008-01-19 14:23:53 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
*pImg = ImgInfo;
|
2011-02-12 10:40:36 +00:00
|
|
|
pImg->m_TexID = m_pEditor->Graphics()->LoadTextureRaw(ImgInfo.m_Width, ImgInfo.m_Height, ImgInfo.m_Format, ImgInfo.m_pData, CImageInfo::FORMAT_AUTO, 0);
|
2012-07-08 11:13:21 +00:00
|
|
|
ImgInfo.m_pData = 0;
|
2010-05-29 07:25:38 +00:00
|
|
|
pImg->m_External = 1;
|
2008-01-19 14:23:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
pImg->m_Width = pItem->m_Width;
|
|
|
|
pImg->m_Height = pItem->m_Height;
|
|
|
|
pImg->m_Format = CImageInfo::FORMAT_RGBA;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-01-19 14:23:53 +00:00
|
|
|
// copy image data
|
2010-05-29 07:25:38 +00:00
|
|
|
void *pData = DataFile.GetData(pItem->m_ImageData);
|
|
|
|
pImg->m_pData = mem_alloc(pImg->m_Width*pImg->m_Height*4, 1);
|
|
|
|
mem_copy(pImg->m_pData, pData, pImg->m_Width*pImg->m_Height*4);
|
2011-02-12 10:40:36 +00:00
|
|
|
pImg->m_TexID = m_pEditor->Graphics()->LoadTextureRaw(pImg->m_Width, pImg->m_Height, pImg->m_Format, pImg->m_pData, CImageInfo::FORMAT_AUTO, 0);
|
2008-01-19 14:23:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// copy image name
|
2010-05-29 07:25:38 +00:00
|
|
|
if(pName)
|
|
|
|
str_copy(pImg->m_aName, pName, 128);
|
2008-01-19 14:23:53 +00:00
|
|
|
|
2011-07-08 23:09:06 +00:00
|
|
|
// load auto mapper file
|
|
|
|
pImg->m_AutoMapper.Load(pImg->m_aName);
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
m_lImages.add(pImg);
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-01-17 23:09:49 +00:00
|
|
|
// unload image
|
2010-05-29 07:25:38 +00:00
|
|
|
DataFile.UnloadData(pItem->m_ImageData);
|
|
|
|
DataFile.UnloadData(pItem->m_ImageName);
|
2008-01-17 23:09:49 +00:00
|
|
|
}
|
|
|
|
}
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-01-17 23:09:49 +00:00
|
|
|
// load groups
|
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
int LayersStart, LayersNum;
|
|
|
|
DataFile.GetType(MAPITEMTYPE_LAYER, &LayersStart, &LayersNum);
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
int Start, Num;
|
|
|
|
DataFile.GetType(MAPITEMTYPE_GROUP, &Start, &Num);
|
|
|
|
for(int g = 0; g < Num; g++)
|
2008-01-17 23:09:49 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
CMapItemGroup *pGItem = (CMapItemGroup *)DataFile.GetItem(Start+g, 0, 0);
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
if(pGItem->m_Version < 1 || pGItem->m_Version > CMapItemGroup::CURRENT_VERSION)
|
2008-03-29 11:44:03 +00:00
|
|
|
continue;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
CLayerGroup *pGroup = NewGroup();
|
|
|
|
pGroup->m_ParallaxX = pGItem->m_ParallaxX;
|
|
|
|
pGroup->m_ParallaxY = pGItem->m_ParallaxY;
|
|
|
|
pGroup->m_OffsetX = pGItem->m_OffsetX;
|
|
|
|
pGroup->m_OffsetY = pGItem->m_OffsetY;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
if(pGItem->m_Version >= 2)
|
2008-03-29 11:44:03 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
pGroup->m_UseClipping = pGItem->m_UseClipping;
|
|
|
|
pGroup->m_ClipX = pGItem->m_ClipX;
|
|
|
|
pGroup->m_ClipY = pGItem->m_ClipY;
|
|
|
|
pGroup->m_ClipW = pGItem->m_ClipW;
|
|
|
|
pGroup->m_ClipH = pGItem->m_ClipH;
|
2008-03-29 11:44:03 +00:00
|
|
|
}
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2011-07-12 01:14:46 +00:00
|
|
|
// load group name
|
|
|
|
if(pGItem->m_Version >= 3)
|
|
|
|
IntsToStr(pGItem->m_aName, sizeof(pGroup->m_aName)/sizeof(int), pGroup->m_aName);
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
for(int l = 0; l < pGItem->m_NumLayers; l++)
|
2008-01-17 23:09:49 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
CLayer *pLayer = 0;
|
|
|
|
CMapItemLayer *pLayerItem = (CMapItemLayer *)DataFile.GetItem(LayersStart+pGItem->m_StartLayer+l, 0, 0);
|
|
|
|
if(!pLayerItem)
|
2008-01-17 23:09:49 +00:00
|
|
|
continue;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
if(pLayerItem->m_Type == LAYERTYPE_TILES)
|
2008-01-17 23:09:49 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
CMapItemLayerTilemap *pTilemapItem = (CMapItemLayerTilemap *)pLayerItem;
|
|
|
|
CLayerTiles *pTiles = 0;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2011-07-18 08:31:57 +00:00
|
|
|
if(pTilemapItem->m_Flags&TILESLAYERFLAG_GAME)
|
2008-01-17 23:09:49 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
pTiles = new CLayerGame(pTilemapItem->m_Width, pTilemapItem->m_Height);
|
|
|
|
MakeGameLayer(pTiles);
|
|
|
|
MakeGameGroup(pGroup);
|
2008-01-17 23:09:49 +00:00
|
|
|
}
|
2011-08-13 00:12:40 +00:00
|
|
|
else if(pTilemapItem->m_Flags&TILESLAYERFLAG_TELE)
|
2010-09-30 21:31:19 +00:00
|
|
|
{
|
2011-08-13 00:12:40 +00:00
|
|
|
if(pTilemapItem->m_Version <= 2)
|
|
|
|
pTilemapItem->m_Tele = *((int*)(pTilemapItem) + 15);
|
|
|
|
|
2010-09-30 21:31:19 +00:00
|
|
|
pTiles = new CLayerTele(pTilemapItem->m_Width, pTilemapItem->m_Height);
|
|
|
|
MakeTeleLayer(pTiles);
|
|
|
|
}
|
2011-08-13 00:12:40 +00:00
|
|
|
else if(pTilemapItem->m_Flags&TILESLAYERFLAG_SPEEDUP)
|
2010-09-30 21:31:19 +00:00
|
|
|
{
|
2011-08-13 00:12:40 +00:00
|
|
|
if(pTilemapItem->m_Version <= 2)
|
|
|
|
pTilemapItem->m_Speedup = *((int*)(pTilemapItem) + 16);
|
|
|
|
|
2010-09-30 21:31:19 +00:00
|
|
|
pTiles = new CLayerSpeedup(pTilemapItem->m_Width, pTilemapItem->m_Height);
|
|
|
|
MakeSpeedupLayer(pTiles);
|
|
|
|
}
|
2011-08-13 00:12:40 +00:00
|
|
|
else if(pTilemapItem->m_Flags&TILESLAYERFLAG_FRONT)
|
2010-09-30 21:31:19 +00:00
|
|
|
{
|
2011-08-13 00:12:40 +00:00
|
|
|
if(pTilemapItem->m_Version <= 2)
|
|
|
|
pTilemapItem->m_Front = *((int*)(pTilemapItem) + 17);
|
|
|
|
|
2010-09-30 21:31:19 +00:00
|
|
|
pTiles = new CLayerFront(pTilemapItem->m_Width, pTilemapItem->m_Height);
|
|
|
|
MakeFrontLayer(pTiles);
|
|
|
|
}
|
2011-08-13 00:12:40 +00:00
|
|
|
else if(pTilemapItem->m_Flags&TILESLAYERFLAG_SWITCH)
|
2010-09-30 21:31:19 +00:00
|
|
|
{
|
2011-08-13 00:12:40 +00:00
|
|
|
if(pTilemapItem->m_Version <= 2)
|
|
|
|
pTilemapItem->m_Switch = *((int*)(pTilemapItem) + 18);
|
|
|
|
|
2010-09-30 21:31:19 +00:00
|
|
|
pTiles = new CLayerSwitch(pTilemapItem->m_Width, pTilemapItem->m_Height);
|
|
|
|
MakeSwitchLayer(pTiles);
|
|
|
|
}
|
2008-01-17 23:09:49 +00:00
|
|
|
else
|
2010-05-29 07:25:38 +00:00
|
|
|
{
|
|
|
|
pTiles = new CLayerTiles(pTilemapItem->m_Width, pTilemapItem->m_Height);
|
|
|
|
pTiles->m_pEditor = m_pEditor;
|
2011-07-18 10:05:12 +00:00
|
|
|
pTiles->m_Color = pTilemapItem->m_Color;
|
|
|
|
pTiles->m_ColorEnv = pTilemapItem->m_ColorEnv;
|
|
|
|
pTiles->m_ColorEnvOffset = pTilemapItem->m_ColorEnvOffset;
|
2010-05-29 07:25:38 +00:00
|
|
|
}
|
2008-03-21 17:39:09 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
pLayer = pTiles;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
pGroup->AddLayer(pTiles);
|
|
|
|
void *pData = DataFile.GetData(pTilemapItem->m_Data);
|
2014-01-10 23:54:52 +00:00
|
|
|
unsigned int Size = DataFile.GetUncompressedDataSize(pTilemapItem->m_Data);
|
2010-05-29 07:25:38 +00:00
|
|
|
pTiles->m_Image = pTilemapItem->m_Image;
|
2011-07-18 08:31:57 +00:00
|
|
|
pTiles->m_Game = pTilemapItem->m_Flags&TILESLAYERFLAG_GAME;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2011-07-12 01:14:46 +00:00
|
|
|
// load layer name
|
|
|
|
if(pTilemapItem->m_Version >= 3)
|
|
|
|
IntsToStr(pTilemapItem->m_aName, sizeof(pTiles->m_aName)/sizeof(int), pTiles->m_aName);
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2014-01-10 23:46:32 +00:00
|
|
|
if (Size >= pTiles->m_Width*pTiles->m_Height*sizeof(CTile))
|
2008-01-17 23:09:49 +00:00
|
|
|
{
|
2014-01-10 23:46:32 +00:00
|
|
|
mem_copy(pTiles->m_pTiles, pData, pTiles->m_Width*pTiles->m_Height*sizeof(CTile));
|
|
|
|
|
|
|
|
if(pTiles->m_Game && pTilemapItem->m_Version == MakeVersion(1, *pTilemapItem))
|
2008-01-17 23:09:49 +00:00
|
|
|
{
|
2014-01-10 23:46:32 +00:00
|
|
|
for(int i = 0; i < pTiles->m_Width*pTiles->m_Height; i++)
|
|
|
|
{
|
|
|
|
if(pTiles->m_pTiles[i].m_Index)
|
|
|
|
pTiles->m_pTiles[i].m_Index += ENTITY_OFFSET;
|
|
|
|
}
|
2008-01-17 23:09:49 +00:00
|
|
|
}
|
|
|
|
}
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
DataFile.UnloadData(pTilemapItem->m_Data);
|
2011-04-09 06:41:31 +00:00
|
|
|
|
2010-09-30 21:31:19 +00:00
|
|
|
if(pTiles->m_Tele)
|
|
|
|
{
|
|
|
|
void *pTeleData = DataFile.GetData(pTilemapItem->m_Tele);
|
2014-01-10 23:54:52 +00:00
|
|
|
unsigned int Size = DataFile.GetUncompressedDataSize(pTilemapItem->m_Tele);
|
2014-01-10 23:46:32 +00:00
|
|
|
if (Size >= pTiles->m_Width*pTiles->m_Height*sizeof(CTeleTile))
|
2010-09-30 21:31:19 +00:00
|
|
|
{
|
2014-01-10 23:46:32 +00:00
|
|
|
mem_copy(((CLayerTele*)pTiles)->m_pTeleTile, pTeleData, pTiles->m_Width*pTiles->m_Height*sizeof(CTeleTile));
|
|
|
|
|
|
|
|
for(int i = 0; i < pTiles->m_Width*pTiles->m_Height; i++)
|
|
|
|
{
|
|
|
|
if(((CLayerTele*)pTiles)->m_pTeleTile[i].m_Type == TILE_TELEIN)
|
|
|
|
((CLayerTiles*)pTiles)->m_pTiles[i].m_Index = TILE_TELEIN;
|
|
|
|
else if(((CLayerTele*)pTiles)->m_pTeleTile[i].m_Type == TILE_TELEINEVIL)
|
|
|
|
((CLayerTiles*)pTiles)->m_pTiles[i].m_Index = TILE_TELEINEVIL;
|
|
|
|
else if(((CLayerTele*)pTiles)->m_pTeleTile[i].m_Type == TILE_TELEOUT)
|
|
|
|
((CLayerTiles*)pTiles)->m_pTiles[i].m_Index = TILE_TELEOUT;
|
|
|
|
else if(((CLayerTele*)pTiles)->m_pTeleTile[i].m_Type == TILE_TELECHECK)
|
|
|
|
((CLayerTiles*)pTiles)->m_pTiles[i].m_Index = TILE_TELECHECK;
|
|
|
|
else if(((CLayerTele*)pTiles)->m_pTeleTile[i].m_Type == TILE_TELECHECKIN)
|
|
|
|
((CLayerTiles*)pTiles)->m_pTiles[i].m_Index = TILE_TELECHECKIN;
|
2014-02-01 21:20:41 +00:00
|
|
|
else if(((CLayerTele*)pTiles)->m_pTeleTile[i].m_Type == TILE_TELECHECKINEVIL)
|
|
|
|
((CLayerTiles*)pTiles)->m_pTiles[i].m_Index = TILE_TELECHECKINEVIL;
|
2014-01-10 23:46:32 +00:00
|
|
|
else if(((CLayerTele*)pTiles)->m_pTeleTile[i].m_Type == TILE_TELECHECKOUT)
|
|
|
|
((CLayerTiles*)pTiles)->m_pTiles[i].m_Index = TILE_TELECHECKOUT;
|
|
|
|
else if(((CLayerTele*)pTiles)->m_pTeleTile[i].m_Type == TILE_TELEINWEAPON)
|
|
|
|
((CLayerTiles*)pTiles)->m_pTiles[i].m_Index = TILE_TELEINWEAPON;
|
|
|
|
else if(((CLayerTele*)pTiles)->m_pTeleTile[i].m_Type == TILE_TELEINHOOK)
|
|
|
|
((CLayerTiles*)pTiles)->m_pTiles[i].m_Index = TILE_TELEINHOOK;
|
|
|
|
else
|
|
|
|
((CLayerTiles*)pTiles)->m_pTiles[i].m_Index = 0;
|
|
|
|
}
|
2010-09-30 21:31:19 +00:00
|
|
|
}
|
|
|
|
DataFile.UnloadData(pTilemapItem->m_Tele);
|
|
|
|
}
|
|
|
|
else if(pTiles->m_Speedup)
|
|
|
|
{
|
|
|
|
void *pSpeedupData = DataFile.GetData(pTilemapItem->m_Speedup);
|
2014-01-10 23:54:52 +00:00
|
|
|
unsigned int Size = DataFile.GetUncompressedDataSize(pTilemapItem->m_Speedup);
|
2011-04-09 06:41:31 +00:00
|
|
|
|
2014-01-10 23:46:32 +00:00
|
|
|
if (Size >= pTiles->m_Width*pTiles->m_Height*sizeof(CSpeedupTile))
|
2010-09-30 21:31:19 +00:00
|
|
|
{
|
2014-01-10 23:46:32 +00:00
|
|
|
mem_copy(((CLayerSpeedup*)pTiles)->m_pSpeedupTile, pSpeedupData, pTiles->m_Width*pTiles->m_Height*sizeof(CSpeedupTile));
|
|
|
|
|
|
|
|
for(int i = 0; i < pTiles->m_Width*pTiles->m_Height; i++)
|
|
|
|
{
|
|
|
|
if(((CLayerSpeedup*)pTiles)->m_pSpeedupTile[i].m_Force > 0)
|
|
|
|
((CLayerTiles*)pTiles)->m_pTiles[i].m_Index = TILE_BOOST;
|
|
|
|
else
|
|
|
|
((CLayerTiles*)pTiles)->m_pTiles[i].m_Index = 0;
|
|
|
|
}
|
2010-09-30 21:31:19 +00:00
|
|
|
}
|
2011-04-09 06:41:31 +00:00
|
|
|
|
2010-09-30 21:31:19 +00:00
|
|
|
DataFile.UnloadData(pTilemapItem->m_Speedup);
|
|
|
|
}
|
|
|
|
else if(pTiles->m_Front)
|
|
|
|
{
|
|
|
|
void *pFrontData = DataFile.GetData(pTilemapItem->m_Front);
|
2014-01-10 23:54:52 +00:00
|
|
|
unsigned int Size = DataFile.GetUncompressedDataSize(pTilemapItem->m_Front);
|
2014-01-10 23:46:32 +00:00
|
|
|
if (Size >= pTiles->m_Width*pTiles->m_Height*sizeof(CTile))
|
|
|
|
mem_copy(((CLayerFront*)pTiles)->m_pTiles, pFrontData, pTiles->m_Width*pTiles->m_Height*sizeof(CTile));
|
2010-09-30 21:31:19 +00:00
|
|
|
|
|
|
|
DataFile.UnloadData(pTilemapItem->m_Front);
|
|
|
|
}
|
|
|
|
else if(pTiles->m_Switch)
|
|
|
|
{
|
|
|
|
void *pSwitchData = DataFile.GetData(pTilemapItem->m_Switch);
|
2014-01-10 23:54:52 +00:00
|
|
|
unsigned int Size = DataFile.GetUncompressedDataSize(pTilemapItem->m_Switch);
|
2014-01-10 23:46:32 +00:00
|
|
|
if (Size >= pTiles->m_Width*pTiles->m_Height*sizeof(CSwitchTile))
|
2010-09-30 21:31:19 +00:00
|
|
|
{
|
2014-01-10 23:46:32 +00:00
|
|
|
mem_copy(((CLayerSwitch*)pTiles)->m_pSwitchTile, pSwitchData, pTiles->m_Width*pTiles->m_Height*sizeof(CSwitchTile));
|
|
|
|
|
|
|
|
for(int i = 0; i < pTiles->m_Width*pTiles->m_Height; i++)
|
2013-08-23 23:03:45 +00:00
|
|
|
{
|
2014-01-10 23:46:32 +00:00
|
|
|
if(((((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Type > (ENTITY_CRAZY_SHOTGUN + ENTITY_OFFSET) && ((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Type < (ENTITY_DRAGGER_WEAK + ENTITY_OFFSET)) || ((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Type == (ENTITY_LASER_O_FAST + 1 + ENTITY_OFFSET)))
|
|
|
|
continue;
|
|
|
|
if(((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Type == TILE_SWITCHTIMEDOPEN)
|
|
|
|
{
|
|
|
|
((CLayerTiles*)pTiles)->m_pTiles[i].m_Index = TILE_SWITCHTIMEDOPEN;
|
|
|
|
((CLayerTiles*)pTiles)->m_pTiles[i].m_Flags = ((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Flags;
|
|
|
|
}
|
|
|
|
else if(((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Type == TILE_SWITCHTIMEDCLOSE)
|
|
|
|
{
|
|
|
|
((CLayerTiles*)pTiles)->m_pTiles[i].m_Index = TILE_SWITCHTIMEDCLOSE;
|
|
|
|
((CLayerTiles*)pTiles)->m_pTiles[i].m_Flags = ((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Flags;
|
|
|
|
}
|
|
|
|
else if(((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Type == TILE_SWITCHOPEN)
|
|
|
|
{
|
|
|
|
((CLayerTiles*)pTiles)->m_pTiles[i].m_Index = TILE_SWITCHOPEN;
|
|
|
|
((CLayerTiles*)pTiles)->m_pTiles[i].m_Flags = ((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Flags;
|
|
|
|
}
|
|
|
|
else if(((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Type == TILE_SWITCHCLOSE)
|
|
|
|
{
|
|
|
|
((CLayerTiles*)pTiles)->m_pTiles[i].m_Index = TILE_SWITCHCLOSE;
|
|
|
|
((CLayerTiles*)pTiles)->m_pTiles[i].m_Flags = ((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Flags;
|
|
|
|
}
|
|
|
|
else if(((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Type == TILE_FREEZE)
|
|
|
|
{
|
|
|
|
((CLayerTiles*)pTiles)->m_pTiles[i].m_Index = TILE_FREEZE;
|
|
|
|
((CLayerTiles*)pTiles)->m_pTiles[i].m_Flags = ((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Flags;
|
|
|
|
}
|
|
|
|
else if(((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Type == TILE_DFREEZE)
|
|
|
|
{
|
|
|
|
((CLayerTiles*)pTiles)->m_pTiles[i].m_Index = TILE_DFREEZE;
|
|
|
|
((CLayerTiles*)pTiles)->m_pTiles[i].m_Flags = ((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Flags;
|
|
|
|
}
|
|
|
|
else if(((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Type == TILE_DUNFREEZE)
|
|
|
|
{
|
|
|
|
((CLayerTiles*)pTiles)->m_pTiles[i].m_Index = TILE_DUNFREEZE;
|
|
|
|
((CLayerTiles*)pTiles)->m_pTiles[i].m_Flags = ((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Flags;
|
|
|
|
}
|
|
|
|
else if(((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Type >= (ENTITY_ARMOR_1 + ENTITY_OFFSET) && ((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Type <= (ENTITY_DOOR + ENTITY_OFFSET))
|
|
|
|
{
|
|
|
|
((CLayerTiles*)pTiles)->m_pTiles[i].m_Index = ((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Type;
|
|
|
|
((CLayerTiles*)pTiles)->m_pTiles[i].m_Flags = ((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Flags;
|
|
|
|
}
|
|
|
|
else if(((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Type == TILE_HIT_START)
|
|
|
|
{
|
|
|
|
((CLayerTiles*)pTiles)->m_pTiles[i].m_Index = TILE_HIT_START;
|
|
|
|
((CLayerTiles*)pTiles)->m_pTiles[i].m_Flags = ((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Flags;
|
|
|
|
}
|
|
|
|
else if(((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Type == TILE_HIT_END)
|
|
|
|
{
|
|
|
|
((CLayerTiles*)pTiles)->m_pTiles[i].m_Index = TILE_HIT_END;
|
|
|
|
((CLayerTiles*)pTiles)->m_pTiles[i].m_Flags = ((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Flags;
|
|
|
|
}
|
|
|
|
else if(((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Type == TILE_JUMP)
|
|
|
|
{
|
|
|
|
((CLayerTiles*)pTiles)->m_pTiles[i].m_Index = TILE_JUMP;
|
|
|
|
((CLayerTiles*)pTiles)->m_pTiles[i].m_Flags = ((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Flags;
|
|
|
|
}
|
2014-02-09 22:31:29 +00:00
|
|
|
else if(((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Type == TILE_PENALTY)
|
|
|
|
{
|
|
|
|
((CLayerTiles*)pTiles)->m_pTiles[i].m_Index = TILE_PENALTY;
|
|
|
|
((CLayerTiles*)pTiles)->m_pTiles[i].m_Flags = ((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Flags;
|
|
|
|
}
|
2011-07-25 20:16:20 +00:00
|
|
|
}
|
2010-09-30 21:31:19 +00:00
|
|
|
}
|
|
|
|
DataFile.UnloadData(pTilemapItem->m_Switch);
|
|
|
|
}
|
2008-01-17 23:09:49 +00:00
|
|
|
}
|
2010-05-29 07:25:38 +00:00
|
|
|
else if(pLayerItem->m_Type == LAYERTYPE_QUADS)
|
2008-01-17 23:09:49 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
CMapItemLayerQuads *pQuadsItem = (CMapItemLayerQuads *)pLayerItem;
|
|
|
|
CLayerQuads *pQuads = new CLayerQuads;
|
|
|
|
pQuads->m_pEditor = m_pEditor;
|
|
|
|
pLayer = pQuads;
|
|
|
|
pQuads->m_Image = pQuadsItem->m_Image;
|
|
|
|
if(pQuads->m_Image < -1 || pQuads->m_Image >= m_lImages.size())
|
|
|
|
pQuads->m_Image = -1;
|
2011-07-12 01:14:46 +00:00
|
|
|
|
|
|
|
// load layer name
|
|
|
|
if(pQuadsItem->m_Version >= 2)
|
|
|
|
IntsToStr(pQuadsItem->m_aName, sizeof(pQuads->m_aName)/sizeof(int), pQuads->m_aName);
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void *pData = DataFile.GetDataSwapped(pQuadsItem->m_Data);
|
|
|
|
pGroup->AddLayer(pQuads);
|
|
|
|
pQuads->m_lQuads.set_size(pQuadsItem->m_NumQuads);
|
|
|
|
mem_copy(pQuads->m_lQuads.base_ptr(), pData, sizeof(CQuad)*pQuadsItem->m_NumQuads);
|
|
|
|
DataFile.UnloadData(pQuadsItem->m_Data);
|
2008-01-17 23:09:49 +00:00
|
|
|
}
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
if(pLayer)
|
|
|
|
pLayer->m_Flags = pLayerItem->m_Flags;
|
2008-01-17 23:09:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-01-17 23:09:49 +00:00
|
|
|
// load envelopes
|
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
CEnvPoint *pPoints = 0;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-01-17 23:09:49 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
int Start, Num;
|
|
|
|
DataFile.GetType(MAPITEMTYPE_ENVPOINTS, &Start, &Num);
|
|
|
|
if(Num)
|
|
|
|
pPoints = (CEnvPoint *)DataFile.GetItem(Start, 0, 0);
|
2008-01-17 23:09:49 +00:00
|
|
|
}
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
int Start, Num;
|
|
|
|
DataFile.GetType(MAPITEMTYPE_ENVELOPE, &Start, &Num);
|
|
|
|
for(int e = 0; e < Num; e++)
|
2008-01-17 23:09:49 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
CMapItemEnvelope *pItem = (CMapItemEnvelope *)DataFile.GetItem(Start+e, 0, 0);
|
|
|
|
CEnvelope *pEnv = new CEnvelope(pItem->m_Channels);
|
|
|
|
pEnv->m_lPoints.set_size(pItem->m_NumPoints);
|
|
|
|
mem_copy(pEnv->m_lPoints.base_ptr(), &pPoints[pItem->m_StartPoint], sizeof(CEnvPoint)*pItem->m_NumPoints);
|
2010-08-06 18:18:53 +00:00
|
|
|
if(pItem->m_aName[0] != -1) // compatibility with old maps
|
|
|
|
IntsToStr(pItem->m_aName, sizeof(pItem->m_aName)/sizeof(int), pEnv->m_aName);
|
2010-05-29 07:25:38 +00:00
|
|
|
m_lEnvelopes.add(pEnv);
|
2011-12-04 13:34:27 +00:00
|
|
|
if(pItem->m_Version >= 2)
|
|
|
|
pEnv->m_Synchronized = pItem->m_Synchronized;
|
2008-01-17 23:09:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-05-26 08:58:03 +00:00
|
|
|
else
|
|
|
|
return 0;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
return 1;
|
2008-01-17 23:09:49 +00:00
|
|
|
}
|
2008-03-05 19:38:47 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
static int gs_ModifyAddAmount = 0;
|
|
|
|
static void ModifyAdd(int *pIndex)
|
2008-03-09 23:29:14 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
if(*pIndex >= 0)
|
|
|
|
*pIndex += gs_ModifyAddAmount;
|
2008-03-09 23:29:14 +00:00
|
|
|
}
|
2008-03-05 19:38:47 +00:00
|
|
|
|
2010-10-07 21:51:07 +00:00
|
|
|
int CEditor::Append(const char *pFileName, int StorageType)
|
2008-03-05 19:38:47 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
CEditorMap NewMap;
|
|
|
|
NewMap.m_pEditor = this;
|
|
|
|
|
|
|
|
int Err;
|
2010-10-07 21:51:07 +00:00
|
|
|
Err = NewMap.Load(Kernel()->RequestInterface<IStorage>(), pFileName, StorageType);
|
2010-05-31 21:55:45 +00:00
|
|
|
if(!Err)
|
2010-05-29 07:25:38 +00:00
|
|
|
return Err;
|
2008-03-09 23:29:14 +00:00
|
|
|
|
2011-04-13 18:37:12 +00:00
|
|
|
// modify indecies
|
2010-05-29 07:25:38 +00:00
|
|
|
gs_ModifyAddAmount = m_Map.m_lImages.size();
|
|
|
|
NewMap.ModifyImageIndex(ModifyAdd);
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
gs_ModifyAddAmount = m_Map.m_lEnvelopes.size();
|
|
|
|
NewMap.ModifyEnvelopeIndex(ModifyAdd);
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-03-09 23:29:14 +00:00
|
|
|
// transfer images
|
2010-05-29 07:25:38 +00:00
|
|
|
for(int i = 0; i < NewMap.m_lImages.size(); i++)
|
|
|
|
m_Map.m_lImages.add(NewMap.m_lImages[i]);
|
|
|
|
NewMap.m_lImages.clear();
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-03-09 23:29:14 +00:00
|
|
|
// transfer envelopes
|
2010-05-29 07:25:38 +00:00
|
|
|
for(int i = 0; i < NewMap.m_lEnvelopes.size(); i++)
|
|
|
|
m_Map.m_lEnvelopes.add(NewMap.m_lEnvelopes[i]);
|
|
|
|
NewMap.m_lEnvelopes.clear();
|
2008-03-09 23:29:14 +00:00
|
|
|
|
|
|
|
// transfer groups
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
for(int i = 0; i < NewMap.m_lGroups.size(); i++)
|
2008-03-09 23:29:14 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
if(NewMap.m_lGroups[i] == NewMap.m_pGameGroup)
|
|
|
|
delete NewMap.m_lGroups[i];
|
2008-03-09 23:29:14 +00:00
|
|
|
else
|
2010-05-29 07:25:38 +00:00
|
|
|
{
|
|
|
|
NewMap.m_lGroups[i]->m_pMap = &m_Map;
|
|
|
|
m_Map.m_lGroups.add(NewMap.m_lGroups[i]);
|
|
|
|
}
|
2008-03-09 23:29:14 +00:00
|
|
|
}
|
2010-05-29 07:25:38 +00:00
|
|
|
NewMap.m_lGroups.clear();
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-03-09 23:29:14 +00:00
|
|
|
// all done \o/
|
2008-03-05 19:38:47 +00:00
|
|
|
return 0;
|
|
|
|
}
|