1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
|
//----------------------------------------------------------------------------
// IMPORT Program (3D tileset)
//----------------------------------------------------------------------------
//
// (C) 2001-2002 Andrew Apted
//
// 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 2
// 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.
//
//------------------------------------------------------------------------
using namespace std;
#include "z_config.h"
#include "z_args.h"
#include "z_string.h"
#include "t_colmap.h"
#include "t_hue.h"
#include "t_tiles.h"
#define SKEW_MONSTER_MODE 1
static Tileset *mon32aja;
static Tileset *obj32aja;
static Tileset *oth32aja;
static int obj_start;
static int oth_start;
static Tileset *mon64aja;
static Tileset *obj64aja;
static Tileset *oth64aja;
static void Do3dImports(Tileset *src, const Tileset *dest)
{
int index;
for (index = 0; index < src->total; index++)
{
Tile *t = src->tiles + index;
if (! t->name)
continue;
int orig_idx = dest->LookupName(t->name);
if (orig_idx < 0)
{
fprintf(stderr, "Pruning (%s)\n", t->name);
free((void *) t->name);
t->name = 0;
continue;
}
t->tile_id = dest->tiles[orig_idx].tile_id;
}
// check for missing stuff
for (index = 0; index < dest->total; index++)
{
const Tile *t = dest->tiles + index;
if (! t->name)
continue;
int new_idx = src->LookupName(t->name);
if (new_idx < 0)
{
fprintf(stderr, "MISSING TILE (%s)\n", t->name);
continue;
}
}
}
//------------------------------------------------------------------------
void DetemineBounds(const Tileset *set, const Tile *T,
int& x1, int& y1, int& x2, int& y2)
{
Pix_t trans = set->cmap->trans_col;
x1 = x2 = T->width / 2;
y1 = y2 = T->height / 2;
int x, y;
for (y = 0; y < T->height; y++)
for (x = 0; x < T->width; x++)
{
Pix_t p = T->pixels[y * T->width + x];
if (p == NO_PIX || p == trans)
continue;
if (x < x1) x1 = x;
if (y < y1) y1 = y;
if (x > x2) x2 = x;
if (y > y2) y2 = y;
}
}
void CopyRawBox(const Tileset *src, const Tile *S,
int sx, int sy, int w, int h,
Tile *D, int dx, int dy)
{
Pix_t trans = src->cmap->trans_col;
int x, y;
for (y=0; y < h; y++)
for (x=0; x < w; x++)
{
ASSERT(0 <= (sx+x) && (sx+x) < S->width);
ASSERT(0 <= (sy+y) && (sy+y) < S->height);
ASSERT(0 <= (dx+x) && (dx+x) < D->width);
ASSERT(0 <= (dy+y) && (dy+y) < D->height);
Pix_t p = S->pixels[(sy + y) * S->width + (sx + x)];
if (p == NO_PIX || p == trans)
continue;
D->pixels[(dy + y) * D->width + (dx + x)] = p;
}
}
void SkewTileset(Tileset *dest, const Tileset *src)
{
for (int idx = 0; idx < src->total; idx++)
{
const Tile *S = src->tiles + idx;
if (! S->name)
continue;
int d_idx = dest->LookupName(S->name);
if (d_idx < 0)
{
fprintf(stderr, "Couldn't find (%s) to SKEW\n", S->name);
continue;
}
Tile *D = dest->tiles + d_idx;
D->Clear(dest->cmap->trans_col);
int x1, y1;
int x2, y2;
DetemineBounds(src, S, x1, y1, x2, y2);
int ww = x2 - x1 + 1;
int hh = y2 - y1 + 1;
int dest_x = 24 - ww / 2;
int dest_y = 64 - 17 - hh;
CopyRawBox(src, S, x1, y1, ww, hh, D, dest_x, dest_y);
}
}
//------------------------------------------------------------------------
static void ShowInfo()
{
fprintf(stdout,
"\n**** Import3D 0.2 ****\n\n"
"Copyright (C) 2001-2002 Andrew Apted.\n"
"Under the GNU General Public License (GPL).\n\n"
"USAGE: import ajadir slashdir\n\n"
);
fflush(stdout);
}
int main(int argc, const char **argv, const char **envp)
{
if (argc > 1 &&
(Z_String::CaseCmp(argv[1], "/?") == 0 ||
Z_String::CaseCmp(argv[1], "-h") == 0 ||
Z_String::CaseCmp(argv[1], "-help") == 0 ||
Z_String::CaseCmp(argv[1], "--help") == 0))
{
ShowInfo();
exit(0);
}
if (argc != 2)
{
fprintf(stderr, "USAGE: import3D ajadir\n");
exit(2);
}
Z_Args::AddMany(argc - 1, argv + 1);
char threedbuf[256];
sprintf(threedbuf, "%s/THREE_D/", argv[1]);
Filename ajdir(argv[1]);
Filename threeddir(threedbuf);
/* ---- colormaps ---- */
T_Colmap::cmap16 = SharedColmap::Load(
Filename("colors16.list").SetPath(ajdir));
T_Colmap::cmap32 = SharedColmap::Load(
Filename("colors32.list").SetPath(ajdir));
/* ---- aja tiles ---- */
mon32aja = Tileset::Load(Filename("mon32aja.txt").SetPath(ajdir),
T_Colmap::cmap32);
obj32aja = Tileset::Load(Filename("obj32aja.txt").SetPath(ajdir),
T_Colmap::cmap32);
oth32aja = Tileset::Load(Filename("oth32aja.txt").SetPath(ajdir),
T_Colmap::cmap32);
obj_start = mon32aja->total;
oth_start = obj_start + obj32aja->total;
/* ---- 3D tiles ---- */
#if (SKEW_MONSTER_MODE)
mon64aja = Tileset::Load(Filename("mon64aja.txt").SetPath(ajdir),
T_Colmap::cmap32);
obj64aja = Tileset::Load(Filename("obj64aja.txt").SetPath(ajdir),
T_Colmap::cmap32);
oth64aja = Tileset::Load(Filename("oth64aja.txt").SetPath(ajdir),
T_Colmap::cmap32);
SkewTileset(mon64aja, mon32aja);
SkewTileset(obj64aja, obj32aja);
#else
mon64aja = Tileset::Load(Filename("mon3d.txt").SetPath(threeddir),
T_Colmap::cmap32);
obj64aja = Tileset::Load(Filename("obj3d.txt").SetPath(threeddir),
T_Colmap::cmap32);
oth64aja = Tileset::Load(Filename("oth3d.txt").SetPath(threeddir),
T_Colmap::cmap32);
mon64aja->SkipEmptyNames(1);
obj64aja->SkipEmptyNames(1);
oth64aja->SkipEmptyNames(1);
mon64aja->ImportPairNames(mon32aja);
obj64aja->ImportPairNames(obj32aja);
oth64aja->ImportPairNames(oth32aja);
Do3dImports(mon64aja, mon32aja);
Do3dImports(obj64aja, obj32aja);
Do3dImports(oth64aja, oth32aja);
#endif /* SKEW_MONSTER_MODE */
/* ---- save it all, baby ---- */
fprintf(stderr, "\n");
mon64aja->Save("mon64new.txt");
obj64aja->Save("obj64new.txt");
oth64aja->Save("oth64new.txt");
return 0;
}
|