diff options
Diffstat (limited to 'crawl-ref/source/rltiles/tool')
19 files changed, 1546 insertions, 4704 deletions
diff --git a/crawl-ref/source/rltiles/tool/bm.c b/crawl-ref/source/rltiles/tool/bm.c deleted file mode 100644 index cd208cecb2..0000000000 --- a/crawl-ref/source/rltiles/tool/bm.c +++ /dev/null @@ -1,558 +0,0 @@ -#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include "palette.h"
-
-char cpath[1024];
-/*** PATH separator ***/
-
-#if defined(_WIN32)|| defined(WINDOWS)
-#define PATHSEP '\\'
-#else
-#define PATHSEP '/'
-#endif
-
-void process_cpath(char *path){
- int i, pos;
-#ifdef LINUX
- cpath[0]=0;
- return;
-#endif
- pos = 0;
- cpath[0]=0;
- printf("path=%s\n",path);
- for(i=0;i<strlen(path);i++)if(path[i]==PATHSEP)pos=i;
-
- if(pos!=0){
- pos++;
- strncpy(cpath,path,pos);
- cpath[pos]=0;
- printf("pos=%d\n",pos);
- }
-}
-
-void fixalloc(char *buf[3], int size)
-{
- buf[0]=malloc(size);
- buf[1]=malloc(size);
- buf[2]=malloc(size);
-}
-
-#if 0
-#define WORD unsigned short
-#define DWORD unsigned int
-
- typedef struct tagBITMAPFILEHEADER {
- WORD bfType; // 常に"BM"
- DWORD bfSize; // ファイルサイズ
- WORD bfReserved1; // 0に設定
- WORD bfReserved2; // 0に設定
- DWORD bfOffBits; // DIB形式ファイルの先頭からピクセルデータ領
- } BITMAPFILEHEADER;
-
- typedef struct tagBITMAPINFOHEADER {
- DWORD biSize; // この構造体のサイズ
- DWORD biWidth; // 幅(ピクセル単位)
- DWORD biHeight; // 高さ(ピクセル単位)
- WORD biPlanes; // 常に1
- WORD biBitCount; // 1ピクセルあたりのカラービットの数
- DWORD biCompression; // BI_RGB, BI_RLE8, BI_RLE4のいずれか
- DWORD biSizeImage; // イメージの全バイト数
- DWORD biXPelsPerMeter; // 0または水平解像度
- DWORD biYPelsPerMeter; // 0または垂直解像度
- DWORD biClrUsed; // 通常は0、biBitCount以下のカラー数に設定可
- DWORD biClrImportant; // 通常は0
- } BITMAPINFOHEADER;
-#endif
-
-#define NHASH 512
-#define HASHMAX 100
-int hashflag;
-
-int hashn[NHASH];
-int hashtab[NHASH][HASHMAX][4];
-#define RGB2H(r,g,b) ( ((r)>>5)|(((b)>>5)<<3)|(((g)>>5)<<6) )
-int palr[256],palg[256],palb[256];
-
-unsigned int rev16(unsigned char *x)
-{
- int r=x[1];
- r = (r<<8)|x[0];
- return r;
-}
-unsigned int rev32(unsigned char *x)
-{
- int r=x[3];
- r = (r<<8)|x[2];
- r = (r<<8)|x[1];
- r = (r<<8)|x[0];
- return r;
-}
-
-/***** BMP read *****/
-int bmread(char *fn, int *x, int *y, unsigned char *buf3[3])
-{
-unsigned char bmHead[14];
-unsigned char bmInfo[40];
-
-unsigned char pbuf[1024];
-int i,j,k;
-int xx,yy,x0,y0;
-FILE *fp;
-unsigned char *b0;
-int bits, ofbits;
-
-if(NULL==(fp=fopen(fn,"rb")))
-{
- //printf("no file %s:",fn);
- return(1);
-}
- fread(&bmHead,1,14,fp);
- fread(&bmInfo,1,40,fp);
-
-xx=rev32(&bmInfo[4]);
-yy=rev32(&bmInfo[8]);
-bits=rev16(&bmInfo[14]);
-
-//fprintf(stderr, "wx = %d wy = %d\n",xx,yy);
-
-if(!buf3[0])buf3[0]=malloc(xx*yy);
-if(!buf3[1])buf3[1]=malloc(xx*yy);
-if(!buf3[2])buf3[2]=malloc(xx*yy);
-
-ofbits = rev32(&bmHead[10]);
-
-if(bits==24){
-fseek(fp, ofbits, SEEK_SET);
-
-b0=malloc(xx*yy*3);
-fread(b0,1,3*xx*yy,fp);
-fclose(fp);
-j=0;
- for(y0=yy-1;y0>=0;y0--){
- for(x0=0;x0<xx;x0++){
- i=y0*xx+x0;
- k=b0[j];j++; buf3[2][i]=k;
- k=b0[j];j++; buf3[1][i]=k;
- k=b0[j];j++; buf3[0][i]=k;
- }}
-free(b0);
-*x=xx;*y=yy;
-return(0);
-}
-
- if(bits==4){
-b0=malloc(xx*yy/2);
-k=ofbits -54;
-k/=4;
-fread(pbuf,1,k*4,fp);
-fread(b0,1,xx*yy/2,fp);
-fclose(fp);
-
-j=0;
-for(y0=yy-1;y0>=0;y0--){
-for(x0=0;x0<xx;x0++){i=y0*xx+x0;
-if(j&1) k=b0[j/2]&0x0f;
- else k=b0[j/2]>>4;
-j++;
-
-
-buf3[0][i]=pbuf[ k*4+2 ];
-buf3[1][i]=pbuf[ k*4+1 ];
-buf3[2][i]=pbuf[ k*4+0 ];
-}}
-free(b0);
-*x=xx;*y=yy;
-return(0);
-
- }
-
-
-
-b0=malloc(xx*yy);
-//k=buf[46]+buf[47]*256;
-k=ofbits -54;
-fread(pbuf,1,k,fp);
-fread(b0,1,xx*yy,fp);
-fclose(fp);
-
-j=0;
-for(y0=yy-1;y0>=0;y0--){
-for(x0=0;x0<xx;x0++){i=y0*xx+x0;
-k=b0[j];j++;
-buf3[0][i]=pbuf[ k*4+2 ];
-buf3[1][i]=pbuf[ k*4+1 ];
-buf3[2][i]=pbuf[ k*4+0 ];
-}}
-free(b0);
-*x=xx;*y=yy;
-return(0);
-}
-
-
-void forcereg(i) int i;{
-int h,n,r,g,b;
-r=palr[i];
-g=palg[i];
-b=palb[i];
-
-h=RGB2H(r,g,b);
-n=hashn[h];
-hashtab[h][n][0]=i;
-hashtab[h][n][1]=r;
-hashtab[h][n][2]=g;
-hashtab[h][n][3]=b;
-n++;
-hashn[h]=n;
-}
-
-void reg_rgb(int i, int r, int g, int b)
-{
-int h,n;
-
-h=RGB2H(r,g,b);
-n=hashn[h];
-hashtab[h][n][0]=i;
-hashtab[h][n][1]=r;
-hashtab[h][n][2]=g;
-hashtab[h][n][3]=b;
-n++;
-hashn[h]=n;
-}
-
-int cidx(r,g,b) int r,g,b;{
-int r2,r2min,i,h,n,ix,dr,dg,db;
-
- ix = -1;
- if(hashflag){
- h=RGB2H(r,g,b);
- n=hashn[h];
- for(i=0;i<n;i++)
- {
- if( (r==hashtab[h][i][1])&&(g==hashtab[h][i][2])&&(b==hashtab[h][i][3]) )
- {
- ix=hashtab[h][i][0];
- break;
- }
- }
- }
-
- if(ix==-1){
- r2min=100000000;
- for(i=0;i<256;i++)
- {
- dr=palr[i]-r;
- dg=palg[i]-g;
- db=palb[i]-b;
- r2=(dr*dr+dg*dg+db*db);
- //r2+=(dr+dg+db)*(dr+dg+db);
- if(r2<r2min){ ix=i;r2min=r2;}
- }
-
- if(hashflag==1){
- fprintf(stderr,"Color %02x%02x%02xapproximated\n",r,g,b);
-
- hashtab[h][n][0]=ix;
- hashtab[h][n][1]=r;
- hashtab[h][n][2]=g;
- hashtab[h][n][3]=b;
- n++;
- hashn[h]=n;
- if(n==HASHMAX)
- {
- fprintf(stderr,"HASHMAX exceed! Turning hash off\n");
- hashflag=0;
- }
- }
- }
-return(ix);
-}
-
-void put4(i,fp) int i;FILE *fp;{
-fputc( ((i>> 0)&0xff) ,fp);
-fputc( ((i>> 8)&0xff) ,fp);
-fputc( ((i>>16)&0xff) ,fp);
-fputc( ((i>>24)&0xff) ,fp);
-}
-
-void put2(i,fp) int i;FILE *fp;{
-fputc( ((i>> 0)&0xff) ,fp);
-fputc( ((i>> 8)&0xff) ,fp); }
-
-void bmwrite(char *fn, int x, int y, unsigned char *buf3[3])
-{
-FILE *fp;
-int i,j,k,xx,yy;
-
-hashflag=1;
-if(fn[0]==0) fp=stdout; else fp=fopen(fn,"wb");
-if (!fp)
-{
- printf("Error opening %s.\n", fn);
- exit(-1);
-}
-fputc('B',fp);fputc('M',fp);
-put4(1024+54+x*y,fp);
-put4(0,fp);
-put4(0x436,fp);
-put4(0x28,fp);
-put4(x,fp); put4(y,fp);
-put2(1,fp);put2(8,fp);
-put4(0,fp);put4(x*y,fp);put4(0xb6d,fp);put4(0xb6d,fp);
-put4(256,fp);put4(256,fp);
-fwrite(pbuf,1,1024,fp);
-for(yy=y-1;yy>=0;yy--){
-for(xx=0;xx<x;xx++){i=yy*x+xx;
-k=cidx( buf3[0][i],buf3[1][i],buf3[2][i] );fputc(k,fp);}}
-fclose(fp);}
-
-void bmwrite24(char *fn, int x, int y, unsigned char *buf3[3])
-{
-FILE *fp;
-int i,xx,yy;
-
-if(fn[0]==0) fp=stdout; else fp=fopen(fn,"wb");
-
-fputc('B',fp);fputc('M',fp);
-put4(54+3*x*y,fp);
-put4(0,fp);
-put4(54,fp);
-put4(0x28,fp);
-put4(x,fp); put4(y,fp);
-put2(1,fp);put2(24,fp);
-put4(0,fp);put4(x*y*3,fp);put4(0xb6d,fp);put4(0xb6d,fp);
-put4(0,fp);put4(0,fp);
-for(yy=y-1;yy>=0;yy--){
-for(xx=0;xx<x;xx++){i=yy*x+xx;
-fputc(buf3[2][i],fp);
-fputc(buf3[1][i],fp);
-fputc(buf3[0][i],fp);
-}}
-fclose(fp);}
-
-
-void bmwrite_dither(char *fn, int x, int y, unsigned char *buf3[3],
- unsigned char *flag)
-{
- FILE *fp;
- int i,j,k,xx,yy;
- int *err_c[3], *err_n[3];
- unsigned char *buf;
- int dx,idat[3],udat[3],putdat[3],err[3];
-
- fprintf(stderr,"Saving %s x=%d y=%d\n",fn,x,y);
-
- for(i=0;i<3;i++){
- err_c[i]=malloc(sizeof(int)*(x+2));
- err_n[i]=malloc(sizeof(int)*(x+2));
- for(j=0;j<x+2;j++)err_c[i][j]=err_n[i][j]=0;
- }
- buf=malloc(x*y);
-
-for(yy=0;yy<y;yy++){
-//fprintf(stderr,"Y=%d x=%d\n",yy,x);
-
- for(i=0;i<3;i++){
- for(j=0;j<x+2;j++){err_c[i][j]=err_n[i][j];err_n[i][j]=0;}}
-
-
-if((yy&1)==0){//even
-
-for(xx=0;xx<x;xx++){
-int do_ep = 1;
-idat[0] = buf3[0][ xx+yy*x];
-idat[1] = buf3[1][ xx+yy*x];
-idat[2] = buf3[2][ xx+yy*x];
-for(i=0;i<3;i++) {idat[i] += err_c[i][xx+1];
-udat[i]=idat[i];if(udat[i]<0)udat[i]=0;
-if(udat[i]>255)udat[i]=255;}
-
-if(buf3[0][xx+yy*x]==0x47 && buf3[1][xx+yy*x]==0x6c && buf3[2][xx+yy*x]==0x6c)
- do_ep=0;
-if (flag!=NULL)
-{
- if (flag[xx+yy*x]==0) do_ep=0;
-}
-if (do_ep == 0)
-k=cidx( buf3[0][xx+yy*x],buf3[1][xx+yy*x],buf3[2][xx+yy*x]);
-else
-k=cidx( udat[0],udat[1],udat[2]);
-
-buf[xx+yy*x]=k;
-//fprintf(stderr,"Y=%d xx=%d\n",yy,xx);
-
-putdat[0]=palr[k];
-putdat[1]=palg[k];
-putdat[2]=palb[k];
-for(i=0;i<3;i++) {
- err[i]=(idat[i]-putdat[i]+8)/16;
- //if(flag[xx+yy*x]!=1)err[i]=0;
- err_c[i][xx+1+1] += err[i]*7;
- err_n[i][xx-1+1] += err[i]*3;
- err_n[i][xx+0+1] += err[i]*5;
- err_n[i][xx+1+1] += err[i];
-}/**i**/
-}/**x**/
-}else{
-for(xx=x-1;xx>=0;xx--){
-int do_ep=1;
-idat[0] = buf3[0][ xx+yy*x];
-idat[1] = buf3[1][ xx+yy*x];
-idat[2] = buf3[2][ xx+yy*x];
-for(i=0;i<3;i++) {idat[i] += err_c[i][xx+1];
-udat[i]=idat[i];if(udat[i]<0)udat[i]=0;
-if(udat[i]>255)udat[i]=255;}
-
-if(buf3[0][xx+yy*x]==0x47 && buf3[1][xx+yy*x]==0x6c && buf3[2][xx+yy*x]==0x6c)
- do_ep=0;
-if (flag!=NULL)
-{
- if (flag[xx+yy*x]==0) do_ep=0;
-}
-if (do_ep == 0)
-k=cidx( buf3[0][xx+yy*x],buf3[1][xx+yy*x],buf3[2][xx+yy*x]);
-else
-k=cidx( udat[0],udat[1],udat[2]);
-
-buf[xx+yy*x]=(unsigned char)k;
-putdat[0]=palr[k];
-putdat[1]=palg[k];
-putdat[2]=palb[k];
-for(i=0;i<3;i++) {
- err[i]=(idat[i]-putdat[i]+8)/16;
- //if(flag[xx+yy*x]!=1)err[i]=0;
-
- err_c[i][xx-1+1] += err[i]*7;
- err_n[i][xx+1+1] += err[i]*3;
- err_n[i][xx+0+1] += err[i]*5;
- err_n[i][xx-1+1] += err[i];
-}/*i*/
-}/*x*/
-
-}/*else*/
-}/*y*/
-
-for(i=0;i<3;i++){
-free(err_c[i]);
-free(err_n[i]);}
-
-if(fn[0]==0) fp=stdout; else fp=fopen(fn,"wb");
-fputc('B',fp);fputc('M',fp);
-put4(1024+54+x*y,fp);
-put4(0,fp);
-put4(0x436,fp);
-put4(0x28,fp);
-put4(x,fp);put4(y,fp);
-put2(1,fp);put2(8,fp);
-put4(0,fp);put4(x*y,fp);put4(0xb6d,fp);put4(0xb6d,fp);
-put4(256,fp);put4(256,fp);
-fwrite(pbuf,1,1024,fp);
-for(yy=y-1;yy>=0;yy--){
-for(xx=0;xx<x;xx++){i=yy*x+xx; fputc(buf[i],fp);}}
-fclose(fp);
-free(buf);
-
-}/** exit**/
-
-
-void myfget(ss,fp) char *ss;FILE *fp;{
-#define STRMAX 200
-/****
-int ix=1;
-while(1){ ss[0]=getc(fp);
- if( ((ss[0]!=32)&&(ss[0]!='#'))||(feof(fp)))break;
- if(ss[0]=='#') fgets(ss,99,fp);}
-
-while(1){
- ss[ix]=getc(fp);ix++;
- if( (ss[ix-1]<33)||(ix==STRMAX)||(feof(fp)) )break;}
-ss[ix-1]=0;printf("%s\n",ss);
-****/
-int l;
-while(1){
- fgets(ss,STRMAX,fp);
- if(feof(fp)){fprintf(stderr,"FILE EOF\n");return;}
- if(ss[0]=='#')continue;
- if(ss[0]<32)continue;
- break;
-}
- l=strlen(ss);ss[l-1]=0;
-}
-
-void oldcolors()
-{
-int coldat[] = {
- // Old gold
- 0xE6, 0x68541f,
- 0xE7, 0x807020,
- 0xE8, 0xaa8834,
- 0xEA, 0xf2c44d,
- 0xEC, 0xfcfc99,
-
- 0xe6, 0x604818,
- 0xe7, 0x806020,
- 0xe8, 0xa07828,
- 0xe9, 0xc09030,
- 0xea, 0xe0a838,
- 0xeb, 0xffc040,
- //Old zombie
- 0xee, 0x756958,
- 0xef, 0x91876e,
- 0xf0, 0xab9a81,
- //Old brass
- 0xf1, 0xe0c0a0,
- 0xe9, 0xd0a850
- -1, -1
-};
-
- int i=0;
-
- while(coldat[i]!= -1)
- {
- int ix = coldat[i+0];
- int col= coldat[i+1];
- int r= col>>16;
- int g= (col>>8)&0xff;
- int b= (col)&0xff;
-
- reg_rgb( ix,r,g,b);
- palr[ix]=r;
- palg[ix]=g;
- palb[ix]=b;
- i+=2;
- }
-}
-
-void stdpal(){
-int i;
-
- for(i=0;i<256;i++){
- palr[i]=pbuf[i*4+2];
- palg[i]=pbuf[i*4+1];
- palb[i]=pbuf[i*4+0];
- }
- for(i=0;i<NHASH;i++)hashn[i]=0;
- for(i=0;i<256;i++)forcereg(i);
-
- oldcolors();
-}
-
-
-int getval(char *buf, char *tag, int *val)
-{
- int len = strlen(tag);
- if(buf[0]!='%') return 0;
- if (strncmp(&buf[1], tag, len)!=0) return 0;
- *val = atoi(&buf[len+2]);
- return 1;
-}
-
-int getname(char *buf, char *tag, char *name)
-{
- int len = strlen(tag);
- if(buf[0]!='%') return 0;
- if (strncmp(&buf[1], tag, len)!=0) return 0;
- strcpy(name, &buf[len+2]);
- return 1;
-}
-
diff --git a/crawl-ref/source/rltiles/tool/bm.h b/crawl-ref/source/rltiles/tool/bm.h deleted file mode 100644 index 8197dd5d4f..0000000000 --- a/crawl-ref/source/rltiles/tool/bm.h +++ /dev/null @@ -1,26 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -extern int bmread(char *fn, int *x, int *y, unsigned char *buf3[3]); -extern void fixalloc(char *buf[3], int size); -extern void bmwrite(char *fn, int x, int y, unsigned char *buf3[3]); -extern void bmwrite24(char *fn, int x, int y, unsigned char *buf3[3]); -extern void bmwrite_dither(char *fn, int x, int y, unsigned char *buf3[3], - unsigned char *flag); -extern void stdpal(); -extern void myfget(char *ss, FILE *fp); -extern int getval(char *buf, char *tag, int *val); -extern int getname(char *buf, char *tag, char *name); -extern void process_cpath(char *path); -extern void newgold(); - - -/*** PATH to this program ***/ -extern char cpath[1024]; -#if defined(_WIN32)|| defined(WINDOWS) -#define PATHSEP '\\' -#else -#define PATHSEP '/' -#endif - diff --git a/crawl-ref/source/rltiles/tool/dcpl.c b/crawl-ref/source/rltiles/tool/dcpl.c deleted file mode 100644 index 8ebdf779d3..0000000000 --- a/crawl-ref/source/rltiles/tool/dcpl.c +++ /dev/null @@ -1,585 +0,0 @@ -#include "bm.h" - -/** Some global **/ -//Flags -int corpse, mesh, slant,rim; -// Files -FILE *mfp,*sfp; -//Strings -char outname[1024], subsname[200], sdir[200]; -char realname[1024]; - -/** Parts related **/ -int parts_n; -#define MAXPARTS 20 -int parts_nx[MAXPARTS], parts_ny[MAXPARTS]; -int parts_ox[MAXPARTS], parts_oy[MAXPARTS]; -int parts_start[MAXPARTS], parts_number[MAXPARTS]; - -char parts_names[MAXPARTS][64]; - -int parts_comment_ofs[MAXPARTS]; -int n_comments, pos_comment; -#define MAXTOTAL 1000 -int part_comment_ofs[MAXTOTAL]; -char comment[MAXTOTAL*60]; - -int part_x,part_y; -int part_n; -int part_nx,part_ny; -char part_name[32]; -int part_wx, part_wy, part_ox, part_oy; - -/*** BUFFER MEMORY ***/ -#define XX 30 -int xx0; -#define LX (XX) - - -/*** tmp buffer, floor , final output, final queue ***/ -unsigned char *tbuf[3],*fbuf[3],*dbuf[3], *obuf[3]; - -/*** normal floor*/ -#define WOADR(x,y,xx,yy) \ -((x)*32+xx+ xx0*32*((y)*32+yy)) - -#define ADR(x,y) ((x)+(y)*32) - -/*** output width/height in block ***/ -int bx,by; - -/****************************/ -/* Wrapper routines ********/ -/**************************/ -int load_pxxx(fnam) - char *fnam; -{ - int x,y; - - sprintf(realname,"%s%s%c%s.bmp",cpath,sdir,PATHSEP,fnam); - if(bmread(realname,&x,&y,tbuf)==0) return 0; - - sprintf(realname,"%s%s.bmp",cpath,fnam); - if(bmread(realname,&x,&y,tbuf)==0) return 0; - - if(subsname[0]) - { - sprintf(realname,"%s%s%c%s.bmp",cpath,sdir,PATHSEP,subsname); - if(bmread(realname,&x,&y,tbuf)==0) return 0; - - sprintf(realname,"%s%s.bmp",cpath,subsname); - if(bmread(realname,&x,&y,tbuf)==0) return 0; - } - - return 1; -} - - -void clr_buf() -{ -int xx,yy; - - for(xx=0;xx<32;xx++) - { - for(yy=0;yy<32;yy++) - { - dbuf[0][ ADR(xx,yy) ]=0x47; - dbuf[1][ ADR(xx,yy) ]=0x6c; - dbuf[2][ ADR(xx,yy) ]=0x6c; - } - } -} - -void cp_floor() -{ - int xx,yy,c; - for(xx=0;xx<32;xx++) - for(yy=0;yy<32;yy++) - for(c=0;c<3;c++) - dbuf[c][ ADR(xx,yy) ]=fbuf[c][ ADR(xx,yy)]; -} - -void cp_monst_32() -{ - int xx,yy,c,dd[3],ad; - char dflag[33][32]; - int xmin,xmax,ymin,ymax,ox,oy; - - if(corpse==1 ) - { - xmin=ymin=31; - xmax=ymax=0; - for(xx=0;xx<32;xx++){ - for(yy=0;yy<32;yy++){ - ad=ADR(xx,yy); - for(c=0;c<3;c++)dd[c]=tbuf[c][ad]; - if( (dd[0]==0x47)&&(dd[1]==0x6c)&& (dd[2]==0x6c))continue; - if( (dd[0]==0)&&(dd[1]==0)&& (dd[2]==0))continue; - if(xx<xmin)xmin=xx; - if(xx>xmax)xmax=xx; - if(yy<ymin)ymin=yy; - if(yy>ymax)ymax=yy; - } - } - ox=(xmax+xmin)/2-16; - oy=(ymax+ymin)/2-16; - } - - /** copy loop **/ - for(xx=0;xx<32;xx++){ - for(yy=0;yy<32;yy++){ - dflag[xx][yy]=0; - ad=ADR(xx,yy); - - if(corpse==1) - { - int x1=xx+ox; - int y1=(yy+oy)*2-16; - int cy=18; - if(xx<4 || xx>=28)cy+=2;else - if(xx<12 || xx>=20) cy+=1; - - if(yy>=cy-1 && yy<=cy+0)continue; - x1 += (y1-16)/4; - if(y1>=cy){y1-=2;x1-=3;}else {y1 +=2;x1+=3;} - if(x1<0 || x1>=32 || y1<0 || y1>=32)continue; - ad=ADR(x1,y1); - } - - /*** normal***/ - for(c=0;c<3;c++){dd[c]=tbuf[c][ad];} - - if(mesh==2) - { - if( (dd[0]!=0x47)||(dd[1]!=0x6c)|| (dd[2]!=0x6c)) - { - if( ((xx+yy)&1) ==0)dd[0]=dd[1]=dd[2]=0; - } - } - if(mesh==1) - { - if((((xx/2)+(yy/2))&1) ==1)dd[0]=dd[1]=dd[2]=0; - } - - if( (dd[0]==0x47)&&(dd[1]==0x6c)&& (dd[2]==0x6c))continue; - if( (corpse==1) &&(dd[0]==0)&&(dd[1]==0)&& (dd[2]==0))continue; - - for(c=0;c<3;c++) {dbuf[c][ADR(xx,yy)]=dd[c];} - dflag[xx][yy]=1; - } - }/*XY*/ - -#if 1 - if(corpse==1) - { - for(xx=0;xx<32;xx++) - { - int cy=18; - if(xx<4 || xx>=28)cy+=2;else - if(xx<12 || xx>=20) cy+=1; - if(dflag[xx][cy-2]==1 && dflag[xx][cy+1]==1 ) - { - for(yy=cy-1;yy<=cy-0;yy++) - { - dbuf[0][ADR(xx,yy)]=32; - dbuf[1][ADR(xx,yy)]=0; - dbuf[2][ADR(xx,yy)]=0; - dflag[xx][yy]=1; - } - } - } - - /** shade**/ - for(xx=1;xx<32;xx++){ - for(yy=1;yy<32;yy++){ - if(dflag[xx][yy]==0 && dflag[xx-1][yy-1]==1) - { - dbuf[0][ADR(xx,yy)]=0; - dbuf[1][ADR(xx,yy)]=0; - dbuf[2][ADR(xx,yy)]=0; - } - } - } - - for(xx=3;xx<32;xx++){ - for(yy=3;yy<32;yy++){ - if(dflag[xx][yy]==0 && dflag[xx-1][yy-1]==0 - && dflag[xx-2][yy-2]==1 && dflag[xx-3][yy-3]==1) - { - dbuf[0][ADR(xx,yy)]=0; - dbuf[1][ADR(xx,yy)]=0; - dbuf[2][ADR(xx,yy)]=0; - } - } - } - - } -#endif -} - - -void bflush() -{ - int xx,yy,c; - for(xx=part_ox;xx<part_ox+part_wx;xx++){ - for(yy=part_oy;yy<part_oy+part_wy;yy++){ - for(c=0;c<3;c++){ - obuf[c][WOADR(bx,by,part_x*part_wx+xx-part_ox,part_y*part_wy+yy-part_oy)] - = dbuf[c][ADR(xx,yy)]; - } - } - } -} - - -void load_monst(fnam) char *fnam;{ - if( load_pxxx(fnam)){ - printf("no file %s.bmp\n",fnam); - getchar(); - exit(1); - } - cp_monst_32(); - bflush(); -} - -void flush_part() -{ - - if(part_x!=0 || part_y!=0) - { - part_x=part_y=0; - bx++;if(bx==xx0){bx=0;by++;;} - } - parts_number[parts_n]=part_n; - parts_n++; - -} - -void process_config(char *fname) -{ - int i,j; - char tmp[100],st[1024]; - char *nuke; - FILE *fp=fopen(fname,"r"); - if(fp==NULL) - { - printf("Error no config file %s\nHit return",fname); - getchar(); - exit(1); - } - - - while(1){ - fgets(tmp,99,fp); - if(feof(fp))break; - i=0; - while(i<99 && tmp[i]>=32) i++; - tmp[i]=0; - - if(getname(tmp,"back",st)) - { - /*** Set Background BMP (format "%back bmpname") ***/ - if(strncmp(st,"none",4)==0) - { - /** clear **/ - for(i=0;i<32*32;i++){fbuf[0][i]=0x47;fbuf[1][i]=fbuf[2][i]=0x6c;} - } - else - { - load_pxxx(st); - for(i=0;i<32*32;i++)for(j=0;j<3;j++)fbuf[j][i]=tbuf[j][i]; - } - continue; - } - - if (getname(tmp,"include",st)){ - char fn2[200]; - sprintf(fn2,"%s%s",cpath, st); - if(strcmp(fname,fn2)!=0) process_config(fn2); - continue; - } - - if (getval(tmp,"slant",&slant)) continue; - if (getval(tmp,"rim",&rim)) continue; - if (getval(tmp,"mesh",&mesh)) continue; - if (getval(tmp,"corpse",&corpse)) continue; - if (getname(tmp,"subst",subsname)) continue; - if (getname(tmp,"sdir",sdir)) continue; - if (getname(tmp,"name", outname)) continue; - if (getval(tmp,"width",&xx0)) continue; - /****/ - if (getname(tmp,"parts_ctg",part_name)) - { - if(part_n!=0) - flush_part(); - part_n=0; - strcpy(parts_names[parts_n],part_name); - parts_comment_ofs[parts_n] = n_comments; - parts_start[parts_n]=bx+by*xx0; - fprintf(sfp,"#define TILEP_PART_%s %d\n",part_name, parts_n); - fprintf(sfp,"enum %s {\n",part_name); - fprintf(sfp," TILEP_%s_000,\n",part_name); - - continue; - } - - if (getval(tmp,"parts_wx",&part_wx)) - { - parts_nx[parts_n]=part_nx=32/part_wx; - continue; - } - - if (getval(tmp,"parts_wy",&part_wy)) - { - parts_ny[parts_n]=part_ny=32/part_wy; - continue; - } - - if (getval(tmp,"parts_ox", &part_ox)) - { - parts_ox[parts_n]=part_ox; - continue; - } - - if (getval(tmp,"parts_oy", &part_oy)) - { - parts_oy[parts_n]=part_oy; - continue; - } - - /****/ - if (tmp[0]=='#' || tmp[0]<32){ - if(tmp[0]=='#') fprintf(sfp,"//%s\n",tmp); - continue; - } - - if (strcmp(tmp, "%end") == 0) - { - fprintf(sfp," N_PART_%s};\n\n",part_name); - continue; - } - /*** normal bitmap ***/ -#define WID 32 - clr_buf(); - cp_floor(); - - i=0; - while(i<99 && tmp[i]>32)i++; - tmp[i]=0; strcpy(st, &tmp[i+1]); - load_monst(tmp); - - fprintf(mfp, - "<area shape=\"rect\" coords=\"%d,%d,%d,%d\" alt=\"%s\" href=%s>\n", - bx*WID + part_x*part_wx, - by*WID + part_y*part_wy, - bx*WID + part_x*part_wx + part_wx-1, - by*WID + part_y*part_wy + part_wy-1, - st, realname); - - if(!strstr(st,"IGNORE_COMMENT")){ - nuke=strstr(st,"/*");if(nuke)*nuke=0; - if (st && strcmp(st,"") != 0 && strcmp(st, "\n") != 0) - { - fprintf(sfp," TILEP_%s_%s,\n", part_name, st); - i=strlen(st); - strncpy(&comment[pos_comment],st,i); - } - else - { - fprintf(sfp," FILLER_%s_%d,\n", part_name, part_n); - parts_names[i][0] = 0; - i = 1; - strncpy(&comment[pos_comment],"\0",i); - } - - part_comment_ofs[n_comments]=pos_comment; - pos_comment += i; - n_comments++; - - // n_comments = pos_comment=0; - //int parts_comment_ofs[]; - //int part_comment_ofs[MAXTOTAL]; - //char comment[MAXTOTAL*60]; - } - else - { - i=0; - part_comment_ofs[n_comments]=pos_comment; - pos_comment += i; - n_comments++; - } - - part_n++; - part_x++; - if(part_x==part_nx) - { - part_x=0; - part_y++; - if(part_y==part_ny) - { - part_y=0; - bx++; - if(bx==xx0) - { - bx=0; - by++; - } - } - } - - /* normal */ - - }/* while */ - fclose(fp); -} - -/********************************************/ - -int main(int argc, char **argv) -{ - - int i,j,k,l,m,n,fl; - char fn[100],st2[100]; - - slant=corpse=mesh=rim=0; - - bx=by=0; - - /* parts related */ - parts_n=0; - - part_x=part_y=0; - part_n=0; - part_wx=part_wy=32; - part_ox=part_oy=0; - - /* comments */ - n_comments = pos_comment=0; - //int parts_comment_ofs[]; - //int part_comment_ofs[MAXTOTAL]; - //char comment[MAXTOTAL*60]; - - - process_cpath(argv[0]); - - xx0=XX; - subsname[0]=0; - sdir[0]=0; - realname[0]=0; - - stdpal(); - fixalloc(tbuf,64*64); - fixalloc(dbuf,64*64); - fixalloc(fbuf,64*64); - fixalloc(obuf, 32*64*(64)*64); - - - strcpy(outname,"tile"); - - sprintf(fn,"%smap.htm",cpath); - mfp=fopen(fn,"w"); - if(mfp==NULL){ - printf("Error could not open %s\nHit return",fn); - getchar(); - exit(1); - } - - sprintf(fn,"%stiledef-p.h",cpath); - sfp=fopen(fn,"w"); - if(sfp==NULL){ - printf("Error could not open %s\nHit return",fn); - getchar(); - exit(1); - } - fprintf(sfp,"/* Automatically generated by tile generator. */\n"); - - fprintf(mfp,"<HTML>\n"); - fprintf(mfp,"<MAP NAME=\"nhmap\">\n"); - - printf("%s\ncpath=%s\n",argv[0],cpath); - if(argc==1) - sprintf(fn,"%sdc-pl.txt",cpath); - else - strcpy(fn,argv[1]); - process_config(fn); - - if(part_n!=0)flush_part(); - - fprintf(sfp,"\n#define TILEP_TOTAL %d\n",bx+by*xx0); - fprintf(sfp,"#define TILEP_PER_ROW %d\n\n",xx0); - - fprintf(sfp,"#define TILEP_PARTS_TOTAL %d\n\n",parts_n); - - fprintf(sfp,"const int tilep_parts_start[TILEP_PARTS_TOTAL]=\n {"); - for(i=0;i<parts_n-1;i++)fprintf(sfp," %d,",parts_start[i]); - fprintf(sfp," %d};\n",parts_start[parts_n-1]); - - fprintf(sfp,"const int tilep_parts_total[TILEP_PARTS_TOTAL]=\n {"); - for(i=0;i<parts_n-1;i++)fprintf(sfp," %d,",parts_number[i]); - fprintf(sfp," %d};\n",parts_number[parts_n-1]); - - fprintf(sfp,"const int tilep_parts_ox[TILEP_PARTS_TOTAL]=\n {"); - for(i=0;i<parts_n-1;i++)fprintf(sfp," %d,",parts_ox[i]); - fprintf(sfp," %d};\n",parts_ox[parts_n-1]); - - fprintf(sfp,"const int tilep_parts_oy[TILEP_PARTS_TOTAL]=\n {"); - for(i=0;i<parts_n-1;i++)fprintf(sfp," %d,",parts_oy[i]); - fprintf(sfp," %d};\n",parts_oy[parts_n-1]); - - fprintf(sfp,"const int tilep_parts_nx[TILEP_PARTS_TOTAL]=\n {"); - for(i=0;i<parts_n-1;i++)fprintf(sfp," %d,",parts_nx[i]); - fprintf(sfp," %d};\n",parts_nx[parts_n-1]); - - fprintf(sfp,"const int tilep_parts_ny[TILEP_PARTS_TOTAL]=\n {"); - for(i=0;i<parts_n-1;i++)fprintf(sfp," %d,",parts_ny[i]); - fprintf(sfp," %d};\n",parts_ny[parts_n-1]); - - fclose(sfp); - - sprintf(fn,"%stilep-cmt.h",cpath); - sfp=fopen(fn,"w"); - if(sfp==NULL){ - printf("Error could not open %s\nHit return",fn); - getchar(); - exit(1); - } - fprintf(sfp,"/* Automatically generated by tile generator. */\n"); - fprintf(sfp,"#include \"tiledef-p.h\"\n"); - - fprintf(sfp,"static const char *tilep_parts_name[%d]={\n",parts_n); - for(i=0;i<parts_n-1;i++) - { - fprintf(sfp," \"%s\",\n",parts_names[i]); - } - i=parts_n-1; - fprintf(sfp," \"%s\"\n};\n",parts_names[i]); - - - fprintf(sfp,"const int tilep_comment_ofs[TILEP_PARTS_TOTAL]= {\n"); - for(i=0;i<parts_n-1;i++)fprintf(sfp," %d,",parts_comment_ofs[i]); - fprintf(sfp," %d};\n",parts_comment_ofs[parts_n-1]); - - fprintf(sfp,"static const char *tilep_comment[%d]={\n",n_comments); - for(i=0;i<n_comments-1;i++) - { - int len=part_comment_ofs[i+1]-part_comment_ofs[i]; - strncpy(st2, &comment[part_comment_ofs[i]],len); - st2[len]=0; - fprintf(sfp," \"%s\",\n",st2); - } - i=pos_comment-part_comment_ofs[n_comments-1]; - strncpy(st2, &comment[part_comment_ofs[n_comments-1]],i); - st2[i]=0; - fprintf(sfp," \"%s\" };\n",st2); - fclose(sfp); - - fprintf(mfp,"<IMG SRC=%s.bmp USEMAP=\"#nhmap\" >\n", outname); - - - fclose(mfp); - i=by*32;if(bx!=0)i+=32; - - sprintf(fn,"%s%s.bmp",cpath,outname); - bmwrite(fn,xx0*32,i,obuf); - -} diff --git a/crawl-ref/source/rltiles/tool/dcqv.c b/crawl-ref/source/rltiles/tool/dcqv.c deleted file mode 100644 index 88fe9cbbc1..0000000000 --- a/crawl-ref/source/rltiles/tool/dcqv.c +++ /dev/null @@ -1,847 +0,0 @@ -#include "bm.h" - -/** Some global **/ -int corpse=0, mesh =0,slant=0; -int rim=0; -int exp_wall; -int dsize; -int sx32 = 16; -int sy32 = 24; -int end_normal = 0; - -FILE *mfp,*sfp; -char outname[1024], ctgname[100], subsname[100]; -char sdir[300]; - - -/*** BUFFER MEMORY ***/ -#define XX 16 -int xx0; -#define YY 30 -#define LX (XX) - -/*** tmp buffer, floor , final output, final queue ***/ -unsigned char *tbuf[3],fbuf[3][128*64], - *obuf[3],dbuf[3][128*64]; - - -unsigned char wallbuf[4][3][32*48]; -unsigned char wall2buf[3][128*64]; - - -int f_wx; - -/*** normal floor*/ -#define WOADR(x,y,xx,yy) \ -((x)*64+xx+ xx0*64*((y)*64+yy)) - - -#define ADR32(x,y) ((x)+(y)*32) -#define ADR64(x,y) ((x)+(y)*64) - - -/*** output width/height in block ***/ -int bx,by; - - -/**************************/ -/* Wrapper routines *******/ -/**************************/ - -int load_it(char *fnam, int *wx, int *wy) -{ - char fn[100]; - sprintf(fn,"%s%s%c%s.bmp",cpath,sdir,PATHSEP,fnam); - if(bmread(fn,wx,wy,tbuf)==0) return 0; - - sprintf(fn,"%s%s.bmp",cpath,fnam); - if(bmread(fn,wx,wy,tbuf)==0) return 0; - - if(subsname[0]){ - sprintf(fn,"%s%s%c%s.bmp",cpath,sdir,PATHSEP,subsname); - if(bmread(fn,wx,wy,tbuf)==0) return 0; - - sprintf(fn,"%s%s.bmp",cpath,subsname); - if(bmread(fn,wx,wy,tbuf)==0) return 0; - } - -return 1; -} - - -void clr_dbuf() { -int xx,yy; - -for(xx=0;xx<64;xx++){ -for(yy=0;yy<64;yy++){ -dbuf[0][ ADR64(xx,yy) ]=0x47; -dbuf[1][ ADR64(xx,yy) ]=0x6c; -dbuf[2][ ADR64(xx,yy) ]=0x6c; -}} -} - -#define TILEX 64 -#define TILEY 64 -void make_rim(){ -static unsigned char dflag[TILEX][TILEY]; -int x,y,c,dd[3],ad; -int n0,n1,n2; - -for(y=0;y<TILEY;y++){ -for(x=0;x<TILEX;x++){ - dflag[x][y]=1; - ad=x + y *TILEX; - for(c=0;c<3;c++)dd[c]=dbuf[c][ad]; - if( (dd[0]==0x47)&&(dd[1]==0x6c)&& (dd[2]==0x6c)) dflag[x][y]=0; - if( (dd[0]==0)&&(dd[1]==0)&& (dd[2]==0)) dflag[x][y]=2; -} -} - -for(x=0;x<TILEX;x++){ -for(y=0;y<TILEY;y++){ - ad=x+y*TILEX; -if(dflag[x][y]==2 || dflag[x][y]==0){ -n0=n1=n2=0; -if(x>0){ - if(dflag[x-1][y]==0) n0++; - if(dflag[x-1][y]==1) n1++; - if(dflag[x-1][y]==2) n2++; -} - -if(y>0){ - if(dflag[x][y-1]==0) n0++; - if(dflag[x][y-1]==1) n1++; - if(dflag[x][y-1]==2) n2++; -} - -if(x<TILEX-1){ - if(dflag[x+1][y]==0) n0++; - if(dflag[x+1][y]==1) n1++; - if(dflag[x+1][y]==2) n2++; -} -if(y<TILEY-1){ - if(dflag[x][y+1]==0) n0++; - if(dflag[x][y+1]==1) n1++; - if(dflag[x][y+1]==2) n2++; -} - -if(n1!=0 ) -dbuf[0][x+y*TILEX]=dbuf[1][x+y*TILEX]=dbuf[2][x+y*TILEX]=0x10; - - -}}} - -} - -void cp_floor_64(){ -int xx,yy,c; -for(xx=0;xx<64;xx++) -for(yy=0;yy<64;yy++) -for(c=0;c<3;c++) -dbuf[c][ ADR64(xx,yy) ]=fbuf[c][ ADR64(xx,yy)]; -} - -void cp_floor_32(){ -int xx,yy,c; -for(xx=0;xx<32;xx++) -for(yy=0;yy<32;yy++) -for(c=0;c<3;c++) -dbuf[c][ ADR64(32+xx-yy,32+(xx+yy)/2) ]=fbuf[c][ ADR32(xx,yy)]; -} - - -void cp_monst_32(){ -int xx,yy,c,dd[3],ad; -char dflag[32][32]; -int xmin,xmax,ymin,ymax; -int ox=0; -int oy=0; - -if(corpse==1 ){ - xmin=ymin=31; - xmax=ymax=0; - for(xx=0;xx<32;xx++){ - for(yy=0;yy<32;yy++){ - ad=ADR32(xx,yy); - for(c=0;c<3;c++)dd[c]=tbuf[c][ad]; - if( (dd[0]==0x47)&&(dd[1]==0x6c)&& (dd[2]==0x6c))continue; - if( (dd[0]==0)&&(dd[1]==0)&& (dd[2]==0))continue; - if(xx<xmin)xmin=xx; - if(xx>xmax)xmax=xx; - if(yy<ymin)ymin=yy; - if(yy>ymax)ymax=yy; - }}/*xy**/ - ox=(xmax+xmin)/2-16; - oy=(ymax+ymin)/2-16; -} - -if(slant==1){ - for(xx=0;xx<32;xx++){ - for(yy=0;yy<32;yy++){ - int x1 = xx-yy+32; - int y1= 32+(xx+yy)/2; - ad = ADR32(xx,yy); - for(c=0;c<3;c++){dd[c]=tbuf[c][ad];} - if(mesh==2){ - if( (dd[0]!=0x47)||(dd[1]!=0x6c)|| (dd[2]!=0x6c)){ - if( ((x1+y1)&1) ==0)dd[0]=dd[1]=dd[2]=0; - } - } - if(mesh==1){ - if( (((x1/2)+(y1/2))&1) ==1)dd[0]=dd[1]=dd[2]=0; - } - if( (dd[0]==0x47)&&(dd[1]==0x6c)&& (dd[2]==0x6c))continue; - for(c=0;c<3;c++) {dbuf[c][ADR64(x1,y1)]=dd[c];} - }} -return; -} - -if(dsize==1){ - for(xx=0;xx<32;xx++){ - for(yy=0;yy<32;yy++){ - int x1 = xx*2; - int y1= yy*2; - ad = ADR32(xx,yy); - for(c=0;c<3;c++){dd[c]=tbuf[c][ad];} - if(mesh==2){ - if( (dd[0]!=0x47)||(dd[1]!=0x6c)|| (dd[2]!=0x6c)){ - if( ((x1+y1)&1) ==0)dd[0]=dd[1]=dd[2]=0; - } - } - if(mesh==1){ - if( (((x1/2)+(y1/2))&1) ==1)dd[0]=dd[1]=dd[2]=0; - } - if( (dd[0]==0x47)&&(dd[1]==0x6c)&& (dd[2]==0x6c))continue; - for(c=0;c<3;c++) - { - dbuf[c][ADR64(x1,y1)]=dd[c]; - dbuf[c][ADR64(x1+1,y1)]=dd[c]; - dbuf[c][ADR64(x1,y1+1)]=dd[c]; - dbuf[c][ADR64(x1+1,y1+1)]=dd[c]; - } - }} -return; -} - - -for(xx=0;xx<32;xx++){ -for(yy=0;yy<32;yy++){ - dflag[xx][yy]=0; - ad=ADR32(xx,yy); - - if(corpse==1){ - int x1=xx+ox; - int y1=(yy+oy)*2-16; - int cy=18; - if(xx<4 || xx>=28)cy+=2;else - if(xx<12 || xx>=20) cy+=1; - - if(yy>=cy-1 && yy<=cy+0)continue; - x1 += (y1-16)/4; - if(y1>=cy){y1-=2;x1-=3;}else {y1 +=2;x1+=3;} - if(x1<0 || x1>=32 || y1<0 || y1>=32)continue; - ad=ADR32(x1,y1); - } - - /*** normal***/ - for(c=0;c<3;c++){dd[c]=tbuf[c][ad];} - if(mesh==2) - { - if( (dd[0]!=0x47)||(dd[1]!=0x6c)|| (dd[2]!=0x6c)) - { - if( ((xx+yy)&1) ==0)dd[0]=dd[1]=dd[2]=0; - } - } - else if(mesh==1) - { - if( (((xx/2)+(yy/2))&1) ==1)dd[0]=dd[1]=dd[2]=0; - } - - if( (dd[0]==0x47)&&(dd[1]==0x6c)&& (dd[2]==0x6c))continue; - if( (corpse==1) &&(dd[0]==0)&&(dd[1]==0)&& (dd[2]==0))continue; - - for(c=0;c<3;c++) {dbuf[c][ADR64(sx32+xx,sy32+yy)]=dd[c];} - dflag[xx][yy]=1; -}} - - -#if 1 -if(corpse==1){ -for(xx=0;xx<32;xx++){ -int cy=18; -if(xx<4 || xx>=28)cy+=2;else -if(xx<12 || xx>=20) cy+=1; -if(dflag[xx][cy-2]==1 && dflag[xx][cy+1]==1 ){ -for(yy=cy-1;yy<=cy-0;yy++){ dbuf[0][ADR64(16+xx,32+yy)]=32; -dbuf[1][ADR64(16+xx,32+yy)]=0;dbuf[2][ADR64(16+xx,32+yy)]=0; -dflag[xx][yy]=1; -}} -} - -/** shade**/ -for(xx=1;xx<32;xx++){ -for(yy=1;yy<32;yy++){ -if(dflag[xx][yy]==0 && dflag[xx-1][yy-1]==1){ -dbuf[0][ADR64(xx,yy)]=0; -dbuf[1][ADR64(xx,yy)]=0; -dbuf[2][ADR64(xx,yy)]=0; -} -}} - -for(xx=3;xx<32;xx++){ -for(yy=3;yy<32;yy++){ -if(dflag[xx][yy]==0 && dflag[xx-1][yy-1]==0 - && dflag[xx-2][yy-2]==1 && dflag[xx-3][yy-3]==1){ -dbuf[0][ADR64(xx,yy)]=0; -dbuf[1][ADR64(xx,yy)]=0; -dbuf[2][ADR64(xx,yy)]=0; -} -}} - -} -#endif -} - -void cp_monst_64(){ -int xx,yy,c,dd[3],ad; -int dflag[64][64]; - -for(xx=0;xx<64;xx++){ -for(yy=0;yy<64;yy++){ - dflag[xx][yy]=0; - ad=ADR64(xx,yy); - - if(corpse==1) - { - int y1=2*(yy-26); - int x1=32+(xx-32)*5/4+(y1-32)*3/4; - - y1 -= (xx-32)/3; - if(x1<0 || x1>=64 || y1<0 || y1>=64)continue; - ad=ADR64(x1,y1); - } - - /*** normal***/ - for(c=0;c<3;c++){dd[c]=tbuf[c][ad];} - - if( (corpse==1) &&(dd[0]==0)&&(dd[1]==0)&& (dd[2]==0))continue; - - if(mesh==2) - { - if( (dd[0]!=0x47)||(dd[1]!=0x6c)|| (dd[2]!=0x6c)) - if( ((xx+yy)&1) ==0)dd[0]=dd[1]=dd[2]=0; - } - - if(mesh==1) - if( (((xx/2)+(yy/2))&1) ==1)dd[0]=dd[1]=dd[2]=0; - - if( (dd[0]==0x47)&&(dd[1]==0x6c)&& (dd[2]==0x6c))continue; - - dflag[xx][yy]=1; - - for(c=0;c<3;c++) {dbuf[c][ADR64(xx,yy)]=dd[c];} -}} - -if (corpse == 1) -{ - for(yy=0;yy<64;yy++) - { - int thick=0; - for(xx=0;xx<64;xx++) - { - if(dflag[xx][yy]==1) - { - thick++; - if (thick>15) thick=15; - continue; - } - if (thick>0) - { - for(c=0;c<3;c++) {dbuf[c][ADR64(xx,yy)]=0;} - thick -= 3; - if (thick<0) thick=0; - } - } - } - - for(xx=0;xx<64;xx++) - { - int thick=0; - for(yy=0;yy<64;yy++) - { - if(dflag[xx][yy]==1) - { - thick++; - if (thick>15) thick=15; - continue; - } - if (thick>0) - { - for(c=0;c<3;c++) {dbuf[c][ADR64(xx,yy)]=0;} - thick -= 5; - if (thick<0) thick=0; - } - } - } - -} - - -} - - -void cp_monst_4864(){ -int xx,yy,c,dd[3],ad; -for(xx=0;xx<48;xx++){ -for(yy=0;yy<64;yy++){ - ad= xx+yy*48; - /*** normal***/ - for(c=0;c<3;c++){dd[c]=tbuf[c][ad];} - if(mesh==2) - { - if( (dd[0]!=0x47)||(dd[1]!=0x6c)|| (dd[2]!=0x6c)) - if( ((xx+yy)&1) ==0)dd[0]=dd[1]=dd[2]=0; - } - - if(mesh==1) - if( (((xx/2)+(yy/2))&1) ==1)dd[0]=dd[1]=dd[2]=0; - - if( (dd[0]==0x47)&&(dd[1]==0x6c)&& (dd[2]==0x6c))continue; - - for(c=0;c<3;c++) {dbuf[c][8+xx+yy*64]=dd[c];} -}} -} - -void bflush(){ -int xx,yy,c; -if(rim==1) make_rim(); - -for(xx=0;xx<64;xx++){ -for(yy=0;yy<64;yy++){ -for(c=0;c<3;c++){ -obuf[c][WOADR(bx,by,xx,yy)]= dbuf[c][ADR64(xx,yy)]; -}}} -} - - -void copy_wall(int wall_ix, int xofs, int yofs){ -int xx,yy,c; -unsigned char dd[3]; - for(xx=0;xx<64;xx++){ - for(yy=0;yy<64;yy++){ - int x=xx-xofs-16; - int y=yy-yofs-8; - int ad = x+y*32; - if(x<0 || y<0 || x>=32 || y>=48) continue; - for(c=0;c<3;c++){dd[c]=wallbuf[wall_ix][c][ad];} - if( (dd[0]==0x47)&&(dd[1]==0x6c)&& (dd[2]==0x6c))continue; - for(c=0;c<3;c++) {dbuf[c][ADR64(xx,yy)]=dd[c];} - }} -} - -void copy_wall_vert(int wall_ix, int xofs, int yofs){ -int xx,yy,c,ymax; -unsigned char dd[3]; - for(xx=0;xx<64;xx++){ - for(yy=0;yy<64;yy++){ - int x=xx-xofs-16; - int y=yy-yofs-8; - int ad = x+y*32; - if(x<0 || y<0 || x>=32 || y>=48) continue; - - ymax= 8+x/2; - if(ymax> 8+(31-x)/2) ymax=8+(31-x)/2; - if(y<ymax) continue; - - for(c=0;c<3;c++){dd[c]=wallbuf[wall_ix][c][ad];} - if( (dd[0]==0x47)&&(dd[1]==0x6c)&& (dd[2]==0x6c))continue; - - //Mesh -// if( ((x/2+y/2)&1) == 0) dd[0]=dd[1]=dd[2]=0; - - for(c=0;c<3;c++) {dbuf[c][ADR64(xx,yy)]=dd[c];} - }} -} - -void expand_wall(){ -//unsigned char wallbuf[4][3][32*48]; -int xx,yy,c,ix; -exp_wall=1; -for(ix=0;ix<4;ix++){ -for(xx=0;xx<32;xx++){ -for(yy=0;yy<48;yy++){ -wallbuf[ix][0][xx+yy*32]=0x47; -wallbuf[ix][1][xx+yy*32]=0x6c; -wallbuf[ix][2][xx+yy*32]=0x6c; -}}} - -//decompose wall bmp -for(xx=0;xx<32;xx++){ - int ymax= 8+xx/2; - if(ymax> 8+(31-xx)/2) ymax=8+(31-xx)/2; - for(yy=0;yy<ymax;yy++){ - ix=0; - if(2*yy+xx >=32)ix +=1; - if(2*yy-xx >=0 )ix +=2; - for(c=0;c<3;c++)wallbuf[ix][c][xx+yy*32]=tbuf[c][xx+yy*32]; - } - - for(yy=ymax;yy<48;yy++){ - if(xx<8) ix=2;else if(xx<24) ix=3; else ix=1; - for(c=0;c<3;c++)wallbuf[ix][c][xx+yy*32]=tbuf[c][xx+yy*32]; - } -}//xx - -/* - 0 -1 1 2 2 - 3 4 5 - 6 7 8 9 - A B C -4 D E 8 - F -*/ - -for(ix=0;ix<16;ix++){ - clr_dbuf(); - if(f_wx==32)cp_floor_32(); else cp_floor_64(); - - if((ix&3)==3) copy_wall(3,0,-16); - - if(ix&1) copy_wall(1,-16,-8); - if(ix&2) copy_wall(2,16,-8); - - if(ix&1) copy_wall(3,-16,-8); - copy_wall(0, 0,0); - if(ix&2) copy_wall(3,16,-8); - - if((ix&5)==5) {copy_wall(1,-32,0);copy_wall_vert(2,-16,0);} - copy_wall(2,0,0); - copy_wall(1,0,0); - if((ix&10)==10) {copy_wall(2,32,0);copy_wall_vert(1,16,0);} - - if(ix&4) {copy_wall(0,-16,8);copy_wall_vert(3,-16,0);} - copy_wall(3,0,0); - if(ix&8) {copy_wall(0,16,8);copy_wall_vert(3,16,0);} - - if(ix&4) {copy_wall(1,-16,8);copy_wall_vert(2,0,8);} - if(ix&8) {copy_wall(2,16,8); copy_wall_vert(1,0,8);} - if((ix&12)==12) {copy_wall(0,0,16);copy_wall_vert(3,0,8);} - - bflush(); - bx++;if(bx==xx0){bx=0;by++;} - }/*ix*/ -}
- -
-static void copy_wall2_h1(int ix, int xofs, int yofs){ -int xx,yy,c,ad; -
-unsigned char dd[3]; - for(xx=0;xx<64;xx++){ - for(yy=0;yy<64;yy++){ - int x=xx-xofs; - int y=yy-yofs;; - ad = x+64+y*128; - if (x<0 || y<0 || x>63 || y>63)continue;
- if(2*y>=x+32) continue;
- if(2*y>=95-x) continue;
- if((ix%3)==0) if (2*y>=47-x)continue;
- if((ix%3)==1) if ((2*y<47-x) || (2*y>=79-x))continue;
- if((ix%3)==2) if(2*y<79-x)continue;
-
- if((ix/3)==0) if(2*y>=x-16)continue;
- if((ix/3)==1) if((2*y<x-16) || (2*y>=x+16))continue;
- if((ix/3)==2) if(2*y<x+16) continue;
-
- for(c=0;c<3;c++){dd[c]=tbuf[c][ad];} - if( (dd[0]==0x47)&&(dd[1]==0x6c)&& (dd[2]==0x6c))continue; - - for(c=0;c<3;c++) {dbuf[c][ADR64(xx,yy)]=dd[c];} - }} -} -
-void copy_wall2_h2(int ix, int xofs, int yofs){ -int xx,yy,c,ad; -
-unsigned char dd[3]; - for(xx=0;xx<64;xx++){ - for(yy=0;yy<64;yy++){ - int x=xx-xofs; - int y=yy-yofs;; - ad = x+y*128; - if (x<0 || y<0 || x>63 || y>63)continue;
- if(2*y>=x+32) continue;
- if(2*y>=95-x) continue;
-
- if ((ix%2)==0)if (2*y>=63-x)continue;
- if((ix%2)==1) if (2*y<63-x)continue;
-
- if((ix/2)==0)if(2*y>=x)continue;
- if((ix/2)==1)if(2*y<x)continue;
-
-
- for(c=0;c<3;c++){dd[c]=tbuf[c][ad];} - if( (dd[0]==0x47)&&(dd[1]==0x6c)&& (dd[2]==0x6c))continue; - - for(c=0;c<3;c++) {dbuf[c][ADR64(xx,yy)]=dd[c];} - }} -}
-
-
-void copy_wall_v2(int ix, int kind, int xofs, int yofs){ -int xx,yy,c,ymax,ad; -unsigned char dd[3]; - for(xx=0;xx<64;xx++){ - for(yy=0;yy<64;yy++){ - int x=xx-xofs; - int y=yy-yofs; - ad = x+kind*64+y*128; - if(x<0 || y<0 || x>=64 || y>=64) continue; - - ymax= 16+x/2; - if(x>=32) ymax=16+(63-x)/2; - if(y<ymax) continue; - if(y>ymax+32)continue;
-
- if(ix==0) if(x>=8)continue;
- if(ix==1) if(x<8 || x>=24)continue;
- if(ix==2) if(x<24 || x>=40)continue;
- if(ix==3) if(x<40 || x>=56)continue;
- if(ix==4) if(x<56)continue;
- - for(c=0;c<3;c++){dd[c]=tbuf[c][ad];} - if( (dd[0]==0x47)&&(dd[1]==0x6c)&& (dd[2]==0x6c))continue; - for(c=0;c<3;c++) {dbuf[c][ADR64(xx,yy)]=dd[c];} - }} -}
-void expand_wall2(){
-//void copy_wall2_h(int kind, int ix, int xofs, int yofs) -int ix; -exp_wall=1; -
-for(ix=0;ix<16;ix++){ - clr_dbuf(); - if(f_wx==32)cp_floor_32(); else cp_floor_64(); -
-if((ix&3)==0) copy_wall2_h1(0, 0, 8);
-if((ix&3)==1) copy_wall2_h1(1, -16, 0);
-if((ix&3)==2) copy_wall2_h1(3, 16, 0);
-if((ix&3)==3) copy_wall2_h2(0, 0, 0);
-
-if((ix&5)==0) copy_wall2_h1(6, 16, 0);
-if((ix&5)==1) copy_wall2_h1(7, 0, -8);
-if((ix&5)==4) copy_wall2_h1(3, 0, 8);
-if((ix&5)==5) copy_wall2_h2(2, 0, 0);
-
-
-if((ix&10)==0) copy_wall2_h1(2, -16, 0);
-if((ix&10)==2) copy_wall2_h1(5, 0, -8);
-if((ix&10)==8) copy_wall2_h1(1, 0, 8);
-if((ix&10)==10) copy_wall2_h2(1, 0, 0);
-
-if((ix&12)==0) copy_wall2_h1(8, 0, -8);
-if((ix&12)==4) copy_wall2_h1(5, -16, 0);
-if((ix&12)==8) copy_wall2_h1(7, 16, 0);
-if((ix&12)==12) copy_wall2_h2(3, 0, 0); -
-
-if((ix&5)==5) copy_wall_v2(0, 0, 0, 0);
-if((ix&10)==10) copy_wall_v2(4, 0, 0, 0);
-
-if((ix&4)!=0) copy_wall_v2(1, 0, 0, 0);
-if((ix&8)!=0) copy_wall_v2(3, 0, 0, 0);
-
-
-if((ix&12)==12) copy_wall_v2(2, 0, 0, 0);
-
-if((ix&5)==1) copy_wall_v2(1, 1, 0, -8);
-if((ix&12)==8) copy_wall_v2(1, 1, 16, 0);
-
-if((ix&10)==2) copy_wall_v2(3, 1, 0, -8);
-if((ix&12)==4) copy_wall_v2(3, 1, -16, 0);
-
-if((ix&5)==0) copy_wall_v2(0, 1, 16, 0);
-if((ix&10)==0) copy_wall_v2(4, 1, -16, 0);
-if((ix&12)==0) copy_wall_v2(2, 1, 0, -8);
-
- bflush(); - bx++;if(bx==xx0){bx=0;by++;} -} -} - - -void load_monst(fnam) char *fnam;{ -int wx, wy; - if( load_it(fnam, &wx, &wy)) - { - printf("no file %s.bmp\n",fnam); - getchar(); - exit(1); - } - exp_wall=0; - if(wx==128 && wy==64) expand_wall2(); - else if(wx==48 && wy==64) cp_monst_4864(); - else if(wx==32 && wy==48) expand_wall(); - else if(wx==32)cp_monst_32(); - else if(wx==64)cp_monst_64(); - bflush(); -} - -void process_config(char *fname) -{ - int i,j; - char tmp[100],st[1024]; - char *nuke; - FILE *fp=fopen(fname,"r"); - if(fp==NULL){ - printf("Error no config file %s\nHit return",fname); - getchar(); - exit(1); - } - - -while(1){ - int dummy; - fgets(tmp,99,fp); - if(feof(fp))break; - i=0;while(i<99 && tmp[i]>=32)i++; - tmp[i]=0; - -fprintf(stderr,"[%s]\n",tmp); - - if(getname(tmp,"back",st)) - { - /*** Set Background BMP (format "%back bmpname") ***/ - if(strncmp(st,"none",4)==0) - { - /** clear **/ - for(i=0;i<32*32;i++){fbuf[0][i]=0x47;fbuf[1][i]=fbuf[2][i]=0x6c;} - f_wx=64; - } - else - { - int wy; - load_it(st, &f_wx, &wy); - for(i=0;i<f_wx*wy;i++)for(j=0;j<3;j++)fbuf[j][i]=tbuf[j][i]; - } - continue; - } - - if (getname(tmp,"include",st)){ - char fn2[200]; - sprintf(fn2,"%s%s",cpath, st); - if(strcmp(fname,fn2)!=0) process_config(fn2); - continue; - } - - if (getval(tmp,"slant",&slant)) continue; - if (getval(tmp,"corpse",&corpse)) continue; - if (getval(tmp,"dsize",&dsize)) continue; - if (getval(tmp,"mesh",&mesh)) continue; - if (getval(tmp,"rim",&rim)) continue; - if (getname(tmp,"ctg",ctgname)) continue; - if (getname(tmp,"subst",subsname)) continue; - if (getname(tmp,"sdir",sdir)) continue; - if (getname(tmp,"name", outname)) continue; - if (getval(tmp,"width",&xx0)) continue; - if (getval(tmp,"sx",&sx32)) continue; - if (getval(tmp,"sy",&sy32)) continue; - if (getval(tmp,"end_normal",&dummy)) - { - fprintf(sfp,"-1, -1 };\n"); - end_normal = 1; - continue; - } - - if (tmp[0]=='#' || tmp[0]<32) - { - if(tmp[0]=='#')fprintf(sfp,"//%s\n",tmp); - if(tmp[0]<32) fprintf(sfp,"\n"); - continue; - } - - /*** normal bitmap ***/ - - clr_dbuf(); - if(f_wx==32)cp_floor_32(); else cp_floor_64(); - i=0;while(i<99 && tmp[i]>32)i++; - tmp[i]=0; strcpy(st, &tmp[i+1]); - load_monst(tmp); - if(!strstr(st,"IGNORE_COMMENT")) - { - nuke=strstr(st,"/*");if(nuke)*nuke=0; - if(exp_wall) - fprintf(sfp,"TILE_%s, (TILE_TOTAL+%d),\n",st,bx+by*xx0-16); - else - if(end_normal) - fprintf(sfp,"#define TILE_%s %d\n",st,bx+by*xx0); - else - fprintf(sfp,"TILE_%s, (TILE_TOTAL+%d),\n",st,bx+by*xx0); - } - - if(!exp_wall){bx++;if(bx==xx0){bx=0;by++;}} - -}/* while */ - - fclose(fp); -} - -int main(argc,argv) -int argc; -char *argv[]; -{ - - int i; - char fn[100]; - - fixalloc(tbuf,256*256); - - slant=corpse=mesh=dsize=0; - - bx=by=0; - process_cpath(argv[0]); - fixalloc(obuf, LX*64*(YY)*64); - - - xx0=XX; - ctgname[0]=0; - subsname[0]=0; - sdir[0]=0; - - stdpal(); - - strcpy(outname,"tile"); - -sprintf(fn,"%stiledef-qv.h",cpath); -sfp=fopen(fn,"w"); -if(sfp==NULL){ - printf("Error could not open %s\nHit return",fn); - getchar(); - exit(1); -} - -fprintf(sfp,"/* Automatically generated by tile generator. */\n"); -fprintf(sfp,"const int tile_qv_pair_table[] ={\n"); - - printf("%s\ncpath=%s\n",argv[0],cpath); - if(argc==1) - sprintf(fn,"%sdc-3d.txt",cpath); - else strcpy(fn,argv[1]); - process_config(fn); - - -if(end_normal == 0)fprintf(sfp,"-1, -1 };\n"); - -fprintf(sfp,"\n#define TILE_TOTAL_EX %d\n",bx+by*xx0); -fprintf(sfp,"#define TILE_PER_ROW_EX %d\n",xx0); - - -fclose(sfp); -i=by*64;if(bx!=0)i+=64; - -sprintf(fn,"%s%s.bmp",cpath,outname); -bmwrite(fn,xx0*64,i,obuf); - -return 0; -} diff --git a/crawl-ref/source/rltiles/tool/dcreverse.c b/crawl-ref/source/rltiles/tool/dcreverse.c deleted file mode 100644 index 66e69685b7..0000000000 --- a/crawl-ref/source/rltiles/tool/dcreverse.c +++ /dev/null @@ -1,216 +0,0 @@ -#include "bm.h" - -#define TILEX (32) -#define TILEY (32) - -unsigned char *tbuf[3]; -unsigned char *dbuf[3]; - -/*** BUFFER MEMORY ***/ -#define XX 30 -#define YY 90 -#define LX (XX) - -#define BIGADR(x,y) ((x)+(y)*LX*32) -#define ADR(x,y) ((x)+(y)*32) - -const int read_size = 2048; -int rim = 0; -int tile = 0; -int sx = 0; -int sy = 0; -int ex = 0; -int ey = 0; -char tilename[2048]; -char compositename[2048]; -unsigned char bkg[3] = -{ - 0x47, - 0x6c, - 0x6c -}; - -int is_background(unsigned char d[3]) -{ - if (bkg[0]==d[0] && bkg[1]==d[1] && bkg[2]==d[2]) - return 1; - else - return 0; -} - -int is_rim(unsigned char d[3]) -{ - if (d[0]==1 && d[1]==1 && d[2]==1) - return 1; - else - return 0; -} - -int is_black(unsigned char d[3]) -{ - if (d[0]==0 && d[1]==0 && d[2]==0) - return 1; - else - return 0; -} - -void remove_rim() -{ - int dflag[32][32]; - unsigned char dd[3]; - int x,y,c; - int ad; - int n0, n1, n2; - - // 0 - background - // 1 - tile - // 2 - black - // 3 - rim - - for (x = 0; x < 32; x++) - for (y = 0; y < 32; y++) - { - ad = ADR(x,y); - dd[0]=dbuf[0][ad]; - dd[1]=dbuf[1][ad]; - dd[2]=dbuf[2][ad]; - if (is_background(dd)) - dflag[x][y] = 0; - else if (is_black(dd)) - dflag[x][y] = 2; - else if (is_rim(dd)) - dflag[x][y] = 3; - else - dflag[x][y] = 1; - } - - for(x=0;x<TILEX;x++){ - for(y=0;y<TILEY;y++){ - ad=ADR(x,y); - if(dflag[x][y]==3) { - n0=n1=n2=0; - if(x>0){ - if(dflag[x-1][y]==0) n0++; - if(dflag[x-1][y]==1) n1++; - if(dflag[x-1][y]==2) n2++; - } - - if(y>0){ - if(dflag[x][y-1]==0) n0++; - if(dflag[x][y-1]==1) n1++; - if(dflag[x][y-1]==2) n2++; - } - - if(x<31){ - if(dflag[x+1][y]==0) n0++; - if(dflag[x+1][y]==1) n1++; - if(dflag[x+1][y]==2) n2++; - } - - if(y<31){ - if(dflag[x][y+1]==0) n0++; - if(dflag[x][y+1]==1) n1++; - if(dflag[x][y+1]==2) n2++; - } - - if (n1 != 0) - { - dbuf[0][ad]=bkg[0]; - dbuf[1][ad]=bkg[1]; - dbuf[2][ad]=bkg[2]; - } - } - } - } -} - -void copy_tile() -{ - // copy relevant part of tbuf into dbuf, removing the rim if necessary - - int xx,yy,c; - for (xx = 0; xx < 32; xx++) - for (yy = 0; yy < 32; yy++) - for (c = 0; c < 3; c++) - dbuf[c][ADR(xx,yy)] = tbuf[c][BIGADR(sx+xx,sy+yy)]; - if (rim) - remove_rim(); -} - -void write_file() -{ - // write dbuf to tilenam - bmwrite(tilename,32,32,dbuf); -} - -void process_list(char *fname) -{ - int i; - int x,y; - char tmp[read_size]; - - FILE *fp=fopen(fname,"r"); - if (fp==NULL){ - printf("Error: couldn't open %s\n", fname); - getchar(); - exit(1); - } - - while(1){ - fgets(tmp,read_size,fp); - if (feof(fp)) - break; - i=0; - while (i < read_size && tmp[i] >= 32) - i++; - tmp[i] = 0; - - if (getname(tmp,"tilefile",compositename)) - { - if (bmread(compositename,&x,&y,tbuf) != 0) - { - break; - } - } - if (getname(tmp,"skip",tilename)) - continue; - if (getval(tmp,"rim",&rim)) - continue; - if (getval(tmp,"sx",&sx)) - continue; - if (getval(tmp,"sy",&sy)) - continue; - if (getval(tmp,"ex",&ex)) - continue; - if (getval(tmp,"ey",&ey)) - continue; - - if (getname(tmp,"file",tilename)) - { - printf("Reading tile %s (%d,%d,%d,%d) rim(%d)\n", - compositename, sx, sy, ex, ey, rim); - copy_tile(); - printf("Writing tile %s.\n", tilename); - write_file(); - } - } - - fclose(fp); -} - -int main(argc, argv) -int argc; -char *argv[]; -{ - if (argc <= 1) return; - - process_cpath(argv[0]); - stdpal(); - - fixalloc(tbuf, LX*64*(YY)*64); - fixalloc(dbuf, 32*32); - - printf("%s\ncpath=%s\n",argv[0],cpath); - - process_list(argv[1]); -} diff --git a/crawl-ref/source/rltiles/tool/dctile.c b/crawl-ref/source/rltiles/tool/dctile.c deleted file mode 100644 index a6e01210b4..0000000000 --- a/crawl-ref/source/rltiles/tool/dctile.c +++ /dev/null @@ -1,672 +0,0 @@ -#include "bm.h" - -/** Some global **/ -int corpse=0; -int mesh=0; -int slant=0; -int rim=0; -FILE *mfp=NULL; // map html -FILE *sfp=NULL; // "tiledef.h" -FILE *tfp=NULL; // tiles.txt -FILE *cfp=NULL; // lengths of tile counts -int tilecount = 0; -int tilecountidx = -1; -int counts[1024]; -int countnames[512][100]; - -char outname[1024], ctgname[100], subsname[100]; -char sdir[300]; -char realname[1024]; -char imgname[1024]; -char tiledefname[1024]; -char enumprefix[100]; -const int read_size = 2048; - -/*** BUFFER MEMORY ***/ -#define XX 30 -int xx0; -#define YY 90 -#define LX (XX) - -/*** tmp buffer, floor , final output, final queue ***/ -unsigned char *tbuf[3],fbuf[3][32*32],*obuf[3], dbuf[3][32*32]; - -/*** compose buffer */ -unsigned char cbuf[3][32*32]; - -/*** normal floor*/ -#define WOADR(x,y,xx,yy) ((x)*32+xx+ xx0*32*((y)*32+yy)) -#define ADR(x,y) ((x)+(y)*32) - -/*** output width/height in block ***/ -int bx,by; -int filler = 0; - -unsigned char bkg[3] = { 0x47, 0x6c, 0x6c }; - -#define WID 32 - -/****************************************/ -/* Wrapper routines **************/ -/**************************/ - -int load_pxxx(fnam) char *fnam;{ - int x,y; - - sprintf(realname,"%s%s%c%s.bmp",cpath,sdir,PATHSEP,fnam); - if(bmread(realname,&x,&y,tbuf)==0) return 0; - - sprintf(realname,"%s%s.bmp",cpath,fnam); - if(bmread(realname,&x,&y,tbuf)==0) return 0; - - if(subsname[0]){ - sprintf(realname,"%s%s%c%s.bmp",cpath,sdir,PATHSEP,subsname); - if(bmread(realname,&x,&y,tbuf)==0) return 0; - - sprintf(realname,"%s%s.bmp",cpath,subsname); - if(bmread(realname,&x,&y,tbuf)==0) return 0; - } - - - return 1; -} - - -void clr_buf() { - int xx,yy; - - for(xx=0;xx<32;xx++){ - for(yy=0;yy<32;yy++){ - dbuf[0][ ADR(xx,yy) ]=bkg[0]; - dbuf[1][ ADR(xx,yy) ]=bkg[1]; - dbuf[2][ ADR(xx,yy) ]=bkg[2]; - } - } -} - -void cp_floor(){ - int xx,yy,c; - for(xx=0;xx<32;xx++) - for(yy=0;yy<32;yy++) - for(c=0;c<3;c++) - dbuf[c][ ADR(xx,yy) ]=fbuf[c][ ADR(xx,yy)]; -} - -#define TILEX 32 -#define TILEY 32 - -void make_rim(unsigned char buf[3][TILEX*TILEY]){ - static unsigned char dflag[TILEX][TILEY]; - int x,y,c,dd[3],ad; - int n0,n1,n2; - - // dflag: - // 0 = background - // 1 = tile - // 2 = black - - for(y=0;y<TILEY;y++){ - for(x=0;x<TILEX;x++){ - dflag[x][y]=1; - ad=ADR(x,y); - for(c=0;c<3;c++)dd[c]=buf[c][ad]; - if( (dd[0]==bkg[0])&&(dd[1]==bkg[1])&& (dd[2]==bkg[2])) dflag[x][y]=0; - if( (dd[0]==0)&&(dd[1]==0)&& (dd[2]==0)) dflag[x][y]=2; - } - } - - for(x=0;x<TILEX;x++){ - for(y=0;y<TILEY;y++){ - ad=x+y*TILEX; - if(dflag[x][y]==2 || dflag[x][y]==0){ - n0=n1=n2=0; - if(x>0){ - if(dflag[x-1][y]==0) n0++; - if(dflag[x-1][y]==1) n1++; - if(dflag[x-1][y]==2) n2++; - } - - if(y>0){ - if(dflag[x][y-1]==0) n0++; - if(dflag[x][y-1]==1) n1++; - if(dflag[x][y-1]==2) n2++; - } - - if(x<31){ - if(dflag[x+1][y]==0) n0++; - if(dflag[x+1][y]==1) n1++; - if(dflag[x+1][y]==2) n2++; - } - if(y<31){ - if(dflag[x][y+1]==0) n0++; - if(dflag[x][y+1]==1) n1++; - if(dflag[x][y+1]==2) n2++; - } - // n1 = tiles adjacent but not diagonal that are tile pixels - if(n1!=0 ) - buf[0][x+y*32]=buf[1][x+y*32]=buf[2][x+y*32]=0x10; - } - } - } - -} - -void cp_monst_32(){ - int xx,yy,c,dd[3],ad; - char dflag[32][32]; - int xmin,xmax,ymin,ymax,ox,oy; - - if(corpse==1) - { - xmin=ymin=31; - xmax=ymax=0; - for(xx=0;xx<32;xx++){ - for(yy=0;yy<32;yy++){ - ad=ADR(xx,yy); - for(c=0;c<3;c++)dd[c]=tbuf[c][ad]; - if( (dd[0]==bkg[0])&&(dd[1]==bkg[1])&& (dd[2]==bkg[2]))continue; - if( (dd[0]==0)&&(dd[1]==0)&& (dd[2]==0))continue; - if(xx<xmin)xmin=xx; - if(xx>xmax)xmax=xx; - if(yy<ymin)ymin=yy; - if(yy>ymax)ymax=yy; - } - } - ox=(xmax+xmin)/2-16; - oy=(ymax+ymin)/2-16; - } - - for(xx=0;xx<32;xx++){ - for(yy=0;yy<32;yy++){ - dflag[xx][yy]=0; - ad=ADR(xx,yy); - if(corpse==1){ - int x1=xx+ox; - int y1=(yy+oy)*2-16; - int cy=18; - if(xx<4 || xx>=28)cy+=2;else - if(xx<12 || xx>=20) cy+=1; - - if(yy>=cy-1 && yy<=cy+0)continue; - x1 += (y1-16)/4; - if(y1>=cy){y1-=2;x1-=3;}else {y1 +=2;x1+=3;} - if(x1<0 || x1>=32 || y1<0 || y1>=32)continue; - ad=ADR(x1,y1); - } - - /*** normal***/ - for(c=0;c<3;c++){dd[c]=tbuf[c][ad];} - if(mesh==2){ - if( (dd[0]!=bkg[0])||(dd[1]!=bkg[1])|| (dd[2]!=bkg[2])){ - if( ((xx+yy)&1) ==0)dd[0]=dd[1]=dd[2]=0; - } - } - if(mesh==1){ - if( (((xx/2)+(yy/2))&1) ==1)dd[0]=dd[1]=dd[2]=0; - } - - if( (dd[0]==bkg[0])&&(dd[1]==bkg[1])&& (dd[2]==bkg[2]))continue; - if( (corpse==1) &&(dd[0]==0)&&(dd[1]==0)&& (dd[2]==0))continue; - - for(c=0;c<3;c++) {dbuf[c][ADR(xx,yy)]=dd[c];} - dflag[xx][yy]=1; - } - } - - -#if 1 -if(corpse==1){ -for(xx=0;xx<32;xx++){ -int cy=18; -if(xx<4 || xx>=28)cy+=2;else -if(xx<12 || xx>=20) cy+=1; -if(dflag[xx][cy-2]==1 && dflag[xx][cy+1]==1 ){ -for(yy=cy-1;yy<=cy-0;yy++){ dbuf[0][ADR(xx,yy)]=32; -dbuf[1][ADR(xx,yy)]=0;dbuf[2][ADR(xx,yy)]=0; -dflag[xx][yy]=1; -}} -} - -/** shade**/ -for(xx=1;xx<32;xx++){ -for(yy=1;yy<32;yy++){ -if(dflag[xx][yy]==0 && dflag[xx-1][yy-1]==1){ -dbuf[0][ADR(xx,yy)]=0; -dbuf[1][ADR(xx,yy)]=0; -dbuf[2][ADR(xx,yy)]=0; -} -}} - -for(xx=3;xx<32;xx++){ -for(yy=3;yy<32;yy++){ -if(dflag[xx][yy]==0 && dflag[xx-1][yy-1]==0 - && dflag[xx-2][yy-2]==1 && dflag[xx-3][yy-3]==1){ -dbuf[0][ADR(xx,yy)]=0; -dbuf[1][ADR(xx,yy)]=0; -dbuf[2][ADR(xx,yy)]=0; -} -}} - - - - -} -#endif -if(rim==1)make_rim(dbuf); -} - - -void bflush(){ -int xx,yy,c; -for(xx=0;xx<32;xx++){ -for(yy=0;yy<32;yy++){ -for(c=0;c<3;c++){ -obuf[c][WOADR(bx,by,xx,yy)]= dbuf[c][ADR(xx,yy)]; -}}} -} - - -void load_monst(fnam) char *fnam;{ - if( load_pxxx(fnam)){ - printf("no file pxxx/%s.bmp or %s/%s.bmp\n",fnam,sdir,fnam); - getchar(); - exit(1); - } - cp_monst_32(); - bflush(); -} - -void process_config(char *fname) -{ - int x,y; - int i,j; - char tmp[read_size],st[read_size]; - char *nuke; - FILE *fp=fopen(fname,"r"); - if(fp==NULL){ - printf("Error no config file %s\nHit return",fname); - getchar(); - exit(1); - } - - while(1){ - fgets(tmp,read_size,fp); - if(feof(fp))break; - i=0;while(i<read_size && tmp[i]>=32)i++; - tmp[i]=0; - - if(getname(tmp,"back",st)) - { - /*** Set Background BMP (format "%back bmpname") ***/ - if(strncmp(st,"none",4)==0) - { - /** clear **/ - for(i=0;i<32*32;i++){fbuf[0][i]=bkg[0];fbuf[1][i]=bkg[1];fbuf[2][i]=bkg[2];} - } - else - { - load_pxxx(st); - for(i=0;i<32*32;i++)for(j=0;j<3;j++)fbuf[j][i]=tbuf[j][i]; - } - continue; - } - - if (getname(tmp,"include",st)){ - char fn2[read_size]; - sprintf(fn2,"%s%s",cpath, st); - if(strcmp(fname,fn2)!=0) process_config(fn2); - continue; - } - - if (getname(tmp,"htmlfile",st)) - { - char fn2[read_size]; - sprintf(fn2,"%s%s",cpath, st); - mfp=fopen(fn2,"w"); - if(mfp==NULL) - { - printf("Error could not open %s\nHit return",fn2); - getchar(); - exit(1); - } - fprintf(mfp,"<HTML><head>\n"); - continue; - } - - if (getname(tmp,"tilelist",st)) - { - char fn2[read_size]; - sprintf(fn2,"%s%s",cpath, st); - tfp=fopen(fn2,"w"); - if(tfp==NULL) - { - printf("Error could not open %s\nHit return",fn2); - getchar(); - exit(1); - } - fprintf(tfp,"%%tilefile %s\n", imgname); - fprintf(tfp,"%%rim %d\n", rim); - continue; - } - - if (getname(tmp,"tiledef",st)) - { - char fn[read_size]; - sprintf(fn,"%s%s",cpath,st); - strcpy(tiledefname, st);; - sfp=fopen(fn,"w"); - if(sfp==NULL) - { - printf("Error could not open %s\nHit return",fn); - getchar(); - exit(1); - } - fprintf(sfp,"/* Automatically generated by tile generator. */\n"); - fprintf(sfp, "enum TILE_%sIDX {\n", enumprefix); - continue; - } - - if (getname(tmp,"tilecount",st)) - { - char fn[read_size]; - sprintf(fn,"%s%s",cpath,st); - cfp=fopen(fn,"w"); - if(cfp==NULL) - { - printf("Error could not open %s\nHit return",fn); - getchar(); - exit(1); - } - fprintf(cfp,"/* Automatically generated by tile generator. */\n"); - fprintf(cfp,"#include \"%s\"\n", tiledefname); - continue; - } - - if (getname(tmp,"enumprefix",st)) - { - strcpy(enumprefix, st); - continue; - } - - if (getname(tmp,"htmlhead",st)) - { - if(mfp)fprintf(mfp,"%s\n",st); - continue; - } - - if (getname(tmp,"htmlbody",st)) - { - if(mfp)fprintf(mfp,"</head><body>\n<map name=\"nhmap\">\n"); - continue; - } - - if (getval(tmp,"slant",&slant)) continue; - if (getval(tmp,"rim",&rim)) - { - if (tfp) fprintf(tfp, "%%rim %d\n", rim); - continue; - } - if (getval(tmp,"mesh",&mesh)) continue; - if (getval(tmp,"corpse",&corpse)) continue; - - if (getname(tmp,"ctg",ctgname)) continue; - if (getname(tmp,"subst",subsname)) continue; - if (getname(tmp,"sdir",sdir)) continue; - if (getname(tmp,"name", outname)) - { - sprintf(imgname, "%s.bmp", outname); - continue; - } - if (getname(tmp,"htmlimg",imgname)) continue; - if (getval(tmp,"width",&xx0)) continue; - if (tmp[0]=='#' || tmp[0]<32){ - if(tmp[0]<32) fprintf(sfp,"\n"); - if(tmp[0]=='#')fprintf(sfp,"//%s\n",tmp); - continue; - } - - // begin a 32x32 composing sequence - if (getname(tmp,"start",st)) - { - clr_buf(); - for (i = 0; i < 32*32; i++) - { - cbuf[0][i] = fbuf[0][i]; - cbuf[1][i] = fbuf[1][i]; - cbuf[2][i] = fbuf[2][i]; - } - continue; - } - - // compose an image onto the current buffer - if (getname(tmp,"compose",st)) - { - unsigned char tempbuf[3][TILEX * TILEY]; - - if(load_pxxx(st)){ - printf("no file pxxx/%s.bmp or %s/%s.bmp\n",st,sdir,st); - getchar(); - exit(1); - } - - // Copy into a temporary buffer so that we can use the rim func. - for(i=0;i<TILEX*TILEY;i++) - { - tempbuf[0][i] = tbuf[0][i]; - tempbuf[1][i] = tbuf[1][i]; - tempbuf[2][i] = tbuf[2][i]; - } - if (rim == 1) - make_rim(tempbuf); - - for(i=0;i<32*32;i++) - { - if (tempbuf[0][i] != bkg[0] || - tempbuf[1][i] != bkg[1] || - tempbuf[2][i] != bkg[2]) - { - cbuf[0][i] = tempbuf[0][i]; - cbuf[1][i] = tempbuf[1][i]; - cbuf[2][i] = tempbuf[2][i]; - } - } - continue; - } - - if (getname(tmp,"nextrow",st)) - { - if (bx == 0) - continue; - - while (bx != xx0) - { - fprintf(sfp, " TILE_%sFILLER%d,\n", enumprefix, filler++); - bx++; - } - - bx = 0; - by ++; - continue; - } - - // finish composing - if (getname(tmp,"finish",st)) - { - realname[0] = 0; - for (i=0;i<32*32;i++) - { - tbuf[0][i] = cbuf[0][i]; - tbuf[1][i] = cbuf[1][i]; - tbuf[2][i] = cbuf[2][i]; - } - - // Rim has already been applied during composing, so turn it off - // temporarily. - int storerim = rim; - rim = 0; - cp_monst_32(); - rim = storerim; - - bflush(); - } - else - { - /*** normal bitmap ***/ - clr_buf();cp_floor(); - i=0;while(i<read_size && tmp[i]>32)i++; - tmp[i]=0; strcpy(st, &tmp[i+1]); - - if (tfp) - { - fprintf(tfp,"%%sx %d\n%%sy %d\n%%ex %d\n%%ey %d\n", - bx*WID,by*WID,bx*WID+WID-1,by*WID+WID-1); - } - - load_monst(tmp); - } - - if(mfp) - { - fprintf( - mfp,"<area shape=\"rect\" coords=\"%d,%d,%d,%d\" alt=\"%s\" href=\"%s\">\n", - bx*WID,by*WID,bx*WID+WID-1,by*WID+WID-1, - st,realname); - } - - if (tfp) - { - if (corpse) - fprintf(tfp,"%%skip\n"); - else - fprintf(tfp,"%%file %s\n", realname); - } - - if(!strstr(st,"IGNORE_COMMENT")){ - nuke=strstr(st,"/*");if(nuke)*nuke=0; - if (st && strcmp(st, "") != 0 && strcmp(st, "\n") != 0) - { - fprintf(sfp," TILE_%s,\n",st); - if (cfp) - { - if (tilecountidx == -1) - tilecountidx++; - else - counts[tilecountidx++] = tilecount; - sprintf(countnames[tilecountidx], "%s", st); - tilecount = 1; - } - } - else - { - fprintf(sfp, " TILE_%sFILLER%d,\n", enumprefix, filler++); - tilecount++; - } - } - - bx++;if(bx==xx0){bx=0;by++;;} - - }/* while */ - fclose(fp); -} - -int main(argc,argv) -int argc; -char *argv[]; -{ - int i; - char fn[100]; - - bx=by=0; - process_cpath(argv[0]); - - xx0=XX; - ctgname[0]=0; - subsname[0]=0; - sdir[0]=0; - enumprefix[0] = 0; - - stdpal(); - fixalloc(tbuf,256*256); - fixalloc(obuf, LX*64*(YY)*64); - - - strcpy(outname,"tile"); - strcpy(imgname,"tile.bmp"); - - - printf("%s\ncpath=%s\n",argv[0],cpath); - if(argc==1) - sprintf(fn,"%sdc-2d.txt",cpath); - else - strcpy(fn,argv[1]); - process_config(fn); - - if(mfp) - { - fprintf(mfp,"</map>\n<img src=%s usemap=\"#nhmap\" >\n", imgname); - fprintf(mfp,"</body></html>\n"); - fclose(mfp); - } - - if (sfp) - { - fprintf(sfp, "TILE_%sTOTAL};\n\n", enumprefix); - fprintf(sfp,"#define TILE_%sPER_ROW %d\n", enumprefix, xx0); - } - - if (cfp) - { - int i; - - counts[tilecountidx++] = tilecount; - - fprintf(sfp, "\n\n"); - fprintf(sfp, "enum TILE_%sCOUNT_IDX {\n", enumprefix); - for (i = 0; i < tilecountidx; i++) - { - fprintf(sfp, " IDX_%s,\n", countnames[i]); - } - fprintf(sfp, " IDX_%sTOTAL\n};\n\n", enumprefix); - fprintf(sfp, "extern int tile_%scount[IDX_%sTOTAL];\n", enumprefix, enumprefix); - fprintf(sfp, "extern int tile_%sstart[IDX_%sTOTAL];\n\n", enumprefix, enumprefix); - - fprintf(cfp, "int tile_%scount[IDX_%sTOTAL] =\n{\n", - enumprefix, enumprefix); - - for (i = 0; i < tilecountidx; i++) - { - fprintf(cfp, (i < tilecountidx - 1) ? " %d,\n" : " %d\n", - counts[i]); - } - - fprintf(cfp, "};\n\n"); - - fprintf(cfp, "int tile_%sstart[IDX_%sTOTAL] = \n{\n", - enumprefix, enumprefix); - - for (i = 0; i < tilecountidx; i++) - { - fprintf(cfp, (i < tilecountidx - 1) ? " TILE_%s,\n" : " TILE_%s\n", - countnames[i]); - } - - fprintf(cfp, "};\n\n"); - close(cfp); - } - - if (sfp) - { - fclose(sfp); - } - - if(tfp) - { - fclose(tfp); - } - - i=by*32; - if(bx!=0)i+=32; - sprintf(fn,"%s%s.bmp",cpath,outname); - bmwrite(fn,xx0*32,i,obuf); - return 0; -} diff --git a/crawl-ref/source/rltiles/tool/main.cc b/crawl-ref/source/rltiles/tool/main.cc new file mode 100644 index 0000000000..8b4b60ce43 --- /dev/null +++ b/crawl-ref/source/rltiles/tool/main.cc @@ -0,0 +1,26 @@ +#include "tile_list_processor.h" + +int main(int argc, char **argv) +{ + if (argc != 2) + { + fprintf(stderr, "Usage: %s (tile_list.txt)\n", argv[0]); + return -1; + } + + tile_list_processor proc; + + if (!proc.process_list(argv[1])) + { + fprintf(stderr, "Error: failed to process '%s'\n", argv[1]); + return -2; + } + + if (!proc.write_data()) + { + fprintf(stderr, "Error: failed to write data for '%s'\n", argv[1]); + return -3; + } + + return 0; +} diff --git a/crawl-ref/source/rltiles/tool/mkmap.c b/crawl-ref/source/rltiles/tool/mkmap.c deleted file mode 100644 index f07ce369ea..0000000000 --- a/crawl-ref/source/rltiles/tool/mkmap.c +++ /dev/null @@ -1,408 +0,0 @@ -#include "bm.h" - -/** Some global **/ -int corpse, mesh,slant, rim; -FILE *mfp,*sfp; -char outname[1024], ctgname[100], subsname[100]; -char sdir[300]; -char realname[1024]; - -/*** BUFFER MEMORY ***/ -#define XX 30 -int xx0; -#define YY 90 -#define LX (XX) - - -/*** tmp buffer, floor , final output, final queue ***/ -unsigned char *tbuf[3],fbuf[3][32*32], *obuf[3],dbuf[3][32*32]; - - -/*** normal floor*/ -#define WOADR(x,y,xx,yy) \ -((x)*32+xx+ xx0*32*((y)*32+yy)) - - -#define ADR(x,y) ((x)+(y)*32) - -/*** output width/height in block ***/ -int bx,by; - - - -/****************************************/ -/* Wrapper routines **************/ -/**************************/ - -int load_pxxx(fnam) char *fnam;{ -int x,y; - -sprintf(realname,"%s%s%c%s.bmp",cpath,sdir,PATHSEP,fnam); -if(bmread(realname,&x,&y,tbuf)==0) return 0; - -sprintf(realname,"%s%s.bmp",cpath,fnam); -if(bmread(realname,&x,&y,tbuf)==0) return 0; - -if(subsname[0]){ - sprintf(realname,"%s%s%c%s.bmp",cpath,sdir,PATHSEP,subsname); - if(bmread(realname,&x,&y,tbuf)==0) return 0; - - sprintf(realname,"%s%s.bmp",cpath,subsname); - if(bmread(realname,&x,&y,tbuf)==0) return 0; -} - - -return 1; -} - - -void clr_buf() { -int xx,yy; - -for(xx=0;xx<32;xx++){ -for(yy=0;yy<32;yy++){ -dbuf[0][ ADR(xx,yy) ]=0x47; -dbuf[1][ ADR(xx,yy) ]=0x6c; -dbuf[2][ ADR(xx,yy) ]=0x6c; -}} -} - -void cp_floor(){ -int xx,yy,c; -for(xx=0;xx<32;xx++) -for(yy=0;yy<32;yy++) -for(c=0;c<3;c++) -dbuf[c][ ADR(xx,yy) ]=fbuf[c][ ADR(xx,yy)]; -} - -#define TILEX 32 -#define TILEY 32 - -void make_rim(){ -static unsigned char dflag[TILEX][TILEY]; -int x,y,c,dd[3],ad; -int n0,n1,n2; - - - -for(y=0;y<TILEY;y++){ -for(x=0;x<TILEX;x++){ - dflag[x][y]=1; - ad=ADR(x,y); - for(c=0;c<3;c++)dd[c]=dbuf[c][ad]; - if( (dd[0]==0x47)&&(dd[1]==0x6c)&& (dd[2]==0x6c)) dflag[x][y]=0; - if( (dd[0]==0)&&(dd[1]==0)&& (dd[2]==0)) dflag[x][y]=2; -} -} - -for(x=0;x<TILEX;x++){ -for(y=0;y<TILEY;y++){ - ad=x+y*TILEX; -if(dflag[x][y]==2 || dflag[x][y]==0){ -n0=n1=n2=0; -if(x>0){ - if(dflag[x-1][y]==0) n0++; - if(dflag[x-1][y]==1) n1++; - if(dflag[x-1][y]==2) n2++; -} - -if(y>0){ - if(dflag[x][y-1]==0) n0++; - if(dflag[x][y-1]==1) n1++; - if(dflag[x][y-1]==2) n2++; -} - -if(x<31){ - if(dflag[x+1][y]==0) n0++; - if(dflag[x+1][y]==1) n1++; - if(dflag[x+1][y]==2) n2++; -} -if(y<31){ - if(dflag[x][y+1]==0) n0++; - if(dflag[x][y+1]==1) n1++; - if(dflag[x][y+1]==2) n2++; -} - -if(n1!=0 ) -dbuf[0][x+y*32]=dbuf[1][x+y*32]=dbuf[2][x+y*32]=0x10; - - - -}}} - -} - -void cp_monst_32(){ -int xx,yy,c,dd[3],ad; -char dflag[32][32]; -int xmin,xmax,ymin,ymax,ox,oy; - -if(corpse==1 ){ - xmin=ymin=31; - xmax=ymax=0; - for(xx=0;xx<32;xx++){ - for(yy=0;yy<32;yy++){ - ad=ADR(xx,yy); - for(c=0;c<3;c++)dd[c]=tbuf[c][ad]; - if( (dd[0]==0x47)&&(dd[1]==0x6c)&& (dd[2]==0x6c))continue; - if( (dd[0]==0)&&(dd[1]==0)&& (dd[2]==0))continue; - if(xx<xmin)xmin=xx; - if(xx>xmax)xmax=xx; - if(yy<ymin)ymin=yy; - if(yy>ymax)ymax=yy; -}}/*xy**/ -ox=(xmax+xmin)/2-16; -oy=(ymax+ymin)/2-16; -} - -for(xx=0;xx<32;xx++){ -for(yy=0;yy<32;yy++){ -dflag[xx][yy]=0; -ad=ADR(xx,yy); -if(corpse==1){ -int x1=xx+ox; -int y1=(yy+oy)*2-16; -int cy=18; -if(xx<4 || xx>=28)cy+=2;else -if(xx<12 || xx>=20) cy+=1; - -if(yy>=cy-1 && yy<=cy+0)continue; -x1 += (y1-16)/4; -if(y1>=cy){y1-=2;x1-=3;}else {y1 +=2;x1+=3;} -if(x1<0 || x1>=32 || y1<0 || y1>=32)continue; -ad=ADR(x1,y1); -} - -/*** normal***/ -for(c=0;c<3;c++){dd[c]=tbuf[c][ad];} -if(mesh==2){ -if( (dd[0]!=0x47)||(dd[1]!=0x6c)|| (dd[2]!=0x6c)){ -if( ((xx+yy)&1) ==0)dd[0]=dd[1]=dd[2]=0; -} -} -if(mesh==1){ -if( (((xx/2)+(yy/2))&1) ==1)dd[0]=dd[1]=dd[2]=0; -} - -if( (dd[0]==0x47)&&(dd[1]==0x6c)&& (dd[2]==0x6c))continue; -if( (corpse==1) &&(dd[0]==0)&&(dd[1]==0)&& (dd[2]==0))continue; - -for(c=0;c<3;c++) {dbuf[c][ADR(xx,yy)]=dd[c];} - dflag[xx][yy]=1; -}} - - -#if 1 -if(corpse==1){ -for(xx=0;xx<32;xx++){ -int cy=18; -if(xx<4 || xx>=28)cy+=2;else -if(xx<12 || xx>=20) cy+=1; -if(dflag[xx][cy-2]==1 && dflag[xx][cy+1]==1 ){ -for(yy=cy-1;yy<=cy-0;yy++){ dbuf[0][ADR(xx,yy)]=32; -dbuf[1][ADR(xx,yy)]=0;dbuf[2][ADR(xx,yy)]=0; -dflag[xx][yy]=1; -}} -} - -/** shade**/ -for(xx=1;xx<32;xx++){ -for(yy=1;yy<32;yy++){ -if(dflag[xx][yy]==0 && dflag[xx-1][yy-1]==1){ -dbuf[0][ADR(xx,yy)]=0; -dbuf[1][ADR(xx,yy)]=0; -dbuf[2][ADR(xx,yy)]=0; -} -}} - -for(xx=3;xx<32;xx++){ -for(yy=3;yy<32;yy++){ -if(dflag[xx][yy]==0 && dflag[xx-1][yy-1]==0 - && dflag[xx-2][yy-2]==1 && dflag[xx-3][yy-3]==1){ -dbuf[0][ADR(xx,yy)]=0; -dbuf[1][ADR(xx,yy)]=0; -dbuf[2][ADR(xx,yy)]=0; -} -}} - - - - -} -#endif -if(rim==1)make_rim(); -} - - -void bflush(){ -int xx,yy,c; -for(xx=0;xx<32;xx++){ -for(yy=0;yy<32;yy++){ -for(c=0;c<3;c++){ -obuf[c][WOADR(bx,by,xx,yy)]= dbuf[c][ADR(xx,yy)]; -}}} -} - - -void load_monst(fnam) char *fnam;{ - if( load_pxxx(fnam)){ - printf("no file pxxx/%s.bmp or %s/%s.bmp\n",fnam,sdir,fnam); - getchar(); - exit(1); - } - cp_monst_32(); - bflush(); -} - -void process_config(char *fname) -{ - int i,j; - char tmp[100],st[1024]; - char *nuke; - FILE *fp=fopen(fname,"r"); - if(fp==NULL){ - printf("Error no config file %s\nHit return",fname); - getchar(); - exit(1); - } - - -while(1){ -fgets(tmp,99,fp); -if(feof(fp))break; -i=0;while(i<99 && tmp[i]>=32)i++; -tmp[i]=0; - - if(getname(tmp,"back",st)) - { - /*** Set Background BMP (format "%back bmpname") ***/ - if(strncmp(st,"none",4)==0) - { - /** clear **/ - for(i=0;i<32*32;i++){fbuf[0][i]=0x47;fbuf[1][i]=fbuf[2][i]=0x6c;} - } - else - { - load_pxxx(st); - for(i=0;i<32*32;i++)for(j=0;j<3;j++)fbuf[j][i]=tbuf[j][i]; - } - continue; - } - - if (getname(tmp,"include",st)){ - char fn2[200]; - sprintf(fn2,"%s%s",cpath, st); - if(strcmp(fname,fn2)!=0) process_config(fn2); - continue; - } - - if (getval(tmp,"slant",&slant)) continue; - if (getval(tmp,"rim",&rim)) continue; - if (getval(tmp,"mesh",&mesh)) continue; - if (getval(tmp,"corpse",&corpse)) continue; - if (getname(tmp,"ctg",ctgname)) continue; - if (getname(tmp,"subst",subsname)) continue; - if (getname(tmp,"sdir",sdir)) continue; - if (getname(tmp,"name", outname)) continue; - if (getval(tmp,"width",&xx0)) continue; - if (tmp[0]=='#' || tmp[0]<32){ - if(tmp[0]=='#')fprintf(sfp,"//%s\n",tmp); - if(tmp[0]<32) fprintf(sfp,"\n"); - continue; - } - -/*** normal bitmap ***/ -#define WID 32 -clr_buf();cp_floor(); -i=0;while(i<99 && tmp[i]>32)i++; -tmp[i]=0; strcpy(st, &tmp[i+1]); - load_monst(tmp); - -fprintf(mfp,"<area shape=\"rect\" coords=\"%d,%d,%d,%d\" href=%s>\n", -bx*WID,by*WID,bx*WID+WID-1,by*WID+WID-1, -realname); - -if(!strstr(st,"IGNORE_COMMENT")){ -nuke=strstr(st,"/*");if(nuke)*nuke=0; -fprintf(sfp,"#define TILE_%s %d\n",st,bx+by*xx0); -} - -bx++;if(bx==xx0){bx=0;by++;;} - - - -}/* while */ - fclose(fp); -} - -int main(argc,argv) -int argc; -char *argv[]; -{ - - int i; - char fn[100],st2[100]; - - slant=corpse=mesh=rim=0; - - bx=by=0; - process_cpath(argv[0]); - - xx0=XX; - ctgname[0]=0; - subsname[0]=0; - sdir[0]=0; - - stdpal(); - fixalloc(tbuf,256*256); - fixalloc(obuf, LX*64*(YY)*64); - - - strcpy(outname,"tile"); - -sprintf(fn,"%smap.htm",cpath); -mfp=fopen(fn,"w"); -if(mfp==NULL){ - printf("Error could not open %s\nHit return",fn); - getchar(); - exit(1); -} - - -sprintf(fn,"%stiledef.h",cpath); -sfp=fopen(fn,"w"); -if(sfp==NULL){ - printf("Error could not open %s\nHit return",fn); - getchar(); - exit(1); -} -fprintf(sfp,"/* Automatically generated by tile generator. */\n"); - - -fprintf(mfp,"<HTML><head>\n"); -fprintf(mfp,"<base href=\"http://cvs.sourceforge.net/viewcvs.py/rltiles/rltiles/\">\n"); -fprintf(mfp,"</head><body><MAP NAME=\"nhmap\">\n"); - - - printf("%s\ncpath=%s\n",argv[0],cpath); - if(argc==1) - sprintf(fn,"%sdc-all.txt",cpath); - else strcpy(fn,argv[1]); - process_config(fn); - - - -fprintf(sfp,"#define TILE_TOTAL %d\n",bx+by*xx0); -fprintf(sfp,"#define TILE_PER_ROW %d\n",xx0); - -fprintf(mfp,"<IMG SRC=http://rltiles.sf.net/%s.png USEMAP=\"#nhmap\" >\n</body>\n</html>\n", outname); - - -fclose(mfp); -fclose(sfp); -i=by*32;if(bx!=0)i+=32; - -sprintf(fn,"%s%s.bmp",cpath,outname); -bmwrite(fn,xx0*32,i,obuf); - -} diff --git a/crawl-ref/source/rltiles/tool/mkmapq.c b/crawl-ref/source/rltiles/tool/mkmapq.c deleted file mode 100644 index ad92344267..0000000000 --- a/crawl-ref/source/rltiles/tool/mkmapq.c +++ /dev/null @@ -1,783 +0,0 @@ -#include "bm.h" - -#define WID 64 -/** Some global **/ -int corpse=0, mesh =0,slant=0; -int rim=0; -int exp_wall; -int dsize; -int sx32 = 16; -int sy32 = 24; - -FILE *mfp,*sfp; -char outname[1024], ctgname[100], subsname[100]; -char sdir[300]; -char realname[1024]; - - -/*** BUFFER MEMORY ***/ -#define XX 16 -int xx0; -#define YY 30 -#define LX (XX) - -/*** tmp buffer, floor , final output, final queue ***/ -unsigned char *tbuf[3],fbuf[3][128*64], - *obuf[3],dbuf[3][128*64]; - - -unsigned char wallbuf[4][3][32*48]; -unsigned char wall2buf[3][128*64]; - - -int f_wx; - -/*** normal floor*/ -#define WOADR(x,y,xx,yy) \ -((x)*64+xx+ xx0*64*((y)*64+yy)) - - -#define ADR32(x,y) ((x)+(y)*32) -#define ADR64(x,y) ((x)+(y)*64) - - -/*** output width/height in block ***/ -int bx,by; - - -/**************************/ -/* Wrapper routines *******/ -/**************************/ - -int load_it(char *fnam, int *wx, int *wy) -{ - sprintf(realname,"%s%s%c%s.bmp",cpath,sdir,PATHSEP,fnam); - if(bmread(realname,wx,wy,tbuf)==0) return 0; - - sprintf(realname,"%s%s.bmp",cpath,fnam); - if(bmread(realname,wx,wy,tbuf)==0) return 0; - - if(subsname[0]){ - sprintf(realname,"%s%s%c%s.bmp",cpath,sdir,PATHSEP,subsname); - if(bmread(realname,wx,wy,tbuf)==0) return 0; - - sprintf(realname,"%s%s.bmp",cpath,subsname); - if(bmread(realname,wx,wy,tbuf)==0) return 0; - } - -return 1; -} - - -void clr_dbuf() { -int xx,yy; - -for(xx=0;xx<64;xx++){ -for(yy=0;yy<64;yy++){ -dbuf[0][ ADR64(xx,yy) ]=0x47; -dbuf[1][ ADR64(xx,yy) ]=0x6c; -dbuf[2][ ADR64(xx,yy) ]=0x6c; -}} -} - -#define TILEX 64 -#define TILEY 64 -void make_rim(){ -static unsigned char dflag[TILEX][TILEY]; -int x,y,c,dd[3],ad; -int n0,n1,n2; - -for(y=0;y<TILEY;y++){ -for(x=0;x<TILEX;x++){ - dflag[x][y]=1; - ad=x + y *TILEX; - for(c=0;c<3;c++)dd[c]=dbuf[c][ad]; - if( (dd[0]==0x47)&&(dd[1]==0x6c)&& (dd[2]==0x6c)) dflag[x][y]=0; - if( (dd[0]==0)&&(dd[1]==0)&& (dd[2]==0)) dflag[x][y]=2; -} -} - -for(x=0;x<TILEX;x++){ -for(y=0;y<TILEY;y++){ - ad=x+y*TILEX; -if(dflag[x][y]==2 || dflag[x][y]==0){ -n0=n1=n2=0; -if(x>0){ - if(dflag[x-1][y]==0) n0++; - if(dflag[x-1][y]==1) n1++; - if(dflag[x-1][y]==2) n2++; -} - -if(y>0){ - if(dflag[x][y-1]==0) n0++; - if(dflag[x][y-1]==1) n1++; - if(dflag[x][y-1]==2) n2++; -} - -if(x<TILEX-1){ - if(dflag[x+1][y]==0) n0++; - if(dflag[x+1][y]==1) n1++; - if(dflag[x+1][y]==2) n2++; -} -if(y<TILEY-1){ - if(dflag[x][y+1]==0) n0++; - if(dflag[x][y+1]==1) n1++; - if(dflag[x][y+1]==2) n2++; -} - -if(n1!=0 ) -dbuf[0][x+y*TILEX]=dbuf[1][x+y*TILEX]=dbuf[2][x+y*TILEX]=0x10; - - -}}} - -} - -void cp_floor_64(){ -int xx,yy,c; -for(xx=0;xx<64;xx++) -for(yy=0;yy<64;yy++) -for(c=0;c<3;c++) -dbuf[c][ ADR64(xx,yy) ]=fbuf[c][ ADR64(xx,yy)]; -} - -void cp_floor_32(){ -int xx,yy,c; -for(xx=0;xx<32;xx++) -for(yy=0;yy<32;yy++) -for(c=0;c<3;c++) -dbuf[c][ ADR64(32+xx-yy,32+(xx+yy)/2) ]=fbuf[c][ ADR32(xx,yy)]; -} - - -void cp_monst_32(){ -int xx,yy,c,dd[3],ad; -char dflag[32][32]; -int xmin,xmax,ymin,ymax; -int ox=0; -int oy=0; - -if(corpse==1 ){ - xmin=ymin=31; - xmax=ymax=0; - for(xx=0;xx<32;xx++){ - for(yy=0;yy<32;yy++){ - ad=ADR32(xx,yy); - for(c=0;c<3;c++)dd[c]=tbuf[c][ad]; - if( (dd[0]==0x47)&&(dd[1]==0x6c)&& (dd[2]==0x6c))continue; - if( (dd[0]==0)&&(dd[1]==0)&& (dd[2]==0))continue; - if(xx<xmin)xmin=xx; - if(xx>xmax)xmax=xx; - if(yy<ymin)ymin=yy; - if(yy>ymax)ymax=yy; - }}/*xy**/ - ox=(xmax+xmin)/2-16; - oy=(ymax+ymin)/2-16; -} - -if(slant==1){ - for(xx=0;xx<32;xx++){ - for(yy=0;yy<32;yy++){ - int x1 = xx-yy+32; - int y1= 32+(xx+yy)/2; - ad = ADR32(xx,yy); - for(c=0;c<3;c++){dd[c]=tbuf[c][ad];} - if(mesh==2){ - if( (dd[0]!=0x47)||(dd[1]!=0x6c)|| (dd[2]!=0x6c)){ - if( ((x1+y1)&1) ==0)dd[0]=dd[1]=dd[2]=0; - } - } - if(mesh==1){ - if( (((x1/2)+(y1/2))&1) ==1)dd[0]=dd[1]=dd[2]=0; - } - if( (dd[0]==0x47)&&(dd[1]==0x6c)&& (dd[2]==0x6c))continue; - for(c=0;c<3;c++) {dbuf[c][ADR64(x1,y1)]=dd[c];} - }} -return; -} - -if(dsize==1){ - for(xx=0;xx<32;xx++){ - for(yy=0;yy<32;yy++){ - int x1 = xx*2; - int y1= yy*2; - ad = ADR32(xx,yy); - for(c=0;c<3;c++){dd[c]=tbuf[c][ad];} - if(mesh==2){ - if( (dd[0]!=0x47)||(dd[1]!=0x6c)|| (dd[2]!=0x6c)){ - if( ((x1+y1)&1) ==0)dd[0]=dd[1]=dd[2]=0; - } - } - if(mesh==1){ - if( (((x1/2)+(y1/2))&1) ==1)dd[0]=dd[1]=dd[2]=0; - } - if( (dd[0]==0x47)&&(dd[1]==0x6c)&& (dd[2]==0x6c))continue; - for(c=0;c<3;c++) - { - dbuf[c][ADR64(x1,y1)]=dd[c]; - dbuf[c][ADR64(x1+1,y1)]=dd[c]; - dbuf[c][ADR64(x1,y1+1)]=dd[c]; - dbuf[c][ADR64(x1+1,y1+1)]=dd[c]; - } - }} -return; -} - - -for(xx=0;xx<32;xx++){ -for(yy=0;yy<32;yy++){ -dflag[xx][yy]=0; -ad=ADR32(xx,yy); - -if(corpse==1){ - int x1=xx+ox; - int y1=(yy+oy)*2-16; - int cy=18; - if(xx<4 || xx>=28)cy+=2;else - if(xx<12 || xx>=20) cy+=1; - - if(yy>=cy-1 && yy<=cy+0)continue; - x1 += (y1-16)/4; - if(y1>=cy){y1-=2;x1-=3;}else {y1 +=2;x1+=3;} - if(x1<0 || x1>=32 || y1<0 || y1>=32)continue; - ad=ADR32(x1,y1); -} - -/*** normal***/ -for(c=0;c<3;c++){dd[c]=tbuf[c][ad];} -if(mesh==2){ -if( (dd[0]!=0x47)||(dd[1]!=0x6c)|| (dd[2]!=0x6c)){ -if( ((xx+yy)&1) ==0)dd[0]=dd[1]=dd[2]=0; -} -} -if(mesh==1){ -if( (((xx/2)+(yy/2))&1) ==1)dd[0]=dd[1]=dd[2]=0; -} - -if( (dd[0]==0x47)&&(dd[1]==0x6c)&& (dd[2]==0x6c))continue; -if( (corpse==1) &&(dd[0]==0)&&(dd[1]==0)&& (dd[2]==0))continue; - -for(c=0;c<3;c++) {dbuf[c][ADR64(sx32+xx,sy32+yy)]=dd[c];} - dflag[xx][yy]=1; -}} - - -#if 1 -if(corpse==1){ -for(xx=0;xx<32;xx++){ -int cy=18; -if(xx<4 || xx>=28)cy+=2;else -if(xx<12 || xx>=20) cy+=1; -if(dflag[xx][cy-2]==1 && dflag[xx][cy+1]==1 ){ -for(yy=cy-1;yy<=cy-0;yy++){ dbuf[0][ADR64(16+xx,32+yy)]=32; -dbuf[1][ADR64(16+xx,32+yy)]=0;dbuf[2][ADR64(16+xx,32+yy)]=0; -dflag[xx][yy]=1; -}} -} - -/** shade**/ -for(xx=1;xx<32;xx++){ -for(yy=1;yy<32;yy++){ -if(dflag[xx][yy]==0 && dflag[xx-1][yy-1]==1){ -dbuf[0][ADR64(xx,yy)]=0; -dbuf[1][ADR64(xx,yy)]=0; -dbuf[2][ADR64(xx,yy)]=0; -} -}} - -for(xx=3;xx<32;xx++){ -for(yy=3;yy<32;yy++){ -if(dflag[xx][yy]==0 && dflag[xx-1][yy-1]==0 - && dflag[xx-2][yy-2]==1 && dflag[xx-3][yy-3]==1){ -dbuf[0][ADR64(xx,yy)]=0; -dbuf[1][ADR64(xx,yy)]=0; -dbuf[2][ADR64(xx,yy)]=0; -} -}} - -} -#endif -} - -void cp_monst_64(){ -int xx,yy,c,dd[3],ad; -for(xx=0;xx<64;xx++){ -for(yy=0;yy<64;yy++){ - ad=ADR64(xx,yy); - /*** normal***/ - for(c=0;c<3;c++){dd[c]=tbuf[c][ad];} - if(mesh==2) - { - if( (dd[0]!=0x47)||(dd[1]!=0x6c)|| (dd[2]!=0x6c)) - if( ((xx+yy)&1) ==0)dd[0]=dd[1]=dd[2]=0; - } - - if(mesh==1) - if( (((xx/2)+(yy/2))&1) ==1)dd[0]=dd[1]=dd[2]=0; - - if( (dd[0]==0x47)&&(dd[1]==0x6c)&& (dd[2]==0x6c))continue; - - for(c=0;c<3;c++) {dbuf[c][ADR64(xx,yy)]=dd[c];} -}} -} - - -void cp_monst_4864(){ -int xx,yy,c,dd[3],ad; -for(xx=0;xx<48;xx++){ -for(yy=0;yy<64;yy++){ - ad= xx+yy*48; - /*** normal***/ - for(c=0;c<3;c++){dd[c]=tbuf[c][ad];} - if(mesh==2) - { - if( (dd[0]!=0x47)||(dd[1]!=0x6c)|| (dd[2]!=0x6c)) - if( ((xx+yy)&1) ==0)dd[0]=dd[1]=dd[2]=0; - } - - if(mesh==1) - if( (((xx/2)+(yy/2))&1) ==1)dd[0]=dd[1]=dd[2]=0; - - if( (dd[0]==0x47)&&(dd[1]==0x6c)&& (dd[2]==0x6c))continue; - - for(c=0;c<3;c++) {dbuf[c][8+xx+yy*64]=dd[c];} -}} -} - -void bflush(){ -int xx,yy,c; -if(rim==1) make_rim(); - - fprintf(mfp,"<area shape=\"rect\" coords=\"%d,%d,%d,%d\" href=%s>\n", - bx*WID,by*WID,bx*WID+WID-1,by*WID+WID-1, - realname); - -for(xx=0;xx<64;xx++){ -for(yy=0;yy<64;yy++){ -for(c=0;c<3;c++){ -obuf[c][WOADR(bx,by,xx,yy)]= dbuf[c][ADR64(xx,yy)]; -}}} -} - - -void copy_wall(int wall_ix, int xofs, int yofs){ -int xx,yy,c; -unsigned char dd[3]; - for(xx=0;xx<64;xx++){ - for(yy=0;yy<64;yy++){ - int x=xx-xofs-16; - int y=yy-yofs-8; - int ad = x+y*32; - if(x<0 || y<0 || x>=32 || y>=48) continue; - for(c=0;c<3;c++){dd[c]=wallbuf[wall_ix][c][ad];} - if( (dd[0]==0x47)&&(dd[1]==0x6c)&& (dd[2]==0x6c))continue; - for(c=0;c<3;c++) {dbuf[c][ADR64(xx,yy)]=dd[c];} - }} -} - -void copy_wall_vert(int wall_ix, int xofs, int yofs){ -int xx,yy,c,ymax; -unsigned char dd[3]; - for(xx=0;xx<64;xx++){ - for(yy=0;yy<64;yy++){ - int x=xx-xofs-16; - int y=yy-yofs-8; - int ad = x+y*32; - if(x<0 || y<0 || x>=32 || y>=48) continue; - - ymax= 8+x/2; - if(ymax> 8+(31-x)/2) ymax=8+(31-x)/2; - if(y<=ymax) continue; - - for(c=0;c<3;c++){dd[c]=wallbuf[wall_ix][c][ad];} - if( (dd[0]==0x47)&&(dd[1]==0x6c)&& (dd[2]==0x6c))continue; - - //Mesh -// if( ((x/2+y/2)&1) == 0) dd[0]=dd[1]=dd[2]=0; - - for(c=0;c<3;c++) {dbuf[c][ADR64(xx,yy)]=dd[c];} - }} -} - -void expand_wall(){ -//unsigned char wallbuf[4][3][32*48]; -int xx,yy,c,ix; -exp_wall=1; -for(ix=0;ix<4;ix++){ -for(xx=0;xx<32;xx++){ -for(yy=0;yy<48;yy++){ -wallbuf[ix][0][xx+yy*32]=0x47; -wallbuf[ix][1][xx+yy*32]=0x6c; -wallbuf[ix][2][xx+yy*32]=0x6c; -}}} - -//decompose wall bmp -for(xx=0;xx<32;xx++){ - int ymax= 8+xx/2; - if(ymax> 8+(31-xx)/2) ymax=8+(31-xx)/2; - for(yy=0;yy<ymax;yy++){ - ix=0; - if(2*yy+xx >=32)ix +=1; - if(2*yy-xx >=0 )ix +=2; - for(c=0;c<3;c++)wallbuf[ix][c][xx+yy*32]=tbuf[c][xx+yy*32]; - } - - for(yy=ymax;yy<48;yy++){ - if(xx<8) ix=2;else if(xx<24) ix=3; else ix=1; - for(c=0;c<3;c++)wallbuf[ix][c][xx+yy*32]=tbuf[c][xx+yy*32]; - } -}//xx - -/* - 0 -1 1 2 2 - 3 4 5 - 6 7 8 9 - A B C -4 D E 8 - F -*/ - -for(ix=0;ix<16;ix++){ - clr_dbuf(); - if(f_wx==32)cp_floor_32(); else cp_floor_64(); - - if((ix&3)==3) copy_wall(3,0,-16); - - if(ix&1) copy_wall(1,-16,-8); - if(ix&2) copy_wall(2,16,-8); - - if(ix&1) copy_wall(3,-16,-8); - copy_wall(0, 0,0); - if(ix&2) copy_wall(3,16,-8); - - if((ix&5)==5) {copy_wall(1,-32,0);copy_wall_vert(2,-16,0);} - copy_wall(2,0,0); - copy_wall(1,0,0); - if((ix&10)==10) {copy_wall(2,32,0);copy_wall_vert(1,16,0);} - - if(ix&4) {copy_wall(0,-16,8);copy_wall_vert(3,-16,0);} - copy_wall(3,0,0); - if(ix&8) {copy_wall(0,16,8);copy_wall_vert(3,16,0);} - - if(ix&4) {copy_wall(1,-16,8);copy_wall_vert(2,0,8);} - if(ix&8) {copy_wall(2,16,8); copy_wall_vert(1,0,8);} - if((ix&12)==12) {copy_wall(0,0,16);copy_wall_vert(3,0,8);} - - bflush(); - - bx++;if(bx==xx0){bx=0;by++;} - }/*ix*/ -}
- -
-static void copy_wall2_h1(int ix, int xofs, int yofs){ -int xx,yy,c,ad; -
-unsigned char dd[3]; - for(xx=0;xx<64;xx++){ - for(yy=0;yy<64;yy++){ - int x=xx-xofs; - int y=yy-yofs;; - ad = x+64+y*128; - if (x<0 || y<0 || x>63 || y>63)continue;
- if(2*y>=x+32) continue;
- if(2*y>=95-x) continue;
- if((ix%3)==0) if (2*y>=47-x)continue;
- if((ix%3)==1) if ((2*y<47-x) || (2*y>=79-x))continue;
- if((ix%3)==2) if(2*y<79-x)continue;
-
- if((ix/3)==0) if(2*y>=x-16)continue;
- if((ix/3)==1) if((2*y<x-16) || (2*y>=x+16))continue;
- if((ix/3)==2) if(2*y<x+16) continue;
-
- for(c=0;c<3;c++){dd[c]=tbuf[c][ad];} - if( (dd[0]==0x47)&&(dd[1]==0x6c)&& (dd[2]==0x6c))continue; - - for(c=0;c<3;c++) {dbuf[c][ADR64(xx,yy)]=dd[c];} - }} -} -
-void copy_wall2_h2(int ix, int xofs, int yofs){ -int xx,yy,c,ad; -
-unsigned char dd[3]; - for(xx=0;xx<64;xx++){ - for(yy=0;yy<64;yy++){ - int x=xx-xofs; - int y=yy-yofs;; - ad = x+y*128; - if (x<0 || y<0 || x>63 || y>63)continue;
- if(2*y>=x+32) continue;
- if(2*y>=95-x) continue;
-
- if ((ix%2)==0)if (2*y>=63-x)continue;
- if((ix%2)==1) if (2*y<63-x)continue;
-
- if((ix/2)==0)if(2*y>=x)continue;
- if((ix/2)==1)if(2*y<x)continue;
-
-
- for(c=0;c<3;c++){dd[c]=tbuf[c][ad];} - if( (dd[0]==0x47)&&(dd[1]==0x6c)&& (dd[2]==0x6c))continue; - - for(c=0;c<3;c++) {dbuf[c][ADR64(xx,yy)]=dd[c];} - }} -}
-
-
-void copy_wall_v2(int ix, int kind, int xofs, int yofs){ -int xx,yy,c,ymax,ad; -unsigned char dd[3]; - for(xx=0;xx<64;xx++){ - for(yy=0;yy<64;yy++){ - int x=xx-xofs; - int y=yy-yofs; - ad = x+kind*64+y*128; - if(x<0 || y<0 || x>=64 || y>=64) continue; - - ymax= 16+x/2; - if(x>=32) ymax=16+(63-x)/2; - if(y<ymax) continue; - if(y>ymax+32)continue;
-
- if(ix==0) if(x>=8)continue;
- if(ix==1) if(x<8 || x>=24)continue;
- if(ix==2) if(x<24 || x>=40)continue;
- if(ix==3) if(x<40 || x>=56)continue;
- if(ix==4) if(x<56)continue;
- - for(c=0;c<3;c++){dd[c]=tbuf[c][ad];} - if( (dd[0]==0x47)&&(dd[1]==0x6c)&& (dd[2]==0x6c))continue; - for(c=0;c<3;c++) {dbuf[c][ADR64(xx,yy)]=dd[c];} - }} -}
-void expand_wall2(){
-//void copy_wall2_h(int kind, int ix, int xofs, int yofs) -int ix; -exp_wall=1; -
-for(ix=0;ix<16;ix++){ - clr_dbuf(); - if(f_wx==32)cp_floor_32(); else cp_floor_64(); -
-if((ix&3)==0) copy_wall2_h1(0, 0, 8);
-if((ix&3)==1) copy_wall2_h1(1, -16, 0);
-if((ix&3)==2) copy_wall2_h1(3, 16, 0);
-if((ix&3)==3) copy_wall2_h2(0, 0, 0);
-
-if((ix&5)==0) copy_wall2_h1(6, 16, 0);
-if((ix&5)==1) copy_wall2_h1(7, 0, -8);
-if((ix&5)==4) copy_wall2_h1(3, 0, 8);
-if((ix&5)==5) copy_wall2_h2(2, 0, 0);
-
-
-if((ix&10)==0) copy_wall2_h1(2, -16, 0);
-if((ix&10)==2) copy_wall2_h1(5, 0, -8);
-if((ix&10)==8) copy_wall2_h1(1, 0, 8);
-if((ix&10)==10) copy_wall2_h2(1, 0, 0);
-
-if((ix&12)==0) copy_wall2_h1(8, 0, -8);
-if((ix&12)==4) copy_wall2_h1(5, -16, 0);
-if((ix&12)==8) copy_wall2_h1(7, 16, 0);
-if((ix&12)==12) copy_wall2_h2(3, 0, 0); -
-
-if((ix&5)==5) copy_wall_v2(0, 0, 0, 0);
-if((ix&10)==10) copy_wall_v2(4, 0, 0, 0);
-
-if((ix&4)!=0) copy_wall_v2(1, 0, 0, 0);
-if((ix&8)!=0) copy_wall_v2(3, 0, 0, 0);
-
-
-if((ix&12)==12) copy_wall_v2(2, 0, 0, 0);
-
-if((ix&5)==1) copy_wall_v2(1, 1, 0, -8);
-if((ix&12)==8) copy_wall_v2(1, 1, 16, 0);
-
-if((ix&10)==2) copy_wall_v2(3, 1, 0, -8);
-if((ix&12)==4) copy_wall_v2(3, 1, -16, 0);
-
-if((ix&5)==0) copy_wall_v2(0, 1, 16, 0);
-if((ix&10)==0) copy_wall_v2(4, 1, -16, 0);
-if((ix&12)==0) copy_wall_v2(2, 1, 0, -8);
-
- bflush(); - bx++;if(bx==xx0){bx=0;by++;} -} -} - - -void load_monst(fnam) char *fnam;{ -int wx, wy; - if( load_it(fnam, &wx, &wy)) - { - printf("no file %s.bmp\n",fnam); - getchar(); - exit(1); - } - exp_wall=0; - if(wx==128 && wy==64) expand_wall2(); - else if(wx==48 && wy==64) cp_monst_4864(); - else if(wx==32 && wy==48) expand_wall(); - else if(wx==32)cp_monst_32(); - else if(wx==64)cp_monst_64(); - bflush(); -} - -void process_config(char *fname) -{ - int i,j; - char tmp[100],st[1024]; - char *nuke; - FILE *fp=fopen(fname,"r"); - if(fp==NULL){ - printf("Error no config file %s\nHit return",fname); - getchar(); - exit(1); - } - - -while(1){ - fgets(tmp,99,fp); - if(feof(fp))break; - i=0;while(i<99 && tmp[i]>=32)i++; - tmp[i]=0; - -fprintf(stderr,"[%s]\n",tmp); - - if(getname(tmp,"back",st)) - { - /*** Set Background BMP (format "%back bmpname") ***/ - if(strncmp(st,"none",4)==0) - { - /** clear **/ - for(i=0;i<32*32;i++){fbuf[0][i]=0x47;fbuf[1][i]=fbuf[2][i]=0x6c;} - f_wx=64; - } - else - { - int wy; - load_it(st, &f_wx, &wy); - for(i=0;i<f_wx*wy;i++)for(j=0;j<3;j++)fbuf[j][i]=tbuf[j][i]; - } - continue; - } - - if (getname(tmp,"include",st)){ - char fn2[200]; - sprintf(fn2,"%s%s",cpath, st); - if(strcmp(fname,fn2)!=0) process_config(fn2); - continue; - } - - if (getval(tmp,"slant",&slant)) continue; - if (getval(tmp,"dsize",&dsize)) continue; - if (getval(tmp,"mesh",&mesh)) continue; - if (getval(tmp,"rim",&rim)) continue; - if (getval(tmp,"corpose",&corpse)) continue; - if (getname(tmp,"ctg",ctgname)) continue; - if (getname(tmp,"subst",subsname)) continue; - if (getname(tmp,"sdir",sdir)) continue; - if (getname(tmp,"name", outname)) continue; - if (getval(tmp,"width",&xx0)) continue; - if (getval(tmp,"sx",&sx32)) continue; - if (getval(tmp,"sy",&sy32)) continue; - if (tmp[0]=='#' || tmp[0]<32){ - if(tmp[0]<32) {} - else fprintf(sfp,"\n//%s\n",tmp); - continue; - } - - /*** normal bitmap ***/ - - clr_dbuf(); - if(f_wx==32)cp_floor_32(); else cp_floor_64(); - i=0;while(i<99 && tmp[i]>32)i++; - tmp[i]=0; strcpy(st, &tmp[i+1]); - load_monst(tmp); - if(!strstr(st,"IGNORE_COMMENT")) - { - nuke=strstr(st,"/*");if(nuke)*nuke=0; - if(exp_wall) - fprintf(sfp,"TILE_%s, (TILE_TOTAL+%d),\n",st,bx+by*xx0-16); - else - fprintf(sfp,"TILE_%s, (TILE_TOTAL+%d),\n",st,bx+by*xx0); - } - - if(!exp_wall){bx++;if(bx==xx0){bx=0;by++;}} - -}/* while */ - - fclose(fp); -} - -int main(argc,argv) -int argc; -char *argv[]; -{ - - int i; - char fn[100]; - - fixalloc(tbuf,256*256); - - slant=corpse=mesh=dsize=0; - - bx=by=0; - process_cpath(argv[0]); - fixalloc(obuf, LX*64*(YY)*64); - - - xx0=XX; - ctgname[0]=0; - subsname[0]=0; - sdir[0]=0; - - stdpal(); - - strcpy(outname,"tile"); - -sprintf(fn,"%stiledef-qv.h",cpath); -sfp=fopen(fn,"w"); -if(sfp==NULL){ - printf("Error could not open %s\nHit return",fn); - getchar(); - exit(1); -} - -mfp=fopen("map.htm","w"); -fprintf(mfp,"<HTML><head>\n"); -fprintf(mfp,"<base href=\"http://cvs.sourceforge.net/viewcvs.py/rltiles/rltiles/ -\">\n"); -fprintf(mfp,"</head><body><MAP NAME=\"nhmap\">\n"); - - -fprintf(sfp,"/* Automatically generated by tile generator. */\n"); -fprintf(sfp,"const int tile_qv_pair_table[] ={\n"); - - printf("%s\ncpath=%s\n",argv[0],cpath); - if(argc==1) - sprintf(fn,"%sdc-qv.txt",cpath); - else strcpy(fn,argv[1]); - process_config(fn); - - -fprintf(sfp,"-1, -1 };\n"); - -fprintf(sfp,"\n#define TILE_TOTAL_EX %d\n",bx+by*xx0); -fprintf(sfp,"#define TILE_PER_ROW_EX %d\n",xx0); - - -fclose(sfp); -i=by*64;if(bx!=0)i+=64; - -sprintf(fn,"%s%s.bmp",cpath,outname); -bmwrite(fn,xx0*64,i,obuf); - -fprintf(mfp,"<IMG SRC=http://rltiles.sf.net/%s.png USEMAP=\"#nhmap\" >\n</body>\ -n</html>\n", outname); -fclose(mfp); - -return 0; -} diff --git a/crawl-ref/source/rltiles/tool/palette.h b/crawl-ref/source/rltiles/tool/palette.h deleted file mode 100644 index c94b0d66f7..0000000000 --- a/crawl-ref/source/rltiles/tool/palette.h +++ /dev/null @@ -1,355 +0,0 @@ -unsigned char pbuf[1024]= { -/* index B G R unused */ - -// Red -/* 0x00 */ 0x00, 0x00, 0xff, 0x00, -/* 0x01 */ 0x00, 0x00, 0xe0, 0x00, -/* 0x02 */ 0x00, 0x00, 0xc0, 0x00, -/* 0x03 */ 0x00, 0x00, 0xa0, 0x00, -/* 0x04 */ 0x00, 0x00, 0x80, 0x00, -/* 0x05 */ 0x00, 0x00, 0x60, 0x00, -/* 0x06 */ 0x00, 0x00, 0x40, 0x00, -/* 0x07 */ 0x00, 0x00, 0x30, 0x00, -// Dark red -/* 0x08 */ 0x00, 0x00, 0x20, 0x00, -/* 0x09 */ 0x00, 0x00, 0x18, 0x00, -/* 0x0a */ 0x00, 0x00, 0x10, 0x00, -//Pale Red -/* 0x0b */ 0x40, 0x40, 0x80, 0x00, -/* 0x0c */ 0x50, 0x50, 0xa0, 0x00, -/* 0x0d */ 0x60, 0x60, 0xc0, 0x00, -/* 0x0e */ 0x70, 0x70, 0xe0, 0x00, -/* 0x0f */ 0x80, 0x80, 0xff, 0x00, - -//Red-Orange -/* 0x10 */ 0x00, 0x40, 0xff, 0x00, -/* 0x11 */ 0x00, 0x38, 0xe0, 0x00, -/* 0x12 */ 0x00, 0x30, 0xc0, 0x00, -/* 0x13 */ 0x00, 0x28, 0xa0, 0x00, -/* 0x14 */ 0x00, 0x20, 0x80, 0x00, -/* 0x15 */ 0x00, 0x18, 0x60, 0x00, -/* 0x16 */ 0x00, 0x10, 0x40, 0x00, -/* 0x17 */ 0x00, 0x0c, 0x30, 0x00, -//Dark Yellow -/* 0x18 */ 0x00, 0x20, 0x20, 0x00, -/* 0x19 */ 0x00, 0x18, 0x18, 0x00, -/* 0x1a */ 0x00, 0x10, 0x10, 0x00, -//Pale Yellow -/* 0x1b */ 0x40, 0x80, 0x80, 0x00, -/* 0x1c */ 0x50, 0xa0, 0xa0, 0x00, -/* 0x1d */ 0x60, 0xc0, 0xc0, 0x00, -/* 0x1e */ 0x70, 0xe0, 0xe0, 0x00, -/* 0x1f */ 0x80, 0xff, 0xff, 0x00, - -//Orange -/* 0x20 */ 0x00, 0x80, 0xff, 0x00, -/* 0x21 */ 0x00, 0x70, 0xe0, 0x00, -/* 0x22 */ 0x00, 0x60, 0xc0, 0x00, -/* 0x23 */ 0x00, 0x50, 0xa0, 0x00, -/* 0x24 */ 0x00, 0x40, 0x80, 0x00, -/* 0x25 */ 0x00, 0x30, 0x60, 0x00, -/* 0x26 */ 0x00, 0x20, 0x40, 0x00, -/* 0x27 */ 0x00, 0x18, 0x30, 0x00, -//Dark Green -/* 0x28 */ 0x00, 0x20, 0x00, 0x00, -/* 0x29 */ 0x00, 0x18, 0x00, 0x00, -/* 0x2a */ 0x00, 0x10, 0x00, 0x00, -//Pale Green -/* 0x2b */ 0x40, 0x80, 0x40, 0x00, -/* 0x2c */ 0x50, 0xa0, 0x50, 0x00, -/* 0x2d */ 0x60, 0xc0, 0x60, 0x00, -/* 0x2e */ 0x70, 0xe0, 0x70, 0x00, -/* 0x2f */ 0x80, 0xff, 0x80, 0x00, - -//Yellow Orange -/* 0x30 */ 0x00, 0xc0, 0xff, 0x00, -/* 0x31 */ 0x00, 0xa8, 0xe0, 0x00, -/* 0x32 */ 0x00, 0x90, 0xc0, 0x00, -/* 0x33 */ 0x00, 0x78, 0xa0, 0x00, -/* 0x34 */ 0x00, 0x60, 0x80, 0x00, -/* 0x35 */ 0x00, 0x48, 0x60, 0x00, -/* 0x36 */ 0x00, 0x30, 0x40, 0x00, -/* 0x37 */ 0x00, 0x24, 0x30, 0x00, -//Dark cyan -/* 0x38 */ 0x20, 0x20, 0x00, 0x00, -/* 0x39 */ 0x18, 0x18, 0x00, 0x00, -/* 0x3a */ 0x10, 0x10, 0x00, 0x00, -//Pale cyan -/* 0x3b */ 0x80, 0x80, 0x40, 0x00, -/* 0x3c */ 0xa0, 0xa0, 0x50, 0x00, -/* 0x3d */ 0xc0, 0xc0, 0x60, 0x00, -/* 0x3e */ 0xe0, 0xe0, 0x70, 0x00, -/* 0x3f */ 0xff, 0xff, 0x80, 0x00, -//Yellow -/* 0x40 */ 0x00, 0xff, 0xff, 0x00, -/* 0x41 */ 0x00, 0xe0, 0xe0, 0x00, -/* 0x42 */ 0x00, 0xc0, 0xc0, 0x00, -/* 0x43 */ 0x00, 0xa0, 0xa0, 0x00, -/* 0x44 */ 0x00, 0x80, 0x80, 0x00, -/* 0x45 */ 0x00, 0x60, 0x60, 0x00, -/* 0x46 */ 0x00, 0x40, 0x40, 0x00, -/* 0x47 */ 0x00, 0x30, 0x30, 0x00, -//Dark Blue -/* 0x48 */ 0x20, 0x00, 0x00, 0x00, -/* 0x49 */ 0x18, 0x00, 0x00, 0x00, -/* 0x4a */ 0x10, 0x00, 0x00, 0x00, -//Pale Blue -/* 0x4b */ 0x80, 0x40, 0x40, 0x00, -/* 0x4c */ 0xa0, 0x50, 0x50, 0x00, -/* 0x4d */ 0xc0, 0x60, 0x60, 0x00, -/* 0x4e */ 0xe0, 0x70, 0x70, 0x00, -/* 0x4f */ 0xff, 0x80, 0x80, 0x00, - -//Yellow Green -/* 0x50 */ 0x00, 0xff, 0x80, 0x00, -/* 0x51 */ 0x00, 0xe0, 0x70, 0x00, -/* 0x52 */ 0x00, 0xc0, 0x60, 0x00, -/* 0x53 */ 0x00, 0xa0, 0x50, 0x00, -/* 0x54 */ 0x00, 0x80, 0x40, 0x00, -/* 0x55 */ 0x00, 0x60, 0x30, 0x00, -/* 0x56 */ 0x00, 0x40, 0x20, 0x00, -/* 0x57 */ 0x00, 0x30, 0x18, 0x00, -//Dark magenta -/* 0x58 */ 0x20, 0x00, 0x20, 0x00, -/* 0x59 */ 0x18, 0x00, 0x18, 0x00, -/* 0x5a */ 0x10, 0x00, 0x10, 0x00, -//Pale Magenta -/* 0x5b */ 0x80, 0x40, 0x80, 0x00, -/* 0x5c */ 0xa0, 0x50, 0xa0, 0x00, -/* 0x5d */ 0xc0, 0x60, 0xc0, 0x00, -/* 0x5e */ 0xe0, 0x70, 0xe0, 0x00, -/* 0x5f */ 0xff, 0x80, 0xff, 0x00, - -//Green -/* 0x60 */ 0x00, 0xff, 0x00, 0x00, -/* 0x61 */ 0x00, 0xe0, 0x00, 0x00, -/* 0x62 */ 0x00, 0xc0, 0x00, 0x00, -/* 0x63 */ 0x00, 0xa0, 0x00, 0x00, -/* 0x64 */ 0x00, 0x80, 0x00, 0x00, -/* 0x65 */ 0x00, 0x60, 0x00, 0x00, -/* 0x66 */ 0x00, 0x40, 0x00, 0x00, -/* 0x67 */ 0x00, 0x30, 0x00, 0x00, -// Dark Pale Red -/* 0x68 */ 0x30, 0x30, 0x60, 0x00, -/* 0x69 */ 0x20, 0x20, 0x40, 0x00, -/* 0x6a */ 0x18, 0x18, 0x30, 0x00, -//Very Pale Red -/* 0x6b */ 0x60, 0x60, 0x80, 0x00, -/* 0x6c */ 0x78, 0x78, 0xa0, 0x00, -/* 0x6d */ 0x90, 0x90, 0xc0, 0x00, -/* 0x6e */ 0xa8, 0xa8, 0xe0, 0x00, -/* 0x6f */ 0xc0, 0xc0, 0xff, 0x00, - -// BlueGreen -/* 0x70 */ 0x80, 0xff, 0x00, 0x00, -/* 0x71 */ 0x70, 0xe0, 0x00, 0x00, -/* 0x72 */ 0x60, 0xc0, 0x00, 0x00, -/* 0x73 */ 0x50, 0xa0, 0x00, 0x00, -/* 0x74 */ 0x40, 0x80, 0x00, 0x00, -/* 0x75 */ 0x30, 0x60, 0x00, 0x00, -/* 0x76 */ 0x20, 0x40, 0x00, 0x00, -/* 0x77 */ 0x18, 0x30, 0x00, 0x00, -// Dark Pale Yellow -/* 0x78 */ 0x30, 0x60, 0x60, 0x00, -/* 0x79 */ 0x20, 0x40, 0x40, 0x00, -/* 0x7a */ 0x18, 0x30, 0x30, 0x00, -//Very Pale Yellow -/* 0x7b */ 0x60, 0x80, 0x80, 0x00, -/* 0x7c */ 0x78, 0xa0, 0xa0, 0x00, -/* 0x7d */ 0x90, 0xc0, 0xc0, 0x00, -/* 0x7e */ 0xa8, 0xe0, 0xe0, 0x00, -/* 0x7f */ 0xc0, 0xff, 0xff, 0x00, - -// Cyan -/* 0x80 */ 0xff, 0xff, 0x00, 0x00, -/* 0x81 */ 0xe0, 0xe0, 0x00, 0x00, -/* 0x82 */ 0xc0, 0xc0, 0x00, 0x00, -/* 0x83 */ 0xa0, 0xa0, 0x00, 0x00, -/* 0x84 */ 0x80, 0x80, 0x00, 0x00, -/* 0x85 */ 0x60, 0x60, 0x00, 0x00, -/* 0x86 */ 0x40, 0x40, 0x00, 0x00, -/* 0x87 */ 0x30, 0x30, 0x00, 0x00, -//Dark Pale Green -/* 0x88 */ 0x30, 0x60, 0x30, 0x00, -/* 0x89 */ 0x20, 0x40, 0x20, 0x00, -/* 0x8a */ 0x18, 0x30, 0x18, 0x00, -//Very Plae Green -/* 0x8b */ 0x60, 0x80, 0x60, 0x00, -/* 0x8c */ 0x78, 0xa0, 0x78, 0x00, -/* 0x8d */ 0x90, 0xc0, 0x90, 0x00, -/* 0x8e */ 0xa8, 0xe0, 0xa8, 0x00, -/* 0x8f */ 0xc0, 0xff, 0xc0, 0x00, - -//Sky Blue -/* 0x90 */ 0xff, 0x80, 0x00, 0x00, -/* 0x91 */ 0xe0, 0x70, 0x00, 0x00, -/* 0x92 */ 0xc0, 0x60, 0x00, 0x00, -/* 0x93 */ 0xa0, 0x50, 0x00, 0x00, -/* 0x94 */ 0x80, 0x40, 0x00, 0x00, -/* 0x95 */ 0x60, 0x30, 0x00, 0x00, -/* 0x96 */ 0x40, 0x20, 0x00, 0x00, -/* 0x97 */ 0x30, 0x18, 0x00, 0x00, -//Dark Plae Cyan -/* 0x98 */ 0x60, 0x60, 0x30, 0x00, -/* 0x99 */ 0x40, 0x40, 0x20, 0x00, -/* 0x9a */ 0x30, 0x30, 0x18, 0x00, -//Very Pale Cyan -/* 0x9b */ 0x80, 0x80, 0x60, 0x00, -/* 0x9c */ 0xa0, 0xa0, 0x78, 0x00, -/* 0x9d */ 0xc0, 0xc0, 0x90, 0x00, -/* 0x9e */ 0xe0, 0xe0, 0xa8, 0x00, -/* 0x9f */ 0xff, 0xff, 0xc0, 0x00, - -// Blue -/* 0xa0 */ 0xff, 0x00, 0x00, 0x00, -/* 0xa1 */ 0xe0, 0x00, 0x00, 0x00, -/* 0xa2 */ 0xc0, 0x00, 0x00, 0x00, -/* 0xa3 */ 0xa0, 0x00, 0x00, 0x00, -/* 0xa4 */ 0x80, 0x00, 0x00, 0x00, -/* 0xa5 */ 0x60, 0x00, 0x00, 0x00, -/* 0xa6 */ 0x40, 0x00, 0x00, 0x00, -/* 0xa7 */ 0x30, 0x00, 0x00, 0x00, -//Dark Pale Blue -/* 0xa8 */ 0x60, 0x30, 0x30, 0x00, -/* 0xa9 */ 0x40, 0x20, 0x20, 0x00, -/* 0xaa */ 0x30, 0x18, 0x18, 0x00, -//Very Pale Blue -/* 0xab */ 0x80, 0x60, 0x60, 0x00, -/* 0xac */ 0xa0, 0x78, 0x78, 0x00, -/* 0xad */ 0xc0, 0x90, 0x90, 0x00, -/* 0xae */ 0xe0, 0xa8, 0xa8, 0x00, -/* 0xaf */ 0xff, 0xc0, 0xc0, 0x00, - -// BlueMagenta -/* 0xb0 */ 0xff, 0x00, 0x80, 0x00, -/* 0xb1 */ 0xe0, 0x00, 0x70, 0x00, -/* 0xb2 */ 0xc0, 0x00, 0x60, 0x00, -/* 0xb3 */ 0xa0, 0x00, 0x50, 0x00, -/* 0xb4 */ 0x80, 0x00, 0x40, 0x00, -/* 0xb5 */ 0x60, 0x00, 0x30, 0x00, -/* 0xb6 */ 0x40, 0x00, 0x20, 0x00, -/* 0xb7 */ 0x30, 0x00, 0x18, 0x00, -//Dark Pale Magenta -/* 0xb8 */ 0x60, 0x30, 0x60, 0x00, -/* 0xb9 */ 0x40, 0x20, 0x40, 0x00, -/* 0xba */ 0x30, 0x18, 0x30, 0x00, -//Very Pale Magenta -/* 0xbb */ 0x80, 0x60, 0x80, 0x00, -/* 0xbc */ 0xa0, 0x78, 0xa0, 0x00, -/* 0xbd */ 0xc0, 0x90, 0xc0, 0x00, -/* 0xbe */ 0xe0, 0xa8, 0xe0, 0x00, -/* 0xbf */ 0xff, 0xc0, 0xff, 0x00, - -//Magenta -/* 0xc0 */ 0xff, 0x00, 0xff, 0x00, -/* 0xc1 */ 0xe0, 0x00, 0xe0, 0x00, -/* 0xc2 */ 0xc0, 0x00, 0xc0, 0x00, -/* 0xc3 */ 0xa0, 0x00, 0xa0, 0x00, -/* 0xc4 */ 0x80, 0x00, 0x80, 0x00, -/* 0xc5 */ 0x60, 0x00, 0x60, 0x00, -/* 0xc6 */ 0x40, 0x00, 0x40, 0x00, -/* 0xc7 */ 0x30, 0x00, 0x30, 0x00, - -//Grayscale -/* 0xc8 */ 0xff, 0xff, 0xff, 0x00, -/* 0xc9 */ 0xe0, 0xe0, 0xe0, 0x00, -/* 0xca */ 0xc0, 0xc0, 0xc0, 0x00, -/* 0xcb */ 0xa0, 0xa0, 0xa0, 0x00, -/* 0xcc */ 0x80, 0x80, 0x80, 0x00, -/* 0xcd */ 0x60, 0x60, 0x60, 0x00, -/* 0xce */ 0x40, 0x40, 0x40, 0x00, -/* 0xcf */ 0x20, 0x20, 0x20, 0x00, - -//Red Magenta -/* 0xd0 */ 0x80, 0x00, 0xff, 0x00, -/* 0xd1 */ 0x70, 0x00, 0xe0, 0x00, -/* 0xd2 */ 0x60, 0x00, 0xc0, 0x00, -/* 0xd3 */ 0x50, 0x00, 0xa0, 0x00, -/* 0xd4 */ 0x40, 0x00, 0x80, 0x00, -/* 0xd5 */ 0x30, 0x00, 0x60, 0x00, -/* 0xd6 */ 0x20, 0x00, 0x40, 0x00, -/* 0xd7 */ 0x18, 0x00, 0x30, 0x00, - -//Grayscale -/* 0xd8 */ 0xf0, 0xf0, 0xf0, 0x00, -/* 0xd9 */ 0xd0, 0xd0, 0xd0, 0x00, -/* 0xda */ 0xb0, 0xb0, 0xb0, 0x00, -/* 0xdb */ 0x90, 0x90, 0x90, 0x00, -/* 0xdc */ 0x70, 0x70, 0x70, 0x00, -/* 0xdd */ 0x50, 0x50, 0x50, 0x00, -/* 0xde */ 0x30, 0x30, 0x30, 0x00, -/* 0xdf */ 0x10, 0x10, 0x10, 0x00, - -// Flesh -/* 0xe0 */ 0x48, 0x5a, 0x7f, 0x00, -/* 0xe1 */ 0x5e, 0x76, 0xa5, 0x00, -/* 0xe2 */ 0x72, 0x8f, 0xca, 0x00, -/* 0xe3 */ 0x82, 0xa2, 0xe5, 0x00, -/* 0xe4 */ 0x91, 0xb6, 0xff, 0x00, -/* 0xe5 */ 0xaf, 0xd3, 0xff, 0x00, - -//Gold 12:10:4 -#if 0 - //Old Gold colors - /* 0xe6 */ 0x1f, 0x54, 0x68, 0x00, - /* 0xe7 */ 0x20, 0x70, 0x80, 0x00, - /* 0xe8 */ 0x34, 0x88, 0xaa, 0x00, - /* 0xe9 */ 0x40, 0xa0, 0xc0, 0x00, - /* 0xea */ 0x4d, 0xc4, 0xf2, 0x00, - /* 0xeb */ 0x60, 0xe0, 0xf8, 0x00, - /* 0xec */ 0x99, 0xfc, 0xfc, 0x00, -#endif - -// New gold colors r:g:b = 6:5:2 -/* 0xe6 */ 0x20, 0x50, 0x60, 0x00, -/* 0xe7 */ 0x2a, 0x6a, 0x80, 0x00, -/* 0xe8 */ 0x35, 0x85, 0xa0, 0x00, -/* 0xe9 */ 0x40, 0xa0, 0xc0, 0x00, -/* 0xea */ 0x4a, 0xba, 0xe0, 0x00, -/* 0xeb */ 0x60, 0xe0, 0xf8, 0x00, -/* 0xec */ 0xa0, 0xff, 0xff, 0x00, - -// Zombie - -#if 0 - // Old zombie skin colors - /* 0xed */ 0x58, 0x69, 0x75, 0x00, -> 607080 - /* 0xee */ 0x6e, 0x87, 0x91, 0x00, -> 788ca0 - /* 0xef */ 0x81, 0x9a, 0xab, 0x00, -> 90a8c0 -#endif - - // New zombie skin colors r:g:b=8:7:6 -/* 0xed */ 0x48, 0x54, 0x60, 0x00, -/* 0xee */ 0x60, 0x70, 0x80, 0x00, -/* 0xef */ 0x78, 0x8c, 0xa0, 0x00, -/* 0xf0 */ 0x90, 0xa8, 0xc0, 0x00, -/* 0xf1 */ 0xa8, 0xc4, 0xe0, 0x00, - -#if 0 - // Old Brass 14:12:10, 13:10.5:5 - /* 0xf0 */ 0xa0, 0xc0, 0xe0, 0x00, -> a8c4e0 - /* 0xf1 */ 0x50, 0xa8, 0xd0, 0x00, -> 40a0c0 -#endif - -// Unused -// (reserving 16 colors for the system seemed a reasonable idea -// when I was using 256 color X-Window display, but it seems -// an obsolete idea now. However, I should be very careful to -// introduce new colors. -/* 0xf2 */ 0x00, 0x00, 0x00, 0x00, -/* 0xf3 */ 0x00, 0x00, 0x00, 0x00, -/* 0xf4 */ 0x00, 0x00, 0x00, 0x00, -/* 0xf5 */ 0x00, 0x00, 0x00, 0x00, -/* 0xf6 */ 0x00, 0x00, 0x00, 0x00, -/* 0xf7 */ 0x00, 0x00, 0x00, 0x00, -/* 0xf8 */ 0x00, 0x00, 0x00, 0x00, -/* 0xf9 */ 0x00, 0x00, 0x00, 0x00, -/* 0xfa */ 0x00, 0x00, 0x00, 0x00, -/* 0xfb */ 0x00, 0x00, 0x00, 0x00, -/* 0xfc */ 0x00, 0x00, 0x00, 0x00, -/* 0xfd */ 0x00, 0x00, 0x00, 0x00, -/* 0xfe */ 0x00, 0x00, 0x00, 0x00, - -//Transparent color -/* 0xff */ 0x6c, 0x6c, 0x47, 0x00 -}; diff --git a/crawl-ref/source/rltiles/tool/shade.c b/crawl-ref/source/rltiles/tool/shade.c deleted file mode 100644 index 3e7d7f715b..0000000000 --- a/crawl-ref/source/rltiles/tool/shade.c +++ /dev/null @@ -1,254 +0,0 @@ -#include "bm.h" - -int myrand() -{ - static int seed=12345; - seed *= 65539; - return(seed&0x7fffffff); -} - -int same_hue(int r, int g, int b, int r0, int g0, int b0) -{ - if (r==255)r=256; - if (g==255)g=256; - if (b==255)b=256; - - if(r0*g == g0*r && g0*b == b0*g && b0*r == r0*b) return 1; - return 0; -} - -void convert_hue(unsigned char *r, unsigned char *g, unsigned char *b, - int r0, int g0, int b0, int modif) -{ - int rr,gg,bb; - int max0 = r0; - int max = *r; - if(max<*g) max=*g; - if(max<*b) max=*b; - if(max==255) max=256; - - if(max0<g0) max0=g0; - if(max0<b0) max0=b0; - - if (max <=32) modif /= 4; - else - if (max <=64) modif /= 2; - - rr = ( (max+modif) * r0 )/ max0; - gg = ( (max+modif) * g0 )/ max0; - bb = ( (max+modif) * b0 )/ max0; - - if(rr>255) rr=255; - else if(rr<0) rr=0; - if(gg>255) gg=255; - else if(gg<0) gg=0; - if(bb>255) bb=255; - else if(bb<0) bb=0; - - *r=rr; *g=gg; *b=bb; -} - - -int main(int argc, char **argv){ - -unsigned char *ibuf[3]; -int x,y; -int i; -char fn[100],st[1024]; -char *flag; -unsigned char *nbuf[3]; -int ncol[3],ccol[10][3],nccol,ccol2[10][3], modif[10]; -FILE *ifp; -int level,l; -int xx,yy,c,f; -float prob,amp; -int thresh; - - stdpal(); - process_cpath(argv[0]); - -if(argc!=1) - strcpy(fn, argv[1]); -else - sprintf(fn,"%sshade.txt",cpath); - -fprintf(stderr,"FILE=[%s]\n",fn); - -ifp=fopen(fn,"r"); -myfget(st,ifp); -sprintf(fn,"%s%s.bmp",cpath,st); -fprintf(stderr,"Orig file=[%s]\n",fn); -ibuf[0]=ibuf[1]=ibuf[2]=NULL; -bmread(fn,&x,&y,ibuf ); -fprintf(stderr,"loaded x=%d y=%d\n",x,y); -flag=malloc(x*y); -for(i=0;i<3;i++)nbuf[i]=malloc(x*y); - -while(1){ -myfget(st,ifp); -if(feof(ifp))break; -level=atoi(st); - -//random perturbation amplitude/prob -myfget(st,ifp); -prob=atof(st); -thresh=(int)(0x7fffffff*prob); -if(prob==-1.0)thresh=-1;//ringmail -if(prob==-2.0)thresh=-2;//chainmail - -myfget(st,ifp); -amp=atof(st); -printf("P=%f Amp=%f\n",prob,amp); - -// Normal col -myfget(st,ifp); -fprintf(stderr,"Normal [%s]\n",st); -sscanf(st,"%d %d %d",&ncol[0],&ncol[1],&ncol[2]); - -//Control col -myfget(st,ifp); -if(feof(ifp))break; -nccol=atoi(st); - -for(i=0;i<nccol;i++){ - myfget(st,ifp); - if(feof(ifp))exit(1); - modif[i]=0; - l=sscanf(st,"%d %d %d %d %d %d %d",&ccol[i][0],&ccol[i][1],&ccol[i][2] - ,&ccol2[i][0],&ccol2[i][1],&ccol2[i][2], &modif[i]); - if(l==3){ - ccol2[i][0]=ccol[i][0]; - ccol2[i][1]=ccol[i][1]; - ccol2[i][2]=ccol[i][2]; - } -}//ncol - -fprintf(stderr,"Level=%d ccol=%d\n",level,nccol); -fprintf(stderr,"Normal=%d %d %d\n",ncol[0],ncol[1],ncol[2]); - -for(xx=0;xx<x;xx++){ -for(yy=0;yy<y;yy++){ -int ad=xx+yy*x; -flag[ad]=0; -if( same_hue(ibuf[0][ad], ibuf[1][ad], ibuf[2][ad], - ncol[0], ncol[1], ncol[2])) flag[ad]=1; -else -{ -for(i=0;i<nccol;i++) - if(same_hue(ibuf[0][ad], ibuf[1][ad], ibuf[2][ad], - ccol[i][0], ccol[i][1], ccol[i][2])) flag[ad]=2+i; -} -}} -/***** convert ******/ -for(xx=0;xx<x;xx++){ -for(yy=0;yy<y;yy++){ - int ad=xx+yy*x; - int f=flag[ad]; - if(f>1) convert_hue(&ibuf[0][ad],&ibuf[1][ad],&ibuf[2][ad], - ccol2[f-2][0],ccol2[f-2][1],ccol2[f-2][2], modif[f-2]); -} -} - -/********************************/ -for(l=0;l<level;l++){ -for(yy=0;yy<y;yy++){ -for(xx=0;xx<x;xx++){ -int ad=xx+yy*x; -int sum,n; -if(flag[ad]!=1){ -for(c=0;c<3;c++)nbuf[c][ad]=ibuf[c][ad]; -continue; -} -for(c=0;c<3;c++){ -n=0;sum=0; // (int)(ibuf[c][ad])*1; -if(xx>0 && flag[ad-1]!=0){n++;sum+=ibuf[c][ad-1];} -if(xx<x-1 && flag[ad+1]!=0){n++;sum+=ibuf[c][ad+1];} -if(yy>0 && flag[ad-x]!=0){n++;sum+=ibuf[c][ad-x];} -if(yy<y-1 && flag[ad+x]!=0){n++;sum+=ibuf[c][ad+x];} -if(n!=0){ -sum +=n/2; -sum/=n; -nbuf[c][ad]=sum; -}else nbuf[c][ad]=ibuf[c][ad]; -}/*c*/ -ad++; -}}/*xy**/ - -for(xx=0;xx<x;xx++){ -for(yy=0;yy<y;yy++){ -int ad=xx+yy*x; -for(c=0;c<3;c++){ -ibuf[c][ad]=nbuf[c][ad];}}} -}/*level*/ - -/**random **/ -if(thresh==-1){//ringmail - -for(xx=0;xx<x;xx++){ -for(yy=0;yy<y;yy++){ - int ad=xx+yy*x; - if(flag[ad]!=0){ - int dd=0; - int flag=(xx+2000-3*yy)%5; - if(flag==0)dd=+64; - if(flag==3||flag==4)dd=-32; - for(c=0;c<3;c++){ - int d=(int)ibuf[c][ad]; - d=(int)(d+dd); - if(d>255)d=255; - if(d<0)d=0; - ibuf[c][ad]=(unsigned char)d; - } -} -}}//XY -}//ringmail -if(thresh==-2){//chainmail - -for(xx=0;xx<x;xx++){ -for(yy=0;yy<y;yy++){ - int ad=xx+yy*x; -if(flag[ad]!=0){ - int dd=0; - int flag=(xx+2000-2*yy)%4; - if(flag==0)dd=+64; - if(flag==1)dd=+32; - if(flag==3)dd=-32; - for(c=0;c<3;c++){ - int d=(int)ibuf[c][ad]; - d=(int)(d+dd); - if(d>255)d=255; - if(d<0)d=0; - ibuf[c][ad]=(unsigned char)d; - } -} -}}//XY -}//chainmail - -if(thresh>0){ -for(xx=0;xx<x;xx++){ -for(yy=0;yy<y;yy++){ - int ad=xx+yy*x; -if(myrand()<thresh && flag[ad]!=0){ - - double r=1.0-amp+2*amp*(myrand()*1.0/0x7fffffff); - if(r<0.0)r=0.0; - for(c=0;c<3;c++){ - int d=(int)ibuf[c][ad]; - d=(int)(d*r); - if(d>255)d=255; - if(d<0)d=0; - ibuf[c][ad]=(unsigned char)d; - } -} -}}//XY -}//if - -}/*while*/ - -sprintf(fn,"%sb.bmp",cpath); -bmwrite_dither(fn,x,y,ibuf ,flag); - - -fclose(ifp); - -} diff --git a/crawl-ref/source/rltiles/tool/tile.cc b/crawl-ref/source/rltiles/tool/tile.cc new file mode 100644 index 0000000000..b96a7d5301 --- /dev/null +++ b/crawl-ref/source/rltiles/tool/tile.cc @@ -0,0 +1,511 @@ +#include "tile.h" + +#include <assert.h> +#include <SDL.h> +#include <SDL_image.h> + +tile::tile() : m_width(0), m_height(0), m_pixels(NULL), m_shrink(true) +{ +} + +tile::tile(const tile &img, const char *enumname, const char *parts_ctg) : + m_width(0), m_height(0), m_pixels(NULL) +{ + copy(img); + + if (enumname) + m_enumname = enumname; + if (parts_ctg) + m_parts_ctg = parts_ctg; +} + +tile::~tile() +{ + unload(); +} + +void tile::unload() +{ + delete[] m_pixels; + m_pixels = NULL; + m_width = m_height = 0; +} + +bool tile::valid() const +{ + return m_pixels && m_width && m_height; +} + +const std::string &tile::filename() +{ + return m_filename; +} + +const std::string &tile::enumname() +{ + return m_enumname; +} + +const std::string &tile::parts_ctg() +{ + return m_parts_ctg; +} + +int tile::width() +{ + return m_width; +} + +int tile::height() +{ + return m_height; +} + +bool tile::shrink() +{ + return m_shrink; +} + +void tile::set_shrink(bool shrink) +{ + m_shrink = shrink; +} + +void tile::resize(int new_width, int new_height) +{ + delete[] m_pixels; + m_width = new_width; + m_height = new_height; + + m_pixels = NULL; + + if (!m_width || !m_height) + return; + + m_pixels = new tile_colour[m_width * m_height]; +} + +void tile::add_rim(const tile_colour &rim) +{ + bool *flags = new bool[m_width * m_height]; + for (unsigned int y = 0; y < m_height; y++) + { + for (unsigned int x = 0; x < m_width; x++) + { + flags[x + y * m_width] = ((get_pixel(x, y).a > 0) && + (get_pixel(x,y) != rim)); + } + } + + for (unsigned int y = 0; y < m_height; y++) + { + for (unsigned int x = 0; x < m_width; x++) + { + if (flags[x + y * m_width]) + continue; + + if (x > 0 && flags[(x-1) + y * m_width] || + y > 0 && flags[x + (y-1) * m_width] || + x < m_width - 1 && flags[(x+1) + y * m_width] || + y < m_height - 1 && flags[x + (y+1) * m_width]) + { + get_pixel(x,y) = rim; + } + } + } + + delete[] flags; +} + +void tile::corpsify() +{ + // TODO enne - different wound colours for different bloods + // TODO enne - use blood variations + tile_colour red_blood(0, 0, 32, 255); + + int separate_x = 3; + int separate_y = 4; + + // force all corpses into 32x32, even if bigger. + corpsify(32, 32, separate_x, separate_y, red_blood); +} + +static int corpse_cut_height(int x, int width, int height) +{ + unsigned int cy = height / 2 + 2; + + // Make the cut bend upwards in the middle + int limit1 = width / 8; + int limit2 = width / 3; + + if (x < limit1 || x >= width - limit1) + cy += 2; + else if (x < limit2 || x >= width - limit2) + cy += 1; + + return cy; +} + +// Adapted from rltiles' cp_monst_32 and then ruthlessly rewritten for clarity. +// rltiles can be found at http://rltiles.sourceforge.net +void tile::corpsify(int corpse_width, int corpse_height, + int cut_separate, int cut_height, const tile_colour &wound) +{ + int wound_height = std::min(2, cut_height); + + // Make a temporary backup + tile orig(*this); + + resize(corpse_width, corpse_height); + fill(tile_colour::transparent); + + // Track which pixels have been written to with valid image data + bool *flags = new bool[corpse_width * corpse_height]; + memset(flags, 0, corpse_width * corpse_height * sizeof(bool)); + +#define flags(x,y) (flags[((x) + (y) * corpse_width)]) + + // Find extents + int xmin, ymin, bbwidth, bbheight; + orig.get_bounding_box(xmin, ymin, bbwidth, bbheight); + + int xmax = xmin + bbwidth - 1; + int ymax = ymin + bbheight - 1; + int centerx = (xmax + xmin) / 2; + int centery = (ymax + ymin) / 2; + + // Use maximum scale in case aspect ratios differ. + float width_scale = (float)m_width / (float)corpse_width; + float height_scale = (float)m_height / (float)corpse_height; + float image_scale = std::max(width_scale, height_scale); + + // Amount to scale height by to fake a projection. + float height_proj = 2.0f; + + for (int y = 0; y < corpse_height; y++) + { + for (int x = 0; x < corpse_width; x++) + { + int cy = corpse_cut_height(x, corpse_width, corpse_height); + if (y > cy - cut_height && y <= cy) + continue; + + // map new center to old center, including image scale + int x1 = ((x - m_width/2) * image_scale) + centerx; + int y1 = ((y - m_height/2) * height_proj * image_scale) + centery; + + if (y >= cy) + { + x1 -= cut_separate; + y1 -= cut_height / 2; + } + else + { + x1 += cut_separate; + y1 += cut_height / 2 + cut_height % 2; + } + + if (x1 < 0 || x1 >= m_width || y1 < 0 || y1 >= m_height) + continue; + + tile_colour &mapped = orig.get_pixel(x1, y1); + + // ignore rims, shadows, and transparent pixels. + if (mapped == tile_colour::black || + mapped == tile_colour::transparent) + { + continue; + } + + get_pixel(x,y) = mapped; + flags(x, y) = true; + } + } + + // Add some colour to the cut wound + for (int x = 0; x < corpse_width; x++) + { + unsigned int cy = corpse_cut_height(x, corpse_width, corpse_height); + if (flags(x, cy-cut_height)) + { + unsigned int start = cy - cut_height + 1; + for (int y = start; y < start + wound_height; y++) + { + get_pixel(x, y) = wound; + } + } + } + + // Add diagonal shadowing... + for (int y = 1; y < corpse_height; y++) + { + for (int x = 1; x < corpse_width; x++) + { + if (!flags(x, y) && flags(x-1, y-1) && + get_pixel(x,y) == tile_colour::transparent) + { + get_pixel(x, y) = tile_colour::black; + } + } + } + + // Extend shadow... + for (int y = 3; y < corpse_height; y++) + { + for (int x = 3; x < corpse_width; x++) + { + // Extend shadow if there are two real pixels along + // the diagonal. Also, don't extend if the top or + // left pixel is not filled in. This prevents lone + // shadow pixels only connected via diagonals. + + if (get_pixel(x-1,y-1) == tile_colour::black && + flags(x-2, y-2) && flags(x-3, y-3) && + get_pixel(x-1, y) == tile_colour::black && + get_pixel(x, y-1) == tile_colour::black) + { + get_pixel(x, y) = tile_colour::black; + } + } + } + + delete[] flags; +} + +void tile::copy(const tile &img) +{ + unload(); + + m_width = img.m_width; + m_height = img.m_height; + m_filename = img.m_filename; + m_pixels = new tile_colour[m_width * m_height]; + m_shrink = img.m_shrink; + memcpy(m_pixels, img.m_pixels, m_width * m_height * sizeof(tile_colour)); + + // enum explicitly not copied + m_enumname.clear(); +} + +bool tile::compose(const tile &img) +{ + if (!valid()) + { + fprintf(stderr, "Error: can't compose onto an unloaded image.\n"); + return false; + } + + if (!img.valid()) + { + fprintf(stderr, "Error: can't compose from an unloaded image.\n"); + return false; + } + + if (m_width != img.m_width || m_height != img.m_height) + { + fprintf(stderr, "Error: can't compose with mismatched dimensions. " + "(%d, %d) onto (%d, %d)\n", img.m_width, img.m_height, m_width, + m_height); + return false; + } + + for (unsigned int i = 0; i < m_width * m_height; i += 1) + { + const tile_colour *src = &img.m_pixels[i]; + tile_colour *dest = &m_pixels[i]; + + dest->r = (src->r * src->a + dest->r * (255 - src->a)) / 255; + dest->g = (src->g * src->a + dest->g * (255 - src->a)) / 255; + dest->b = (src->b * src->a + dest->b * (255 - src->a)) / 255; + dest->a = (src->a * 255 + dest->a * (255 - src->a)) / 255; + } + + return true; +} + +bool tile::load(const std::string &filename) +{ + if (m_pixels) + { + unload(); + } + + SDL_Surface *img = IMG_Load(filename.c_str()); + if (!img) + { + return false; + } + + m_width = img->w; + m_height = img->h; + + // blow out all formats to non-palettised RGBA. + m_pixels = new tile_colour[m_width * m_height]; + unsigned int bpp = img->format->BytesPerPixel; + if (bpp == 1) + { + SDL_Palette *pal = img->format->palette; + assert(pal); + assert(pal->colors); + + int src = 0; + int dest = 0; + for (int y = 0; y < img->h; y++) + { + for (int x = 0; x < img->w; x++) + { + int index = ((unsigned char*)img->pixels)[src++]; + m_pixels[dest].r = pal->colors[index].r; + m_pixels[dest].g = pal->colors[index].g; + m_pixels[dest].b = pal->colors[index].b; + m_pixels[dest].a = 255; + dest++; + } + } + } + else + { + SDL_LockSurface(img); + + int dest = 0; + for (int y = 0; y < img->h; y++) + { + for (int x = 0; x < img->w; x++) + { + unsigned char *p = (unsigned char*)img->pixels + + y*img->pitch + x*bpp; + + unsigned int pixel; + switch (img->format->BytesPerPixel) + { + case 1: + pixel = *p; + break; + case 2: + pixel = *(unsigned short*)p; + break; + case 3: + if (SDL_BYTEORDER == SDL_BIG_ENDIAN) + pixel = p[0] << 16 | p[1] << 8 | p[2]; + else + pixel = p[0] | p[1] << 8 | p[2] << 16; + break; + case 4: + pixel = *(unsigned int*)p; + break; + default: + assert(!"Invalid bpp"); + SDL_UnlockSurface(img); + SDL_FreeSurface(img); + return false; + } + + SDL_GetRGBA(pixel, img->format, &m_pixels[dest].r, + &m_pixels[dest].g, &m_pixels[dest].b, + &m_pixels[dest].a); + dest++; + } + } + + SDL_UnlockSurface(img); + } + + SDL_FreeSurface(img); + + replace_colour(tile_colour::background, tile_colour::transparent); + + return true; +} + +void tile::fill(const tile_colour &fill) +{ + for (int y = 0; y < m_height; y++) + { + for (int x = 0; x < m_width; x++) + { + get_pixel(x, y) = fill; + } + } +} + +void tile::replace_colour(tile_colour &find, tile_colour &replace) +{ + for (int y = 0; y < m_height; y++) + { + for (int x = 0; x < m_width; x++) + { + tile_colour &p = get_pixel(x, y); + if (p == find) + p = replace; + } + } +} + +tile_colour &tile::get_pixel(unsigned int x, unsigned int y) +{ + assert(m_pixels && x < m_width && y < m_height); + return m_pixels[x + y * m_width]; +} + +void tile::get_bounding_box(int &x0, int &y0, int &width, int &height) +{ + if (!valid()) + { + x0 = y0 = width = height = 0; + return; + } + + x0 = y0 = 0; + unsigned int x1 = m_width - 1; + unsigned int y1 = m_height - 1; + while (x0 <= x1) + { + bool found = false; + for (unsigned int y = y0; !found && y < y1; y++) + { + found |= (get_pixel(x0, y).a > 0); + } + if (found) + break; + x0++; + } + + while (x0 <= x1) + { + bool found = false; + for (unsigned int y = y0; !found && y < y1; y++) + { + found |= (get_pixel(x1, y).a > 0); + } + if (found) + break; + x1--; + } + + while (y0 <= y1) + { + bool found = false; + for (unsigned int x = x0; !found && x < x1; x++) + { + found |= (get_pixel(x, y0).a > 0); + } + if (found) + break; + y0++; + } + + while (y0 <= y1) + { + bool found = false; + for (unsigned int x = x0; !found && x < x1; x++) + { + found |= (get_pixel(x, y1).a > 0); + } + if (found) + break; + y1--; + } + + width = x1 - x0 + 1; + height = y1 - y0 + 1; +} diff --git a/crawl-ref/source/rltiles/tool/tile.h b/crawl-ref/source/rltiles/tool/tile.h new file mode 100644 index 0000000000..c3c7652691 --- /dev/null +++ b/crawl-ref/source/rltiles/tool/tile.h @@ -0,0 +1,55 @@ +#ifndef TILE_H +#define TILE_H + +#include "tile_colour.h" +#include <string> + +class tile +{ +public: + tile(); + tile(const tile &img, const char *enumname = NULL, + const char *parts_ctg = NULL); + virtual ~tile(); + + bool load(const std::string &filename); + bool load(const std::string &filename, const std::string &enumname); + + void unload(); + bool valid() const; + + void resize(int new_width, int new_height); + + void add_rim(const tile_colour &rim); + void corpsify(); + void corpsify(int corpse_width, int corpse_height, + int cut_separate, int cut_height, const tile_colour &wound); + + void copy(const tile &img); + bool compose(const tile &img); + + void replace_colour(tile_colour &find, tile_colour &replace); + void fill(const tile_colour &fill); + + const std::string &filename(); + const std::string &enumname(); + const std::string &parts_ctg(); + int width(); + int height(); + bool shrink(); + void set_shrink(bool shrink); + + void get_bounding_box(int &x0, int &y0, int &width, int &height); + + tile_colour &get_pixel(unsigned int x, unsigned int y); +protected: + int m_width; + int m_height; + std::string m_filename; + std::string m_enumname; + std::string m_parts_ctg; + tile_colour *m_pixels; + bool m_shrink; +}; + +#endif diff --git a/crawl-ref/source/rltiles/tool/tile_colour.cc b/crawl-ref/source/rltiles/tool/tile_colour.cc new file mode 100644 index 0000000000..88cb69c75f --- /dev/null +++ b/crawl-ref/source/rltiles/tool/tile_colour.cc @@ -0,0 +1,25 @@ +#include "tile_colour.h" + +tile_colour tile_colour::background(71, 108, 108, 255); +tile_colour tile_colour::transparent(0, 0, 0, 0); +tile_colour tile_colour::black(0, 0, 0, 255); + +bool tile_colour::operator==(const tile_colour &rhs) const +{ + return (r == rhs.r && g == rhs.g && b == rhs.b && a == rhs.a); +} + +bool tile_colour::operator!=(const tile_colour &rhs) const +{ + return (r != rhs.r || g != rhs.g || b != rhs.b || a != rhs.a); +} + +const tile_colour &tile_colour::operator=(const tile_colour &rhs) +{ + r = rhs.r; + g = rhs.g; + b = rhs.b; + a = rhs.a; + + return *this; +} diff --git a/crawl-ref/source/rltiles/tool/tile_colour.h b/crawl-ref/source/rltiles/tool/tile_colour.h new file mode 100644 index 0000000000..f994010bac --- /dev/null +++ b/crawl-ref/source/rltiles/tool/tile_colour.h @@ -0,0 +1,25 @@ +#ifndef TILE_COLOUR_H +#define TILE_COLOUR_H + +class tile_colour +{ +public: + tile_colour() {}; + tile_colour(unsigned char _r, unsigned char _g, unsigned char _b, + unsigned char _a) : r(_r), g(_g), b(_b), a(_a) {} + + bool operator==(const tile_colour &rhs) const; + bool operator!=(const tile_colour &rhs) const; + const tile_colour &operator=(const tile_colour &rhs); + + unsigned char r; + unsigned char g; + unsigned char b; + unsigned char a; + + static tile_colour background; + static tile_colour transparent; + static tile_colour black; +}; + +#endif diff --git a/crawl-ref/source/rltiles/tool/tile_list_processor.cc b/crawl-ref/source/rltiles/tool/tile_list_processor.cc new file mode 100644 index 0000000000..5a21e11675 --- /dev/null +++ b/crawl-ref/source/rltiles/tool/tile_list_processor.cc @@ -0,0 +1,660 @@ +#include "tile_list_processor.h" + +#include <assert.h> +#include <iostream> +#include <fstream> + +tile_list_processor::tile_list_processor() : + m_last_enum(~0), + m_rim(false), + m_corpsify(false), + m_composing(false), + m_shrink(true), + m_prefix("TILE") +{ +} + +bool tile_list_processor::load_image(tile &img, const char *filename) +{ + assert(filename); + + char temp[1024]; + + const int num_ext = 3; + const char *ext[3] = + { + ".png", + ".bmp", + "" + }; + + if (m_sdir != "") + { + for (unsigned int e = 0; e < num_ext; e++) + { + sprintf(temp, "%s/%s%s", m_sdir.c_str(), filename, ext[e]); + if (img.load(temp)) + return true; + } + } + + for (unsigned int e = 0; e < num_ext; e++) + { + sprintf(temp, "%s%s", filename, ext[e]); + if (img.load(temp)) + return true; + } + + return false; +} + +bool tile_list_processor::process_list(const char *list_file) +{ + int line = 1; + + std::ifstream input(list_file); + if (!input.is_open()) + { + fprintf(stderr, "Error: couldn't open '%s' for read.\n", list_file); + return false; + } + + const size_t bufsize = 1024; + char read_line[bufsize]; + bool success = true; + while (!input.getline(read_line, bufsize).eof()) + { + success &= process_line(read_line, list_file, line++); + } + + return success; +} + +static void eat_whitespace(char *&text) +{ + if (!text) + return; + + while (*text) + { + if (*text != ' ' && *text != '\n' && *text != '\r') + break; + text++; + } + + if (!*text) + return; + + char *idx = &text[strlen(text) - 1]; + while (*idx) + { + if (*idx != ' ' && *idx != '\n' && *idx != '\r') + break; + *idx = 0; + idx--; + } +} + +static void eat_comments(char *&text) +{ + if (!text) + return; + + char *idx = text; + while (*idx) + { + if (idx[0] == '/' && idx[1] == '*') + { + char *end = idx + 2; + bool found = false; + while (*end) + { + if (end[0] == '*' && end[1] == '/') + { + found = true; + + end += 2; + char *begin = idx; + while (*end) + { + *begin = *end; + begin++; + end++; + } + *begin = 0; + } + + end++; + } + + if (!found) + { + *idx = 0; + break; + } + } + + idx++; + } +} + +bool tile_list_processor::process_line(char *read_line, const char *list_file, + int line) +{ + eat_comments(read_line); + + const char *delim = " "; + char *arg1 = strtok(read_line, delim); + if (!arg1) + return true; + + eat_whitespace(arg1); + + if (!*arg1) + return true; + + if (arg1[0] == '#') + return true; + + char *arg2 = strtok(NULL, delim); + eat_whitespace(arg2); + + while (char *extra = strtok(NULL, delim)) + { + eat_whitespace(extra); + if (!*extra) + continue; + + fprintf(stderr, "Error (%s:%d): too many args.\n", list_file, line); + return false; + } + + if (arg1[0] == '%') + { + arg1++; + + #define CHECK_NO_ARG2 \ + if (arg2) \ + { \ + fprintf(stderr, "Error (%s:%d): " \ + "invalid arg following '%s'.\n", \ + list_file, line, arg1); \ + return false; \ + } + + #define CHECK_ARG2 \ + if (!arg2) \ + { \ + fprintf(stderr, "Error (%s:%d): " \ + "missing arg following '%s'.\n", \ + list_file, line, arg1); \ + return false; \ + } + + if (strcmp(arg1, "back") == 0) + { + CHECK_ARG2; + + if (strcmp(arg2, "none") == 0) + { + m_back.unload(); + } + else + { + if (!load_image(m_back, arg2)) + { + fprintf(stderr, "Error(%s:%d): couldn't load image " + "'%s'.\n", list_file, line, arg2); + return false; + } + } + } + else if (strcmp(arg1, "compose") == 0) + { + CHECK_ARG2; + if (!m_composing) + { + fprintf(stderr, "Error (%s:%d): not composing yet.\n", + list_file, line); + return false; + } + + if (m_compose.valid()) + { + tile img; + if (!load_image(img, arg2)) + { + fprintf(stderr, "Error(%s:%d): couldn't load image " + "'%s'.\n", list_file, line, arg2); + return false; + } + + if (m_rim) + img.add_rim(tile_colour::black); + + if (!m_compose.compose(img)) + { + fprintf(stderr, "Error (%s:%d): failed composing '%s'" + " onto compose image.\n", list_file, line, arg2); + return false; + } + } + else + { + if (!load_image(m_compose, arg2)) + { + fprintf(stderr, "Error(%s:%d): couldn't load image " + "'%s'.\n", list_file, line, arg2); + return false; + } + } + } + else if (strcmp(arg1, "corpse") == 0) + { + CHECK_ARG2; + m_corpsify = (bool)atoi(arg2); + } + else if (strcmp(arg1, "end") == 0) + { + CHECK_NO_ARG2; + + if (m_parts_ctg.empty()) + { + fprintf(stderr, "Error (%s:%d): no category to end.\n", + list_file, line); + return false; + } + + m_parts_ctg.clear(); + } + else if (strcmp(arg1, "finish") == 0) + { + if (!m_composing) + { + fprintf(stderr, "Error (%s:%d): not composing yet.\n", + list_file, line); + return false; + } + + if (m_corpsify) + m_compose.corpsify(); + else if (m_rim) + m_compose.add_rim(tile_colour::black); + + if (m_back.valid()) + { + tile img(m_back); + if (!img.compose(m_compose)) + { + fprintf(stderr, "Error (%s:%d): failed composing '%s'" + " onto back image '%s'.\n", list_file, line, + arg1, m_back.filename().c_str()); + return false; + } + add_image(img, arg2); + } + else + { + add_image(m_compose, arg2); + } + + m_compose.unload(); + m_composing = false; + } + else if (strcmp(arg1, "include") == 0) + { + CHECK_ARG2; + if (!process_list(arg2)) + { + fprintf(stderr, "Error (%s:%d): include failed.\n", + list_file, line); + return false; + } + } + else if (strcmp(arg1, "name") == 0) + { + CHECK_ARG2; + + if (m_name != "") + { + fprintf(stderr, + "Error (%s:%d): name already specified as '%s'\n", + list_file, line, m_name.c_str()); + return false; + } + + m_name = arg2; + } + else if (strcmp(arg1, "parts_ctg") == 0) + { + CHECK_ARG2; + + for (unsigned int i = 0; i < m_categories.size(); i++) + { + if (arg2 == m_categories[i]) + { + fprintf(stderr, + "Error (%s:%d): category '%s' already used.\n", + list_file, line, arg2); + return false; + } + } + + m_parts_ctg = arg2; + m_categories.push_back(m_parts_ctg); + m_ctg_counts.push_back(0); + } + else if (strcmp(arg1, "prefix") == 0) + { + CHECK_ARG2; + m_prefix = arg2; + } + else if (strcmp(arg1, "rim") == 0) + { + CHECK_ARG2; + m_rim = (bool)atoi(arg2); + } + else if (strcmp(arg1, "sdir") == 0) + { + CHECK_ARG2; + m_sdir = arg2; + } + else if (strcmp(arg1, "shrink") == 0) + { + CHECK_ARG2; + m_shrink = (bool)atoi(arg2); + } + else if (strcmp(arg1, "start") == 0) + { + CHECK_NO_ARG2; + + if (m_composing) + { + fprintf(stderr, "Error (%s:%d): already composing.\n", + list_file, line); + return false; + } + m_composing = true; + m_compose.unload(); + } + else + { + fprintf(stderr, "Error (%s:%d): unknown command '%%%s'\n", + list_file, line, arg1); + return false; + } + } + else + { + if (m_composing) + { + fprintf(stderr, "Error (%s:%d): can't load while composing.\n", + list_file, line); + return false; + } + + tile img; + + if (m_back.valid()) + { + // compose + if (!load_image(m_compose, arg1)) + { + fprintf(stderr, "Error (%s:%d): couldn't load image " + "'%s'.\n", list_file, line, arg1); + return false; + } + + if (m_corpsify) + m_compose.corpsify(); + + img.copy(m_back); + if (!img.compose(m_compose)) + { + fprintf(stderr, "Error (%s:%d): failed composing '%s'" + " onto back image '%s'.\n", list_file, line, + arg1, m_back.filename().c_str()); + return false; + } + } + else + { + if (!load_image(img, arg1)) + { + fprintf(stderr, "Error (%s:%d): couldn't load image " + "'%s'.\n", list_file, line, arg1); + return false; + } + + if (m_corpsify) + img.corpsify(); + } + + if (m_rim && !m_corpsify) + img.add_rim(tile_colour::black); + + // push tile onto tile page + add_image(img, arg2); + } + + return true; +} + +void tile_list_processor::add_image(tile &img, const char *enumname) +{ + tile *new_img = new tile(img, enumname, m_parts_ctg.c_str()); + new_img->set_shrink(m_shrink); + + m_page.m_tiles.push_back(new_img); + m_page.m_counts.push_back(1); + + if (enumname) + m_last_enum = m_page.m_counts.size() - 1; + else if (m_last_enum < m_page.m_counts.size()) + m_page.m_counts[m_last_enum]++; + + if (m_categories.size() > 0) + { + m_ctg_counts[m_categories.size()-1]++; + } +} + +bool tile_list_processor::write_data() +{ + if (m_name == "") + { + fprintf(stderr, "Error: can't write data with no %name specified.\n"); + return false; + } + + std::string lcname = m_name; + std::string ucname = m_name; + for (unsigned int i = 0; i < m_name.size(); i++) + { + lcname[i] = std::tolower(m_name[i]); + ucname[i] = std::toupper(m_name[i]); + } + std::string max = m_prefix; + max += "_"; + max += ucname; + max += "_MAX"; + + std::string ctg_max = m_prefix; + ctg_max += "_PART_MAX"; + + // write image page + { + if (!m_page.place_images()) + return false; + + char filename[1024]; + sprintf(filename, "%s.png", lcname.c_str()); + if (!m_page.write_image(filename)) + return false; + } + + int *part_min = NULL; + + // write "tiledef-%name.h" + { + char filename[1024]; + sprintf(filename, "tiledef-%s.h", lcname.c_str()); + FILE *fp = fopen(filename, "w"); + + if (!fp) + { + fprintf(stderr, "Error: couldn't open '%s' for write.\n", filename); + return false; + } + + if (m_categories.size() > 0) + { + part_min = new int[m_categories.size()]; + memset(part_min, 0, sizeof(int) * m_categories.size()); + } + + fprintf(fp, "// This file has been automatically generated.\n\n"); + fprintf(fp, "#ifndef TILEDEF_%s_H\n#define TILEDEF_%s_H\n\n", + ucname.c_str(), ucname.c_str()); + fprintf(fp, "#include \"tiledef_defines.h\"\n\n"); + + fprintf(fp, "enum tile_%s_type\n{\n", lcname.c_str()); + + for (unsigned int i = 0; i < m_page.m_tiles.size(); i++) + { + const std::string &enumname = m_page.m_tiles[i]->enumname(); + const std::string &parts_ctg = m_page.m_tiles[i]->parts_ctg(); + if (enumname.empty()) + { + fprintf(fp, " %s_%s_FILLER_%d,\n", m_prefix.c_str(), + ucname.c_str(), i); + } + else if (parts_ctg.empty()) + { + fprintf(fp, " %s_%s,\n", m_prefix.c_str(), + enumname.c_str()); + } + else + { + fprintf(fp, " %s_%s_%s,\n", m_prefix.c_str(), + parts_ctg.c_str(), enumname.c_str()); + } + + if (!parts_ctg.empty()) + { + int idx; + for (idx = 0; idx < m_categories.size(); idx++) + { + if (parts_ctg == m_categories[idx]) + break; + } + assert(idx < m_categories.size()); + if (part_min[idx] == 0) + part_min[idx] = i; + } + } + + fprintf(fp, " %s_%s_MAX\n};\n\n", m_prefix.c_str(), ucname.c_str()); + + fprintf(fp, "extern int tile_%s_count[%s];\n", + lcname.c_str(), max.c_str()); + fprintf(fp, "extern const char *tile_%s_name[%s];\n", + lcname.c_str(), max.c_str()); + fprintf(fp, "extern tile_info tile_%s_info[%s];\n", + lcname.c_str(), max.c_str()); + + if (m_categories.size() > 0) + { + fprintf(fp, "\nenum tile_%s_parts\n{\n", lcname.c_str()); + for (unsigned int i = 0; i < m_categories.size(); i++) + { + fprintf(fp, " %s_PART_%s,\n", m_prefix.c_str(), + m_categories[i].c_str()); + } + + fprintf(fp, " %s\n};\n\n", ctg_max.c_str()); + + fprintf(fp, "extern int tile_%s_part_count[%s];\n", + lcname.c_str(), ctg_max.c_str()); + fprintf(fp, "extern int tile_%s_part_start[%s];\n", + lcname.c_str(), ctg_max.c_str()); + } + + fprintf(fp, "\n#endif\n\n"); + + fclose(fp); + } + + // write "tiledef-%name.cc" + { + char filename[1024]; + sprintf(filename, "tiledef-%s.cc", lcname.c_str()); + FILE *fp = fopen(filename, "w"); + + if (!fp) + { + fprintf(stderr, "Error: couldn't open '%s' for write.\n", filename); + return false; + } + + fprintf(fp, "// This file has been automatically generated.\n\n"); + fprintf(fp, "#include \"tiledef-%s.h\"\n\n", lcname.c_str()); + + fprintf(fp, "int tile_%s_count[%s] =\n{\n", + lcname.c_str(), max.c_str()); + for (unsigned int i = 0; i < m_page.m_counts.size(); i++) + fprintf(fp, " %d,\n", m_page.m_counts[i]); + fprintf(fp, "};\n\n"); + + fprintf(fp, "const char *tile_%s_name[%s] =\n{\n", + lcname.c_str(), max.c_str()); + for (unsigned int i = 0; i < m_page.m_tiles.size(); i++) + { + const std::string &enumname = m_page.m_tiles[i]->enumname(); + if (enumname.empty()) + fprintf(fp, " \"%s_FILLER_%d\",\n", ucname.c_str(), i); + else + fprintf(fp, " \"%s\",\n", enumname.c_str()); + } + fprintf(fp, "};\n\n"); + + fprintf(fp, "tile_info tile_%s_info[%s] =\n{\n", + lcname.c_str(), max.c_str()); + for (unsigned int i = 0; i < m_page.m_offsets.size(); i+=4) + { + fprintf(fp, " tile_info(%d, %d, %d, %d, %d, %d, %d, %d),\n", + m_page.m_offsets[i+2], m_page.m_offsets[i+3], + m_page.m_offsets[i], m_page.m_offsets[i+1], + m_page.m_texcoords[i], m_page.m_texcoords[i+1], + m_page.m_texcoords[i+2], m_page.m_texcoords[i+3]); + } + fprintf(fp, "};\n\n"); + + if (m_categories.size() > 0) + { + fprintf(fp, "int tile_%s_part_count[%s] =\n{\n", + lcname.c_str(), ctg_max.c_str()); + + for (int i = 0; i < m_ctg_counts.size(); i++) + { + fprintf(fp, " %d,\n", m_ctg_counts[i]); + } + + fprintf(fp, "};\n\n"); + + fprintf(fp, "int tile_%s_part_start[%s] =\n{\n", + lcname.c_str(), ctg_max.c_str()); + + for (int i = 0; i < m_categories.size(); i++) + { + fprintf(fp, " %d,\n", part_min[i]); + } + + fprintf(fp, "};\n\n"); + } + } + + delete[] part_min; + + return true; +} diff --git a/crawl-ref/source/rltiles/tool/tile_list_processor.h b/crawl-ref/source/rltiles/tool/tile_list_processor.h new file mode 100644 index 0000000000..cb3c22da49 --- /dev/null +++ b/crawl-ref/source/rltiles/tool/tile_list_processor.h @@ -0,0 +1,40 @@ +#ifndef TILE_LIST_PROCESSOR_H +#define TILE_LIST_PROCESSOR_H + +#include "tile.h" +#include "tile_page.h" +#include <string> +#include <vector> + +class tile_list_processor +{ +public: + tile_list_processor(); + + bool process_list(const char *list_file); + bool write_data(); +protected: + bool load_image(tile &img, const char *filename); + bool process_line(char *read_line, const char *list_file, int line); + void add_image(tile &img, const char *enumname); + + std::string m_name; + + tile_page m_page; + unsigned int m_last_enum; + + // image options + bool m_rim; + bool m_corpsify; + bool m_composing; + bool m_shrink; + tile m_back; + std::string m_parts_ctg; + std::string m_sdir; + std::string m_prefix; + std::vector<std::string> m_categories; + std::vector<int> m_ctg_counts; + tile m_compose; +}; + +#endif diff --git a/crawl-ref/source/rltiles/tool/tile_page.cc b/crawl-ref/source/rltiles/tool/tile_page.cc new file mode 100644 index 0000000000..6d2aaa1883 --- /dev/null +++ b/crawl-ref/source/rltiles/tool/tile_page.cc @@ -0,0 +1,179 @@ +#include "tile_page.h" +#include "tile_colour.h" +#include "tile.h" +#include <png.h> + +static bool write_png(const char *filename, tile_colour *pixels, + int width, int height) +{ + FILE *fp = fopen(filename, "wb"); + if (!fp) + { + fprintf(stderr, "Error: Can't open file '%s' for write.\n", filename); + return false; + } + + png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, + NULL, NULL, NULL); + if (!png_ptr) + return false; + + png_infop info_ptr = png_create_info_struct(png_ptr); + if (!info_ptr) + { + png_destroy_write_struct(&png_ptr, (png_infopp)NULL); + return false; + } + + png_init_io(png_ptr, fp); + + int bit_depth = 8; + int colour_type = PNG_COLOR_TYPE_RGB_ALPHA; + int interlace_type = PNG_INTERLACE_NONE; + int compression_type = PNG_COMPRESSION_TYPE_DEFAULT; + int filter_method = PNG_FILTER_TYPE_DEFAULT; + png_set_IHDR(png_ptr, info_ptr, width, height, + bit_depth, colour_type, interlace_type, + compression_type, filter_method); + + png_bytep* row_pointers = (png_bytep*)alloca(sizeof(png_bytep) * height); + for (unsigned int y = 0; y < height; y++) + row_pointers[y] = (png_byte*)&pixels[y * width]; + + png_set_rows(png_ptr, info_ptr, row_pointers); + + int png_transforms = PNG_TRANSFORM_IDENTITY; + png_write_png(png_ptr, info_ptr, png_transforms, NULL); + png_write_end(png_ptr, info_ptr); + png_destroy_write_struct(&png_ptr, &info_ptr); + + fclose(fp); + + return true; +} + +tile_page::tile_page() : m_width(1024), m_height(0) +{ +} + +tile_page::~tile_page() +{ + for (unsigned int i = 0; i < m_tiles.size(); i++) + { + delete m_tiles[i]; + } + m_tiles.clear(); + m_counts.clear(); +} + +bool tile_page::place_images() +{ + // locate all the tiles on the page, so we can determine its size + // and the tex coords. + + m_offsets.clear(); + m_texcoords.clear(); + + int ymin, ycur, ymax; + int xmin, xcur, xmax; + ymin = ycur = ymax = xmin = xcur = xmax = 0; + + for (unsigned int i = 0; i < m_tiles.size(); i++) + { + int ofs_x, ofs_y, tilew, tileh; + if (m_tiles[i]->shrink()) + { + m_tiles[i]->get_bounding_box(ofs_x, ofs_y, tilew, tileh); + } + else + { + ofs_x = 0; + ofs_y = 0; + tilew = m_tiles[i]->width(); + tileh = m_tiles[i]->height(); + } + + m_offsets.push_back(ofs_x); + m_offsets.push_back(ofs_y); + m_offsets.push_back(m_tiles[i]->width()); + m_offsets.push_back(m_tiles[i]->height()); + + if (xcur + tilew > m_width) + { + ycur = ymin = ymax; + xcur = xmin = xmax = 0; + } + + if (tileh + ycur >= ymax) + { + if (ycur != ymin) + { + ycur = ymin; + xcur = xmax; + xmin = xmax = xcur; + } + + if (xcur + tilew > m_width) + { + ycur = ymin = ymax; + xcur = xmin = xmax = 0; + } + + if (ycur == ymin) + { + ymax = std::max(ymin + (int)tileh, ymax); + } + } + + m_height = ymax; + + m_texcoords.push_back(xcur); + m_texcoords.push_back(ycur); + m_texcoords.push_back(xcur + tilew); + m_texcoords.push_back(ycur + tileh); + + // Only add downwards, stretching out xmax as we go. + xmax = std::max(xmax, xcur + (int)tilew); + xcur = xmin; + ycur += tileh; + } + + return true; +} + +bool tile_page::write_image(const char *filename) +{ + if (m_width * m_height <= 0) + { + fprintf(stderr, "Error: failed to write image. No images placed?\n"); + return false; + } + + tile_colour *pixels = new tile_colour[m_width * m_height]; + memset(pixels, 0, m_width * m_height * sizeof(tile_colour)); + + for (unsigned int i = 0; i < m_tiles.size(); i++) + { + int sx = m_texcoords[i*4]; + int sy = m_texcoords[i*4+1]; + int ex = m_texcoords[i*4+2]; + int ey = m_texcoords[i*4+3]; + int wx = ex - sx; + int wy = ey - sy; + int ofs_x = m_offsets[i*4]; + int ofs_y = m_offsets[i*4+1]; + for (int y = 0; y < wy; y++) + { + for (int x = 0; x < wx; x++) + { + tile_colour &dest = pixels[(sx+x) + (sy+y)*m_width]; + tile_colour &src = m_tiles[i]->get_pixel(ofs_x+x, ofs_y+y); + dest = src; + } + } + } + + bool success = write_png(filename, pixels, m_width, m_height); + delete[] pixels; + return success; +} diff --git a/crawl-ref/source/rltiles/tool/tile_page.h b/crawl-ref/source/rltiles/tool/tile_page.h new file mode 100644 index 0000000000..9f13651a1d --- /dev/null +++ b/crawl-ref/source/rltiles/tool/tile_page.h @@ -0,0 +1,25 @@ +#ifndef TILE_PAGE_H +#define TILE_PAGE_H + +#include <vector> +class tile; + +class tile_page +{ +public: + tile_page(); + virtual ~tile_page(); + + bool place_images(); + bool write_image(const char *filename); + + std::vector<tile*> m_tiles; + std::vector<unsigned int> m_counts; + std::vector<int> m_texcoords; + std::vector<int> m_offsets; +protected: + int m_width; + int m_height; +}; + +#endif |